public Expression Parse(Parser parser, Token token) { var values = new List<KeyValuePair<string, Expression>>(); while (!parser.Match(TokenType.RightBrace)) { var identifier = parser.Take(TokenType.Identifier); Expression value; if (parser.Match(TokenType.Comma) || parser.Match(TokenType.RightBrace)) { value = new IdentifierExpression(identifier); } else { parser.Take(TokenType.Colon); value = parser.ParseExpession(); } values.Add(new KeyValuePair<string, Expression>(identifier.Contents, value)); if (!parser.Match(TokenType.Comma)) break; parser.Take(TokenType.Comma); } parser.Take(TokenType.RightBrace); return new ObjectExpression(token, values); }
public Expression Parse(Parser parser, Token token) { var values = new List<KeyValuePair<string, Expression>>(); while (!parser.Match(TokenType.RightBrace)) { string key; Expression value = null; if (parser.Match(TokenType.Identifier)) { var identifier = parser.Take(TokenType.Identifier); key = identifier.Contents; if (parser.Match(TokenType.Comma) || parser.Match(TokenType.RightBrace)) { value = new IdentifierExpression(identifier); } } else if (parser.Match(TokenType.String)) { key = parser.Take(TokenType.String).Contents; } else { var errorToken = parser.Take(); throw new MondCompilerException(errorToken, CompilerError.ExpectedButFound2, TokenType.Identifier, TokenType.String, errorToken); } if (value == null) { parser.Take(TokenType.Colon); value = parser.ParseExpression(); var function = value as FunctionExpression; if (function != null) function.DebugName = key; } values.Add(new KeyValuePair<string, Expression>(key, value)); if (!parser.Match(TokenType.Comma)) break; parser.Take(TokenType.Comma); } parser.Take(TokenType.RightBrace); return new ObjectExpression(token, values); }