public override void Parse(ParseContext context) { switch (context.LookaheadToken.TokenType) { case TinyTokenizer.TokenType.EndLine: break; default: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } switch (context.CurrentToken.TokenType) { case TinyTokenizer.TokenType.Word: { var value = context.CurrentToken.Value; Match match; if ((match = floatRegex.Match(value)).Success) { Callback(new TinyValue(value, TinyTokenType.Float)); } else if ((match = integerRegex.Match(value)).Success) { Callback(new TinyValue(value, TinyTokenType.Integer)); } else if ((match = boolRegex.Match(value)).Success) { Callback(new TinyValue(value == TinyValue.BooleanTrue)); } else { Callback(new TinyValue(value)); } context.ConsumeToken(); context.PopParser(); } return; case TinyTokenizer.TokenType.WordQuoted: { var value = TinyUtil.UnescapeString(context.CurrentToken.Value); Callback(new TinyValue(value)); context.ConsumeToken(); context.PopParser(); } return; } throw new InvalidDataException("Unexpected token: " + context.CurrentToken); }
public override void Parse(ParseContext context) { if (CheckIndent(context)) { return; } switch (context.LookaheadToken.TokenType) { case TinyTokenizer.TokenType.ArrayIndicator: case TinyTokenizer.TokenType.Property: case TinyTokenizer.TokenType.PropertyQuoted: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } switch (context.CurrentToken.TokenType) { case TinyTokenizer.TokenType.Property: case TinyTokenizer.TokenType.PropertyQuoted: var key = context.CurrentToken.Value; if (context.CurrentToken.TokenType == TinyTokenizer.TokenType.PropertyQuoted) { key = TinyUtil.UnescapeString(key); } switch (context.LookaheadToken.TokenType) { case TinyTokenizer.TokenType.Word: case TinyTokenizer.TokenType.WordQuoted: context.PushParser(new ValueParser(r => result.Add(key, r))); break; case TinyTokenizer.TokenType.EndLine: context.PushParser(new EmptyProperyParser(r => result.Add(key, r), context.IndentLevel + 1)); break; default: throw new InvalidDataException("Unexpected token: " + context.LookaheadToken + ", after: " + context.CurrentToken); } context.ConsumeToken(); return; } throw new InvalidDataException("Unexpected token: " + context.CurrentToken); }