public Expression Parse(Parser parser, Token token, out bool trailingSemicolon) { trailingSemicolon = true; if (parser.MatchAndTake(TokenType.LeftBrace)) { var fields = ParseObjectDestructuring(parser); parser.Take(TokenType.Assign); return(new DestructuredObjectExpression(token, fields, parser.ParseExpression(), _isReadOnly)); } if (parser.MatchAndTake(TokenType.LeftSquare)) { var indices = ParseArrayDestructuring(parser); parser.Take(TokenType.Assign); return(new DestructuredArrayExpression(token, indices, parser.ParseExpression(), _isReadOnly)); } var declarations = new List <VarExpression.Declaration>(); do { var identifier = parser.Take(TokenType.Identifier); Expression initializer = null; if (_isReadOnly || parser.Match(TokenType.Assign)) { parser.Take(TokenType.Assign); initializer = parser.ParseExpression(); } var declaration = new VarExpression.Declaration(identifier.Contents, initializer); declarations.Add(declaration); } while (parser.MatchAndTake(TokenType.Comma)); return(new VarExpression(token, declarations, _isReadOnly)); }
public Expression Parse(Parser parser, Token token, out bool trailingSemicolon) { trailingSemicolon = true; var declarations = new List <VarExpression.Declaration>(); do { var identifier = parser.Take(TokenType.Identifier); Expression initializer = null; if (parser.MatchAndTake(TokenType.Assign)) { initializer = parser.ParseExpession(); } var declaration = new VarExpression.Declaration(identifier.Contents, initializer); declarations.Add(declaration); } while (parser.MatchAndTake(TokenType.Comma)); return(new VarExpression(token, declarations, _isReadOnly)); }