Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 109853003: New analyzer snapshot. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.parser; 4 library engine.parser;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'java_core.dart'; 7 import 'java_core.dart';
8 import 'instrumentation.dart'; 8 import 'instrumentation.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'source.dart'; 10 import 'source.dart';
11 import 'scanner.dart'; 11 import 'scanner.dart';
12 import 'ast.dart'; 12 import 'ast.dart';
13 import 'utilities_dart.dart'; 13 import 'utilities_dart.dart';
14 import 'engine.dart' show AnalysisEngine; 14 import 'engine.dart' show AnalysisEngine;
15 import 'utilities_collection.dart' show TokenMap; 15 import 'utilities_collection.dart' show TokenMap;
16 16
17 /** 17 /**
18 * Instances of the class `CommentAndMetadata` implement a simple data-holder fo r a method 18 * Instances of the class `CommentAndMetadata` implement a simple data-holder fo r a method
19 * that needs to return multiple values. 19 * that needs to return multiple values.
20 * 20 *
21 * @coverage dart.engine.parser 21 * @coverage dart.engine.parser
22 */ 22 */
23 class CommentAndMetadata { 23 class CommentAndMetadata {
24 /** 24 /**
25 * The documentation comment that was parsed, or `null` if none was given. 25 * The documentation comment that was parsed, or `null` if none was given.
26 */ 26 */
27 Comment comment; 27 final Comment comment;
28 28
29 /** 29 /**
30 * The metadata that was parsed. 30 * The metadata that was parsed.
31 */ 31 */
32 List<Annotation> metadata; 32 final List<Annotation> metadata;
33 33
34 /** 34 /**
35 * Initialize a newly created holder with the given data. 35 * Initialize a newly created holder with the given data.
36 * 36 *
37 * @param comment the documentation comment that was parsed 37 * @param comment the documentation comment that was parsed
38 * @param metadata the metadata that was parsed 38 * @param metadata the metadata that was parsed
39 */ 39 */
40 CommentAndMetadata(Comment comment, List<Annotation> metadata) { 40 CommentAndMetadata(this.comment, this.metadata);
41 this.comment = comment;
42 this.metadata = metadata;
43 }
44 } 41 }
45 42
46 /** 43 /**
47 * Instances of the class `FinalConstVarOrType` implement a simple data-holder f or a method 44 * Instances of the class `FinalConstVarOrType` implement a simple data-holder f or a method
48 * that needs to return multiple values. 45 * that needs to return multiple values.
49 * 46 *
50 * @coverage dart.engine.parser 47 * @coverage dart.engine.parser
51 */ 48 */
52 class FinalConstVarOrType { 49 class FinalConstVarOrType {
53 /** 50 /**
54 * The 'final', 'const' or 'var' keyword, or `null` if none was given. 51 * The 'final', 'const' or 'var' keyword, or `null` if none was given.
55 */ 52 */
56 Token keyword; 53 final Token keyword;
57 54
58 /** 55 /**
59 * The type, of `null` if no type was specified. 56 * The type, of `null` if no type was specified.
60 */ 57 */
61 TypeName type; 58 final TypeName type;
62 59
63 /** 60 /**
64 * Initialize a newly created holder with the given data. 61 * Initialize a newly created holder with the given data.
65 * 62 *
66 * @param keyword the 'final', 'const' or 'var' keyword 63 * @param keyword the 'final', 'const' or 'var' keyword
67 * @param type the type 64 * @param type the type
68 */ 65 */
69 FinalConstVarOrType(Token keyword, TypeName type) { 66 FinalConstVarOrType(this.keyword, this.type);
70 this.keyword = keyword;
71 this.type = type;
72 }
73 } 67 }
74 68
75 /** 69 /**
76 * Instances of the class `Modifiers` implement a simple data-holder for a metho d that needs 70 * Instances of the class `Modifiers` implement a simple data-holder for a metho d that needs
77 * to return multiple values. 71 * to return multiple values.
78 * 72 *
79 * @coverage dart.engine.parser 73 * @coverage dart.engine.parser
80 */ 74 */
81 class Modifiers { 75 class Modifiers {
82 /** 76 /**
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 * A map from old tokens to new tokens used during the cloning process. 1135 * A map from old tokens to new tokens used during the cloning process.
1142 */ 1136 */
1143 TokenMap _tokenMap; 1137 TokenMap _tokenMap;
1144 1138
1145 /** 1139 /**
1146 * The error listener that will be informed of any errors that are found durin g the parse. 1140 * The error listener that will be informed of any errors that are found durin g the parse.
1147 */ 1141 */
1148 AnalysisErrorListener _errorListener; 1142 AnalysisErrorListener _errorListener;
1149 1143
1150 /** 1144 /**
1145 * The node in the AST structure that contains the revised content.
1146 */
1147 ASTNode _updatedNode;
1148
1149 /**
1151 * Initialize a newly created incremental parser to parse a portion of the con tent of the given 1150 * Initialize a newly created incremental parser to parse a portion of the con tent of the given
1152 * source. 1151 * source.
1153 * 1152 *
1154 * @param source the source being parsed 1153 * @param source the source being parsed
1155 * @param tokenMap a map from old tokens to new tokens used during the cloning process 1154 * @param tokenMap a map from old tokens to new tokens used during the cloning process
1156 * @param errorListener the error listener that will be informed of any errors that are found 1155 * @param errorListener the error listener that will be informed of any errors that are found
1157 * during the parse 1156 * during the parse
1158 */ 1157 */
1159 IncrementalParser(Source source, TokenMap tokenMap, AnalysisErrorListener erro rListener) { 1158 IncrementalParser(Source source, TokenMap tokenMap, AnalysisErrorListener erro rListener) {
1160 this._source = source; 1159 this._source = source;
1161 this._tokenMap = tokenMap; 1160 this._tokenMap = tokenMap;
1162 this._errorListener = errorListener; 1161 this._errorListener = errorListener;
1163 } 1162 }
1164 1163
1165 /** 1164 /**
1165 * Return the node in the AST structure that contains the revised content.
1166 *
1167 * @return the updated node
1168 */
1169 ASTNode get updatedNode => _updatedNode;
1170
1171 /**
1166 * Given a range of tokens that were re-scanned, re-parse the minimum number o f tokens to produce 1172 * Given a range of tokens that were re-scanned, re-parse the minimum number o f tokens to produce
1167 * a consistent AST structure. The range is represented by the first and last tokens in the range. 1173 * a consistent AST structure. The range is represented by the first and last tokens in the range.
1168 * The tokens are assumed to be contained in the same token stream. 1174 * The tokens are assumed to be contained in the same token stream.
1169 * 1175 *
1170 * @param leftToken the token in the new token stream immediately to the left of the range of 1176 * @param leftToken the token in the new token stream immediately to the left of the range of
1171 * tokens that were inserted 1177 * tokens that were inserted
1172 * @param rightToken the token in the new token stream immediately to the righ t of the range of 1178 * @param rightToken the token in the new token stream immediately to the righ t of the range of
1173 * tokens that were inserted 1179 * tokens that were inserted
1174 * @param originalStart the offset in the original source of the first charact er that was modified 1180 * @param originalStart the offset in the original source of the first charact er that was modified
1175 * @param originalEnd the offset in the original source of the last character that was modified 1181 * @param originalEnd the offset in the original source of the last character that was modified
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 return null; 1220 return null;
1215 } 1221 }
1216 if (advanceToParent) { 1222 if (advanceToParent) {
1217 newNode = null; 1223 newNode = null;
1218 oldNode = parent; 1224 oldNode = parent;
1219 originalOffset = oldNode.offset; 1225 originalOffset = oldNode.offset;
1220 parseToken = findTokenAt(parseToken, originalOffset); 1226 parseToken = findTokenAt(parseToken, originalOffset);
1221 parser.currentToken = parseToken; 1227 parser.currentToken = parseToken;
1222 } 1228 }
1223 } 1229 }
1230 _updatedNode = newNode;
1224 if (identical(oldNode, originalStructure)) { 1231 if (identical(oldNode, originalStructure)) {
1225 ResolutionCopier.copyResolutionData(oldNode, newNode); 1232 ResolutionCopier.copyResolutionData(oldNode, newNode);
1226 return newNode as ASTNode; 1233 return newNode as ASTNode;
1227 } 1234 }
1228 ResolutionCopier.copyResolutionData(oldNode, newNode); 1235 ResolutionCopier.copyResolutionData(oldNode, newNode);
1229 IncrementalASTCloner cloner = new IncrementalASTCloner(oldNode, newNode, _to kenMap); 1236 IncrementalASTCloner cloner = new IncrementalASTCloner(oldNode, newNode, _to kenMap);
1230 return originalStructure.accept(cloner) as ASTNode; 1237 return originalStructure.accept(cloner) as ASTNode;
1231 } 1238 }
1232 1239
1233 /** 1240 /**
(...skipping 14 matching lines...) Expand all
1248 * no such token. 1255 * no such token.
1249 * 1256 *
1250 * @param firstToken the token from which the search is to begin 1257 * @param firstToken the token from which the search is to begin
1251 * @param offset the offset of the token to be returned 1258 * @param offset the offset of the token to be returned
1252 * @return the token with the given offset 1259 * @return the token with the given offset
1253 */ 1260 */
1254 Token findTokenAt(Token firstToken, int offset) { 1261 Token findTokenAt(Token firstToken, int offset) {
1255 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) { 1262 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) {
1256 firstToken = firstToken.previous; 1263 firstToken = firstToken.previous;
1257 } 1264 }
1258 if (firstToken.offset == offset) { 1265 return firstToken;
1259 return firstToken;
1260 }
1261 return null;
1262 } 1266 }
1263 } 1267 }
1264 1268
1265 /** 1269 /**
1266 * Instances of the class `InsufficientContextException` represent a situation i n which an AST 1270 * Instances of the class `InsufficientContextException` represent a situation i n which an AST
1267 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node. 1271 * node cannot be re-parsed because there is not enough context to know how to r e-parse the node.
1268 * Clients can attempt to re-parse the parent of the node. 1272 * Clients can attempt to re-parse the parent of the node.
1269 */ 1273 */
1270 class InsufficientContextException extends IncrementalParseException { 1274 class InsufficientContextException extends IncrementalParseException {
1271 /** 1275 /**
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 Token period = null; 1447 Token period = null;
1444 SimpleIdentifier constructorName = null; 1448 SimpleIdentifier constructorName = null;
1445 if (matches5(TokenType.PERIOD)) { 1449 if (matches5(TokenType.PERIOD)) {
1446 period = andAdvance; 1450 period = andAdvance;
1447 constructorName = parseSimpleIdentifier(); 1451 constructorName = parseSimpleIdentifier();
1448 } 1452 }
1449 ArgumentList arguments = null; 1453 ArgumentList arguments = null;
1450 if (matches5(TokenType.OPEN_PAREN)) { 1454 if (matches5(TokenType.OPEN_PAREN)) {
1451 arguments = parseArgumentList(); 1455 arguments = parseArgumentList();
1452 } 1456 }
1453 return new Annotation.full(atSign, name, period, constructorName, arguments) ; 1457 return new Annotation(atSign, name, period, constructorName, arguments);
1454 } 1458 }
1455 1459
1456 /** 1460 /**
1457 * Parse an argument. 1461 * Parse an argument.
1458 * 1462 *
1459 * <pre> 1463 * <pre>
1460 * argument ::= 1464 * argument ::=
1461 * namedArgument 1465 * namedArgument
1462 * | expression 1466 * | expression
1463 * 1467 *
1464 * namedArgument ::= 1468 * namedArgument ::=
1465 * label expression 1469 * label expression
1466 * </pre> 1470 * </pre>
1467 * 1471 *
1468 * @return the argument that was parsed 1472 * @return the argument that was parsed
1469 */ 1473 */
1470 Expression parseArgument() { 1474 Expression parseArgument() {
1471 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 1475 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
1472 return new NamedExpression.full(parseLabel(), parseExpression2()); 1476 return new NamedExpression(parseLabel(), parseExpression2());
1473 } else { 1477 } else {
1474 return parseExpression2(); 1478 return parseExpression2();
1475 } 1479 }
1476 } 1480 }
1477 1481
1478 /** 1482 /**
1479 * Parse a list of arguments. 1483 * Parse a list of arguments.
1480 * 1484 *
1481 * <pre> 1485 * <pre>
1482 * arguments ::= 1486 * arguments ::=
1483 * '(' argumentList? ')' 1487 * '(' argumentList? ')'
1484 * 1488 *
1485 * argumentList ::= 1489 * argumentList ::=
1486 * namedArgument (',' namedArgument)* 1490 * namedArgument (',' namedArgument)*
1487 * | expressionList (',' namedArgument)* 1491 * | expressionList (',' namedArgument)*
1488 * </pre> 1492 * </pre>
1489 * 1493 *
1490 * @return the argument list that was parsed 1494 * @return the argument list that was parsed
1491 */ 1495 */
1492 ArgumentList parseArgumentList() { 1496 ArgumentList parseArgumentList() {
1493 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 1497 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
1494 List<Expression> arguments = new List<Expression>(); 1498 List<Expression> arguments = new List<Expression>();
1495 if (matches5(TokenType.CLOSE_PAREN)) { 1499 if (matches5(TokenType.CLOSE_PAREN)) {
1496 return new ArgumentList.full(leftParenthesis, arguments, andAdvance); 1500 return new ArgumentList(leftParenthesis, arguments, andAdvance);
1497 } 1501 }
1498 Expression argument = parseArgument(); 1502 Expression argument = parseArgument();
1499 arguments.add(argument); 1503 arguments.add(argument);
1500 bool foundNamedArgument = argument is NamedExpression; 1504 bool foundNamedArgument = argument is NamedExpression;
1501 bool generatedError = false; 1505 bool generatedError = false;
1502 while (optional(TokenType.COMMA)) { 1506 while (optional(TokenType.COMMA)) {
1503 argument = parseArgument(); 1507 argument = parseArgument();
1504 arguments.add(argument); 1508 arguments.add(argument);
1505 if (foundNamedArgument) { 1509 if (foundNamedArgument) {
1506 if (!generatedError && argument is! NamedExpression) { 1510 if (!generatedError && argument is! NamedExpression) {
1507 reportError10(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); 1511 reportError10(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []);
1508 generatedError = true; 1512 generatedError = true;
1509 } 1513 }
1510 } else if (argument is NamedExpression) { 1514 } else if (argument is NamedExpression) {
1511 foundNamedArgument = true; 1515 foundNamedArgument = true;
1512 } 1516 }
1513 } 1517 }
1514 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 1518 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
1515 return new ArgumentList.full(leftParenthesis, arguments, rightParenthesis); 1519 return new ArgumentList(leftParenthesis, arguments, rightParenthesis);
1516 } 1520 }
1517 1521
1518 /** 1522 /**
1519 * Parse a bitwise or expression. 1523 * Parse a bitwise or expression.
1520 * 1524 *
1521 * <pre> 1525 * <pre>
1522 * bitwiseOrExpression ::= 1526 * bitwiseOrExpression ::=
1523 * bitwiseXorExpression ('|' bitwiseXorExpression)* 1527 * bitwiseXorExpression ('|' bitwiseXorExpression)*
1524 * | 'super' ('|' bitwiseXorExpression)+ 1528 * | 'super' ('|' bitwiseXorExpression)+
1525 * </pre> 1529 * </pre>
1526 * 1530 *
1527 * @return the bitwise or expression that was parsed 1531 * @return the bitwise or expression that was parsed
1528 */ 1532 */
1529 Expression parseBitwiseOrExpression() { 1533 Expression parseBitwiseOrExpression() {
1530 Expression expression; 1534 Expression expression;
1531 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) { 1535 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) {
1532 expression = new SuperExpression.full(andAdvance); 1536 expression = new SuperExpression(andAdvance);
1533 } else { 1537 } else {
1534 expression = parseBitwiseXorExpression(); 1538 expression = parseBitwiseXorExpression();
1535 } 1539 }
1536 while (matches5(TokenType.BAR)) { 1540 while (matches5(TokenType.BAR)) {
1537 Token operator = andAdvance; 1541 Token operator = andAdvance;
1538 expression = new BinaryExpression.full(expression, operator, parseBitwiseX orExpression()); 1542 expression = new BinaryExpression(expression, operator, parseBitwiseXorExp ression());
1539 } 1543 }
1540 return expression; 1544 return expression;
1541 } 1545 }
1542 1546
1543 /** 1547 /**
1544 * Parse a block. 1548 * Parse a block.
1545 * 1549 *
1546 * <pre> 1550 * <pre>
1547 * block ::= 1551 * block ::=
1548 * '{' statements '}' 1552 * '{' statements '}'
(...skipping 10 matching lines...) Expand all
1559 if (statement != null) { 1563 if (statement != null) {
1560 statements.add(statement); 1564 statements.add(statement);
1561 } 1565 }
1562 if (identical(_currentToken, statementStart)) { 1566 if (identical(_currentToken, statementStart)) {
1563 reportError11(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1567 reportError11(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1564 advance(); 1568 advance();
1565 } 1569 }
1566 statementStart = _currentToken; 1570 statementStart = _currentToken;
1567 } 1571 }
1568 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 1572 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
1569 return new Block.full(leftBracket, statements, rightBracket); 1573 return new Block(leftBracket, statements, rightBracket);
1570 } 1574 }
1571 1575
1572 /** 1576 /**
1573 * Parse a class member. 1577 * Parse a class member.
1574 * 1578 *
1575 * <pre> 1579 * <pre>
1576 * classMemberDefinition ::= 1580 * classMemberDefinition ::=
1577 * declaration ';' 1581 * declaration ';'
1578 * | methodSignature functionBody 1582 * | methodSignature functionBody
1579 * </pre> 1583 * </pre>
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 * directive 1711 * directive
1708 * | topLevelDeclaration 1712 * | topLevelDeclaration
1709 * </pre> 1713 * </pre>
1710 * 1714 *
1711 * @return the compilation unit that was parsed 1715 * @return the compilation unit that was parsed
1712 */ 1716 */
1713 CompilationUnit parseCompilationUnit2() { 1717 CompilationUnit parseCompilationUnit2() {
1714 Token firstToken = _currentToken; 1718 Token firstToken = _currentToken;
1715 ScriptTag scriptTag = null; 1719 ScriptTag scriptTag = null;
1716 if (matches5(TokenType.SCRIPT_TAG)) { 1720 if (matches5(TokenType.SCRIPT_TAG)) {
1717 scriptTag = new ScriptTag.full(andAdvance); 1721 scriptTag = new ScriptTag(andAdvance);
1718 } 1722 }
1719 bool libraryDirectiveFound = false; 1723 bool libraryDirectiveFound = false;
1720 bool partOfDirectiveFound = false; 1724 bool partOfDirectiveFound = false;
1721 bool partDirectiveFound = false; 1725 bool partDirectiveFound = false;
1722 bool directiveFoundAfterDeclaration = false; 1726 bool directiveFoundAfterDeclaration = false;
1723 List<Directive> directives = new List<Directive>(); 1727 List<Directive> directives = new List<Directive>();
1724 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 1728 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
1725 Token memberStart = _currentToken; 1729 Token memberStart = _currentToken;
1726 while (!matches5(TokenType.EOF)) { 1730 while (!matches5(TokenType.EOF)) {
1727 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1731 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 } 1780 }
1777 if (identical(_currentToken, memberStart)) { 1781 if (identical(_currentToken, memberStart)) {
1778 reportError11(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]); 1782 reportError11(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_current Token.lexeme]);
1779 advance(); 1783 advance();
1780 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) { 1784 while (!matches5(TokenType.EOF) && !couldBeStartOfCompilationUnitMember( )) {
1781 advance(); 1785 advance();
1782 } 1786 }
1783 } 1787 }
1784 memberStart = _currentToken; 1788 memberStart = _currentToken;
1785 } 1789 }
1786 return new CompilationUnit.full(firstToken, scriptTag, directives, declarati ons, _currentToken); 1790 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken);
1787 } 1791 }
1788 1792
1789 /** 1793 /**
1790 * Parse a conditional expression. 1794 * Parse a conditional expression.
1791 * 1795 *
1792 * <pre> 1796 * <pre>
1793 * conditionalExpression ::= 1797 * conditionalExpression ::=
1794 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)? 1798 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithout Cascade)?
1795 * </pre> 1799 * </pre>
1796 * 1800 *
1797 * @return the conditional expression that was parsed 1801 * @return the conditional expression that was parsed
1798 */ 1802 */
1799 Expression parseConditionalExpression() { 1803 Expression parseConditionalExpression() {
1800 Expression condition = parseLogicalOrExpression(); 1804 Expression condition = parseLogicalOrExpression();
1801 if (!matches5(TokenType.QUESTION)) { 1805 if (!matches5(TokenType.QUESTION)) {
1802 return condition; 1806 return condition;
1803 } 1807 }
1804 Token question = andAdvance; 1808 Token question = andAdvance;
1805 Expression thenExpression = parseExpressionWithoutCascade(); 1809 Expression thenExpression = parseExpressionWithoutCascade();
1806 Token colon = expect2(TokenType.COLON); 1810 Token colon = expect2(TokenType.COLON);
1807 Expression elseExpression = parseExpressionWithoutCascade(); 1811 Expression elseExpression = parseExpressionWithoutCascade();
1808 return new ConditionalExpression.full(condition, question, thenExpression, c olon, elseExpression); 1812 return new ConditionalExpression(condition, question, thenExpression, colon, elseExpression);
1809 } 1813 }
1810 1814
1811 /** 1815 /**
1812 * Parse the name of a constructor. 1816 * Parse the name of a constructor.
1813 * 1817 *
1814 * <pre> 1818 * <pre>
1815 * constructorName: 1819 * constructorName:
1816 * type ('.' identifier)? 1820 * type ('.' identifier)?
1817 * </pre> 1821 * </pre>
1818 * 1822 *
1819 * @return the constructor name that was parsed 1823 * @return the constructor name that was parsed
1820 */ 1824 */
1821 ConstructorName parseConstructorName() { 1825 ConstructorName parseConstructorName() {
1822 TypeName type = parseTypeName(); 1826 TypeName type = parseTypeName();
1823 Token period = null; 1827 Token period = null;
1824 SimpleIdentifier name = null; 1828 SimpleIdentifier name = null;
1825 if (matches5(TokenType.PERIOD)) { 1829 if (matches5(TokenType.PERIOD)) {
1826 period = andAdvance; 1830 period = andAdvance;
1827 name = parseSimpleIdentifier(); 1831 name = parseSimpleIdentifier();
1828 } 1832 }
1829 return new ConstructorName.full(type, period, name); 1833 return new ConstructorName(type, period, name);
1830 } 1834 }
1831 1835
1832 /** 1836 /**
1833 * Parse an expression that does not contain any cascades. 1837 * Parse an expression that does not contain any cascades.
1834 * 1838 *
1835 * <pre> 1839 * <pre>
1836 * expression ::= 1840 * expression ::=
1837 * assignableExpression assignmentOperator expression 1841 * assignableExpression assignmentOperator expression
1838 * | conditionalExpression cascadeSection* 1842 * | conditionalExpression cascadeSection*
1839 * | throwExpression 1843 * | throwExpression
(...skipping 11 matching lines...) Expand all
1851 TokenType tokenType = _currentToken.type; 1855 TokenType tokenType = _currentToken.type;
1852 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1856 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1853 List<Expression> cascadeSections = new List<Expression>(); 1857 List<Expression> cascadeSections = new List<Expression>();
1854 while (identical(tokenType, TokenType.PERIOD_PERIOD)) { 1858 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1855 Expression section = parseCascadeSection(); 1859 Expression section = parseCascadeSection();
1856 if (section != null) { 1860 if (section != null) {
1857 cascadeSections.add(section); 1861 cascadeSections.add(section);
1858 } 1862 }
1859 tokenType = _currentToken.type; 1863 tokenType = _currentToken.type;
1860 } 1864 }
1861 return new CascadeExpression.full(expression, cascadeSections); 1865 return new CascadeExpression(expression, cascadeSections);
1862 } else if (tokenType.isAssignmentOperator) { 1866 } else if (tokenType.isAssignmentOperator) {
1863 Token operator = andAdvance; 1867 Token operator = andAdvance;
1864 ensureAssignable(expression); 1868 ensureAssignable(expression);
1865 return new AssignmentExpression.full(expression, operator, parseExpression 2()); 1869 return new AssignmentExpression(expression, operator, parseExpression2());
1866 } 1870 }
1867 return expression; 1871 return expression;
1868 } 1872 }
1869 1873
1870 /** 1874 /**
1871 * Parse an expression that does not contain any cascades. 1875 * Parse an expression that does not contain any cascades.
1872 * 1876 *
1873 * <pre> 1877 * <pre>
1874 * expressionWithoutCascade ::= 1878 * expressionWithoutCascade ::=
1875 * assignableExpression assignmentOperator expressionWithoutCascade 1879 * assignableExpression assignmentOperator expressionWithoutCascade
1876 * | conditionalExpression 1880 * | conditionalExpression
1877 * | throwExpressionWithoutCascade 1881 * | throwExpressionWithoutCascade
1878 * </pre> 1882 * </pre>
1879 * 1883 *
1880 * @return the expression that was parsed 1884 * @return the expression that was parsed
1881 */ 1885 */
1882 Expression parseExpressionWithoutCascade() { 1886 Expression parseExpressionWithoutCascade() {
1883 if (matches(Keyword.THROW)) { 1887 if (matches(Keyword.THROW)) {
1884 return parseThrowExpressionWithoutCascade(); 1888 return parseThrowExpressionWithoutCascade();
1885 } else if (matches(Keyword.RETHROW)) { 1889 } else if (matches(Keyword.RETHROW)) {
1886 return parseRethrowExpression(); 1890 return parseRethrowExpression();
1887 } 1891 }
1888 Expression expression = parseConditionalExpression(); 1892 Expression expression = parseConditionalExpression();
1889 if (_currentToken.type.isAssignmentOperator) { 1893 if (_currentToken.type.isAssignmentOperator) {
1890 Token operator = andAdvance; 1894 Token operator = andAdvance;
1891 ensureAssignable(expression); 1895 ensureAssignable(expression);
1892 expression = new AssignmentExpression.full(expression, operator, parseExpr essionWithoutCascade()); 1896 expression = new AssignmentExpression(expression, operator, parseExpressio nWithoutCascade());
1893 } 1897 }
1894 return expression; 1898 return expression;
1895 } 1899 }
1896 1900
1897 /** 1901 /**
1898 * Parse a class extends clause. 1902 * Parse a class extends clause.
1899 * 1903 *
1900 * <pre> 1904 * <pre>
1901 * classExtendsClause ::= 1905 * classExtendsClause ::=
1902 * 'extends' type 1906 * 'extends' type
1903 * </pre> 1907 * </pre>
1904 * 1908 *
1905 * @return the class extends clause that was parsed 1909 * @return the class extends clause that was parsed
1906 */ 1910 */
1907 ExtendsClause parseExtendsClause() { 1911 ExtendsClause parseExtendsClause() {
1908 Token keyword = expect(Keyword.EXTENDS); 1912 Token keyword = expect(Keyword.EXTENDS);
1909 TypeName superclass = parseTypeName(); 1913 TypeName superclass = parseTypeName();
1910 return new ExtendsClause.full(keyword, superclass); 1914 return new ExtendsClause(keyword, superclass);
1911 } 1915 }
1912 1916
1913 /** 1917 /**
1914 * Parse a list of formal parameters. 1918 * Parse a list of formal parameters.
1915 * 1919 *
1916 * <pre> 1920 * <pre>
1917 * formalParameterList ::= 1921 * formalParameterList ::=
1918 * '(' ')' 1922 * '(' ')'
1919 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' 1923 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')'
1920 * | '(' optionalFormalParameters ')' 1924 * | '(' optionalFormalParameters ')'
(...skipping 10 matching lines...) Expand all
1931 * 1935 *
1932 * namedFormalParameters ::= 1936 * namedFormalParameters ::=
1933 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' 1937 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}'
1934 * </pre> 1938 * </pre>
1935 * 1939 *
1936 * @return the formal parameters that were parsed 1940 * @return the formal parameters that were parsed
1937 */ 1941 */
1938 FormalParameterList parseFormalParameterList() { 1942 FormalParameterList parseFormalParameterList() {
1939 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 1943 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
1940 if (matches5(TokenType.CLOSE_PAREN)) { 1944 if (matches5(TokenType.CLOSE_PAREN)) {
1941 return new FormalParameterList.full(leftParenthesis, null, null, null, and Advance); 1945 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce);
1942 } 1946 }
1943 List<FormalParameter> parameters = new List<FormalParameter>(); 1947 List<FormalParameter> parameters = new List<FormalParameter>();
1944 List<FormalParameter> normalParameters = new List<FormalParameter>(); 1948 List<FormalParameter> normalParameters = new List<FormalParameter>();
1945 List<FormalParameter> positionalParameters = new List<FormalParameter>(); 1949 List<FormalParameter> positionalParameters = new List<FormalParameter>();
1946 List<FormalParameter> namedParameters = new List<FormalParameter>(); 1950 List<FormalParameter> namedParameters = new List<FormalParameter>();
1947 List<FormalParameter> currentParameters = normalParameters; 1951 List<FormalParameter> currentParameters = normalParameters;
1948 Token leftSquareBracket = null; 1952 Token leftSquareBracket = null;
1949 Token rightSquareBracket = null; 1953 Token rightSquareBracket = null;
1950 Token leftCurlyBracket = null; 1954 Token leftCurlyBracket = null;
1951 Token rightCurlyBracket = null; 1955 Token rightCurlyBracket = null;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 } 2039 }
2036 if (leftCurlyBracket != null && rightCurlyBracket == null) { 2040 if (leftCurlyBracket != null && rightCurlyBracket == null) {
2037 reportError10(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]); 2041 reportError10(ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP, ["}" ]);
2038 } 2042 }
2039 if (leftSquareBracket == null) { 2043 if (leftSquareBracket == null) {
2040 leftSquareBracket = leftCurlyBracket; 2044 leftSquareBracket = leftCurlyBracket;
2041 } 2045 }
2042 if (rightSquareBracket == null) { 2046 if (rightSquareBracket == null) {
2043 rightSquareBracket = rightCurlyBracket; 2047 rightSquareBracket = rightCurlyBracket;
2044 } 2048 }
2045 return new FormalParameterList.full(leftParenthesis, parameters, leftSquareB racket, rightSquareBracket, rightParenthesis); 2049 return new FormalParameterList(leftParenthesis, parameters, leftSquareBracke t, rightSquareBracket, rightParenthesis);
2046 } 2050 }
2047 2051
2048 /** 2052 /**
2049 * Parse a function expression. 2053 * Parse a function expression.
2050 * 2054 *
2051 * <pre> 2055 * <pre>
2052 * functionExpression ::= 2056 * functionExpression ::=
2053 * formalParameterList functionExpressionBody 2057 * formalParameterList functionExpressionBody
2054 * </pre> 2058 * </pre>
2055 * 2059 *
2056 * @return the function expression that was parsed 2060 * @return the function expression that was parsed
2057 */ 2061 */
2058 FunctionExpression parseFunctionExpression() { 2062 FunctionExpression parseFunctionExpression() {
2059 FormalParameterList parameters = parseFormalParameterList(); 2063 FormalParameterList parameters = parseFormalParameterList();
2060 validateFormalParameterList(parameters); 2064 validateFormalParameterList(parameters);
2061 FunctionBody body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTIO N_BODY, true); 2065 FunctionBody body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTIO N_BODY, true);
2062 return new FunctionExpression.full(parameters, body); 2066 return new FunctionExpression(parameters, body);
2063 } 2067 }
2064 2068
2065 /** 2069 /**
2066 * Parse an implements clause. 2070 * Parse an implements clause.
2067 * 2071 *
2068 * <pre> 2072 * <pre>
2069 * implementsClause ::= 2073 * implementsClause ::=
2070 * 'implements' type (',' type)* 2074 * 'implements' type (',' type)*
2071 * </pre> 2075 * </pre>
2072 * 2076 *
2073 * @return the implements clause that was parsed 2077 * @return the implements clause that was parsed
2074 */ 2078 */
2075 ImplementsClause parseImplementsClause() { 2079 ImplementsClause parseImplementsClause() {
2076 Token keyword = expect(Keyword.IMPLEMENTS); 2080 Token keyword = expect(Keyword.IMPLEMENTS);
2077 List<TypeName> interfaces = new List<TypeName>(); 2081 List<TypeName> interfaces = new List<TypeName>();
2078 interfaces.add(parseTypeName()); 2082 interfaces.add(parseTypeName());
2079 while (optional(TokenType.COMMA)) { 2083 while (optional(TokenType.COMMA)) {
2080 interfaces.add(parseTypeName()); 2084 interfaces.add(parseTypeName());
2081 } 2085 }
2082 return new ImplementsClause.full(keyword, interfaces); 2086 return new ImplementsClause(keyword, interfaces);
2083 } 2087 }
2084 2088
2085 /** 2089 /**
2086 * Parse a label. 2090 * Parse a label.
2087 * 2091 *
2088 * <pre> 2092 * <pre>
2089 * label ::= 2093 * label ::=
2090 * identifier ':' 2094 * identifier ':'
2091 * </pre> 2095 * </pre>
2092 * 2096 *
2093 * @return the label that was parsed 2097 * @return the label that was parsed
2094 */ 2098 */
2095 Label parseLabel() { 2099 Label parseLabel() {
2096 SimpleIdentifier label = parseSimpleIdentifier(); 2100 SimpleIdentifier label = parseSimpleIdentifier();
2097 Token colon = expect2(TokenType.COLON); 2101 Token colon = expect2(TokenType.COLON);
2098 return new Label.full(label, colon); 2102 return new Label(label, colon);
2099 } 2103 }
2100 2104
2101 /** 2105 /**
2102 * Parse a library identifier. 2106 * Parse a library identifier.
2103 * 2107 *
2104 * <pre> 2108 * <pre>
2105 * libraryIdentifier ::= 2109 * libraryIdentifier ::=
2106 * identifier ('.' identifier)* 2110 * identifier ('.' identifier)*
2107 * </pre> 2111 * </pre>
2108 * 2112 *
2109 * @return the library identifier that was parsed 2113 * @return the library identifier that was parsed
2110 */ 2114 */
2111 LibraryIdentifier parseLibraryIdentifier() { 2115 LibraryIdentifier parseLibraryIdentifier() {
2112 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 2116 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
2113 components.add(parseSimpleIdentifier()); 2117 components.add(parseSimpleIdentifier());
2114 while (matches5(TokenType.PERIOD)) { 2118 while (matches5(TokenType.PERIOD)) {
2115 advance(); 2119 advance();
2116 components.add(parseSimpleIdentifier()); 2120 components.add(parseSimpleIdentifier());
2117 } 2121 }
2118 return new LibraryIdentifier.full(components); 2122 return new LibraryIdentifier(components);
2119 } 2123 }
2120 2124
2121 /** 2125 /**
2122 * Parse a logical or expression. 2126 * Parse a logical or expression.
2123 * 2127 *
2124 * <pre> 2128 * <pre>
2125 * logicalOrExpression ::= 2129 * logicalOrExpression ::=
2126 * logicalAndExpression ('||' logicalAndExpression)* 2130 * logicalAndExpression ('||' logicalAndExpression)*
2127 * </pre> 2131 * </pre>
2128 * 2132 *
2129 * @return the logical or expression that was parsed 2133 * @return the logical or expression that was parsed
2130 */ 2134 */
2131 Expression parseLogicalOrExpression() { 2135 Expression parseLogicalOrExpression() {
2132 Expression expression = parseLogicalAndExpression(); 2136 Expression expression = parseLogicalAndExpression();
2133 while (matches5(TokenType.BAR_BAR)) { 2137 while (matches5(TokenType.BAR_BAR)) {
2134 Token operator = andAdvance; 2138 Token operator = andAdvance;
2135 expression = new BinaryExpression.full(expression, operator, parseLogicalA ndExpression()); 2139 expression = new BinaryExpression(expression, operator, parseLogicalAndExp ression());
2136 } 2140 }
2137 return expression; 2141 return expression;
2138 } 2142 }
2139 2143
2140 /** 2144 /**
2141 * Parse a map literal entry. 2145 * Parse a map literal entry.
2142 * 2146 *
2143 * <pre> 2147 * <pre>
2144 * mapLiteralEntry ::= 2148 * mapLiteralEntry ::=
2145 * expression ':' expression 2149 * expression ':' expression
2146 * </pre> 2150 * </pre>
2147 * 2151 *
2148 * @return the map literal entry that was parsed 2152 * @return the map literal entry that was parsed
2149 */ 2153 */
2150 MapLiteralEntry parseMapLiteralEntry() { 2154 MapLiteralEntry parseMapLiteralEntry() {
2151 Expression key = parseExpression2(); 2155 Expression key = parseExpression2();
2152 Token separator = expect2(TokenType.COLON); 2156 Token separator = expect2(TokenType.COLON);
2153 Expression value = parseExpression2(); 2157 Expression value = parseExpression2();
2154 return new MapLiteralEntry.full(key, separator, value); 2158 return new MapLiteralEntry(key, separator, value);
2155 } 2159 }
2156 2160
2157 /** 2161 /**
2158 * Parse a normal formal parameter. 2162 * Parse a normal formal parameter.
2159 * 2163 *
2160 * <pre> 2164 * <pre>
2161 * normalFormalParameter ::= 2165 * normalFormalParameter ::=
2162 * functionSignature 2166 * functionSignature
2163 * | fieldFormalParameter 2167 * | fieldFormalParameter
2164 * | simpleFormalParameter 2168 * | simpleFormalParameter
(...skipping 20 matching lines...) Expand all
2185 thisKeyword = andAdvance; 2189 thisKeyword = andAdvance;
2186 period = expect2(TokenType.PERIOD); 2190 period = expect2(TokenType.PERIOD);
2187 } 2191 }
2188 SimpleIdentifier identifier = parseSimpleIdentifier(); 2192 SimpleIdentifier identifier = parseSimpleIdentifier();
2189 if (matches5(TokenType.OPEN_PAREN)) { 2193 if (matches5(TokenType.OPEN_PAREN)) {
2190 FormalParameterList parameters = parseFormalParameterList(); 2194 FormalParameterList parameters = parseFormalParameterList();
2191 if (thisKeyword == null) { 2195 if (thisKeyword == null) {
2192 if (holder.keyword != null) { 2196 if (holder.keyword != null) {
2193 reportError11(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []); 2197 reportError11(ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.key word, []);
2194 } 2198 }
2195 return new FunctionTypedFormalParameter.full(commentAndMetadata.comment, commentAndMetadata.metadata, holder.type, identifier, parameters); 2199 return new FunctionTypedFormalParameter(commentAndMetadata.comment, comm entAndMetadata.metadata, holder.type, identifier, parameters);
2196 } else { 2200 } else {
2197 return new FieldFormalParameter.full(commentAndMetadata.comment, comment AndMetadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifi er, parameters); 2201 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMe tadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, p arameters);
2198 } 2202 }
2199 } 2203 }
2200 TypeName type = holder.type; 2204 TypeName type = holder.type;
2201 if (type != null) { 2205 if (type != null) {
2202 if (matches3(type.name.beginToken, Keyword.VOID)) { 2206 if (matches3(type.name.beginToken, Keyword.VOID)) {
2203 reportError11(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []); 2207 reportError11(ParserErrorCode.VOID_PARAMETER, type.name.beginToken, []);
2204 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) { 2208 } else if (holder.keyword != null && matches3(holder.keyword, Keyword.VAR) ) {
2205 reportError11(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []); 2209 reportError11(ParserErrorCode.VAR_AND_TYPE, holder.keyword, []);
2206 } 2210 }
2207 } 2211 }
2208 if (thisKeyword != null) { 2212 if (thisKeyword != null) {
2209 return new FieldFormalParameter.full(commentAndMetadata.comment, commentAn dMetadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier , null); 2213 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier, nul l);
2210 } 2214 }
2211 return new SimpleFormalParameter.full(commentAndMetadata.comment, commentAnd Metadata.metadata, holder.keyword, holder.type, identifier); 2215 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier);
2212 } 2216 }
2213 2217
2214 /** 2218 /**
2215 * Parse a prefixed identifier. 2219 * Parse a prefixed identifier.
2216 * 2220 *
2217 * <pre> 2221 * <pre>
2218 * prefixedIdentifier ::= 2222 * prefixedIdentifier ::=
2219 * identifier ('.' identifier)? 2223 * identifier ('.' identifier)?
2220 * </pre> 2224 * </pre>
2221 * 2225 *
2222 * @return the prefixed identifier that was parsed 2226 * @return the prefixed identifier that was parsed
2223 */ 2227 */
2224 Identifier parsePrefixedIdentifier() { 2228 Identifier parsePrefixedIdentifier() {
2225 SimpleIdentifier qualifier = parseSimpleIdentifier(); 2229 SimpleIdentifier qualifier = parseSimpleIdentifier();
2226 if (!matches5(TokenType.PERIOD)) { 2230 if (!matches5(TokenType.PERIOD)) {
2227 return qualifier; 2231 return qualifier;
2228 } 2232 }
2229 Token period = andAdvance; 2233 Token period = andAdvance;
2230 SimpleIdentifier qualified = parseSimpleIdentifier(); 2234 SimpleIdentifier qualified = parseSimpleIdentifier();
2231 return new PrefixedIdentifier.full(qualifier, period, qualified); 2235 return new PrefixedIdentifier(qualifier, period, qualified);
2232 } 2236 }
2233 2237
2234 /** 2238 /**
2235 * Parse a return type. 2239 * Parse a return type.
2236 * 2240 *
2237 * <pre> 2241 * <pre>
2238 * returnType ::= 2242 * returnType ::=
2239 * 'void' 2243 * 'void'
2240 * | type 2244 * | type
2241 * </pre> 2245 * </pre>
2242 * 2246 *
2243 * @return the return type that was parsed 2247 * @return the return type that was parsed
2244 */ 2248 */
2245 TypeName parseReturnType() { 2249 TypeName parseReturnType() {
2246 if (matches(Keyword.VOID)) { 2250 if (matches(Keyword.VOID)) {
2247 return new TypeName.full(new SimpleIdentifier.full(andAdvance), null); 2251 return new TypeName(new SimpleIdentifier(andAdvance), null);
2248 } else { 2252 } else {
2249 return parseTypeName(); 2253 return parseTypeName();
2250 } 2254 }
2251 } 2255 }
2252 2256
2253 /** 2257 /**
2254 * Parse a simple identifier. 2258 * Parse a simple identifier.
2255 * 2259 *
2256 * <pre> 2260 * <pre>
2257 * identifier ::= 2261 * identifier ::=
2258 * IDENTIFIER 2262 * IDENTIFIER
2259 * </pre> 2263 * </pre>
2260 * 2264 *
2261 * @return the simple identifier that was parsed 2265 * @return the simple identifier that was parsed
2262 */ 2266 */
2263 SimpleIdentifier parseSimpleIdentifier() { 2267 SimpleIdentifier parseSimpleIdentifier() {
2264 if (matchesIdentifier()) { 2268 if (matchesIdentifier()) {
2265 return new SimpleIdentifier.full(andAdvance); 2269 return new SimpleIdentifier(andAdvance);
2266 } 2270 }
2267 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []); 2271 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []);
2268 return createSyntheticIdentifier(); 2272 return createSyntheticIdentifier();
2269 } 2273 }
2270 2274
2271 /** 2275 /**
2272 * Parse a statement. 2276 * Parse a statement.
2273 * 2277 *
2274 * <pre> 2278 * <pre>
2275 * statement ::= 2279 * statement ::=
2276 * label* nonLabeledStatement 2280 * label* nonLabeledStatement
2277 * </pre> 2281 * </pre>
2278 * 2282 *
2279 * @return the statement that was parsed 2283 * @return the statement that was parsed
2280 */ 2284 */
2281 Statement parseStatement2() { 2285 Statement parseStatement2() {
2282 List<Label> labels = new List<Label>(); 2286 List<Label> labels = new List<Label>();
2283 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 2287 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
2284 labels.add(parseLabel()); 2288 labels.add(parseLabel());
2285 } 2289 }
2286 Statement statement = parseNonLabeledStatement(); 2290 Statement statement = parseNonLabeledStatement();
2287 if (labels.isEmpty) { 2291 if (labels.isEmpty) {
2288 return statement; 2292 return statement;
2289 } 2293 }
2290 return new LabeledStatement.full(labels, statement); 2294 return new LabeledStatement(labels, statement);
2291 } 2295 }
2292 2296
2293 /** 2297 /**
2294 * Parse a string literal. 2298 * Parse a string literal.
2295 * 2299 *
2296 * <pre> 2300 * <pre>
2297 * stringLiteral ::= 2301 * stringLiteral ::=
2298 * MULTI_LINE_STRING+ 2302 * MULTI_LINE_STRING+
2299 * | SINGLE_LINE_STRING+ 2303 * | SINGLE_LINE_STRING+
2300 * </pre> 2304 * </pre>
2301 * 2305 *
2302 * @return the string literal that was parsed 2306 * @return the string literal that was parsed
2303 */ 2307 */
2304 StringLiteral parseStringLiteral() { 2308 StringLiteral parseStringLiteral() {
2305 List<StringLiteral> strings = new List<StringLiteral>(); 2309 List<StringLiteral> strings = new List<StringLiteral>();
2306 while (matches5(TokenType.STRING)) { 2310 while (matches5(TokenType.STRING)) {
2307 Token string = andAdvance; 2311 Token string = andAdvance;
2308 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) { 2312 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) {
2309 strings.add(parseStringInterpolation(string)); 2313 strings.add(parseStringInterpolation(string));
2310 } else { 2314 } else {
2311 strings.add(new SimpleStringLiteral.full(string, computeStringValue(stri ng.lexeme, true, true))); 2315 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme, true, true)));
2312 } 2316 }
2313 } 2317 }
2314 if (strings.length < 1) { 2318 if (strings.length < 1) {
2315 reportError10(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 2319 reportError10(ParserErrorCode.EXPECTED_STRING_LITERAL, []);
2316 return createSyntheticStringLiteral(); 2320 return createSyntheticStringLiteral();
2317 } else if (strings.length == 1) { 2321 } else if (strings.length == 1) {
2318 return strings[0]; 2322 return strings[0];
2319 } else { 2323 } else {
2320 return new AdjacentStrings.full(strings); 2324 return new AdjacentStrings(strings);
2321 } 2325 }
2322 } 2326 }
2323 2327
2324 /** 2328 /**
2325 * Parse a list of type arguments. 2329 * Parse a list of type arguments.
2326 * 2330 *
2327 * <pre> 2331 * <pre>
2328 * typeArguments ::= 2332 * typeArguments ::=
2329 * '<' typeList '>' 2333 * '<' typeList '>'
2330 * 2334 *
2331 * typeList ::= 2335 * typeList ::=
2332 * type (',' type)* 2336 * type (',' type)*
2333 * </pre> 2337 * </pre>
2334 * 2338 *
2335 * @return the type argument list that was parsed 2339 * @return the type argument list that was parsed
2336 */ 2340 */
2337 TypeArgumentList parseTypeArgumentList() { 2341 TypeArgumentList parseTypeArgumentList() {
2338 Token leftBracket = expect2(TokenType.LT); 2342 Token leftBracket = expect2(TokenType.LT);
2339 List<TypeName> arguments = new List<TypeName>(); 2343 List<TypeName> arguments = new List<TypeName>();
2340 arguments.add(parseTypeName()); 2344 arguments.add(parseTypeName());
2341 while (optional(TokenType.COMMA)) { 2345 while (optional(TokenType.COMMA)) {
2342 arguments.add(parseTypeName()); 2346 arguments.add(parseTypeName());
2343 } 2347 }
2344 Token rightBracket = expect2(TokenType.GT); 2348 Token rightBracket = expect2(TokenType.GT);
2345 return new TypeArgumentList.full(leftBracket, arguments, rightBracket); 2349 return new TypeArgumentList(leftBracket, arguments, rightBracket);
2346 } 2350 }
2347 2351
2348 /** 2352 /**
2349 * Parse a type name. 2353 * Parse a type name.
2350 * 2354 *
2351 * <pre> 2355 * <pre>
2352 * type ::= 2356 * type ::=
2353 * qualified typeArguments? 2357 * qualified typeArguments?
2354 * </pre> 2358 * </pre>
2355 * 2359 *
2356 * @return the type name that was parsed 2360 * @return the type name that was parsed
2357 */ 2361 */
2358 TypeName parseTypeName() { 2362 TypeName parseTypeName() {
2359 Identifier typeName; 2363 Identifier typeName;
2360 if (matches(Keyword.VAR)) { 2364 if (matches(Keyword.VAR)) {
2361 reportError10(ParserErrorCode.VAR_AS_TYPE_NAME, []); 2365 reportError10(ParserErrorCode.VAR_AS_TYPE_NAME, []);
2362 typeName = new SimpleIdentifier.full(andAdvance); 2366 typeName = new SimpleIdentifier(andAdvance);
2363 } else if (matchesIdentifier()) { 2367 } else if (matchesIdentifier()) {
2364 typeName = parsePrefixedIdentifier(); 2368 typeName = parsePrefixedIdentifier();
2365 } else { 2369 } else {
2366 typeName = createSyntheticIdentifier(); 2370 typeName = createSyntheticIdentifier();
2367 reportError10(ParserErrorCode.EXPECTED_TYPE_NAME, []); 2371 reportError10(ParserErrorCode.EXPECTED_TYPE_NAME, []);
2368 } 2372 }
2369 TypeArgumentList typeArguments = null; 2373 TypeArgumentList typeArguments = null;
2370 if (matches5(TokenType.LT)) { 2374 if (matches5(TokenType.LT)) {
2371 typeArguments = parseTypeArgumentList(); 2375 typeArguments = parseTypeArgumentList();
2372 } 2376 }
2373 return new TypeName.full(typeName, typeArguments); 2377 return new TypeName(typeName, typeArguments);
2374 } 2378 }
2375 2379
2376 /** 2380 /**
2377 * Parse a type parameter. 2381 * Parse a type parameter.
2378 * 2382 *
2379 * <pre> 2383 * <pre>
2380 * typeParameter ::= 2384 * typeParameter ::=
2381 * metadata name ('extends' bound)? 2385 * metadata name ('extends' bound)?
2382 * </pre> 2386 * </pre>
2383 * 2387 *
2384 * @return the type parameter that was parsed 2388 * @return the type parameter that was parsed
2385 */ 2389 */
2386 TypeParameter parseTypeParameter() { 2390 TypeParameter parseTypeParameter() {
2387 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 2391 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
2388 SimpleIdentifier name = parseSimpleIdentifier(); 2392 SimpleIdentifier name = parseSimpleIdentifier();
2389 if (matches(Keyword.EXTENDS)) { 2393 if (matches(Keyword.EXTENDS)) {
2390 Token keyword = andAdvance; 2394 Token keyword = andAdvance;
2391 TypeName bound = parseTypeName(); 2395 TypeName bound = parseTypeName();
2392 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetada ta.metadata, name, keyword, bound); 2396 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.me tadata, name, keyword, bound);
2393 } 2397 }
2394 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetadata .metadata, name, null, null); 2398 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.meta data, name, null, null);
2395 } 2399 }
2396 2400
2397 /** 2401 /**
2398 * Parse a list of type parameters. 2402 * Parse a list of type parameters.
2399 * 2403 *
2400 * <pre> 2404 * <pre>
2401 * typeParameterList ::= 2405 * typeParameterList ::=
2402 * '<' typeParameter (',' typeParameter)* '>' 2406 * '<' typeParameter (',' typeParameter)* '>'
2403 * </pre> 2407 * </pre>
2404 * 2408 *
2405 * @return the list of type parameters that were parsed 2409 * @return the list of type parameters that were parsed
2406 */ 2410 */
2407 TypeParameterList parseTypeParameterList() { 2411 TypeParameterList parseTypeParameterList() {
2408 Token leftBracket = expect2(TokenType.LT); 2412 Token leftBracket = expect2(TokenType.LT);
2409 List<TypeParameter> typeParameters = new List<TypeParameter>(); 2413 List<TypeParameter> typeParameters = new List<TypeParameter>();
2410 typeParameters.add(parseTypeParameter()); 2414 typeParameters.add(parseTypeParameter());
2411 while (optional(TokenType.COMMA)) { 2415 while (optional(TokenType.COMMA)) {
2412 typeParameters.add(parseTypeParameter()); 2416 typeParameters.add(parseTypeParameter());
2413 } 2417 }
2414 Token rightBracket = expect2(TokenType.GT); 2418 Token rightBracket = expect2(TokenType.GT);
2415 return new TypeParameterList.full(leftBracket, typeParameters, rightBracket) ; 2419 return new TypeParameterList(leftBracket, typeParameters, rightBracket);
2416 } 2420 }
2417 2421
2418 /** 2422 /**
2419 * Parse a with clause. 2423 * Parse a with clause.
2420 * 2424 *
2421 * <pre> 2425 * <pre>
2422 * withClause ::= 2426 * withClause ::=
2423 * 'with' typeName (',' typeName)* 2427 * 'with' typeName (',' typeName)*
2424 * </pre> 2428 * </pre>
2425 * 2429 *
2426 * @return the with clause that was parsed 2430 * @return the with clause that was parsed
2427 */ 2431 */
2428 WithClause parseWithClause() { 2432 WithClause parseWithClause() {
2429 Token with2 = expect(Keyword.WITH); 2433 Token with2 = expect(Keyword.WITH);
2430 List<TypeName> types = new List<TypeName>(); 2434 List<TypeName> types = new List<TypeName>();
2431 types.add(parseTypeName()); 2435 types.add(parseTypeName());
2432 while (optional(TokenType.COMMA)) { 2436 while (optional(TokenType.COMMA)) {
2433 types.add(parseTypeName()); 2437 types.add(parseTypeName());
2434 } 2438 }
2435 return new WithClause.full(with2, types); 2439 return new WithClause(with2, types);
2436 } 2440 }
2437 2441
2438 void set currentToken(Token currentToken) { 2442 void set currentToken(Token currentToken) {
2439 this._currentToken = currentToken; 2443 this._currentToken = currentToken;
2440 } 2444 }
2441 2445
2442 /** 2446 /**
2443 * Advance to the next token in the token stream. 2447 * Advance to the next token in the token stream.
2444 */ 2448 */
2445 void advance() { 2449 void advance() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 return builder.toString(); 2520 return builder.toString();
2517 } 2521 }
2518 2522
2519 /** 2523 /**
2520 * Convert the given method declaration into the nearest valid top-level funct ion declaration. 2524 * Convert the given method declaration into the nearest valid top-level funct ion declaration.
2521 * 2525 *
2522 * @param method the method to be converted 2526 * @param method the method to be converted
2523 * @return the function declaration that most closely captures the components of the given method 2527 * @return the function declaration that most closely captures the components of the given method
2524 * declaration 2528 * declaration
2525 */ 2529 */
2526 FunctionDeclaration convertToFunctionDeclaration(MethodDeclaration method) => new FunctionDeclaration.full(method.documentationComment, method.metadata, metho d.externalKeyword, method.returnType, method.propertyKeyword, method.name, new F unctionExpression.full(method.parameters, method.body)); 2530 FunctionDeclaration convertToFunctionDeclaration(MethodDeclaration method) => new FunctionDeclaration(method.documentationComment, method.metadata, method.ext ernalKeyword, method.returnType, method.propertyKeyword, method.name, new Functi onExpression(method.parameters, method.body));
2527 2531
2528 /** 2532 /**
2529 * Return `true` if the current token could be the start of a compilation unit member. This 2533 * Return `true` if the current token could be the start of a compilation unit member. This
2530 * method is used for recovery purposes to decide when to stop skipping tokens after finding an 2534 * method is used for recovery purposes to decide when to stop skipping tokens after finding an
2531 * error while parsing a compilation unit member. 2535 * error while parsing a compilation unit member.
2532 * 2536 *
2533 * @return `true` if the current token could be the start of a compilation uni t member 2537 * @return `true` if the current token could be the start of a compilation uni t member
2534 */ 2538 */
2535 bool couldBeStartOfCompilationUnitMember() { 2539 bool couldBeStartOfCompilationUnitMember() {
2536 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword.L IBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !mat ches4(peek(), TokenType.LT)) { 2540 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword.L IBRARY) || matches(Keyword.PART)) && !matches4(peek(), TokenType.PERIOD) && !mat ches4(peek(), TokenType.LT)) {
(...skipping 24 matching lines...) Expand all
2561 * 2565 *
2562 * @return the synthetic identifier that was created 2566 * @return the synthetic identifier that was created
2563 */ 2567 */
2564 SimpleIdentifier createSyntheticIdentifier() { 2568 SimpleIdentifier createSyntheticIdentifier() {
2565 Token syntheticToken; 2569 Token syntheticToken;
2566 if (identical(_currentToken.type, TokenType.KEYWORD)) { 2570 if (identical(_currentToken.type, TokenType.KEYWORD)) {
2567 syntheticToken = injectToken(new SyntheticStringToken(TokenType.IDENTIFIER , _currentToken.lexeme, _currentToken.offset)); 2571 syntheticToken = injectToken(new SyntheticStringToken(TokenType.IDENTIFIER , _currentToken.lexeme, _currentToken.offset));
2568 } else { 2572 } else {
2569 syntheticToken = createSyntheticToken2(TokenType.IDENTIFIER); 2573 syntheticToken = createSyntheticToken2(TokenType.IDENTIFIER);
2570 } 2574 }
2571 return new SimpleIdentifier.full(syntheticToken); 2575 return new SimpleIdentifier(syntheticToken);
2572 } 2576 }
2573 2577
2574 /** 2578 /**
2575 * Create a synthetic string literal. 2579 * Create a synthetic string literal.
2576 * 2580 *
2577 * @return the synthetic string literal that was created 2581 * @return the synthetic string literal that was created
2578 */ 2582 */
2579 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral. full(createSyntheticToken2(TokenType.STRING), ""); 2583 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral( createSyntheticToken2(TokenType.STRING), "");
2580 2584
2581 /** 2585 /**
2582 * Create a synthetic token representing the given keyword. 2586 * Create a synthetic token representing the given keyword.
2583 * 2587 *
2584 * @return the synthetic token that was created 2588 * @return the synthetic token that was created
2585 */ 2589 */
2586 Token createSyntheticToken(Keyword keyword) => injectToken(new Parser_Syntheti cKeywordToken(keyword, _currentToken.offset)); 2590 Token createSyntheticToken(Keyword keyword) => injectToken(new Parser_Syntheti cKeywordToken(keyword, _currentToken.offset));
2587 2591
2588 /** 2592 /**
2589 * Create a synthetic token with the given type. 2593 * Create a synthetic token with the given type.
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 * additiveExpression ::= 3135 * additiveExpression ::=
3132 * multiplicativeExpression (additiveOperator multiplicativeExpression)* 3136 * multiplicativeExpression (additiveOperator multiplicativeExpression)*
3133 * | 'super' (additiveOperator multiplicativeExpression)+ 3137 * | 'super' (additiveOperator multiplicativeExpression)+
3134 * </pre> 3138 * </pre>
3135 * 3139 *
3136 * @return the additive expression that was parsed 3140 * @return the additive expression that was parsed
3137 */ 3141 */
3138 Expression parseAdditiveExpression() { 3142 Expression parseAdditiveExpression() {
3139 Expression expression; 3143 Expression expression;
3140 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator) { 3144 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator) {
3141 expression = new SuperExpression.full(andAdvance); 3145 expression = new SuperExpression(andAdvance);
3142 } else { 3146 } else {
3143 expression = parseMultiplicativeExpression(); 3147 expression = parseMultiplicativeExpression();
3144 } 3148 }
3145 while (_currentToken.type.isAdditiveOperator) { 3149 while (_currentToken.type.isAdditiveOperator) {
3146 Token operator = andAdvance; 3150 Token operator = andAdvance;
3147 expression = new BinaryExpression.full(expression, operator, parseMultipli cativeExpression()); 3151 expression = new BinaryExpression(expression, operator, parseMultiplicativ eExpression());
3148 } 3152 }
3149 return expression; 3153 return expression;
3150 } 3154 }
3151 3155
3152 /** 3156 /**
3153 * Parse an argument definition test. 3157 * Parse an argument definition test.
3154 * 3158 *
3155 * <pre> 3159 * <pre>
3156 * argumentDefinitionTest ::= 3160 * argumentDefinitionTest ::=
3157 * '?' identifier 3161 * '?' identifier
3158 * </pre> 3162 * </pre>
3159 * 3163 *
3160 * @return the argument definition test that was parsed 3164 * @return the argument definition test that was parsed
3161 */ 3165 */
3162 ArgumentDefinitionTest parseArgumentDefinitionTest() { 3166 ArgumentDefinitionTest parseArgumentDefinitionTest() {
3163 Token question = expect2(TokenType.QUESTION); 3167 Token question = expect2(TokenType.QUESTION);
3164 SimpleIdentifier identifier = parseSimpleIdentifier(); 3168 SimpleIdentifier identifier = parseSimpleIdentifier();
3165 reportError11(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []); 3169 reportError11(ParserErrorCode.DEPRECATED_ARGUMENT_DEFINITION_TEST, question, []);
3166 return new ArgumentDefinitionTest.full(question, identifier); 3170 return new ArgumentDefinitionTest(question, identifier);
3167 } 3171 }
3168 3172
3169 /** 3173 /**
3170 * Parse an assert statement. 3174 * Parse an assert statement.
3171 * 3175 *
3172 * <pre> 3176 * <pre>
3173 * assertStatement ::= 3177 * assertStatement ::=
3174 * 'assert' '(' conditionalExpression ')' ';' 3178 * 'assert' '(' conditionalExpression ')' ';'
3175 * </pre> 3179 * </pre>
3176 * 3180 *
3177 * @return the assert statement 3181 * @return the assert statement
3178 */ 3182 */
3179 AssertStatement parseAssertStatement() { 3183 AssertStatement parseAssertStatement() {
3180 Token keyword = expect(Keyword.ASSERT); 3184 Token keyword = expect(Keyword.ASSERT);
3181 Token leftParen = expect2(TokenType.OPEN_PAREN); 3185 Token leftParen = expect2(TokenType.OPEN_PAREN);
3182 Expression expression = parseExpression2(); 3186 Expression expression = parseExpression2();
3183 if (expression is AssignmentExpression) { 3187 if (expression is AssignmentExpression) {
3184 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []); 3188 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT, expression, []);
3185 } else if (expression is CascadeExpression) { 3189 } else if (expression is CascadeExpression) {
3186 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, []) ; 3190 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE, expression, []) ;
3187 } else if (expression is ThrowExpression) { 3191 } else if (expression is ThrowExpression) {
3188 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []); 3192 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW, expression, []);
3189 } else if (expression is RethrowExpression) { 3193 } else if (expression is RethrowExpression) {
3190 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, []) ; 3194 reportError9(ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW, expression, []) ;
3191 } 3195 }
3192 Token rightParen = expect2(TokenType.CLOSE_PAREN); 3196 Token rightParen = expect2(TokenType.CLOSE_PAREN);
3193 Token semicolon = expect2(TokenType.SEMICOLON); 3197 Token semicolon = expect2(TokenType.SEMICOLON);
3194 return new AssertStatement.full(keyword, leftParen, expression, rightParen, semicolon); 3198 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon);
3195 } 3199 }
3196 3200
3197 /** 3201 /**
3198 * Parse an assignable expression. 3202 * Parse an assignable expression.
3199 * 3203 *
3200 * <pre> 3204 * <pre>
3201 * assignableExpression ::= 3205 * assignableExpression ::=
3202 * primary (arguments* assignableSelector)+ 3206 * primary (arguments* assignableSelector)+
3203 * | 'super' assignableSelector 3207 * | 'super' assignableSelector
3204 * | identifier 3208 * | identifier
3205 * </pre> 3209 * </pre>
3206 * 3210 *
3207 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any 3211 * @param primaryAllowed `true` if the expression is allowed to be a primary w ithout any
3208 * assignable selector 3212 * assignable selector
3209 * @return the assignable expression that was parsed 3213 * @return the assignable expression that was parsed
3210 */ 3214 */
3211 Expression parseAssignableExpression(bool primaryAllowed) { 3215 Expression parseAssignableExpression(bool primaryAllowed) {
3212 if (matches(Keyword.SUPER)) { 3216 if (matches(Keyword.SUPER)) {
3213 return parseAssignableSelector(new SuperExpression.full(andAdvance), false ); 3217 return parseAssignableSelector(new SuperExpression(andAdvance), false);
3214 } 3218 }
3215 Expression expression = parsePrimaryExpression(); 3219 Expression expression = parsePrimaryExpression();
3216 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 3220 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
3217 while (true) { 3221 while (true) {
3218 while (matches5(TokenType.OPEN_PAREN)) { 3222 while (matches5(TokenType.OPEN_PAREN)) {
3219 ArgumentList argumentList = parseArgumentList(); 3223 ArgumentList argumentList = parseArgumentList();
3220 if (expression is SimpleIdentifier) { 3224 if (expression is SimpleIdentifier) {
3221 expression = new MethodInvocation.full(null, null, expression as Simpl eIdentifier, argumentList); 3225 expression = new MethodInvocation(null, null, expression as SimpleIden tifier, argumentList);
3222 } else if (expression is PrefixedIdentifier) { 3226 } else if (expression is PrefixedIdentifier) {
3223 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 3227 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
3224 expression = new MethodInvocation.full(identifier.prefix, identifier.p eriod, identifier.identifier, argumentList); 3228 expression = new MethodInvocation(identifier.prefix, identifier.period , identifier.identifier, argumentList);
3225 } else if (expression is PropertyAccess) { 3229 } else if (expression is PropertyAccess) {
3226 PropertyAccess access = expression as PropertyAccess; 3230 PropertyAccess access = expression as PropertyAccess;
3227 expression = new MethodInvocation.full(access.target, access.operator, access.propertyName, argumentList); 3231 expression = new MethodInvocation(access.target, access.operator, acce ss.propertyName, argumentList);
3228 } else { 3232 } else {
3229 expression = new FunctionExpressionInvocation.full(expression, argumen tList); 3233 expression = new FunctionExpressionInvocation(expression, argumentList );
3230 } 3234 }
3231 if (!primaryAllowed) { 3235 if (!primaryAllowed) {
3232 isOptional = false; 3236 isOptional = false;
3233 } 3237 }
3234 } 3238 }
3235 Expression selectorExpression = parseAssignableSelector(expression, isOpti onal || (expression is PrefixedIdentifier)); 3239 Expression selectorExpression = parseAssignableSelector(expression, isOpti onal || (expression is PrefixedIdentifier));
3236 if (identical(selectorExpression, expression)) { 3240 if (identical(selectorExpression, expression)) {
3237 if (!isOptional && (expression is PrefixedIdentifier)) { 3241 if (!isOptional && (expression is PrefixedIdentifier)) {
3238 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 3242 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
3239 expression = new PropertyAccess.full(identifier.prefix, identifier.per iod, identifier.identifier); 3243 expression = new PropertyAccess(identifier.prefix, identifier.period, identifier.identifier);
3240 } 3244 }
3241 return expression; 3245 return expression;
3242 } 3246 }
3243 expression = selectorExpression; 3247 expression = selectorExpression;
3244 isOptional = true; 3248 isOptional = true;
3245 } 3249 }
3246 } 3250 }
3247 3251
3248 /** 3252 /**
3249 * Parse an assignable selector. 3253 * Parse an assignable selector.
3250 * 3254 *
3251 * <pre> 3255 * <pre>
3252 * assignableSelector ::= 3256 * assignableSelector ::=
3253 * '[' expression ']' 3257 * '[' expression ']'
3254 * | '.' identifier 3258 * | '.' identifier
3255 * </pre> 3259 * </pre>
3256 * 3260 *
3257 * @param prefix the expression preceding the selector 3261 * @param prefix the expression preceding the selector
3258 * @param optional `true` if the selector is optional 3262 * @param optional `true` if the selector is optional
3259 * @return the assignable selector that was parsed 3263 * @return the assignable selector that was parsed
3260 */ 3264 */
3261 Expression parseAssignableSelector(Expression prefix, bool optional) { 3265 Expression parseAssignableSelector(Expression prefix, bool optional) {
3262 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 3266 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
3263 Token leftBracket = andAdvance; 3267 Token leftBracket = andAdvance;
3264 Expression index = parseExpression2(); 3268 Expression index = parseExpression2();
3265 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3269 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3266 return new IndexExpression.forTarget_full(prefix, leftBracket, index, righ tBracket); 3270 return new IndexExpression.forTarget(prefix, leftBracket, index, rightBrac ket);
3267 } else if (matches5(TokenType.PERIOD)) { 3271 } else if (matches5(TokenType.PERIOD)) {
3268 Token period = andAdvance; 3272 Token period = andAdvance;
3269 return new PropertyAccess.full(prefix, period, parseSimpleIdentifier()); 3273 return new PropertyAccess(prefix, period, parseSimpleIdentifier());
3270 } else { 3274 } else {
3271 if (!optional) { 3275 if (!optional) {
3272 reportError10(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3276 reportError10(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
3273 } 3277 }
3274 return prefix; 3278 return prefix;
3275 } 3279 }
3276 } 3280 }
3277 3281
3278 /** 3282 /**
3279 * Parse a bitwise and expression. 3283 * Parse a bitwise and expression.
3280 * 3284 *
3281 * <pre> 3285 * <pre>
3282 * bitwiseAndExpression ::= 3286 * bitwiseAndExpression ::=
3283 * shiftExpression ('&' shiftExpression)* 3287 * shiftExpression ('&' shiftExpression)*
3284 * | 'super' ('&' shiftExpression)+ 3288 * | 'super' ('&' shiftExpression)+
3285 * </pre> 3289 * </pre>
3286 * 3290 *
3287 * @return the bitwise and expression that was parsed 3291 * @return the bitwise and expression that was parsed
3288 */ 3292 */
3289 Expression parseBitwiseAndExpression() { 3293 Expression parseBitwiseAndExpression() {
3290 Expression expression; 3294 Expression expression;
3291 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) { 3295 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) {
3292 expression = new SuperExpression.full(andAdvance); 3296 expression = new SuperExpression(andAdvance);
3293 } else { 3297 } else {
3294 expression = parseShiftExpression(); 3298 expression = parseShiftExpression();
3295 } 3299 }
3296 while (matches5(TokenType.AMPERSAND)) { 3300 while (matches5(TokenType.AMPERSAND)) {
3297 Token operator = andAdvance; 3301 Token operator = andAdvance;
3298 expression = new BinaryExpression.full(expression, operator, parseShiftExp ression()); 3302 expression = new BinaryExpression(expression, operator, parseShiftExpressi on());
3299 } 3303 }
3300 return expression; 3304 return expression;
3301 } 3305 }
3302 3306
3303 /** 3307 /**
3304 * Parse a bitwise exclusive-or expression. 3308 * Parse a bitwise exclusive-or expression.
3305 * 3309 *
3306 * <pre> 3310 * <pre>
3307 * bitwiseXorExpression ::= 3311 * bitwiseXorExpression ::=
3308 * bitwiseAndExpression ('^' bitwiseAndExpression)* 3312 * bitwiseAndExpression ('^' bitwiseAndExpression)*
3309 * | 'super' ('^' bitwiseAndExpression)+ 3313 * | 'super' ('^' bitwiseAndExpression)+
3310 * </pre> 3314 * </pre>
3311 * 3315 *
3312 * @return the bitwise exclusive-or expression that was parsed 3316 * @return the bitwise exclusive-or expression that was parsed
3313 */ 3317 */
3314 Expression parseBitwiseXorExpression() { 3318 Expression parseBitwiseXorExpression() {
3315 Expression expression; 3319 Expression expression;
3316 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) { 3320 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) {
3317 expression = new SuperExpression.full(andAdvance); 3321 expression = new SuperExpression(andAdvance);
3318 } else { 3322 } else {
3319 expression = parseBitwiseAndExpression(); 3323 expression = parseBitwiseAndExpression();
3320 } 3324 }
3321 while (matches5(TokenType.CARET)) { 3325 while (matches5(TokenType.CARET)) {
3322 Token operator = andAdvance; 3326 Token operator = andAdvance;
3323 expression = new BinaryExpression.full(expression, operator, parseBitwiseA ndExpression()); 3327 expression = new BinaryExpression(expression, operator, parseBitwiseAndExp ression());
3324 } 3328 }
3325 return expression; 3329 return expression;
3326 } 3330 }
3327 3331
3328 /** 3332 /**
3329 * Parse a break statement. 3333 * Parse a break statement.
3330 * 3334 *
3331 * <pre> 3335 * <pre>
3332 * breakStatement ::= 3336 * breakStatement ::=
3333 * 'break' identifier? ';' 3337 * 'break' identifier? ';'
3334 * </pre> 3338 * </pre>
3335 * 3339 *
3336 * @return the break statement that was parsed 3340 * @return the break statement that was parsed
3337 */ 3341 */
3338 Statement parseBreakStatement() { 3342 Statement parseBreakStatement() {
3339 Token breakKeyword = expect(Keyword.BREAK); 3343 Token breakKeyword = expect(Keyword.BREAK);
3340 SimpleIdentifier label = null; 3344 SimpleIdentifier label = null;
3341 if (matchesIdentifier()) { 3345 if (matchesIdentifier()) {
3342 label = parseSimpleIdentifier(); 3346 label = parseSimpleIdentifier();
3343 } 3347 }
3344 if (!_inLoop && !_inSwitch && label == null) { 3348 if (!_inLoop && !_inSwitch && label == null) {
3345 reportError11(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 3349 reportError11(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []);
3346 } 3350 }
3347 Token semicolon = expect2(TokenType.SEMICOLON); 3351 Token semicolon = expect2(TokenType.SEMICOLON);
3348 return new BreakStatement.full(breakKeyword, label, semicolon); 3352 return new BreakStatement(breakKeyword, label, semicolon);
3349 } 3353 }
3350 3354
3351 /** 3355 /**
3352 * Parse a cascade section. 3356 * Parse a cascade section.
3353 * 3357 *
3354 * <pre> 3358 * <pre>
3355 * cascadeSection ::= 3359 * cascadeSection ::=
3356 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* casc adeAssignment? 3360 * '..' (cascadeSelector arguments*) (assignableSelector arguments*)* casc adeAssignment?
3357 * 3361 *
3358 * cascadeSelector ::= 3362 * cascadeSelector ::=
3359 * '[' expression ']' 3363 * '[' expression ']'
3360 * | identifier 3364 * | identifier
3361 * 3365 *
3362 * cascadeAssignment ::= 3366 * cascadeAssignment ::=
3363 * assignmentOperator expressionWithoutCascade 3367 * assignmentOperator expressionWithoutCascade
3364 * </pre> 3368 * </pre>
3365 * 3369 *
3366 * @return the expression representing the cascaded method invocation 3370 * @return the expression representing the cascaded method invocation
3367 */ 3371 */
3368 Expression parseCascadeSection() { 3372 Expression parseCascadeSection() {
3369 Token period = expect2(TokenType.PERIOD_PERIOD); 3373 Token period = expect2(TokenType.PERIOD_PERIOD);
3370 Expression expression = null; 3374 Expression expression = null;
3371 SimpleIdentifier functionName = null; 3375 SimpleIdentifier functionName = null;
3372 if (matchesIdentifier()) { 3376 if (matchesIdentifier()) {
3373 functionName = parseSimpleIdentifier(); 3377 functionName = parseSimpleIdentifier();
3374 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) { 3378 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) {
3375 Token leftBracket = andAdvance; 3379 Token leftBracket = andAdvance;
3376 Expression index = parseExpression2(); 3380 Expression index = parseExpression2();
3377 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 3381 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
3378 expression = new IndexExpression.forCascade_full(period, leftBracket, inde x, rightBracket); 3382 expression = new IndexExpression.forCascade(period, leftBracket, index, ri ghtBracket);
3379 period = null; 3383 period = null;
3380 } else { 3384 } else {
3381 reportError11(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]); 3385 reportError11(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, [_current Token.lexeme]);
3382 functionName = createSyntheticIdentifier(); 3386 functionName = createSyntheticIdentifier();
3383 } 3387 }
3384 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3388 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3385 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3389 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3386 if (functionName != null) { 3390 if (functionName != null) {
3387 expression = new MethodInvocation.full(expression, period, functionNam e, parseArgumentList()); 3391 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList());
3388 period = null; 3392 period = null;
3389 functionName = null; 3393 functionName = null;
3390 } else if (expression == null) { 3394 } else if (expression == null) {
3391 expression = new MethodInvocation.full(expression, period, createSynth eticIdentifier(), parseArgumentList()); 3395 expression = new MethodInvocation(expression, period, createSyntheticI dentifier(), parseArgumentList());
3392 } else { 3396 } else {
3393 expression = new FunctionExpressionInvocation.full(expression, parseAr gumentList()); 3397 expression = new FunctionExpressionInvocation(expression, parseArgumen tList());
3394 } 3398 }
3395 } 3399 }
3396 } else if (functionName != null) { 3400 } else if (functionName != null) {
3397 expression = new PropertyAccess.full(expression, period, functionName); 3401 expression = new PropertyAccess(expression, period, functionName);
3398 period = null; 3402 period = null;
3399 } 3403 }
3400 bool progress = true; 3404 bool progress = true;
3401 while (progress) { 3405 while (progress) {
3402 progress = false; 3406 progress = false;
3403 Expression selector = parseAssignableSelector(expression, true); 3407 Expression selector = parseAssignableSelector(expression, true);
3404 if (selector != expression) { 3408 if (selector != expression) {
3405 expression = selector; 3409 expression = selector;
3406 progress = true; 3410 progress = true;
3407 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) { 3411 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
3408 if (expression is PropertyAccess) { 3412 if (expression is PropertyAccess) {
3409 PropertyAccess propertyAccess = expression as PropertyAccess; 3413 PropertyAccess propertyAccess = expression as PropertyAccess;
3410 expression = new MethodInvocation.full(propertyAccess.target, proper tyAccess.operator, propertyAccess.propertyName, parseArgumentList()); 3414 expression = new MethodInvocation(propertyAccess.target, propertyAcc ess.operator, propertyAccess.propertyName, parseArgumentList());
3411 } else { 3415 } else {
3412 expression = new FunctionExpressionInvocation.full(expression, parse ArgumentList()); 3416 expression = new FunctionExpressionInvocation(expression, parseArgum entList());
3413 } 3417 }
3414 } 3418 }
3415 } 3419 }
3416 } 3420 }
3417 if (_currentToken.type.isAssignmentOperator) { 3421 if (_currentToken.type.isAssignmentOperator) {
3418 Token operator = andAdvance; 3422 Token operator = andAdvance;
3419 ensureAssignable(expression); 3423 ensureAssignable(expression);
3420 expression = new AssignmentExpression.full(expression, operator, parseExpr essionWithoutCascade()); 3424 expression = new AssignmentExpression(expression, operator, parseExpressio nWithoutCascade());
3421 } 3425 }
3422 return expression; 3426 return expression;
3423 } 3427 }
3424 3428
3425 /** 3429 /**
3426 * Parse a class declaration. 3430 * Parse a class declaration.
3427 * 3431 *
3428 * <pre> 3432 * <pre>
3429 * classDeclaration ::= 3433 * classDeclaration ::=
3430 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause wit hClause?)? implementsClause? '{' classMembers '}' | 3434 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause wit hClause?)? implementsClause? '{' classMembers '}' |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3505 Token rightBracket = null; 3509 Token rightBracket = null;
3506 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3510 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3507 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 3511 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
3508 members = parseClassMembers(className, getEndToken(leftBracket)); 3512 members = parseClassMembers(className, getEndToken(leftBracket));
3509 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3513 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
3510 } else { 3514 } else {
3511 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET); 3515 leftBracket = createSyntheticToken2(TokenType.OPEN_CURLY_BRACKET);
3512 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET); 3516 rightBracket = createSyntheticToken2(TokenType.CLOSE_CURLY_BRACKET);
3513 reportError10(ParserErrorCode.MISSING_CLASS_BODY, []); 3517 reportError10(ParserErrorCode.MISSING_CLASS_BODY, []);
3514 } 3518 }
3515 ClassDeclaration classDeclaration = new ClassDeclaration.full(commentAndMeta data.comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeP arameters, extendsClause, withClause, implementsClause, leftBracket, members, ri ghtBracket); 3519 ClassDeclaration classDeclaration = new ClassDeclaration(commentAndMetadata. comment, commentAndMetadata.metadata, abstractKeyword, keyword, name, typeParame ters, extendsClause, withClause, implementsClause, leftBracket, members, rightBr acket);
3516 classDeclaration.nativeClause = nativeClause; 3520 classDeclaration.nativeClause = nativeClause;
3517 return classDeclaration; 3521 return classDeclaration;
3518 } 3522 }
3519 3523
3520 /** 3524 /**
3521 * Parse a list of class members. 3525 * Parse a list of class members.
3522 * 3526 *
3523 * <pre> 3527 * <pre>
3524 * classMembers ::= 3528 * classMembers ::=
3525 * (metadata memberDefinition)* 3529 * (metadata memberDefinition)*
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3598 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3595 reportError10(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]); 3599 reportError10(ParserErrorCode.EXPECTED_TOKEN, [TokenType.SEMICOLON.lexem e]);
3596 Token leftBracket = andAdvance; 3600 Token leftBracket = andAdvance;
3597 parseClassMembers(className.name, getEndToken(leftBracket)); 3601 parseClassMembers(className.name, getEndToken(leftBracket));
3598 expect2(TokenType.CLOSE_CURLY_BRACKET); 3602 expect2(TokenType.CLOSE_CURLY_BRACKET);
3599 } else { 3603 } else {
3600 reportError11(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]); 3604 reportError11(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [T okenType.SEMICOLON.lexeme]);
3601 } 3605 }
3602 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 3606 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
3603 } 3607 }
3604 return new ClassTypeAlias.full(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, className, typeParameters, equals, abstractKeyword, supercl ass, withClause, implementsClause, semicolon); 3608 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, keyword, className, typeParameters, equals, abstractKeyword, superclass, withClause, implementsClause, semicolon);
3605 } 3609 }
3606 3610
3607 /** 3611 /**
3608 * Parse a list of combinators in a directive. 3612 * Parse a list of combinators in a directive.
3609 * 3613 *
3610 * <pre> 3614 * <pre>
3611 * combinator ::= 3615 * combinator ::=
3612 * 'show' identifier (',' identifier)* 3616 * 'show' identifier (',' identifier)*
3613 * | 'hide' identifier (',' identifier)* 3617 * | 'hide' identifier (',' identifier)*
3614 * </pre> 3618 * </pre>
3615 * 3619 *
3616 * @return the combinators that were parsed 3620 * @return the combinators that were parsed
3617 */ 3621 */
3618 List<Combinator> parseCombinators() { 3622 List<Combinator> parseCombinators() {
3619 List<Combinator> combinators = new List<Combinator>(); 3623 List<Combinator> combinators = new List<Combinator>();
3620 while (matches2(_SHOW) || matches2(_HIDE)) { 3624 while (matches2(_SHOW) || matches2(_HIDE)) {
3621 Token keyword = expect2(TokenType.IDENTIFIER); 3625 Token keyword = expect2(TokenType.IDENTIFIER);
3622 if (keyword.lexeme == _SHOW) { 3626 if (keyword.lexeme == _SHOW) {
3623 List<SimpleIdentifier> shownNames = parseIdentifierList(); 3627 List<SimpleIdentifier> shownNames = parseIdentifierList();
3624 combinators.add(new ShowCombinator.full(keyword, shownNames)); 3628 combinators.add(new ShowCombinator(keyword, shownNames));
3625 } else { 3629 } else {
3626 List<SimpleIdentifier> hiddenNames = parseIdentifierList(); 3630 List<SimpleIdentifier> hiddenNames = parseIdentifierList();
3627 combinators.add(new HideCombinator.full(keyword, hiddenNames)); 3631 combinators.add(new HideCombinator(keyword, hiddenNames));
3628 } 3632 }
3629 } 3633 }
3630 return combinators; 3634 return combinators;
3631 } 3635 }
3632 3636
3633 /** 3637 /**
3634 * Parse the documentation comment and metadata preceding a declaration. This method allows any 3638 * Parse the documentation comment and metadata preceding a declaration. This method allows any
3635 * number of documentation comments to occur before, after or between the meta data, but only 3639 * number of documentation comments to occur before, after or between the meta data, but only
3636 * returns the last (right-most) documentation comment that is found. 3640 * returns the last (right-most) documentation comment that is found.
3637 * 3641 *
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 if (matches3(firstToken, Keyword.NEW)) { 3688 if (matches3(firstToken, Keyword.NEW)) {
3685 newKeyword = firstToken; 3689 newKeyword = firstToken;
3686 firstToken = firstToken.next; 3690 firstToken = firstToken.next;
3687 } 3691 }
3688 if (matchesIdentifier2(firstToken)) { 3692 if (matchesIdentifier2(firstToken)) {
3689 Token secondToken = firstToken.next; 3693 Token secondToken = firstToken.next;
3690 Token thirdToken = secondToken.next; 3694 Token thirdToken = secondToken.next;
3691 Token nextToken; 3695 Token nextToken;
3692 Identifier identifier; 3696 Identifier identifier;
3693 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thirdT oken)) { 3697 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thirdT oken)) {
3694 identifier = new PrefixedIdentifier.full(new SimpleIdentifier.full(fir stToken), secondToken, new SimpleIdentifier.full(thirdToken)); 3698 identifier = new PrefixedIdentifier(new SimpleIdentifier(firstToken), secondToken, new SimpleIdentifier(thirdToken));
3695 nextToken = thirdToken.next; 3699 nextToken = thirdToken.next;
3696 } else { 3700 } else {
3697 identifier = new SimpleIdentifier.full(firstToken); 3701 identifier = new SimpleIdentifier(firstToken);
3698 nextToken = firstToken.next; 3702 nextToken = firstToken.next;
3699 } 3703 }
3700 if (nextToken.type != TokenType.EOF) { 3704 if (nextToken.type != TokenType.EOF) {
3701 return null; 3705 return null;
3702 } 3706 }
3703 return new CommentReference.full(newKeyword, identifier); 3707 return new CommentReference(newKeyword, identifier);
3704 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword. FALSE)) { 3708 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Keyw ord.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keyword. FALSE)) {
3705 return null; 3709 return null;
3706 } 3710 }
3707 } on JavaException catch (exception) { 3711 } on JavaException catch (exception) {
3708 } 3712 }
3709 return null; 3713 return null;
3710 } 3714 }
3711 3715
3712 /** 3716 /**
3713 * Parse all of the comment references occurring in the given array of documen tation comments. 3717 * Parse all of the comment references occurring in the given array of documen tation comments.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
3796 } else if (matchesIdentifier() && matchesAny(peek(), [ 3800 } else if (matchesIdentifier() && matchesAny(peek(), [
3797 TokenType.OPEN_PAREN, 3801 TokenType.OPEN_PAREN,
3798 TokenType.OPEN_CURLY_BRACKET, 3802 TokenType.OPEN_CURLY_BRACKET,
3799 TokenType.FUNCTION])) { 3803 TokenType.FUNCTION])) {
3800 validateModifiersForTopLevelFunction(modifiers); 3804 validateModifiersForTopLevelFunction(modifiers);
3801 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType); 3805 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, returnType);
3802 } else { 3806 } else {
3803 if (matchesIdentifier()) { 3807 if (matchesIdentifier()) {
3804 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 3808 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
3805 reportError9(ParserErrorCode.VOID_VARIABLE, returnType, []); 3809 reportError9(ParserErrorCode.VOID_VARIABLE, returnType, []);
3806 return new TopLevelVariableDeclaration.full(commentAndMetadata.comme nt, commentAndMetadata.metadata, parseVariableDeclarationList2(null, validateMod ifiersForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 3810 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifier sForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
3807 } 3811 }
3808 } 3812 }
3809 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3813 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3810 return null; 3814 return null;
3811 } 3815 }
3812 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) { 3816 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) {
3813 validateModifiersForTopLevelFunction(modifiers); 3817 validateModifiersForTopLevelFunction(modifiers);
3814 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3818 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3815 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3819 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3816 reportError11(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3820 reportError11(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3817 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null)); 3821 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, null));
3818 } else if (!matchesIdentifier()) { 3822 } else if (!matchesIdentifier()) {
3819 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3823 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3820 return null; 3824 return null;
3821 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 3825 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
3822 validateModifiersForTopLevelFunction(modifiers); 3826 validateModifiersForTopLevelFunction(modifiers);
3823 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null); 3827 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null);
3824 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 3828 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
3825 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) { 3829 if (modifiers.constKeyword == null && modifiers.finalKeyword == null && mo difiers.varKeyword == null) {
3826 reportError10(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []); 3830 reportError10(ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, []);
3827 } 3831 }
3828 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co mmentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiers ForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 3832 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
3829 } 3833 }
3830 TypeName returnType = parseReturnType(); 3834 TypeName returnType = parseReturnType();
3831 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) { 3835 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier2(pee k())) {
3832 validateModifiersForTopLevelFunction(modifiers); 3836 validateModifiersForTopLevelFunction(modifiers);
3833 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 3837 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
3834 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 3838 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
3835 reportError11(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []); 3839 reportError11(ParserErrorCode.TOP_LEVEL_OPERATOR, _currentToken, []);
3836 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType)); 3840 return convertToFunctionDeclaration(parseOperator(commentAndMetadata, modi fiers.externalKeyword, returnType));
3837 } else if (matches5(TokenType.AT)) { 3841 } else if (matches5(TokenType.AT)) {
3838 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co mmentAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiers ForTopLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 3842 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTo pLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON));
3839 } else if (!matchesIdentifier()) { 3843 } else if (!matchesIdentifier()) {
3840 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []); 3844 reportError11(ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken, []);
3841 Token semicolon; 3845 Token semicolon;
3842 if (matches5(TokenType.SEMICOLON)) { 3846 if (matches5(TokenType.SEMICOLON)) {
3843 semicolon = andAdvance; 3847 semicolon = andAdvance;
3844 } else { 3848 } else {
3845 semicolon = createSyntheticToken2(TokenType.SEMICOLON); 3849 semicolon = createSyntheticToken2(TokenType.SEMICOLON);
3846 } 3850 }
3847 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 3851 List<VariableDeclaration> variables = new List<VariableDeclaration>();
3848 variables.add(new VariableDeclaration.full(null, null, createSyntheticIden tifier(), null, null)); 3852 variables.add(new VariableDeclaration(null, null, createSyntheticIdentifie r(), null, null));
3849 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co mmentAndMetadata.metadata, new VariableDeclarationList.full(null, null, null, re turnType, variables), semicolon); 3853 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, new VariableDeclarationList(null, null, null, returnType, variables), semicolon);
3850 } 3854 }
3851 if (matchesAny(peek(), [ 3855 if (matchesAny(peek(), [
3852 TokenType.OPEN_PAREN, 3856 TokenType.OPEN_PAREN,
3853 TokenType.FUNCTION, 3857 TokenType.FUNCTION,
3854 TokenType.OPEN_CURLY_BRACKET])) { 3858 TokenType.OPEN_CURLY_BRACKET])) {
3855 validateModifiersForTopLevelFunction(modifiers); 3859 validateModifiersForTopLevelFunction(modifiers);
3856 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType); 3860 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType);
3857 } 3861 }
3858 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, comm entAndMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersFo rTopLevelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 3862 return new TopLevelVariableDeclaration(commentAndMetadata.comment, commentAn dMetadata.metadata, parseVariableDeclarationList2(null, validateModifiersForTopL evelVariable(modifiers), returnType), expect2(TokenType.SEMICOLON));
3859 } 3863 }
3860 3864
3861 /** 3865 /**
3862 * Parse a const expression. 3866 * Parse a const expression.
3863 * 3867 *
3864 * <pre> 3868 * <pre>
3865 * constExpression ::= 3869 * constExpression ::=
3866 * instanceCreationExpression 3870 * instanceCreationExpression
3867 * | listLiteral 3871 * | listLiteral
3868 * | mapLiteral 3872 * | mapLiteral
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3905 } else { 3909 } else {
3906 initializers.add(parseConstructorFieldInitializer()); 3910 initializers.add(parseConstructorFieldInitializer());
3907 } 3911 }
3908 } while (optional(TokenType.COMMA)); 3912 } while (optional(TokenType.COMMA));
3909 } 3913 }
3910 ConstructorName redirectedConstructor = null; 3914 ConstructorName redirectedConstructor = null;
3911 FunctionBody body; 3915 FunctionBody body;
3912 if (matches5(TokenType.EQ)) { 3916 if (matches5(TokenType.EQ)) {
3913 separator = andAdvance; 3917 separator = andAdvance;
3914 redirectedConstructor = parseConstructorName(); 3918 redirectedConstructor = parseConstructorName();
3915 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); 3919 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
3916 if (factoryKeyword == null) { 3920 if (factoryKeyword == null) {
3917 reportError9(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, red irectedConstructor, []); 3921 reportError9(ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, red irectedConstructor, []);
3918 } 3922 }
3919 } else { 3923 } else {
3920 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e); 3924 body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, fals e);
3921 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) { 3925 if (constKeyword != null && factoryKeyword != null && externalKeyword == n ull) {
3922 reportError11(ParserErrorCode.CONST_FACTORY, factoryKeyword, []); 3926 reportError11(ParserErrorCode.CONST_FACTORY, factoryKeyword, []);
3923 } else if (body is EmptyFunctionBody) { 3927 } else if (body is EmptyFunctionBody) {
3924 if (factoryKeyword != null && externalKeyword == null) { 3928 if (factoryKeyword != null && externalKeyword == null) {
3925 reportError11(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] ); 3929 reportError11(ParserErrorCode.FACTORY_WITHOUT_BODY, factoryKeyword, [] );
3926 } 3930 }
3927 } else { 3931 } else {
3928 if (constKeyword != null) { 3932 if (constKeyword != null) {
3929 reportError9(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []); 3933 reportError9(ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY, body, []);
3930 } else if (!bodyAllowed) { 3934 } else if (!bodyAllowed) {
3931 reportError9(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, []) ; 3935 reportError9(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, body, []) ;
3932 } 3936 }
3933 } 3937 }
3934 } 3938 }
3935 return new ConstructorDeclaration.full(commentAndMetadata.comment, commentAn dMetadata.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, p eriod, name, parameters, separator, initializers, redirectedConstructor, body); 3939 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body);
3936 } 3940 }
3937 3941
3938 /** 3942 /**
3939 * Parse a field initializer within a constructor. 3943 * Parse a field initializer within a constructor.
3940 * 3944 *
3941 * <pre> 3945 * <pre>
3942 * fieldInitializer: 3946 * fieldInitializer:
3943 * ('this' '.')? identifier '=' conditionalExpression cascadeSection* 3947 * ('this' '.')? identifier '=' conditionalExpression cascadeSection*
3944 * </pre> 3948 * </pre>
3945 * 3949 *
(...skipping 12 matching lines...) Expand all
3958 TokenType tokenType = _currentToken.type; 3962 TokenType tokenType = _currentToken.type;
3959 if (identical(tokenType, TokenType.PERIOD_PERIOD)) { 3963 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
3960 List<Expression> cascadeSections = new List<Expression>(); 3964 List<Expression> cascadeSections = new List<Expression>();
3961 while (identical(tokenType, TokenType.PERIOD_PERIOD)) { 3965 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
3962 Expression section = parseCascadeSection(); 3966 Expression section = parseCascadeSection();
3963 if (section != null) { 3967 if (section != null) {
3964 cascadeSections.add(section); 3968 cascadeSections.add(section);
3965 } 3969 }
3966 tokenType = _currentToken.type; 3970 tokenType = _currentToken.type;
3967 } 3971 }
3968 expression = new CascadeExpression.full(expression, cascadeSections); 3972 expression = new CascadeExpression(expression, cascadeSections);
3969 } 3973 }
3970 return new ConstructorFieldInitializer.full(keyword, period, fieldName, equa ls, expression); 3974 return new ConstructorFieldInitializer(keyword, period, fieldName, equals, e xpression);
3971 } 3975 }
3972 3976
3973 /** 3977 /**
3974 * Parse a continue statement. 3978 * Parse a continue statement.
3975 * 3979 *
3976 * <pre> 3980 * <pre>
3977 * continueStatement ::= 3981 * continueStatement ::=
3978 * 'continue' identifier? ';' 3982 * 'continue' identifier? ';'
3979 * </pre> 3983 * </pre>
3980 * 3984 *
3981 * @return the continue statement that was parsed 3985 * @return the continue statement that was parsed
3982 */ 3986 */
3983 Statement parseContinueStatement() { 3987 Statement parseContinueStatement() {
3984 Token continueKeyword = expect(Keyword.CONTINUE); 3988 Token continueKeyword = expect(Keyword.CONTINUE);
3985 if (!_inLoop && !_inSwitch) { 3989 if (!_inLoop && !_inSwitch) {
3986 reportError11(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]); 3990 reportError11(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [ ]);
3987 } 3991 }
3988 SimpleIdentifier label = null; 3992 SimpleIdentifier label = null;
3989 if (matchesIdentifier()) { 3993 if (matchesIdentifier()) {
3990 label = parseSimpleIdentifier(); 3994 label = parseSimpleIdentifier();
3991 } 3995 }
3992 if (_inSwitch && !_inLoop && label == null) { 3996 if (_inSwitch && !_inLoop && label == null) {
3993 reportError11(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []); 3997 reportError11(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeyw ord, []);
3994 } 3998 }
3995 Token semicolon = expect2(TokenType.SEMICOLON); 3999 Token semicolon = expect2(TokenType.SEMICOLON);
3996 return new ContinueStatement.full(continueKeyword, label, semicolon); 4000 return new ContinueStatement(continueKeyword, label, semicolon);
3997 } 4001 }
3998 4002
3999 /** 4003 /**
4000 * Parse a directive. 4004 * Parse a directive.
4001 * 4005 *
4002 * <pre> 4006 * <pre>
4003 * directive ::= 4007 * directive ::=
4004 * exportDirective 4008 * exportDirective
4005 * | libraryDirective 4009 * | libraryDirective
4006 * | importDirective 4010 * | importDirective
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 bool wasInLoop = _inLoop; 4080 bool wasInLoop = _inLoop;
4077 _inLoop = true; 4081 _inLoop = true;
4078 try { 4082 try {
4079 Token doKeyword = expect(Keyword.DO); 4083 Token doKeyword = expect(Keyword.DO);
4080 Statement body = parseStatement2(); 4084 Statement body = parseStatement2();
4081 Token whileKeyword = expect(Keyword.WHILE); 4085 Token whileKeyword = expect(Keyword.WHILE);
4082 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4086 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4083 Expression condition = parseExpression2(); 4087 Expression condition = parseExpression2();
4084 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4088 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4085 Token semicolon = expect2(TokenType.SEMICOLON); 4089 Token semicolon = expect2(TokenType.SEMICOLON);
4086 return new DoStatement.full(doKeyword, body, whileKeyword, leftParenthesis , condition, rightParenthesis, semicolon); 4090 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon);
4087 } finally { 4091 } finally {
4088 _inLoop = wasInLoop; 4092 _inLoop = wasInLoop;
4089 } 4093 }
4090 } 4094 }
4091 4095
4092 /** 4096 /**
4093 * Parse an empty statement. 4097 * Parse an empty statement.
4094 * 4098 *
4095 * <pre> 4099 * <pre>
4096 * emptyStatement ::= 4100 * emptyStatement ::=
4097 * ';' 4101 * ';'
4098 * </pre> 4102 * </pre>
4099 * 4103 *
4100 * @return the empty statement that was parsed 4104 * @return the empty statement that was parsed
4101 */ 4105 */
4102 Statement parseEmptyStatement() => new EmptyStatement.full(andAdvance); 4106 Statement parseEmptyStatement() => new EmptyStatement(andAdvance);
4103 4107
4104 /** 4108 /**
4105 * Parse an equality expression. 4109 * Parse an equality expression.
4106 * 4110 *
4107 * <pre> 4111 * <pre>
4108 * equalityExpression ::= 4112 * equalityExpression ::=
4109 * relationalExpression (equalityOperator relationalExpression)? 4113 * relationalExpression (equalityOperator relationalExpression)?
4110 * | 'super' equalityOperator relationalExpression 4114 * | 'super' equalityOperator relationalExpression
4111 * </pre> 4115 * </pre>
4112 * 4116 *
4113 * @return the equality expression that was parsed 4117 * @return the equality expression that was parsed
4114 */ 4118 */
4115 Expression parseEqualityExpression() { 4119 Expression parseEqualityExpression() {
4116 Expression expression; 4120 Expression expression;
4117 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) { 4121 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator) {
4118 expression = new SuperExpression.full(andAdvance); 4122 expression = new SuperExpression(andAdvance);
4119 } else { 4123 } else {
4120 expression = parseRelationalExpression(); 4124 expression = parseRelationalExpression();
4121 } 4125 }
4122 bool leftEqualityExpression = false; 4126 bool leftEqualityExpression = false;
4123 while (_currentToken.type.isEqualityOperator) { 4127 while (_currentToken.type.isEqualityOperator) {
4124 Token operator = andAdvance; 4128 Token operator = andAdvance;
4125 if (leftEqualityExpression) { 4129 if (leftEqualityExpression) {
4126 reportError9(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expres sion, []); 4130 reportError9(ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND, expres sion, []);
4127 } 4131 }
4128 expression = new BinaryExpression.full(expression, operator, parseRelation alExpression()); 4132 expression = new BinaryExpression(expression, operator, parseRelationalExp ression());
4129 leftEqualityExpression = true; 4133 leftEqualityExpression = true;
4130 } 4134 }
4131 return expression; 4135 return expression;
4132 } 4136 }
4133 4137
4134 /** 4138 /**
4135 * Parse an export directive. 4139 * Parse an export directive.
4136 * 4140 *
4137 * <pre> 4141 * <pre>
4138 * exportDirective ::= 4142 * exportDirective ::=
4139 * metadata 'export' stringLiteral combinator*';' 4143 * metadata 'export' stringLiteral combinator*';'
4140 * </pre> 4144 * </pre>
4141 * 4145 *
4142 * @param commentAndMetadata the metadata to be associated with the directive 4146 * @param commentAndMetadata the metadata to be associated with the directive
4143 * @return the export directive that was parsed 4147 * @return the export directive that was parsed
4144 */ 4148 */
4145 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { 4149 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) {
4146 Token exportKeyword = expect(Keyword.EXPORT); 4150 Token exportKeyword = expect(Keyword.EXPORT);
4147 StringLiteral libraryUri = parseStringLiteral(); 4151 StringLiteral libraryUri = parseStringLiteral();
4148 List<Combinator> combinators = parseCombinators(); 4152 List<Combinator> combinators = parseCombinators();
4149 Token semicolon = expect2(TokenType.SEMICOLON); 4153 Token semicolon = expect2(TokenType.SEMICOLON);
4150 return new ExportDirective.full(commentAndMetadata.comment, commentAndMetada ta.metadata, exportKeyword, libraryUri, combinators, semicolon); 4154 return new ExportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, exportKeyword, libraryUri, combinators, semicolon);
4151 } 4155 }
4152 4156
4153 /** 4157 /**
4154 * Parse a list of expressions. 4158 * Parse a list of expressions.
4155 * 4159 *
4156 * <pre> 4160 * <pre>
4157 * expressionList ::= 4161 * expressionList ::=
4158 * expression (',' expression)* 4162 * expression (',' expression)*
4159 * </pre> 4163 * </pre>
4160 * 4164 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4222 FormalParameter parseFormalParameter(ParameterKind kind) { 4226 FormalParameter parseFormalParameter(ParameterKind kind) {
4223 NormalFormalParameter parameter = parseNormalFormalParameter(); 4227 NormalFormalParameter parameter = parseNormalFormalParameter();
4224 if (matches5(TokenType.EQ)) { 4228 if (matches5(TokenType.EQ)) {
4225 Token seperator = andAdvance; 4229 Token seperator = andAdvance;
4226 Expression defaultValue = parseExpression2(); 4230 Expression defaultValue = parseExpression2();
4227 if (identical(kind, ParameterKind.NAMED)) { 4231 if (identical(kind, ParameterKind.NAMED)) {
4228 reportError11(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []); 4232 reportError11(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, seper ator, []);
4229 } else if (identical(kind, ParameterKind.REQUIRED)) { 4233 } else if (identical(kind, ParameterKind.REQUIRED)) {
4230 reportError9(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramet er, []); 4234 reportError9(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramet er, []);
4231 } 4235 }
4232 return new DefaultFormalParameter.full(parameter, kind, seperator, default Value); 4236 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4233 } else if (matches5(TokenType.COLON)) { 4237 } else if (matches5(TokenType.COLON)) {
4234 Token seperator = andAdvance; 4238 Token seperator = andAdvance;
4235 Expression defaultValue = parseExpression2(); 4239 Expression defaultValue = parseExpression2();
4236 if (identical(kind, ParameterKind.POSITIONAL)) { 4240 if (identical(kind, ParameterKind.POSITIONAL)) {
4237 reportError11(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []); 4241 reportError11(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, seperator, []);
4238 } else if (identical(kind, ParameterKind.REQUIRED)) { 4242 } else if (identical(kind, ParameterKind.REQUIRED)) {
4239 reportError9(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, [ ]); 4243 reportError9(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, [ ]);
4240 } 4244 }
4241 return new DefaultFormalParameter.full(parameter, kind, seperator, default Value); 4245 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue );
4242 } else if (kind != ParameterKind.REQUIRED) { 4246 } else if (kind != ParameterKind.REQUIRED) {
4243 return new DefaultFormalParameter.full(parameter, kind, null, null); 4247 return new DefaultFormalParameter(parameter, kind, null, null);
4244 } 4248 }
4245 return parameter; 4249 return parameter;
4246 } 4250 }
4247 4251
4248 /** 4252 /**
4249 * Parse a for statement. 4253 * Parse a for statement.
4250 * 4254 *
4251 * <pre> 4255 * <pre>
4252 * forStatement ::= 4256 * forStatement ::=
4253 * 'for' '(' forLoopParts ')' statement 4257 * 'for' '(' forLoopParts ')' statement
(...skipping 16 matching lines...) Expand all
4270 try { 4274 try {
4271 Token forKeyword = expect(Keyword.FOR); 4275 Token forKeyword = expect(Keyword.FOR);
4272 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4276 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4273 VariableDeclarationList variableList = null; 4277 VariableDeclarationList variableList = null;
4274 Expression initialization = null; 4278 Expression initialization = null;
4275 if (!matches5(TokenType.SEMICOLON)) { 4279 if (!matches5(TokenType.SEMICOLON)) {
4276 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4280 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4277 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) { 4281 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) {
4278 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 4282 List<VariableDeclaration> variables = new List<VariableDeclaration>();
4279 SimpleIdentifier variableName = parseSimpleIdentifier(); 4283 SimpleIdentifier variableName = parseSimpleIdentifier();
4280 variables.add(new VariableDeclaration.full(null, null, variableName, n ull, null)); 4284 variables.add(new VariableDeclaration(null, null, variableName, null, null));
4281 variableList = new VariableDeclarationList.full(commentAndMetadata.com ment, commentAndMetadata.metadata, null, null, variables); 4285 variableList = new VariableDeclarationList(commentAndMetadata.comment, commentAndMetadata.metadata, null, null, variables);
4282 } else if (isInitializedVariableDeclaration()) { 4286 } else if (isInitializedVariableDeclaration()) {
4283 variableList = parseVariableDeclarationList(commentAndMetadata); 4287 variableList = parseVariableDeclarationList(commentAndMetadata);
4284 } else { 4288 } else {
4285 initialization = parseExpression2(); 4289 initialization = parseExpression2();
4286 } 4290 }
4287 if (matches(Keyword.IN)) { 4291 if (matches(Keyword.IN)) {
4288 DeclaredIdentifier loopVariable = null; 4292 DeclaredIdentifier loopVariable = null;
4289 SimpleIdentifier identifier = null; 4293 SimpleIdentifier identifier = null;
4290 if (variableList == null) { 4294 if (variableList == null) {
4291 reportError10(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); 4295 reportError10(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []);
4292 } else { 4296 } else {
4293 NodeList<VariableDeclaration> variables = variableList.variables; 4297 NodeList<VariableDeclaration> variables = variableList.variables;
4294 if (variables.length > 1) { 4298 if (variables.length > 1) {
4295 reportError10(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]); 4299 reportError10(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [var iables.length.toString()]);
4296 } 4300 }
4297 VariableDeclaration variable = variables[0]; 4301 VariableDeclaration variable = variables[0];
4298 if (variable.initializer != null) { 4302 if (variable.initializer != null) {
4299 reportError10(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] ); 4303 reportError10(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, [] );
4300 } 4304 }
4301 Token keyword = variableList.keyword; 4305 Token keyword = variableList.keyword;
4302 TypeName type = variableList.type; 4306 TypeName type = variableList.type;
4303 if (keyword != null || type != null) { 4307 if (keyword != null || type != null) {
4304 loopVariable = new DeclaredIdentifier.full(commentAndMetadata.comm ent, commentAndMetadata.metadata, keyword, type, variable.name); 4308 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, commentAndMetadata.metadata, keyword, type, variable.name);
4305 } else { 4309 } else {
4306 if (!commentAndMetadata.metadata.isEmpty) { 4310 if (!commentAndMetadata.metadata.isEmpty) {
4307 } 4311 }
4308 identifier = variable.name; 4312 identifier = variable.name;
4309 } 4313 }
4310 } 4314 }
4311 Token inKeyword = expect(Keyword.IN); 4315 Token inKeyword = expect(Keyword.IN);
4312 Expression iterator = parseExpression2(); 4316 Expression iterator = parseExpression2();
4313 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4317 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4314 Statement body = parseStatement2(); 4318 Statement body = parseStatement2();
4315 if (loopVariable == null) { 4319 if (loopVariable == null) {
4316 return new ForEachStatement.con2_full(forKeyword, leftParenthesis, i dentifier, inKeyword, iterator, rightParenthesis, body); 4320 return new ForEachStatement.con2(forKeyword, leftParenthesis, identi fier, inKeyword, iterator, rightParenthesis, body);
4317 } 4321 }
4318 return new ForEachStatement.con1_full(forKeyword, leftParenthesis, loo pVariable, inKeyword, iterator, rightParenthesis, body); 4322 return new ForEachStatement.con1(forKeyword, leftParenthesis, loopVari able, inKeyword, iterator, rightParenthesis, body);
4319 } 4323 }
4320 } 4324 }
4321 Token leftSeparator = expect2(TokenType.SEMICOLON); 4325 Token leftSeparator = expect2(TokenType.SEMICOLON);
4322 Expression condition = null; 4326 Expression condition = null;
4323 if (!matches5(TokenType.SEMICOLON)) { 4327 if (!matches5(TokenType.SEMICOLON)) {
4324 condition = parseExpression2(); 4328 condition = parseExpression2();
4325 } 4329 }
4326 Token rightSeparator = expect2(TokenType.SEMICOLON); 4330 Token rightSeparator = expect2(TokenType.SEMICOLON);
4327 List<Expression> updaters = null; 4331 List<Expression> updaters = null;
4328 if (!matches5(TokenType.CLOSE_PAREN)) { 4332 if (!matches5(TokenType.CLOSE_PAREN)) {
4329 updaters = parseExpressionList(); 4333 updaters = parseExpressionList();
4330 } 4334 }
4331 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4335 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4332 Statement body = parseStatement2(); 4336 Statement body = parseStatement2();
4333 return new ForStatement.full(forKeyword, leftParenthesis, variableList, in itialization, leftSeparator, condition, rightSeparator, updaters, rightParenthes is, body); 4337 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody);
4334 } finally { 4338 } finally {
4335 _inLoop = wasInLoop; 4339 _inLoop = wasInLoop;
4336 } 4340 }
4337 } 4341 }
4338 4342
4339 /** 4343 /**
4340 * Parse a function body. 4344 * Parse a function body.
4341 * 4345 *
4342 * <pre> 4346 * <pre>
4343 * functionBody ::= 4347 * functionBody ::=
(...skipping 14 matching lines...) Expand all
4358 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) { 4362 FunctionBody parseFunctionBody(bool mayBeEmpty, ParserErrorCode emptyErrorCode , bool inExpression) {
4359 bool wasInLoop = _inLoop; 4363 bool wasInLoop = _inLoop;
4360 bool wasInSwitch = _inSwitch; 4364 bool wasInSwitch = _inSwitch;
4361 _inLoop = false; 4365 _inLoop = false;
4362 _inSwitch = false; 4366 _inSwitch = false;
4363 try { 4367 try {
4364 if (matches5(TokenType.SEMICOLON)) { 4368 if (matches5(TokenType.SEMICOLON)) {
4365 if (!mayBeEmpty) { 4369 if (!mayBeEmpty) {
4366 reportError10(emptyErrorCode, []); 4370 reportError10(emptyErrorCode, []);
4367 } 4371 }
4368 return new EmptyFunctionBody.full(andAdvance); 4372 return new EmptyFunctionBody(andAdvance);
4369 } else if (matches5(TokenType.FUNCTION)) { 4373 } else if (matches5(TokenType.FUNCTION)) {
4370 Token functionDefinition = andAdvance; 4374 Token functionDefinition = andAdvance;
4371 Expression expression = parseExpression2(); 4375 Expression expression = parseExpression2();
4372 Token semicolon = null; 4376 Token semicolon = null;
4373 if (!inExpression) { 4377 if (!inExpression) {
4374 semicolon = expect2(TokenType.SEMICOLON); 4378 semicolon = expect2(TokenType.SEMICOLON);
4375 } 4379 }
4376 if (!_parseFunctionBodies) { 4380 if (!_parseFunctionBodies) {
4377 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMI COLON)); 4381 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4378 } 4382 }
4379 return new ExpressionFunctionBody.full(functionDefinition, expression, s emicolon); 4383 return new ExpressionFunctionBody(functionDefinition, expression, semico lon);
4380 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4384 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4381 if (!_parseFunctionBodies) { 4385 if (!_parseFunctionBodies) {
4382 skipBlock(); 4386 skipBlock();
4383 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMI COLON)); 4387 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON ));
4384 } 4388 }
4385 return new BlockFunctionBody.full(parseBlock()); 4389 return new BlockFunctionBody(parseBlock());
4386 } else if (matches2(_NATIVE)) { 4390 } else if (matches2(_NATIVE)) {
4387 Token nativeToken = andAdvance; 4391 Token nativeToken = andAdvance;
4388 StringLiteral stringLiteral = null; 4392 StringLiteral stringLiteral = null;
4389 if (matches5(TokenType.STRING)) { 4393 if (matches5(TokenType.STRING)) {
4390 stringLiteral = parseStringLiteral(); 4394 stringLiteral = parseStringLiteral();
4391 } 4395 }
4392 return new NativeFunctionBody.full(nativeToken, stringLiteral, expect2(T okenType.SEMICOLON)); 4396 return new NativeFunctionBody(nativeToken, stringLiteral, expect2(TokenT ype.SEMICOLON));
4393 } else { 4397 } else {
4394 reportError10(emptyErrorCode, []); 4398 reportError10(emptyErrorCode, []);
4395 return new EmptyFunctionBody.full(createSyntheticToken2(TokenType.SEMICO LON)); 4399 return new EmptyFunctionBody(createSyntheticToken2(TokenType.SEMICOLON)) ;
4396 } 4400 }
4397 } finally { 4401 } finally {
4398 _inLoop = wasInLoop; 4402 _inLoop = wasInLoop;
4399 _inSwitch = wasInSwitch; 4403 _inSwitch = wasInSwitch;
4400 } 4404 }
4401 } 4405 }
4402 4406
4403 /** 4407 /**
4404 * Parse a function declaration. 4408 * Parse a function declaration.
4405 * 4409 *
(...skipping 29 matching lines...) Expand all
4435 reportError10(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []); 4439 reportError10(ParserErrorCode.MISSING_FUNCTION_PARAMETERS, []);
4436 } 4440 }
4437 } else if (matches5(TokenType.OPEN_PAREN)) { 4441 } else if (matches5(TokenType.OPEN_PAREN)) {
4438 reportError10(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4442 reportError10(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4439 parseFormalParameterList(); 4443 parseFormalParameterList();
4440 } 4444 }
4441 FunctionBody body; 4445 FunctionBody body;
4442 if (externalKeyword == null) { 4446 if (externalKeyword == null) {
4443 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se); 4447 body = parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, fal se);
4444 } else { 4448 } else {
4445 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON)); 4449 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON));
4446 } 4450 }
4447 return new FunctionDeclaration.full(commentAndMetadata.comment, commentAndMe tadata.metadata, externalKeyword, returnType, keyword, name, new FunctionExpress ion.full(parameters, body)); 4451 return new FunctionDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, externalKeyword, returnType, keyword, name, new FunctionExpression(p arameters, body));
4448 } 4452 }
4449 4453
4450 /** 4454 /**
4451 * Parse a function declaration statement. 4455 * Parse a function declaration statement.
4452 * 4456 *
4453 * <pre> 4457 * <pre>
4454 * functionDeclarationStatement ::= 4458 * functionDeclarationStatement ::=
4455 * functionSignature functionBody 4459 * functionSignature functionBody
4456 * </pre> 4460 * </pre>
4457 * 4461 *
(...skipping 21 matching lines...) Expand all
4479 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) { 4483 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) {
4480 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType); 4484 FunctionDeclaration declaration = parseFunctionDeclaration(commentAndMetadat a, null, returnType);
4481 Token propertyKeyword = declaration.propertyKeyword; 4485 Token propertyKeyword = declaration.propertyKeyword;
4482 if (propertyKeyword != null) { 4486 if (propertyKeyword != null) {
4483 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) { 4487 if (identical((propertyKeyword as KeywordToken).keyword, Keyword.GET)) {
4484 reportError11(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []); 4488 reportError11(ParserErrorCode.GETTER_IN_FUNCTION, propertyKeyword, []);
4485 } else { 4489 } else {
4486 reportError11(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []); 4490 reportError11(ParserErrorCode.SETTER_IN_FUNCTION, propertyKeyword, []);
4487 } 4491 }
4488 } 4492 }
4489 return new FunctionDeclarationStatement.full(declaration); 4493 return new FunctionDeclarationStatement(declaration);
4490 } 4494 }
4491 4495
4492 /** 4496 /**
4493 * Parse a function type alias. 4497 * Parse a function type alias.
4494 * 4498 *
4495 * <pre> 4499 * <pre>
4496 * functionTypeAlias ::= 4500 * functionTypeAlias ::=
4497 * functionPrefix typeParameterList? formalParameterList ';' 4501 * functionPrefix typeParameterList? formalParameterList ';'
4498 * 4502 *
4499 * functionPrefix ::= 4503 * functionPrefix ::=
4500 * returnType? name 4504 * returnType? name
4501 * </pre> 4505 * </pre>
4502 * 4506 *
4503 * @param commentAndMetadata the metadata to be associated with the member 4507 * @param commentAndMetadata the metadata to be associated with the member
4504 * @param keyword the token representing the 'typedef' keyword 4508 * @param keyword the token representing the 'typedef' keyword
4505 * @return the function type alias that was parsed 4509 * @return the function type alias that was parsed
4506 */ 4510 */
4507 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) { 4511 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) {
4508 TypeName returnType = null; 4512 TypeName returnType = null;
4509 if (hasReturnTypeInTypeAlias()) { 4513 if (hasReturnTypeInTypeAlias()) {
4510 returnType = parseReturnType(); 4514 returnType = parseReturnType();
4511 } 4515 }
4512 SimpleIdentifier name = parseSimpleIdentifier(); 4516 SimpleIdentifier name = parseSimpleIdentifier();
4513 TypeParameterList typeParameters = null; 4517 TypeParameterList typeParameters = null;
4514 if (matches5(TokenType.LT)) { 4518 if (matches5(TokenType.LT)) {
4515 typeParameters = parseTypeParameterList(); 4519 typeParameters = parseTypeParameterList();
4516 } 4520 }
4517 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) { 4521 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.EOF)) {
4518 reportError10(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4522 reportError10(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4519 FormalParameterList parameters = new FormalParameterList.full(createSynthe ticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenTy pe.CLOSE_PAREN)); 4523 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken2(TokenType.CL OSE_PAREN));
4520 Token semicolon = expect2(TokenType.SEMICOLON); 4524 Token semicolon = expect2(TokenType.SEMICOLON);
4521 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe tadata.metadata, keyword, returnType, name, typeParameters, parameters, semicolo n); 4525 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4522 } else if (!matches5(TokenType.OPEN_PAREN)) { 4526 } else if (!matches5(TokenType.OPEN_PAREN)) {
4523 reportError10(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 4527 reportError10(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
4524 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe tadata.metadata, keyword, returnType, name, typeParameters, new FormalParameterL ist.full(createSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSy ntheticToken2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON )); 4528 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, new FormalParameterList(c reateSyntheticToken2(TokenType.OPEN_PAREN), null, null, null, createSyntheticTok en2(TokenType.CLOSE_PAREN)), createSyntheticToken2(TokenType.SEMICOLON));
4525 } 4529 }
4526 FormalParameterList parameters = parseFormalParameterList(); 4530 FormalParameterList parameters = parseFormalParameterList();
4527 validateFormalParameterList(parameters); 4531 validateFormalParameterList(parameters);
4528 Token semicolon = expect2(TokenType.SEMICOLON); 4532 Token semicolon = expect2(TokenType.SEMICOLON);
4529 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMeta data.metadata, keyword, returnType, name, typeParameters, parameters, semicolon) ; 4533 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon);
4530 } 4534 }
4531 4535
4532 /** 4536 /**
4533 * Parse a getter. 4537 * Parse a getter.
4534 * 4538 *
4535 * <pre> 4539 * <pre>
4536 * getter ::= 4540 * getter ::=
4537 * getterSignature functionBody? 4541 * getterSignature functionBody?
4538 * 4542 *
4539 * getterSignature ::= 4543 * getterSignature ::=
(...skipping 13 matching lines...) Expand all
4553 SimpleIdentifier name = parseSimpleIdentifier(); 4557 SimpleIdentifier name = parseSimpleIdentifier();
4554 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) { 4558 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) {
4555 reportError10(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 4559 reportError10(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
4556 advance(); 4560 advance();
4557 advance(); 4561 advance();
4558 } 4562 }
4559 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); 4563 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false);
4560 if (externalKeyword != null && body is! EmptyFunctionBody) { 4564 if (externalKeyword != null && body is! EmptyFunctionBody) {
4561 reportError10(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); 4565 reportError10(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []);
4562 } 4566 }
4563 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null , name, null, body); 4567 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body);
4564 } 4568 }
4565 4569
4566 /** 4570 /**
4567 * Parse a list of identifiers. 4571 * Parse a list of identifiers.
4568 * 4572 *
4569 * <pre> 4573 * <pre>
4570 * identifierList ::= 4574 * identifierList ::=
4571 * identifier (',' identifier)* 4575 * identifier (',' identifier)*
4572 * </pre> 4576 * </pre>
4573 * 4577 *
(...skipping 24 matching lines...) Expand all
4598 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 4602 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
4599 Expression condition = parseExpression2(); 4603 Expression condition = parseExpression2();
4600 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 4604 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
4601 Statement thenStatement = parseStatement2(); 4605 Statement thenStatement = parseStatement2();
4602 Token elseKeyword = null; 4606 Token elseKeyword = null;
4603 Statement elseStatement = null; 4607 Statement elseStatement = null;
4604 if (matches(Keyword.ELSE)) { 4608 if (matches(Keyword.ELSE)) {
4605 elseKeyword = andAdvance; 4609 elseKeyword = andAdvance;
4606 elseStatement = parseStatement2(); 4610 elseStatement = parseStatement2();
4607 } 4611 }
4608 return new IfStatement.full(ifKeyword, leftParenthesis, condition, rightPare nthesis, thenStatement, elseKeyword, elseStatement); 4612 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement);
4609 } 4613 }
4610 4614
4611 /** 4615 /**
4612 * Parse an import directive. 4616 * Parse an import directive.
4613 * 4617 *
4614 * <pre> 4618 * <pre>
4615 * importDirective ::= 4619 * importDirective ::=
4616 * metadata 'import' stringLiteral ('as' identifier)? combinator*';' 4620 * metadata 'import' stringLiteral ('as' identifier)? combinator*';'
4617 * </pre> 4621 * </pre>
4618 * 4622 *
4619 * @param commentAndMetadata the metadata to be associated with the directive 4623 * @param commentAndMetadata the metadata to be associated with the directive
4620 * @return the import directive that was parsed 4624 * @return the import directive that was parsed
4621 */ 4625 */
4622 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) { 4626 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) {
4623 Token importKeyword = expect(Keyword.IMPORT); 4627 Token importKeyword = expect(Keyword.IMPORT);
4624 StringLiteral libraryUri = parseStringLiteral(); 4628 StringLiteral libraryUri = parseStringLiteral();
4625 Token asToken = null; 4629 Token asToken = null;
4626 SimpleIdentifier prefix = null; 4630 SimpleIdentifier prefix = null;
4627 if (matches(Keyword.AS)) { 4631 if (matches(Keyword.AS)) {
4628 asToken = andAdvance; 4632 asToken = andAdvance;
4629 prefix = parseSimpleIdentifier(); 4633 prefix = parseSimpleIdentifier();
4630 } 4634 }
4631 List<Combinator> combinators = parseCombinators(); 4635 List<Combinator> combinators = parseCombinators();
4632 Token semicolon = expect2(TokenType.SEMICOLON); 4636 Token semicolon = expect2(TokenType.SEMICOLON);
4633 return new ImportDirective.full(commentAndMetadata.comment, commentAndMetada ta.metadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon) ; 4637 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon);
4634 } 4638 }
4635 4639
4636 /** 4640 /**
4637 * Parse a list of initialized identifiers. 4641 * Parse a list of initialized identifiers.
4638 * 4642 *
4639 * <pre> 4643 * <pre>
4640 * ?? ::= 4644 * ?? ::=
4641 * 'static'? ('var' | type) initializedIdentifierList ';' 4645 * 'static'? ('var' | type) initializedIdentifierList ';'
4642 * | 'final' type? initializedIdentifierList ';' 4646 * | 'final' type? initializedIdentifierList ';'
4643 * 4647 *
4644 * initializedIdentifierList ::= 4648 * initializedIdentifierList ::=
4645 * initializedIdentifier (',' initializedIdentifier)* 4649 * initializedIdentifier (',' initializedIdentifier)*
4646 * 4650 *
4647 * initializedIdentifier ::= 4651 * initializedIdentifier ::=
4648 * identifier ('=' expression)? 4652 * identifier ('=' expression)?
4649 * </pre> 4653 * </pre>
4650 * 4654 *
4651 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 4655 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
4652 * declaration 4656 * declaration
4653 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic 4657 * @param staticKeyword the static keyword, or `null` if the getter is not sta tic
4654 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 4658 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
4655 * there is no keyword 4659 * there is no keyword
4656 * @param type the type that has already been parsed, or `null` if 'var' was p rovided 4660 * @param type the type that has already been parsed, or `null` if 'var' was p rovided
4657 * @return the getter that was parsed 4661 * @return the getter that was parsed
4658 */ 4662 */
4659 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) { 4663 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) {
4660 VariableDeclarationList fieldList = parseVariableDeclarationList2(null, keyw ord, type); 4664 VariableDeclarationList fieldList = parseVariableDeclarationList2(null, keyw ord, type);
4661 return new FieldDeclaration.full(commentAndMetadata.comment, commentAndMetad ata.metadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON)); 4665 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetadata.m etadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON));
4662 } 4666 }
4663 4667
4664 /** 4668 /**
4665 * Parse an instance creation expression. 4669 * Parse an instance creation expression.
4666 * 4670 *
4667 * <pre> 4671 * <pre>
4668 * instanceCreationExpression ::= 4672 * instanceCreationExpression ::=
4669 * ('new' | 'const') type ('.' identifier)? argumentList 4673 * ('new' | 'const') type ('.' identifier)? argumentList
4670 * </pre> 4674 * </pre>
4671 * 4675 *
4672 * @param keyword the 'new' or 'const' keyword that introduces the expression 4676 * @param keyword the 'new' or 'const' keyword that introduces the expression
4673 * @return the instance creation expression that was parsed 4677 * @return the instance creation expression that was parsed
4674 */ 4678 */
4675 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { 4679 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) {
4676 ConstructorName constructorName = parseConstructorName(); 4680 ConstructorName constructorName = parseConstructorName();
4677 ArgumentList argumentList = parseArgumentList(); 4681 ArgumentList argumentList = parseArgumentList();
4678 return new InstanceCreationExpression.full(keyword, constructorName, argumen tList); 4682 return new InstanceCreationExpression(keyword, constructorName, argumentList );
4679 } 4683 }
4680 4684
4681 /** 4685 /**
4682 * Parse a library directive. 4686 * Parse a library directive.
4683 * 4687 *
4684 * <pre> 4688 * <pre>
4685 * libraryDirective ::= 4689 * libraryDirective ::=
4686 * metadata 'library' identifier ';' 4690 * metadata 'library' identifier ';'
4687 * </pre> 4691 * </pre>
4688 * 4692 *
4689 * @param commentAndMetadata the metadata to be associated with the directive 4693 * @param commentAndMetadata the metadata to be associated with the directive
4690 * @return the library directive that was parsed 4694 * @return the library directive that was parsed
4691 */ 4695 */
4692 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) { 4696 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) {
4693 Token keyword = expect(Keyword.LIBRARY); 4697 Token keyword = expect(Keyword.LIBRARY);
4694 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword); 4698 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword);
4695 Token semicolon = expect2(TokenType.SEMICOLON); 4699 Token semicolon = expect2(TokenType.SEMICOLON);
4696 return new LibraryDirective.full(commentAndMetadata.comment, commentAndMetad ata.metadata, keyword, libraryName, semicolon); 4700 return new LibraryDirective(commentAndMetadata.comment, commentAndMetadata.m etadata, keyword, libraryName, semicolon);
4697 } 4701 }
4698 4702
4699 /** 4703 /**
4700 * Parse a library name. 4704 * Parse a library name.
4701 * 4705 *
4702 * <pre> 4706 * <pre>
4703 * libraryName ::= 4707 * libraryName ::=
4704 * libraryIdentifier 4708 * libraryIdentifier
4705 * </pre> 4709 * </pre>
4706 * 4710 *
4707 * @param missingNameError the error code to be used if the library name is mi ssing 4711 * @param missingNameError the error code to be used if the library name is mi ssing
4708 * @param missingNameToken the token associated with the error produced if the library name is 4712 * @param missingNameToken the token associated with the error produced if the library name is
4709 * missing 4713 * missing
4710 * @return the library name that was parsed 4714 * @return the library name that was parsed
4711 */ 4715 */
4712 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) { 4716 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) {
4713 if (matchesIdentifier()) { 4717 if (matchesIdentifier()) {
4714 return parseLibraryIdentifier(); 4718 return parseLibraryIdentifier();
4715 } else if (matches5(TokenType.STRING)) { 4719 } else if (matches5(TokenType.STRING)) {
4716 StringLiteral string = parseStringLiteral(); 4720 StringLiteral string = parseStringLiteral();
4717 reportError9(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); 4721 reportError9(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []);
4718 } else { 4722 } else {
4719 reportError11(missingNameError, missingNameToken, []); 4723 reportError11(missingNameError, missingNameToken, []);
4720 } 4724 }
4721 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 4725 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
4722 components.add(createSyntheticIdentifier()); 4726 components.add(createSyntheticIdentifier());
4723 return new LibraryIdentifier.full(components); 4727 return new LibraryIdentifier(components);
4724 } 4728 }
4725 4729
4726 /** 4730 /**
4727 * Parse a list literal. 4731 * Parse a list literal.
4728 * 4732 *
4729 * <pre> 4733 * <pre>
4730 * listLiteral ::= 4734 * listLiteral ::=
4731 * 'const'? typeArguments? '[' (expressionList ','?)? ']' 4735 * 'const'? typeArguments? '[' (expressionList ','?)? ']'
4732 * </pre> 4736 * </pre>
4733 * 4737 *
4734 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4738 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
4735 * no modifier 4739 * no modifier
4736 * @param typeArguments the type arguments appearing before the literal, or `n ull` if there 4740 * @param typeArguments the type arguments appearing before the literal, or `n ull` if there
4737 * are no type arguments 4741 * are no type arguments
4738 * @return the list literal that was parsed 4742 * @return the list literal that was parsed
4739 */ 4743 */
4740 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { 4744 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) {
4741 if (matches5(TokenType.INDEX)) { 4745 if (matches5(TokenType.INDEX)) {
4742 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset); 4746 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset);
4743 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1); 4747 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1);
4744 leftBracket.endToken = rightBracket; 4748 leftBracket.endToken = rightBracket;
4745 rightBracket.setNext(_currentToken.next); 4749 rightBracket.setNext(_currentToken.next);
4746 leftBracket.setNext(rightBracket); 4750 leftBracket.setNext(rightBracket);
4747 _currentToken.previous.setNext(leftBracket); 4751 _currentToken.previous.setNext(leftBracket);
4748 _currentToken = _currentToken.next; 4752 _currentToken = _currentToken.next;
4749 return new ListLiteral.full(modifier, typeArguments, leftBracket, null, ri ghtBracket); 4753 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket);
4750 } 4754 }
4751 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET); 4755 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET);
4752 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4756 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4753 return new ListLiteral.full(modifier, typeArguments, leftBracket, null, an dAdvance); 4757 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce);
4754 } 4758 }
4755 List<Expression> elements = new List<Expression>(); 4759 List<Expression> elements = new List<Expression>();
4756 elements.add(parseExpression2()); 4760 elements.add(parseExpression2());
4757 while (optional(TokenType.COMMA)) { 4761 while (optional(TokenType.COMMA)) {
4758 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 4762 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
4759 return new ListLiteral.full(modifier, typeArguments, leftBracket, elemen ts, andAdvance); 4763 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance);
4760 } 4764 }
4761 elements.add(parseExpression2()); 4765 elements.add(parseExpression2());
4762 } 4766 }
4763 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 4767 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
4764 return new ListLiteral.full(modifier, typeArguments, leftBracket, elements, rightBracket); 4768 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket);
4765 } 4769 }
4766 4770
4767 /** 4771 /**
4768 * Parse a list or map literal. 4772 * Parse a list or map literal.
4769 * 4773 *
4770 * <pre> 4774 * <pre>
4771 * listOrMapLiteral ::= 4775 * listOrMapLiteral ::=
4772 * listLiteral 4776 * listLiteral
4773 * | mapLiteral 4777 * | mapLiteral
4774 * </pre> 4778 * </pre>
4775 * 4779 *
4776 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4780 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
4777 * no modifier 4781 * no modifier
4778 * @return the list or map literal that was parsed 4782 * @return the list or map literal that was parsed
4779 */ 4783 */
4780 TypedLiteral parseListOrMapLiteral(Token modifier) { 4784 TypedLiteral parseListOrMapLiteral(Token modifier) {
4781 TypeArgumentList typeArguments = null; 4785 TypeArgumentList typeArguments = null;
4782 if (matches5(TokenType.LT)) { 4786 if (matches5(TokenType.LT)) {
4783 typeArguments = parseTypeArgumentList(); 4787 typeArguments = parseTypeArgumentList();
4784 } 4788 }
4785 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 4789 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
4786 return parseMapLiteral(modifier, typeArguments); 4790 return parseMapLiteral(modifier, typeArguments);
4787 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 4791 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
4788 return parseListLiteral(modifier, typeArguments); 4792 return parseListLiteral(modifier, typeArguments);
4789 } 4793 }
4790 reportError10(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); 4794 reportError10(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []);
4791 return new ListLiteral.full(modifier, typeArguments, createSyntheticToken2(T okenType.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUAR E_BRACKET)); 4795 return new ListLiteral(modifier, typeArguments, createSyntheticToken2(TokenT ype.OPEN_SQUARE_BRACKET), null, createSyntheticToken2(TokenType.CLOSE_SQUARE_BRA CKET));
4792 } 4796 }
4793 4797
4794 /** 4798 /**
4795 * Parse a logical and expression. 4799 * Parse a logical and expression.
4796 * 4800 *
4797 * <pre> 4801 * <pre>
4798 * logicalAndExpression ::= 4802 * logicalAndExpression ::=
4799 * equalityExpression ('&&' equalityExpression)* 4803 * equalityExpression ('&&' equalityExpression)*
4800 * </pre> 4804 * </pre>
4801 * 4805 *
4802 * @return the logical and expression that was parsed 4806 * @return the logical and expression that was parsed
4803 */ 4807 */
4804 Expression parseLogicalAndExpression() { 4808 Expression parseLogicalAndExpression() {
4805 Expression expression = parseEqualityExpression(); 4809 Expression expression = parseEqualityExpression();
4806 while (matches5(TokenType.AMPERSAND_AMPERSAND)) { 4810 while (matches5(TokenType.AMPERSAND_AMPERSAND)) {
4807 Token operator = andAdvance; 4811 Token operator = andAdvance;
4808 expression = new BinaryExpression.full(expression, operator, parseEquality Expression()); 4812 expression = new BinaryExpression(expression, operator, parseEqualityExpre ssion());
4809 } 4813 }
4810 return expression; 4814 return expression;
4811 } 4815 }
4812 4816
4813 /** 4817 /**
4814 * Parse a map literal. 4818 * Parse a map literal.
4815 * 4819 *
4816 * <pre> 4820 * <pre>
4817 * mapLiteral ::= 4821 * mapLiteral ::=
4818 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}' 4822 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ',' ?)? '}'
4819 * </pre> 4823 * </pre>
4820 * 4824 *
4821 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is 4825 * @param modifier the 'const' modifier appearing before the literal, or `null ` if there is
4822 * no modifier 4826 * no modifier
4823 * @param typeArguments the type arguments that were declared, or `null` if th ere are no 4827 * @param typeArguments the type arguments that were declared, or `null` if th ere are no
4824 * type arguments 4828 * type arguments
4825 * @return the map literal that was parsed 4829 * @return the map literal that was parsed
4826 */ 4830 */
4827 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { 4831 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
4828 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 4832 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
4829 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); 4833 List<MapLiteralEntry> entries = new List<MapLiteralEntry>();
4830 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 4834 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
4831 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, andAdvance); 4835 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd vance);
4832 } 4836 }
4833 entries.add(parseMapLiteralEntry()); 4837 entries.add(parseMapLiteralEntry());
4834 while (optional(TokenType.COMMA)) { 4838 while (optional(TokenType.COMMA)) {
4835 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 4839 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
4836 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries , andAdvance); 4840 return new MapLiteral(modifier, typeArguments, leftBracket, entries, and Advance);
4837 } 4841 }
4838 entries.add(parseMapLiteralEntry()); 4842 entries.add(parseMapLiteralEntry());
4839 } 4843 }
4840 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 4844 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
4841 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, ri ghtBracket); 4845 return new MapLiteral(modifier, typeArguments, leftBracket, entries, rightBr acket);
4842 } 4846 }
4843 4847
4844 /** 4848 /**
4845 * Parse a method declaration. 4849 * Parse a method declaration.
4846 * 4850 *
4847 * <pre> 4851 * <pre>
4848 * functionDeclaration ::= 4852 * functionDeclaration ::=
4849 * 'external'? 'static'? functionSignature functionBody 4853 * 'external'? 'static'? functionSignature functionBody
4850 * | 'external'? functionSignature ';' 4854 * | 'external'? functionSignature ';'
4851 * </pre> 4855 * </pre>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4886 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false); 4890 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.MISSING_FUNCTION_BODY, false);
4887 if (externalKeyword != null) { 4891 if (externalKeyword != null) {
4888 if (body is! EmptyFunctionBody) { 4892 if (body is! EmptyFunctionBody) {
4889 reportError9(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); 4893 reportError9(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []);
4890 } 4894 }
4891 } else if (staticKeyword != null) { 4895 } else if (staticKeyword != null) {
4892 if (body is EmptyFunctionBody) { 4896 if (body is EmptyFunctionBody) {
4893 reportError9(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); 4897 reportError9(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
4894 } 4898 }
4895 } 4899 }
4896 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, null, null, name, par ameters, body); 4900 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body);
4897 } 4901 }
4898 4902
4899 /** 4903 /**
4900 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any 4904 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any
4901 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as 4905 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as
4902 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are 4906 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are
4903 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`. 4907 * reported in one of the methods whose name is prefixed with `validateModifie rsFor`.
4904 * 4908 *
4905 * <pre> 4909 * <pre>
4906 * modifiers ::= 4910 * modifiers ::=
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
4979 * multiplicativeExpression ::= 4983 * multiplicativeExpression ::=
4980 * unaryExpression (multiplicativeOperator unaryExpression)* 4984 * unaryExpression (multiplicativeOperator unaryExpression)*
4981 * | 'super' (multiplicativeOperator unaryExpression)+ 4985 * | 'super' (multiplicativeOperator unaryExpression)+
4982 * </pre> 4986 * </pre>
4983 * 4987 *
4984 * @return the multiplicative expression that was parsed 4988 * @return the multiplicative expression that was parsed
4985 */ 4989 */
4986 Expression parseMultiplicativeExpression() { 4990 Expression parseMultiplicativeExpression() {
4987 Expression expression; 4991 Expression expression;
4988 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat or) { 4992 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat or) {
4989 expression = new SuperExpression.full(andAdvance); 4993 expression = new SuperExpression(andAdvance);
4990 } else { 4994 } else {
4991 expression = parseUnaryExpression(); 4995 expression = parseUnaryExpression();
4992 } 4996 }
4993 while (_currentToken.type.isMultiplicativeOperator) { 4997 while (_currentToken.type.isMultiplicativeOperator) {
4994 Token operator = andAdvance; 4998 Token operator = andAdvance;
4995 expression = new BinaryExpression.full(expression, operator, parseUnaryExp ression()); 4999 expression = new BinaryExpression(expression, operator, parseUnaryExpressi on());
4996 } 5000 }
4997 return expression; 5001 return expression;
4998 } 5002 }
4999 5003
5000 /** 5004 /**
5001 * Parse a class native clause. 5005 * Parse a class native clause.
5002 * 5006 *
5003 * <pre> 5007 * <pre>
5004 * classNativeClause ::= 5008 * classNativeClause ::=
5005 * 'native' name 5009 * 'native' name
5006 * </pre> 5010 * </pre>
5007 * 5011 *
5008 * @return the class native clause that was parsed 5012 * @return the class native clause that was parsed
5009 */ 5013 */
5010 NativeClause parseNativeClause() { 5014 NativeClause parseNativeClause() {
5011 Token keyword = andAdvance; 5015 Token keyword = andAdvance;
5012 StringLiteral name = parseStringLiteral(); 5016 StringLiteral name = parseStringLiteral();
5013 return new NativeClause.full(keyword, name); 5017 return new NativeClause(keyword, name);
5014 } 5018 }
5015 5019
5016 /** 5020 /**
5017 * Parse a new expression. 5021 * Parse a new expression.
5018 * 5022 *
5019 * <pre> 5023 * <pre>
5020 * newExpression ::= 5024 * newExpression ::=
5021 * instanceCreationExpression 5025 * instanceCreationExpression
5022 * </pre> 5026 * </pre>
5023 * 5027 *
(...skipping 23 matching lines...) Expand all
5047 * </pre> 5051 * </pre>
5048 * 5052 *
5049 * @return the non-labeled statement that was parsed 5053 * @return the non-labeled statement that was parsed
5050 */ 5054 */
5051 Statement parseNonLabeledStatement() { 5055 Statement parseNonLabeledStatement() {
5052 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 5056 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
5053 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5057 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
5054 if (matches4(peek(), TokenType.STRING)) { 5058 if (matches4(peek(), TokenType.STRING)) {
5055 Token afterString = skipStringLiteral(_currentToken.next); 5059 Token afterString = skipStringLiteral(_currentToken.next);
5056 if (afterString != null && identical(afterString.type, TokenType.COLON)) { 5060 if (afterString != null && identical(afterString.type, TokenType.COLON)) {
5057 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT ype.SEMICOLON)); 5061 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON));
5058 } 5062 }
5059 } 5063 }
5060 return parseBlock(); 5064 return parseBlock();
5061 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) { 5065 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword) {
5062 Keyword keyword = (_currentToken as KeywordToken).keyword; 5066 Keyword keyword = (_currentToken as KeywordToken).keyword;
5063 if (identical(keyword, Keyword.ASSERT)) { 5067 if (identical(keyword, Keyword.ASSERT)) {
5064 return parseAssertStatement(); 5068 return parseAssertStatement();
5065 } else if (identical(keyword, Keyword.BREAK)) { 5069 } else if (identical(keyword, Keyword.BREAK)) {
5066 return parseBreakStatement(); 5070 return parseBreakStatement();
5067 } else if (identical(keyword, Keyword.CONTINUE)) { 5071 } else if (identical(keyword, Keyword.CONTINUE)) {
5068 return parseContinueStatement(); 5072 return parseContinueStatement();
5069 } else if (identical(keyword, Keyword.DO)) { 5073 } else if (identical(keyword, Keyword.DO)) {
5070 return parseDoStatement(); 5074 return parseDoStatement();
5071 } else if (identical(keyword, Keyword.FOR)) { 5075 } else if (identical(keyword, Keyword.FOR)) {
5072 return parseForStatement(); 5076 return parseForStatement();
5073 } else if (identical(keyword, Keyword.IF)) { 5077 } else if (identical(keyword, Keyword.IF)) {
5074 return parseIfStatement(); 5078 return parseIfStatement();
5075 } else if (identical(keyword, Keyword.RETHROW)) { 5079 } else if (identical(keyword, Keyword.RETHROW)) {
5076 return new ExpressionStatement.full(parseRethrowExpression(), expect2(To kenType.SEMICOLON)); 5080 return new ExpressionStatement(parseRethrowExpression(), expect2(TokenTy pe.SEMICOLON));
5077 } else if (identical(keyword, Keyword.RETURN)) { 5081 } else if (identical(keyword, Keyword.RETURN)) {
5078 return parseReturnStatement(); 5082 return parseReturnStatement();
5079 } else if (identical(keyword, Keyword.SWITCH)) { 5083 } else if (identical(keyword, Keyword.SWITCH)) {
5080 return parseSwitchStatement(); 5084 return parseSwitchStatement();
5081 } else if (identical(keyword, Keyword.THROW)) { 5085 } else if (identical(keyword, Keyword.THROW)) {
5082 return new ExpressionStatement.full(parseThrowExpression(), expect2(Toke nType.SEMICOLON)); 5086 return new ExpressionStatement(parseThrowExpression(), expect2(TokenType .SEMICOLON));
5083 } else if (identical(keyword, Keyword.TRY)) { 5087 } else if (identical(keyword, Keyword.TRY)) {
5084 return parseTryStatement(); 5088 return parseTryStatement();
5085 } else if (identical(keyword, Keyword.WHILE)) { 5089 } else if (identical(keyword, Keyword.WHILE)) {
5086 return parseWhileStatement(); 5090 return parseWhileStatement();
5087 } else if (identical(keyword, Keyword.VAR) || identical(keyword, Keyword.F INAL)) { 5091 } else if (identical(keyword, Keyword.VAR) || identical(keyword, Keyword.F INAL)) {
5088 return parseVariableDeclarationStatement(commentAndMetadata); 5092 return parseVariableDeclarationStatement(commentAndMetadata);
5089 } else if (identical(keyword, Keyword.VOID)) { 5093 } else if (identical(keyword, Keyword.VOID)) {
5090 TypeName returnType = parseReturnType(); 5094 TypeName returnType = parseReturnType();
5091 if (matchesIdentifier() && matchesAny(peek(), [ 5095 if (matchesIdentifier() && matchesAny(peek(), [
5092 TokenType.OPEN_PAREN, 5096 TokenType.OPEN_PAREN,
5093 TokenType.OPEN_CURLY_BRACKET, 5097 TokenType.OPEN_CURLY_BRACKET,
5094 TokenType.FUNCTION])) { 5098 TokenType.FUNCTION])) {
5095 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe); 5099 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe);
5096 } else { 5100 } else {
5097 if (matchesIdentifier()) { 5101 if (matchesIdentifier()) {
5098 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 5102 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
5099 reportError9(ParserErrorCode.VOID_VARIABLE, returnType, []); 5103 reportError9(ParserErrorCode.VOID_VARIABLE, returnType, []);
5100 return parseVariableDeclarationStatement(commentAndMetadata); 5104 return parseVariableDeclarationStatement(commentAndMetadata);
5101 } 5105 }
5102 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5106 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5103 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType); 5107 return parseVariableDeclarationStatement2(commentAndMetadata, null, returnType);
5104 } 5108 }
5105 reportError10(ParserErrorCode.MISSING_STATEMENT, []); 5109 reportError10(ParserErrorCode.MISSING_STATEMENT, []);
5106 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOL ON)); 5110 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5107 } 5111 }
5108 } else if (identical(keyword, Keyword.CONST)) { 5112 } else if (identical(keyword, Keyword.CONST)) {
5109 if (matchesAny(peek(), [ 5113 if (matchesAny(peek(), [
5110 TokenType.LT, 5114 TokenType.LT,
5111 TokenType.OPEN_CURLY_BRACKET, 5115 TokenType.OPEN_CURLY_BRACKET,
5112 TokenType.OPEN_SQUARE_BRACKET, 5116 TokenType.OPEN_SQUARE_BRACKET,
5113 TokenType.INDEX])) { 5117 TokenType.INDEX])) {
5114 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT ype.SEMICOLON)); 5118 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON));
5115 } else if (matches4(peek(), TokenType.IDENTIFIER)) { 5119 } else if (matches4(peek(), TokenType.IDENTIFIER)) {
5116 Token afterType = skipTypeName(peek()); 5120 Token afterType = skipTypeName(peek());
5117 if (afterType != null) { 5121 if (afterType != null) {
5118 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) { 5122 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) {
5119 return new ExpressionStatement.full(parseExpression2(), expect2(To kenType.SEMICOLON)); 5123 return new ExpressionStatement(parseExpression2(), expect2(TokenTy pe.SEMICOLON));
5120 } 5124 }
5121 } 5125 }
5122 } 5126 }
5123 return parseVariableDeclarationStatement(commentAndMetadata); 5127 return parseVariableDeclarationStatement(commentAndMetadata);
5124 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) { 5128 } else if (identical(keyword, Keyword.NEW) || identical(keyword, Keyword.T RUE) || identical(keyword, Keyword.FALSE) || identical(keyword, Keyword.NULL) || identical(keyword, Keyword.SUPER) || identical(keyword, Keyword.THIS)) {
5125 return new ExpressionStatement.full(parseExpression2(), expect2(TokenTyp e.SEMICOLON)); 5129 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEM ICOLON));
5126 } else { 5130 } else {
5127 reportError10(ParserErrorCode.MISSING_STATEMENT, []); 5131 reportError10(ParserErrorCode.MISSING_STATEMENT, []);
5128 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOLON )); 5132 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5129 } 5133 }
5130 } else if (matches5(TokenType.SEMICOLON)) { 5134 } else if (matches5(TokenType.SEMICOLON)) {
5131 return parseEmptyStatement(); 5135 return parseEmptyStatement();
5132 } else if (isInitializedVariableDeclaration()) { 5136 } else if (isInitializedVariableDeclaration()) {
5133 return parseVariableDeclarationStatement(commentAndMetadata); 5137 return parseVariableDeclarationStatement(commentAndMetadata);
5134 } else if (isFunctionDeclaration()) { 5138 } else if (isFunctionDeclaration()) {
5135 return parseFunctionDeclarationStatement(); 5139 return parseFunctionDeclarationStatement();
5136 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 5140 } else if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
5137 reportError10(ParserErrorCode.MISSING_STATEMENT, []); 5141 reportError10(ParserErrorCode.MISSING_STATEMENT, []);
5138 return new EmptyStatement.full(createSyntheticToken2(TokenType.SEMICOLON)) ; 5142 return new EmptyStatement(createSyntheticToken2(TokenType.SEMICOLON));
5139 } else { 5143 } else {
5140 return new ExpressionStatement.full(parseExpression2(), expect2(TokenType. SEMICOLON)); 5144 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEMIC OLON));
5141 } 5145 }
5142 } 5146 }
5143 5147
5144 /** 5148 /**
5145 * Parse an operator declaration. 5149 * Parse an operator declaration.
5146 * 5150 *
5147 * <pre> 5151 * <pre>
5148 * operatorDeclaration ::= 5152 * operatorDeclaration ::=
5149 * operatorSignature (';' | functionBody) 5153 * operatorSignature (';' | functionBody)
5150 * 5154 *
(...skipping 12 matching lines...) Expand all
5163 Token operatorKeyword; 5167 Token operatorKeyword;
5164 if (matches(Keyword.OPERATOR)) { 5168 if (matches(Keyword.OPERATOR)) {
5165 operatorKeyword = andAdvance; 5169 operatorKeyword = andAdvance;
5166 } else { 5170 } else {
5167 reportError11(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ; 5171 reportError11(ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken, []) ;
5168 operatorKeyword = createSyntheticToken(Keyword.OPERATOR); 5172 operatorKeyword = createSyntheticToken(Keyword.OPERATOR);
5169 } 5173 }
5170 if (!_currentToken.isUserDefinableOperator) { 5174 if (!_currentToken.isUserDefinableOperator) {
5171 reportError10(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]); 5175 reportError10(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken. lexeme]);
5172 } 5176 }
5173 SimpleIdentifier name = new SimpleIdentifier.full(andAdvance); 5177 SimpleIdentifier name = new SimpleIdentifier(andAdvance);
5174 if (matches5(TokenType.EQ)) { 5178 if (matches5(TokenType.EQ)) {
5175 Token previous = _currentToken.previous; 5179 Token previous = _currentToken.previous;
5176 if ((matches4(previous, TokenType.EQ_EQ) || matches4(previous, TokenType.B ANG_EQ)) && _currentToken.offset == previous.offset + 2) { 5180 if ((matches4(previous, TokenType.EQ_EQ) || matches4(previous, TokenType.B ANG_EQ)) && _currentToken.offset == previous.offset + 2) {
5177 reportError10(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]); 5181 reportError10(ParserErrorCode.INVALID_OPERATOR, ["${previous.lexeme}${_c urrentToken.lexeme}"]);
5178 advance(); 5182 advance();
5179 } 5183 }
5180 } 5184 }
5181 FormalParameterList parameters = parseFormalParameterList(); 5185 FormalParameterList parameters = parseFormalParameterList();
5182 validateFormalParameterList(parameters); 5186 validateFormalParameterList(parameters);
5183 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false); 5187 FunctionBody body = parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION _BODY, false);
5184 if (externalKeyword != null && body is! EmptyFunctionBody) { 5188 if (externalKeyword != null && body is! EmptyFunctionBody) {
5185 reportError10(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); 5189 reportError10(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []);
5186 } 5190 }
5187 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, null, returnType, null, operatorKeyword, name, p arameters, body); 5191 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body);
5188 } 5192 }
5189 5193
5190 /** 5194 /**
5191 * Parse a return type if one is given, otherwise return `null` without advanc ing. 5195 * Parse a return type if one is given, otherwise return `null` without advanc ing.
5192 * 5196 *
5193 * @return the return type that was parsed 5197 * @return the return type that was parsed
5194 */ 5198 */
5195 TypeName parseOptionalReturnType() { 5199 TypeName parseOptionalReturnType() {
5196 if (matches(Keyword.VOID)) { 5200 if (matches(Keyword.VOID)) {
5197 return parseReturnType(); 5201 return parseReturnType();
(...skipping 18 matching lines...) Expand all
5216 * 5220 *
5217 * @param commentAndMetadata the metadata to be associated with the directive 5221 * @param commentAndMetadata the metadata to be associated with the directive
5218 * @return the part or part-of directive that was parsed 5222 * @return the part or part-of directive that was parsed
5219 */ 5223 */
5220 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) { 5224 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) {
5221 Token partKeyword = expect(Keyword.PART); 5225 Token partKeyword = expect(Keyword.PART);
5222 if (matches2(_OF)) { 5226 if (matches2(_OF)) {
5223 Token ofKeyword = andAdvance; 5227 Token ofKeyword = andAdvance;
5224 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword); 5228 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword);
5225 Token semicolon = expect2(TokenType.SEMICOLON); 5229 Token semicolon = expect2(TokenType.SEMICOLON);
5226 return new PartOfDirective.full(commentAndMetadata.comment, commentAndMeta data.metadata, partKeyword, ofKeyword, libraryName, semicolon); 5230 return new PartOfDirective(commentAndMetadata.comment, commentAndMetadata. metadata, partKeyword, ofKeyword, libraryName, semicolon);
5227 } 5231 }
5228 StringLiteral partUri = parseStringLiteral(); 5232 StringLiteral partUri = parseStringLiteral();
5229 Token semicolon = expect2(TokenType.SEMICOLON); 5233 Token semicolon = expect2(TokenType.SEMICOLON);
5230 return new PartDirective.full(commentAndMetadata.comment, commentAndMetadata .metadata, partKeyword, partUri, semicolon); 5234 return new PartDirective(commentAndMetadata.comment, commentAndMetadata.meta data, partKeyword, partUri, semicolon);
5231 } 5235 }
5232 5236
5233 /** 5237 /**
5234 * Parse a postfix expression. 5238 * Parse a postfix expression.
5235 * 5239 *
5236 * <pre> 5240 * <pre>
5237 * postfixExpression ::= 5241 * postfixExpression ::=
5238 * assignableExpression postfixOperator 5242 * assignableExpression postfixOperator
5239 * | primary selector* 5243 * | primary selector*
5240 * 5244 *
5241 * selector ::= 5245 * selector ::=
5242 * assignableSelector 5246 * assignableSelector
5243 * | argumentList 5247 * | argumentList
5244 * </pre> 5248 * </pre>
5245 * 5249 *
5246 * @return the postfix expression that was parsed 5250 * @return the postfix expression that was parsed
5247 */ 5251 */
5248 Expression parsePostfixExpression() { 5252 Expression parsePostfixExpression() {
5249 Expression operand = parseAssignableExpression(true); 5253 Expression operand = parseAssignableExpression(true);
5250 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PERIOD) || matches5(TokenType.OPEN_PAREN)) { 5254 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PERIOD) || matches5(TokenType.OPEN_PAREN)) {
5251 do { 5255 do {
5252 if (matches5(TokenType.OPEN_PAREN)) { 5256 if (matches5(TokenType.OPEN_PAREN)) {
5253 ArgumentList argumentList = parseArgumentList(); 5257 ArgumentList argumentList = parseArgumentList();
5254 if (operand is PropertyAccess) { 5258 if (operand is PropertyAccess) {
5255 PropertyAccess access = operand as PropertyAccess; 5259 PropertyAccess access = operand as PropertyAccess;
5256 operand = new MethodInvocation.full(access.target, access.operator, access.propertyName, argumentList); 5260 operand = new MethodInvocation(access.target, access.operator, acces s.propertyName, argumentList);
5257 } else { 5261 } else {
5258 operand = new FunctionExpressionInvocation.full(operand, argumentLis t); 5262 operand = new FunctionExpressionInvocation(operand, argumentList);
5259 } 5263 }
5260 } else { 5264 } else {
5261 operand = parseAssignableSelector(operand, true); 5265 operand = parseAssignableSelector(operand, true);
5262 } 5266 }
5263 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN)); 5267 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN));
5264 return operand; 5268 return operand;
5265 } 5269 }
5266 if (!_currentToken.type.isIncrementOperator) { 5270 if (!_currentToken.type.isIncrementOperator) {
5267 return operand; 5271 return operand;
5268 } 5272 }
5269 if (operand is Literal || operand is FunctionExpressionInvocation) { 5273 if (operand is Literal || operand is FunctionExpressionInvocation) {
5270 reportError10(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 5274 reportError10(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
5271 } 5275 }
5272 Token operator = andAdvance; 5276 Token operator = andAdvance;
5273 return new PostfixExpression.full(operand, operator); 5277 return new PostfixExpression(operand, operator);
5274 } 5278 }
5275 5279
5276 /** 5280 /**
5277 * Parse a primary expression. 5281 * Parse a primary expression.
5278 * 5282 *
5279 * <pre> 5283 * <pre>
5280 * primary ::= 5284 * primary ::=
5281 * thisExpression 5285 * thisExpression
5282 * | 'super' assignableSelector 5286 * | 'super' assignableSelector
5283 * | functionExpression 5287 * | functionExpression
(...skipping 11 matching lines...) Expand all
5295 * | stringLiteral 5299 * | stringLiteral
5296 * | symbolLiteral 5300 * | symbolLiteral
5297 * | mapLiteral 5301 * | mapLiteral
5298 * | listLiteral 5302 * | listLiteral
5299 * </pre> 5303 * </pre>
5300 * 5304 *
5301 * @return the primary expression that was parsed 5305 * @return the primary expression that was parsed
5302 */ 5306 */
5303 Expression parsePrimaryExpression() { 5307 Expression parsePrimaryExpression() {
5304 if (matches(Keyword.THIS)) { 5308 if (matches(Keyword.THIS)) {
5305 return new ThisExpression.full(andAdvance); 5309 return new ThisExpression(andAdvance);
5306 } else if (matches(Keyword.SUPER)) { 5310 } else if (matches(Keyword.SUPER)) {
5307 return parseAssignableSelector(new SuperExpression.full(andAdvance), false ); 5311 return parseAssignableSelector(new SuperExpression(andAdvance), false);
5308 } else if (matches(Keyword.NULL)) { 5312 } else if (matches(Keyword.NULL)) {
5309 return new NullLiteral.full(andAdvance); 5313 return new NullLiteral(andAdvance);
5310 } else if (matches(Keyword.FALSE)) { 5314 } else if (matches(Keyword.FALSE)) {
5311 return new BooleanLiteral.full(andAdvance, false); 5315 return new BooleanLiteral(andAdvance, false);
5312 } else if (matches(Keyword.TRUE)) { 5316 } else if (matches(Keyword.TRUE)) {
5313 return new BooleanLiteral.full(andAdvance, true); 5317 return new BooleanLiteral(andAdvance, true);
5314 } else if (matches5(TokenType.DOUBLE)) { 5318 } else if (matches5(TokenType.DOUBLE)) {
5315 Token token = andAdvance; 5319 Token token = andAdvance;
5316 double value = 0.0; 5320 double value = 0.0;
5317 try { 5321 try {
5318 value = double.parse(token.lexeme); 5322 value = double.parse(token.lexeme);
5319 } on FormatException catch (exception) { 5323 } on FormatException catch (exception) {
5320 } 5324 }
5321 return new DoubleLiteral.full(token, value); 5325 return new DoubleLiteral(token, value);
5322 } else if (matches5(TokenType.HEXADECIMAL)) { 5326 } else if (matches5(TokenType.HEXADECIMAL)) {
5323 Token token = andAdvance; 5327 Token token = andAdvance;
5324 int value = null; 5328 int value = null;
5325 try { 5329 try {
5326 value = int.parse(token.lexeme.substring(2), radix: 16); 5330 value = int.parse(token.lexeme.substring(2), radix: 16);
5327 } on FormatException catch (exception) { 5331 } on FormatException catch (exception) {
5328 } 5332 }
5329 return new IntegerLiteral.full(token, value); 5333 return new IntegerLiteral(token, value);
5330 } else if (matches5(TokenType.INT)) { 5334 } else if (matches5(TokenType.INT)) {
5331 Token token = andAdvance; 5335 Token token = andAdvance;
5332 int value = null; 5336 int value = null;
5333 try { 5337 try {
5334 value = int.parse(token.lexeme); 5338 value = int.parse(token.lexeme);
5335 } on FormatException catch (exception) { 5339 } on FormatException catch (exception) {
5336 } 5340 }
5337 return new IntegerLiteral.full(token, value); 5341 return new IntegerLiteral(token, value);
5338 } else if (matches5(TokenType.STRING)) { 5342 } else if (matches5(TokenType.STRING)) {
5339 return parseStringLiteral(); 5343 return parseStringLiteral();
5340 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 5344 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
5341 return parseMapLiteral(null, null); 5345 return parseMapLiteral(null, null);
5342 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 5346 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
5343 return parseListLiteral(null, null); 5347 return parseListLiteral(null, null);
5344 } else if (matchesIdentifier()) { 5348 } else if (matchesIdentifier()) {
5345 return parsePrefixedIdentifier(); 5349 return parsePrefixedIdentifier();
5346 } else if (matches(Keyword.NEW)) { 5350 } else if (matches(Keyword.NEW)) {
5347 return parseNewExpression(); 5351 return parseNewExpression();
5348 } else if (matches(Keyword.CONST)) { 5352 } else if (matches(Keyword.CONST)) {
5349 return parseConstExpression(); 5353 return parseConstExpression();
5350 } else if (matches5(TokenType.OPEN_PAREN)) { 5354 } else if (matches5(TokenType.OPEN_PAREN)) {
5351 if (isFunctionExpression(_currentToken)) { 5355 if (isFunctionExpression(_currentToken)) {
5352 return parseFunctionExpression(); 5356 return parseFunctionExpression();
5353 } 5357 }
5354 Token leftParenthesis = andAdvance; 5358 Token leftParenthesis = andAdvance;
5355 Expression expression = parseExpression2(); 5359 Expression expression = parseExpression2();
5356 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5360 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5357 return new ParenthesizedExpression.full(leftParenthesis, expression, right Parenthesis); 5361 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis);
5358 } else if (matches5(TokenType.LT)) { 5362 } else if (matches5(TokenType.LT)) {
5359 return parseListOrMapLiteral(null); 5363 return parseListOrMapLiteral(null);
5360 } else if (matches5(TokenType.QUESTION)) { 5364 } else if (matches5(TokenType.QUESTION)) {
5361 return parseArgumentDefinitionTest(); 5365 return parseArgumentDefinitionTest();
5362 } else if (matches(Keyword.VOID)) { 5366 } else if (matches(Keyword.VOID)) {
5363 reportError10(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 5367 reportError10(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
5364 advance(); 5368 advance();
5365 return parsePrimaryExpression(); 5369 return parsePrimaryExpression();
5366 } else if (matches5(TokenType.HASH)) { 5370 } else if (matches5(TokenType.HASH)) {
5367 return parseSymbolLiteral(); 5371 return parseSymbolLiteral();
(...skipping 15 matching lines...) Expand all
5383 */ 5387 */
5384 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() { 5388 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() {
5385 Token keyword = expect(Keyword.THIS); 5389 Token keyword = expect(Keyword.THIS);
5386 Token period = null; 5390 Token period = null;
5387 SimpleIdentifier constructorName = null; 5391 SimpleIdentifier constructorName = null;
5388 if (matches5(TokenType.PERIOD)) { 5392 if (matches5(TokenType.PERIOD)) {
5389 period = andAdvance; 5393 period = andAdvance;
5390 constructorName = parseSimpleIdentifier(); 5394 constructorName = parseSimpleIdentifier();
5391 } 5395 }
5392 ArgumentList argumentList = parseArgumentList(); 5396 ArgumentList argumentList = parseArgumentList();
5393 return new RedirectingConstructorInvocation.full(keyword, period, constructo rName, argumentList); 5397 return new RedirectingConstructorInvocation(keyword, period, constructorName , argumentList);
5394 } 5398 }
5395 5399
5396 /** 5400 /**
5397 * Parse a relational expression. 5401 * Parse a relational expression.
5398 * 5402 *
5399 * <pre> 5403 * <pre>
5400 * relationalExpression ::= 5404 * relationalExpression ::=
5401 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)? 5405 * bitwiseOrExpression ('is' '!'? type | 'as' type | relationalOperator bi twiseOrExpression)?
5402 * | 'super' relationalOperator bitwiseOrExpression 5406 * | 'super' relationalOperator bitwiseOrExpression
5403 * </pre> 5407 * </pre>
5404 * 5408 *
5405 * @return the relational expression that was parsed 5409 * @return the relational expression that was parsed
5406 */ 5410 */
5407 Expression parseRelationalExpression() { 5411 Expression parseRelationalExpression() {
5408 if (matches(Keyword.SUPER) && _currentToken.next.type.isRelationalOperator) { 5412 if (matches(Keyword.SUPER) && _currentToken.next.type.isRelationalOperator) {
5409 Expression expression = new SuperExpression.full(andAdvance); 5413 Expression expression = new SuperExpression(andAdvance);
5410 Token operator = andAdvance; 5414 Token operator = andAdvance;
5411 expression = new BinaryExpression.full(expression, operator, parseBitwiseO rExpression()); 5415 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession());
5412 return expression; 5416 return expression;
5413 } 5417 }
5414 Expression expression = parseBitwiseOrExpression(); 5418 Expression expression = parseBitwiseOrExpression();
5415 if (matches(Keyword.AS)) { 5419 if (matches(Keyword.AS)) {
5416 Token asOperator = andAdvance; 5420 Token asOperator = andAdvance;
5417 expression = new AsExpression.full(expression, asOperator, parseTypeName() ); 5421 expression = new AsExpression(expression, asOperator, parseTypeName());
5418 } else if (matches(Keyword.IS)) { 5422 } else if (matches(Keyword.IS)) {
5419 Token isOperator = andAdvance; 5423 Token isOperator = andAdvance;
5420 Token notOperator = null; 5424 Token notOperator = null;
5421 if (matches5(TokenType.BANG)) { 5425 if (matches5(TokenType.BANG)) {
5422 notOperator = andAdvance; 5426 notOperator = andAdvance;
5423 } 5427 }
5424 expression = new IsExpression.full(expression, isOperator, notOperator, pa rseTypeName()); 5428 expression = new IsExpression(expression, isOperator, notOperator, parseTy peName());
5425 } else if (_currentToken.type.isRelationalOperator) { 5429 } else if (_currentToken.type.isRelationalOperator) {
5426 Token operator = andAdvance; 5430 Token operator = andAdvance;
5427 expression = new BinaryExpression.full(expression, operator, parseBitwiseO rExpression()); 5431 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession());
5428 } 5432 }
5429 return expression; 5433 return expression;
5430 } 5434 }
5431 5435
5432 /** 5436 /**
5433 * Parse a rethrow expression. 5437 * Parse a rethrow expression.
5434 * 5438 *
5435 * <pre> 5439 * <pre>
5436 * rethrowExpression ::= 5440 * rethrowExpression ::=
5437 * 'rethrow' 5441 * 'rethrow'
5438 * </pre> 5442 * </pre>
5439 * 5443 *
5440 * @return the rethrow expression that was parsed 5444 * @return the rethrow expression that was parsed
5441 */ 5445 */
5442 Expression parseRethrowExpression() => new RethrowExpression.full(expect(Keywo rd.RETHROW)); 5446 Expression parseRethrowExpression() => new RethrowExpression(expect(Keyword.RE THROW));
5443 5447
5444 /** 5448 /**
5445 * Parse a return statement. 5449 * Parse a return statement.
5446 * 5450 *
5447 * <pre> 5451 * <pre>
5448 * returnStatement ::= 5452 * returnStatement ::=
5449 * 'return' expression? ';' 5453 * 'return' expression? ';'
5450 * </pre> 5454 * </pre>
5451 * 5455 *
5452 * @return the return statement that was parsed 5456 * @return the return statement that was parsed
5453 */ 5457 */
5454 Statement parseReturnStatement() { 5458 Statement parseReturnStatement() {
5455 Token returnKeyword = expect(Keyword.RETURN); 5459 Token returnKeyword = expect(Keyword.RETURN);
5456 if (matches5(TokenType.SEMICOLON)) { 5460 if (matches5(TokenType.SEMICOLON)) {
5457 return new ReturnStatement.full(returnKeyword, null, andAdvance); 5461 return new ReturnStatement(returnKeyword, null, andAdvance);
5458 } 5462 }
5459 Expression expression = parseExpression2(); 5463 Expression expression = parseExpression2();
5460 Token semicolon = expect2(TokenType.SEMICOLON); 5464 Token semicolon = expect2(TokenType.SEMICOLON);
5461 return new ReturnStatement.full(returnKeyword, expression, semicolon); 5465 return new ReturnStatement(returnKeyword, expression, semicolon);
5462 } 5466 }
5463 5467
5464 /** 5468 /**
5465 * Parse a setter. 5469 * Parse a setter.
5466 * 5470 *
5467 * <pre> 5471 * <pre>
5468 * setter ::= 5472 * setter ::=
5469 * setterSignature functionBody? 5473 * setterSignature functionBody?
5470 * 5474 *
5471 * setterSignature ::= 5475 * setterSignature ::=
(...skipping 10 matching lines...) Expand all
5482 */ 5486 */
5483 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 5487 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
5484 Token propertyKeyword = expect(Keyword.SET); 5488 Token propertyKeyword = expect(Keyword.SET);
5485 SimpleIdentifier name = parseSimpleIdentifier(); 5489 SimpleIdentifier name = parseSimpleIdentifier();
5486 FormalParameterList parameters = parseFormalParameterList(); 5490 FormalParameterList parameters = parseFormalParameterList();
5487 validateFormalParameterList(parameters); 5491 validateFormalParameterList(parameters);
5488 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); 5492 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false);
5489 if (externalKeyword != null && body is! EmptyFunctionBody) { 5493 if (externalKeyword != null && body is! EmptyFunctionBody) {
5490 reportError10(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); 5494 reportError10(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []);
5491 } 5495 }
5492 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null , name, parameters, body); 5496 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body);
5493 } 5497 }
5494 5498
5495 /** 5499 /**
5496 * Parse a shift expression. 5500 * Parse a shift expression.
5497 * 5501 *
5498 * <pre> 5502 * <pre>
5499 * shiftExpression ::= 5503 * shiftExpression ::=
5500 * additiveExpression (shiftOperator additiveExpression)* 5504 * additiveExpression (shiftOperator additiveExpression)*
5501 * | 'super' (shiftOperator additiveExpression)+ 5505 * | 'super' (shiftOperator additiveExpression)+
5502 * </pre> 5506 * </pre>
5503 * 5507 *
5504 * @return the shift expression that was parsed 5508 * @return the shift expression that was parsed
5505 */ 5509 */
5506 Expression parseShiftExpression() { 5510 Expression parseShiftExpression() {
5507 Expression expression; 5511 Expression expression;
5508 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator) { 5512 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator) {
5509 expression = new SuperExpression.full(andAdvance); 5513 expression = new SuperExpression(andAdvance);
5510 } else { 5514 } else {
5511 expression = parseAdditiveExpression(); 5515 expression = parseAdditiveExpression();
5512 } 5516 }
5513 while (_currentToken.type.isShiftOperator) { 5517 while (_currentToken.type.isShiftOperator) {
5514 Token operator = andAdvance; 5518 Token operator = andAdvance;
5515 expression = new BinaryExpression.full(expression, operator, parseAdditive Expression()); 5519 expression = new BinaryExpression(expression, operator, parseAdditiveExpre ssion());
5516 } 5520 }
5517 return expression; 5521 return expression;
5518 } 5522 }
5519 5523
5520 /** 5524 /**
5521 * Parse a list of statements within a switch statement. 5525 * Parse a list of statements within a switch statement.
5522 * 5526 *
5523 * <pre> 5527 * <pre>
5524 * statements ::= 5528 * statements ::=
5525 * statement* 5529 * statement*
(...skipping 16 matching lines...) Expand all
5542 } 5546 }
5543 5547
5544 /** 5548 /**
5545 * Parse a string literal that contains interpolations. 5549 * Parse a string literal that contains interpolations.
5546 * 5550 *
5547 * @return the string literal that was parsed 5551 * @return the string literal that was parsed
5548 */ 5552 */
5549 StringInterpolation parseStringInterpolation(Token string) { 5553 StringInterpolation parseStringInterpolation(Token string) {
5550 List<InterpolationElement> elements = new List<InterpolationElement>(); 5554 List<InterpolationElement> elements = new List<InterpolationElement>();
5551 bool hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matche s5(TokenType.STRING_INTERPOLATION_IDENTIFIER); 5555 bool hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matche s5(TokenType.STRING_INTERPOLATION_IDENTIFIER);
5552 elements.add(new InterpolationString.full(string, computeStringValue(string. lexeme, true, !hasMore))); 5556 elements.add(new InterpolationString(string, computeStringValue(string.lexem e, true, !hasMore)));
5553 while (hasMore) { 5557 while (hasMore) {
5554 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 5558 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
5555 Token openToken = andAdvance; 5559 Token openToken = andAdvance;
5556 Expression expression = parseExpression2(); 5560 Expression expression = parseExpression2();
5557 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5561 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5558 elements.add(new InterpolationExpression.full(openToken, expression, rig htBracket)); 5562 elements.add(new InterpolationExpression(openToken, expression, rightBra cket));
5559 } else { 5563 } else {
5560 Token openToken = andAdvance; 5564 Token openToken = andAdvance;
5561 Expression expression = null; 5565 Expression expression = null;
5562 if (matches(Keyword.THIS)) { 5566 if (matches(Keyword.THIS)) {
5563 expression = new ThisExpression.full(andAdvance); 5567 expression = new ThisExpression(andAdvance);
5564 } else { 5568 } else {
5565 expression = parseSimpleIdentifier(); 5569 expression = parseSimpleIdentifier();
5566 } 5570 }
5567 elements.add(new InterpolationExpression.full(openToken, expression, nul l)); 5571 elements.add(new InterpolationExpression(openToken, expression, null));
5568 } 5572 }
5569 if (matches5(TokenType.STRING)) { 5573 if (matches5(TokenType.STRING)) {
5570 string = andAdvance; 5574 string = andAdvance;
5571 hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches 5(TokenType.STRING_INTERPOLATION_IDENTIFIER); 5575 hasMore = matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches 5(TokenType.STRING_INTERPOLATION_IDENTIFIER);
5572 elements.add(new InterpolationString.full(string, computeStringValue(str ing.lexeme, false, !hasMore))); 5576 elements.add(new InterpolationString(string, computeStringValue(string.l exeme, false, !hasMore)));
5573 } 5577 }
5574 } 5578 }
5575 return new StringInterpolation.full(elements); 5579 return new StringInterpolation(elements);
5576 } 5580 }
5577 5581
5578 /** 5582 /**
5579 * Parse a super constructor invocation. 5583 * Parse a super constructor invocation.
5580 * 5584 *
5581 * <pre> 5585 * <pre>
5582 * superConstructorInvocation ::= 5586 * superConstructorInvocation ::=
5583 * 'super' ('.' identifier)? arguments 5587 * 'super' ('.' identifier)? arguments
5584 * </pre> 5588 * </pre>
5585 * 5589 *
5586 * @return the super constructor invocation that was parsed 5590 * @return the super constructor invocation that was parsed
5587 */ 5591 */
5588 SuperConstructorInvocation parseSuperConstructorInvocation() { 5592 SuperConstructorInvocation parseSuperConstructorInvocation() {
5589 Token keyword = expect(Keyword.SUPER); 5593 Token keyword = expect(Keyword.SUPER);
5590 Token period = null; 5594 Token period = null;
5591 SimpleIdentifier constructorName = null; 5595 SimpleIdentifier constructorName = null;
5592 if (matches5(TokenType.PERIOD)) { 5596 if (matches5(TokenType.PERIOD)) {
5593 period = andAdvance; 5597 period = andAdvance;
5594 constructorName = parseSimpleIdentifier(); 5598 constructorName = parseSimpleIdentifier();
5595 } 5599 }
5596 ArgumentList argumentList = parseArgumentList(); 5600 ArgumentList argumentList = parseArgumentList();
5597 return new SuperConstructorInvocation.full(keyword, period, constructorName, argumentList); 5601 return new SuperConstructorInvocation(keyword, period, constructorName, argu mentList);
5598 } 5602 }
5599 5603
5600 /** 5604 /**
5601 * Parse a switch statement. 5605 * Parse a switch statement.
5602 * 5606 *
5603 * <pre> 5607 * <pre>
5604 * switchStatement ::= 5608 * switchStatement ::=
5605 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' 5609 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}'
5606 * 5610 *
5607 * switchCase ::= 5611 * switchCase ::=
(...skipping 21 matching lines...) Expand all
5629 List<Label> labels = new List<Label>(); 5633 List<Label> labels = new List<Label>();
5630 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 5634 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
5631 SimpleIdentifier identifier = parseSimpleIdentifier(); 5635 SimpleIdentifier identifier = parseSimpleIdentifier();
5632 String label = identifier.token.lexeme; 5636 String label = identifier.token.lexeme;
5633 if (definedLabels.contains(label)) { 5637 if (definedLabels.contains(label)) {
5634 reportError11(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]); 5638 reportError11(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, i dentifier.token, [label]);
5635 } else { 5639 } else {
5636 definedLabels.add(label); 5640 definedLabels.add(label);
5637 } 5641 }
5638 Token colon = expect2(TokenType.COLON); 5642 Token colon = expect2(TokenType.COLON);
5639 labels.add(new Label.full(identifier, colon)); 5643 labels.add(new Label(identifier, colon));
5640 } 5644 }
5641 if (matches(Keyword.CASE)) { 5645 if (matches(Keyword.CASE)) {
5642 Token caseKeyword = andAdvance; 5646 Token caseKeyword = andAdvance;
5643 Expression caseExpression = parseExpression2(); 5647 Expression caseExpression = parseExpression2();
5644 Token colon = expect2(TokenType.COLON); 5648 Token colon = expect2(TokenType.COLON);
5645 members.add(new SwitchCase.full(labels, caseKeyword, caseExpression, c olon, parseStatements2())); 5649 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2()));
5646 if (defaultKeyword != null) { 5650 if (defaultKeyword != null) {
5647 reportError11(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []); 5651 reportError11(ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, ca seKeyword, []);
5648 } 5652 }
5649 } else if (matches(Keyword.DEFAULT)) { 5653 } else if (matches(Keyword.DEFAULT)) {
5650 if (defaultKeyword != null) { 5654 if (defaultKeyword != null) {
5651 reportError11(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []); 5655 reportError11(ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, pee k(), []);
5652 } 5656 }
5653 defaultKeyword = andAdvance; 5657 defaultKeyword = andAdvance;
5654 Token colon = expect2(TokenType.COLON); 5658 Token colon = expect2(TokenType.COLON);
5655 members.add(new SwitchDefault.full(labels, defaultKeyword, colon, pars eStatements2())); 5659 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2()));
5656 } else { 5660 } else {
5657 reportError10(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 5661 reportError10(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []);
5658 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { 5662 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) {
5659 advance(); 5663 advance();
5660 } 5664 }
5661 } 5665 }
5662 } 5666 }
5663 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 5667 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
5664 return new SwitchStatement.full(keyword, leftParenthesis, expression, righ tParenthesis, leftBracket, members, rightBracket); 5668 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket);
5665 } finally { 5669 } finally {
5666 _inSwitch = wasInSwitch; 5670 _inSwitch = wasInSwitch;
5667 } 5671 }
5668 } 5672 }
5669 5673
5670 /** 5674 /**
5671 * Parse a symbol literal. 5675 * Parse a symbol literal.
5672 * 5676 *
5673 * <pre> 5677 * <pre>
5674 * symbolLiteral ::= 5678 * symbolLiteral ::=
(...skipping 16 matching lines...) Expand all
5691 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5695 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5692 break; 5696 break;
5693 } 5697 }
5694 } 5698 }
5695 } else if (_currentToken.isOperator) { 5699 } else if (_currentToken.isOperator) {
5696 components.add(andAdvance); 5700 components.add(andAdvance);
5697 } else { 5701 } else {
5698 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []); 5702 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []);
5699 components.add(createSyntheticToken2(TokenType.IDENTIFIER)); 5703 components.add(createSyntheticToken2(TokenType.IDENTIFIER));
5700 } 5704 }
5701 return new SymbolLiteral.full(poundSign, new List.from(components)); 5705 return new SymbolLiteral(poundSign, new List.from(components));
5702 } 5706 }
5703 5707
5704 /** 5708 /**
5705 * Parse a throw expression. 5709 * Parse a throw expression.
5706 * 5710 *
5707 * <pre> 5711 * <pre>
5708 * throwExpression ::= 5712 * throwExpression ::=
5709 * 'throw' expression 5713 * 'throw' expression
5710 * </pre> 5714 * </pre>
5711 * 5715 *
5712 * @return the throw expression that was parsed 5716 * @return the throw expression that was parsed
5713 */ 5717 */
5714 Expression parseThrowExpression() { 5718 Expression parseThrowExpression() {
5715 Token keyword = expect(Keyword.THROW); 5719 Token keyword = expect(Keyword.THROW);
5716 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5720 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5717 reportError11(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5721 reportError11(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5718 return new ThrowExpression.full(keyword, createSyntheticIdentifier()); 5722 return new ThrowExpression(keyword, createSyntheticIdentifier());
5719 } 5723 }
5720 Expression expression = parseExpression2(); 5724 Expression expression = parseExpression2();
5721 return new ThrowExpression.full(keyword, expression); 5725 return new ThrowExpression(keyword, expression);
5722 } 5726 }
5723 5727
5724 /** 5728 /**
5725 * Parse a throw expression. 5729 * Parse a throw expression.
5726 * 5730 *
5727 * <pre> 5731 * <pre>
5728 * throwExpressionWithoutCascade ::= 5732 * throwExpressionWithoutCascade ::=
5729 * 'throw' expressionWithoutCascade 5733 * 'throw' expressionWithoutCascade
5730 * </pre> 5734 * </pre>
5731 * 5735 *
5732 * @return the throw expression that was parsed 5736 * @return the throw expression that was parsed
5733 */ 5737 */
5734 Expression parseThrowExpressionWithoutCascade() { 5738 Expression parseThrowExpressionWithoutCascade() {
5735 Token keyword = expect(Keyword.THROW); 5739 Token keyword = expect(Keyword.THROW);
5736 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 5740 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
5737 reportError11(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []); 5741 reportError11(ParserErrorCode.MISSING_EXPRESSION_IN_THROW, _currentToken, []);
5738 return new ThrowExpression.full(keyword, createSyntheticIdentifier()); 5742 return new ThrowExpression(keyword, createSyntheticIdentifier());
5739 } 5743 }
5740 Expression expression = parseExpressionWithoutCascade(); 5744 Expression expression = parseExpressionWithoutCascade();
5741 return new ThrowExpression.full(keyword, expression); 5745 return new ThrowExpression(keyword, expression);
5742 } 5746 }
5743 5747
5744 /** 5748 /**
5745 * Parse a try statement. 5749 * Parse a try statement.
5746 * 5750 *
5747 * <pre> 5751 * <pre>
5748 * tryStatement ::= 5752 * tryStatement ::=
5749 * 'try' block (onPart+ finallyPart? | finallyPart) 5753 * 'try' block (onPart+ finallyPart? | finallyPart)
5750 * 5754 *
5751 * onPart ::= 5755 * onPart ::=
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5783 catchKeyword = andAdvance; 5787 catchKeyword = andAdvance;
5784 leftParenthesis = expect2(TokenType.OPEN_PAREN); 5788 leftParenthesis = expect2(TokenType.OPEN_PAREN);
5785 exceptionParameter = parseSimpleIdentifier(); 5789 exceptionParameter = parseSimpleIdentifier();
5786 if (matches5(TokenType.COMMA)) { 5790 if (matches5(TokenType.COMMA)) {
5787 comma = andAdvance; 5791 comma = andAdvance;
5788 stackTraceParameter = parseSimpleIdentifier(); 5792 stackTraceParameter = parseSimpleIdentifier();
5789 } 5793 }
5790 rightParenthesis = expect2(TokenType.CLOSE_PAREN); 5794 rightParenthesis = expect2(TokenType.CLOSE_PAREN);
5791 } 5795 }
5792 Block catchBody = parseBlock(); 5796 Block catchBody = parseBlock();
5793 catchClauses.add(new CatchClause.full(onKeyword, exceptionType, catchKeywo rd, leftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParent hesis, catchBody)); 5797 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody));
5794 } 5798 }
5795 Token finallyKeyword = null; 5799 Token finallyKeyword = null;
5796 if (matches(Keyword.FINALLY)) { 5800 if (matches(Keyword.FINALLY)) {
5797 finallyKeyword = andAdvance; 5801 finallyKeyword = andAdvance;
5798 finallyClause = parseBlock(); 5802 finallyClause = parseBlock();
5799 } else { 5803 } else {
5800 if (catchClauses.isEmpty) { 5804 if (catchClauses.isEmpty) {
5801 reportError10(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); 5805 reportError10(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []);
5802 } 5806 }
5803 } 5807 }
5804 return new TryStatement.full(tryKeyword, body, catchClauses, finallyKeyword, finallyClause); 5808 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause);
5805 } 5809 }
5806 5810
5807 /** 5811 /**
5808 * Parse a type alias. 5812 * Parse a type alias.
5809 * 5813 *
5810 * <pre> 5814 * <pre>
5811 * typeAlias ::= 5815 * typeAlias ::=
5812 * 'typedef' typeAliasBody 5816 * 'typedef' typeAliasBody
5813 * 5817 *
5814 * typeAliasBody ::= 5818 * typeAliasBody ::=
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
5863 * | incrementOperator assignableExpression 5867 * | incrementOperator assignableExpression
5864 * </pre> 5868 * </pre>
5865 * 5869 *
5866 * @return the unary expression that was parsed 5870 * @return the unary expression that was parsed
5867 */ 5871 */
5868 Expression parseUnaryExpression() { 5872 Expression parseUnaryExpression() {
5869 if (matches5(TokenType.MINUS) || matches5(TokenType.BANG) || matches5(TokenT ype.TILDE)) { 5873 if (matches5(TokenType.MINUS) || matches5(TokenType.BANG) || matches5(TokenT ype.TILDE)) {
5870 Token operator = andAdvance; 5874 Token operator = andAdvance;
5871 if (matches(Keyword.SUPER)) { 5875 if (matches(Keyword.SUPER)) {
5872 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) { 5876 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) {
5873 return new PrefixExpression.full(operator, parseUnaryExpression()); 5877 return new PrefixExpression(operator, parseUnaryExpression());
5874 } 5878 }
5875 return new PrefixExpression.full(operator, new SuperExpression.full(andA dvance)); 5879 return new PrefixExpression(operator, new SuperExpression(andAdvance));
5876 } 5880 }
5877 return new PrefixExpression.full(operator, parseUnaryExpression()); 5881 return new PrefixExpression(operator, parseUnaryExpression());
5878 } else if (_currentToken.type.isIncrementOperator) { 5882 } else if (_currentToken.type.isIncrementOperator) {
5879 Token operator = andAdvance; 5883 Token operator = andAdvance;
5880 if (matches(Keyword.SUPER)) { 5884 if (matches(Keyword.SUPER)) {
5881 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) { 5885 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) {
5882 return new PrefixExpression.full(operator, parseUnaryExpression()); 5886 return new PrefixExpression(operator, parseUnaryExpression());
5883 } 5887 }
5884 if (identical(operator.type, TokenType.MINUS_MINUS)) { 5888 if (identical(operator.type, TokenType.MINUS_MINUS)) {
5885 int offset = operator.offset; 5889 int offset = operator.offset;
5886 Token firstOperator = new Token(TokenType.MINUS, offset); 5890 Token firstOperator = new Token(TokenType.MINUS, offset);
5887 Token secondOperator = new Token(TokenType.MINUS, offset + 1); 5891 Token secondOperator = new Token(TokenType.MINUS, offset + 1);
5888 secondOperator.setNext(_currentToken); 5892 secondOperator.setNext(_currentToken);
5889 firstOperator.setNext(secondOperator); 5893 firstOperator.setNext(secondOperator);
5890 operator.previous.setNext(firstOperator); 5894 operator.previous.setNext(firstOperator);
5891 return new PrefixExpression.full(firstOperator, new PrefixExpression.f ull(secondOperator, new SuperExpression.full(andAdvance))); 5895 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance)));
5892 } else { 5896 } else {
5893 reportError10(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]); 5897 reportError10(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.le xeme]);
5894 return new PrefixExpression.full(operator, new SuperExpression.full(an dAdvance)); 5898 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ;
5895 } 5899 }
5896 } 5900 }
5897 return new PrefixExpression.full(operator, parseAssignableExpression(false )); 5901 return new PrefixExpression(operator, parseAssignableExpression(false));
5898 } else if (matches5(TokenType.PLUS)) { 5902 } else if (matches5(TokenType.PLUS)) {
5899 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []); 5903 reportError10(ParserErrorCode.MISSING_IDENTIFIER, []);
5900 return createSyntheticIdentifier(); 5904 return createSyntheticIdentifier();
5901 } 5905 }
5902 return parsePostfixExpression(); 5906 return parsePostfixExpression();
5903 } 5907 }
5904 5908
5905 /** 5909 /**
5906 * Parse a variable declaration. 5910 * Parse a variable declaration.
5907 * 5911 *
5908 * <pre> 5912 * <pre>
5909 * variableDeclaration ::= 5913 * variableDeclaration ::=
5910 * identifier ('=' expression)? 5914 * identifier ('=' expression)?
5911 * </pre> 5915 * </pre>
5912 * 5916 *
5913 * @return the variable declaration that was parsed 5917 * @return the variable declaration that was parsed
5914 */ 5918 */
5915 VariableDeclaration parseVariableDeclaration() { 5919 VariableDeclaration parseVariableDeclaration() {
5916 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 5920 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
5917 SimpleIdentifier name = parseSimpleIdentifier(); 5921 SimpleIdentifier name = parseSimpleIdentifier();
5918 Token equals = null; 5922 Token equals = null;
5919 Expression initializer = null; 5923 Expression initializer = null;
5920 if (matches5(TokenType.EQ)) { 5924 if (matches5(TokenType.EQ)) {
5921 equals = andAdvance; 5925 equals = andAdvance;
5922 initializer = parseExpression2(); 5926 initializer = parseExpression2();
5923 } 5927 }
5924 return new VariableDeclaration.full(commentAndMetadata.comment, commentAndMe tadata.metadata, name, equals, initializer); 5928 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer);
5925 } 5929 }
5926 5930
5927 /** 5931 /**
5928 * Parse a variable declaration list. 5932 * Parse a variable declaration list.
5929 * 5933 *
5930 * <pre> 5934 * <pre>
5931 * variableDeclarationList ::= 5935 * variableDeclarationList ::=
5932 * finalConstVarOrType variableDeclaration (',' variableDeclaration)* 5936 * finalConstVarOrType variableDeclaration (',' variableDeclaration)*
5933 * </pre> 5937 * </pre>
5934 * 5938 *
(...skipping 23 matching lines...) Expand all
5958 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) { 5962 VariableDeclarationList parseVariableDeclarationList2(CommentAndMetadata comme ntAndMetadata, Token keyword, TypeName type) {
5959 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) { 5963 if (type != null && keyword != null && matches3(keyword, Keyword.VAR)) {
5960 reportError11(ParserErrorCode.VAR_AND_TYPE, keyword, []); 5964 reportError11(ParserErrorCode.VAR_AND_TYPE, keyword, []);
5961 } 5965 }
5962 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 5966 List<VariableDeclaration> variables = new List<VariableDeclaration>();
5963 variables.add(parseVariableDeclaration()); 5967 variables.add(parseVariableDeclaration());
5964 while (matches5(TokenType.COMMA)) { 5968 while (matches5(TokenType.COMMA)) {
5965 advance(); 5969 advance();
5966 variables.add(parseVariableDeclaration()); 5970 variables.add(parseVariableDeclaration());
5967 } 5971 }
5968 return new VariableDeclarationList.full(commentAndMetadata != null ? comment AndMetadata.comment : null, commentAndMetadata != null ? commentAndMetadata.meta data : null, keyword, type, variables); 5972 return new VariableDeclarationList(commentAndMetadata != null ? commentAndMe tadata.comment : null, commentAndMetadata != null ? commentAndMetadata.metadata : null, keyword, type, variables);
5969 } 5973 }
5970 5974
5971 /** 5975 /**
5972 * Parse a variable declaration statement. 5976 * Parse a variable declaration statement.
5973 * 5977 *
5974 * <pre> 5978 * <pre>
5975 * variableDeclarationStatement ::= 5979 * variableDeclarationStatement ::=
5976 * variableDeclarationList ';' 5980 * variableDeclarationList ';'
5977 * </pre> 5981 * </pre>
5978 * 5982 *
5979 * @param commentAndMetadata the metadata to be associated with the variable d eclaration 5983 * @param commentAndMetadata the metadata to be associated with the variable d eclaration
5980 * statement, or `null` if there is no attempt at parsing the comment and metadata 5984 * statement, or `null` if there is no attempt at parsing the comment and metadata
5981 * @return the variable declaration statement that was parsed 5985 * @return the variable declaration statement that was parsed
5982 */ 5986 */
5983 VariableDeclarationStatement parseVariableDeclarationStatement(CommentAndMetad ata commentAndMetadata) { 5987 VariableDeclarationStatement parseVariableDeclarationStatement(CommentAndMetad ata commentAndMetadata) {
5984 VariableDeclarationList variableList = parseVariableDeclarationList(commentA ndMetadata); 5988 VariableDeclarationList variableList = parseVariableDeclarationList(commentA ndMetadata);
5985 Token semicolon = expect2(TokenType.SEMICOLON); 5989 Token semicolon = expect2(TokenType.SEMICOLON);
5986 return new VariableDeclarationStatement.full(variableList, semicolon); 5990 return new VariableDeclarationStatement(variableList, semicolon);
5987 } 5991 }
5988 5992
5989 /** 5993 /**
5990 * Parse a variable declaration statement. 5994 * Parse a variable declaration statement.
5991 * 5995 *
5992 * <pre> 5996 * <pre>
5993 * variableDeclarationStatement ::= 5997 * variableDeclarationStatement ::=
5994 * variableDeclarationList ';' 5998 * variableDeclarationList ';'
5995 * </pre> 5999 * </pre>
5996 * 6000 *
5997 * @param commentAndMetadata the metadata to be associated with the variable d eclaration 6001 * @param commentAndMetadata the metadata to be associated with the variable d eclaration
5998 * statement, or `null` if there is no attempt at parsing the comment and metadata 6002 * statement, or `null` if there is no attempt at parsing the comment and metadata
5999 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if 6003 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or `null` if
6000 * there is no keyword 6004 * there is no keyword
6001 * @param type the type of the variables in the list 6005 * @param type the type of the variables in the list
6002 * @return the variable declaration statement that was parsed 6006 * @return the variable declaration statement that was parsed
6003 */ 6007 */
6004 VariableDeclarationStatement parseVariableDeclarationStatement2(CommentAndMeta data commentAndMetadata, Token keyword, TypeName type) { 6008 VariableDeclarationStatement parseVariableDeclarationStatement2(CommentAndMeta data commentAndMetadata, Token keyword, TypeName type) {
6005 VariableDeclarationList variableList = parseVariableDeclarationList2(comment AndMetadata, keyword, type); 6009 VariableDeclarationList variableList = parseVariableDeclarationList2(comment AndMetadata, keyword, type);
6006 Token semicolon = expect2(TokenType.SEMICOLON); 6010 Token semicolon = expect2(TokenType.SEMICOLON);
6007 return new VariableDeclarationStatement.full(variableList, semicolon); 6011 return new VariableDeclarationStatement(variableList, semicolon);
6008 } 6012 }
6009 6013
6010 /** 6014 /**
6011 * Parse a while statement. 6015 * Parse a while statement.
6012 * 6016 *
6013 * <pre> 6017 * <pre>
6014 * whileStatement ::= 6018 * whileStatement ::=
6015 * 'while' '(' expression ')' statement 6019 * 'while' '(' expression ')' statement
6016 * </pre> 6020 * </pre>
6017 * 6021 *
6018 * @return the while statement that was parsed 6022 * @return the while statement that was parsed
6019 */ 6023 */
6020 Statement parseWhileStatement() { 6024 Statement parseWhileStatement() {
6021 bool wasInLoop = _inLoop; 6025 bool wasInLoop = _inLoop;
6022 _inLoop = true; 6026 _inLoop = true;
6023 try { 6027 try {
6024 Token keyword = expect(Keyword.WHILE); 6028 Token keyword = expect(Keyword.WHILE);
6025 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 6029 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
6026 Expression condition = parseExpression2(); 6030 Expression condition = parseExpression2();
6027 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 6031 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
6028 Statement body = parseStatement2(); 6032 Statement body = parseStatement2();
6029 return new WhileStatement.full(keyword, leftParenthesis, condition, rightP arenthesis, body); 6033 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body);
6030 } finally { 6034 } finally {
6031 _inLoop = wasInLoop; 6035 _inLoop = wasInLoop;
6032 } 6036 }
6033 } 6037 }
6034 6038
6035 /** 6039 /**
6036 * Return the token that is immediately after the current token. This is equiv alent to 6040 * Return the token that is immediately after the current token. This is equiv alent to
6037 * [peek]. 6041 * [peek].
6038 * 6042 *
6039 * @return the token that is immediately after the current token 6043 * @return the token that is immediately after the current token
(...skipping 3252 matching lines...) Expand 10 before | Expand all | Expand 10 after
9292 if ("\n" == separator) { 9296 if ("\n" == separator) {
9293 _writer.print("\n"); 9297 _writer.print("\n");
9294 indent(); 9298 indent();
9295 } else if (i > 0) { 9299 } else if (i > 0) {
9296 _writer.print(separator); 9300 _writer.print(separator);
9297 } 9301 }
9298 _writer.print(tokens[i].lexeme); 9302 _writer.print(tokens[i].lexeme);
9299 } 9303 }
9300 } 9304 }
9301 } 9305 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/instrumentation.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698