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

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

Issue 12253009: Fresh drop of analyzer-experimental. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 months 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 'java_engine.dart'; 8 import 'java_engine.dart';
9 import 'error.dart'; 9 import 'error.dart';
10 import 'source.dart'; 10 import 'source.dart';
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 Token get staticKeyword => _staticKeyword; 154 Token get staticKeyword => _staticKeyword;
155 /** 155 /**
156 * Return the token representing the keyword 'var', or {@code null} if the key word was not found. 156 * Return the token representing the keyword 'var', or {@code null} if the key word was not found.
157 * @return the token representing the keyword 'var' 157 * @return the token representing the keyword 'var'
158 */ 158 */
159 Token get varKeyword => _varKeyword; 159 Token get varKeyword => _varKeyword;
160 /** 160 /**
161 * Set the token representing the keyword 'abstract' to the given token. 161 * Set the token representing the keyword 'abstract' to the given token.
162 * @param abstractKeyword the token representing the keyword 'abstract' 162 * @param abstractKeyword the token representing the keyword 'abstract'
163 */ 163 */
164 void set abstractKeyword4(Token abstractKeyword) { 164 void set abstractKeyword(Token abstractKeyword4) {
165 this._abstractKeyword = abstractKeyword; 165 this._abstractKeyword = abstractKeyword4;
166 } 166 }
167 /** 167 /**
168 * Set the token representing the keyword 'const' to the given token. 168 * Set the token representing the keyword 'const' to the given token.
169 * @param constKeyword the token representing the keyword 'const' 169 * @param constKeyword the token representing the keyword 'const'
170 */ 170 */
171 void set constKeyword3(Token constKeyword) { 171 void set constKeyword(Token constKeyword3) {
172 this._constKeyword = constKeyword; 172 this._constKeyword = constKeyword3;
173 } 173 }
174 /** 174 /**
175 * Set the token representing the keyword 'external' to the given token. 175 * Set the token representing the keyword 'external' to the given token.
176 * @param externalKeyword the token representing the keyword 'external' 176 * @param externalKeyword the token representing the keyword 'external'
177 */ 177 */
178 void set externalKeyword5(Token externalKeyword) { 178 void set externalKeyword(Token externalKeyword5) {
179 this._externalKeyword = externalKeyword; 179 this._externalKeyword = externalKeyword5;
180 } 180 }
181 /** 181 /**
182 * Set the token representing the keyword 'factory' to the given token. 182 * Set the token representing the keyword 'factory' to the given token.
183 * @param factoryKeyword the token representing the keyword 'factory' 183 * @param factoryKeyword the token representing the keyword 'factory'
184 */ 184 */
185 void set factoryKeyword3(Token factoryKeyword) { 185 void set factoryKeyword(Token factoryKeyword3) {
186 this._factoryKeyword = factoryKeyword; 186 this._factoryKeyword = factoryKeyword3;
187 } 187 }
188 /** 188 /**
189 * Set the token representing the keyword 'final' to the given token. 189 * Set the token representing the keyword 'final' to the given token.
190 * @param finalKeyword the token representing the keyword 'final' 190 * @param finalKeyword the token representing the keyword 'final'
191 */ 191 */
192 void set finalKeyword2(Token finalKeyword) { 192 void set finalKeyword(Token finalKeyword2) {
193 this._finalKeyword = finalKeyword; 193 this._finalKeyword = finalKeyword2;
194 } 194 }
195 /** 195 /**
196 * Set the token representing the keyword 'static' to the given token. 196 * Set the token representing the keyword 'static' to the given token.
197 * @param staticKeyword the token representing the keyword 'static' 197 * @param staticKeyword the token representing the keyword 'static'
198 */ 198 */
199 void set staticKeyword2(Token staticKeyword) { 199 void set staticKeyword(Token staticKeyword2) {
200 this._staticKeyword = staticKeyword; 200 this._staticKeyword = staticKeyword2;
201 } 201 }
202 /** 202 /**
203 * Set the token representing the keyword 'var' to the given token. 203 * Set the token representing the keyword 'var' to the given token.
204 * @param varKeyword the token representing the keyword 'var' 204 * @param varKeyword the token representing the keyword 'var'
205 */ 205 */
206 void set varKeyword2(Token varKeyword) { 206 void set varKeyword(Token varKeyword2) {
207 this._varKeyword = varKeyword; 207 this._varKeyword = varKeyword2;
208 } 208 }
209 String toString() { 209 String toString() {
210 StringBuffer builder = new StringBuffer(); 210 StringBuffer builder = new StringBuffer();
211 bool needsSpace = appendKeyword(builder, false, _abstractKeyword); 211 bool needsSpace = appendKeyword(builder, false, _abstractKeyword);
212 needsSpace = appendKeyword(builder, needsSpace, _constKeyword); 212 needsSpace = appendKeyword(builder, needsSpace, _constKeyword);
213 needsSpace = appendKeyword(builder, needsSpace, _externalKeyword); 213 needsSpace = appendKeyword(builder, needsSpace, _externalKeyword);
214 needsSpace = appendKeyword(builder, needsSpace, _factoryKeyword); 214 needsSpace = appendKeyword(builder, needsSpace, _factoryKeyword);
215 needsSpace = appendKeyword(builder, needsSpace, _finalKeyword); 215 needsSpace = appendKeyword(builder, needsSpace, _finalKeyword);
216 needsSpace = appendKeyword(builder, needsSpace, _staticKeyword); 216 needsSpace = appendKeyword(builder, needsSpace, _staticKeyword);
217 appendKeyword(builder, needsSpace, _varKeyword); 217 appendKeyword(builder, needsSpace, _varKeyword);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 /** 306 /**
307 * Parse a sequence of statements, starting with the given token. 307 * Parse a sequence of statements, starting with the given token.
308 * @param token the first token of the sequence of statement 308 * @param token the first token of the sequence of statement
309 * @return the statements that were parsed, or {@code null} if the tokens do n ot represent a 309 * @return the statements that were parsed, or {@code null} if the tokens do n ot represent a
310 * recognizable sequence of statements 310 * recognizable sequence of statements
311 */ 311 */
312 List<Statement> parseStatements(Token token) { 312 List<Statement> parseStatements(Token token) {
313 _currentToken = token; 313 _currentToken = token;
314 return parseStatements2(); 314 return parseStatements2();
315 } 315 }
316 void set currentToken(Token currentToken) { 316 void set currentToken(Token currentToken2) {
317 this._currentToken = currentToken; 317 this._currentToken = currentToken2;
318 } 318 }
319 /** 319 /**
320 * Advance to the next token in the token stream. 320 * Advance to the next token in the token stream.
321 */ 321 */
322 void advance() { 322 void advance() {
323 _currentToken = _currentToken.next; 323 _currentToken = _currentToken.next;
324 } 324 }
325 /** 325 /**
326 * Append the character equivalent of the given scalar value to the given buil der. Use the start 326 * Append the character equivalent of the given scalar value to the given buil der. Use the start
327 * and end indices to report an error, and don't append anything to the builde r, if the scalar 327 * and end indices to report an error, and don't append anything to the builde r, if the scalar
328 * value is invalid. 328 * value is invalid.
329 * @param builder the builder to which the scalar value is to be appended 329 * @param builder the builder to which the scalar value is to be appended
330 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value 330 * @param escapeSequence the escape sequence that was parsed to produce the sc alar value
331 * @param scalarValue the value to be appended 331 * @param scalarValue the value to be appended
332 * @param startIndex the index of the first character representing the scalar value 332 * @param startIndex the index of the first character representing the scalar value
333 * @param endIndex the index of the last character representing the scalar val ue 333 * @param endIndex the index of the last character representing the scalar val ue
334 */ 334 */
335 void appendScalarValue(StringBuffer builder, String escapeSequence, int scalar Value, int startIndex, int endIndex) { 335 void appendScalarValue(StringBuffer builder, String escapeSequence, int scalar Value, int startIndex, int endIndex) {
336 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) { 336 if (scalarValue < 0 || scalarValue > Character.MAX_CODE_POINT || (scalarValu e >= 0xD800 && scalarValue <= 0xDFFF)) {
337 reportError3(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]); 337 reportError3(ParserErrorCode.INVALID_CODE_POINT, [escapeSequence]);
338 return; 338 return;
339 } 339 }
340 if (scalarValue < Character.MAX_VALUE) { 340 if (scalarValue < Character.MAX_VALUE) {
341 builder.addCharCode(scalarValue as int); 341 builder.addCharCode((scalarValue as int));
342 } else { 342 } else {
343 builder.add(Character.toChars(scalarValue)); 343 builder.add(Character.toChars(scalarValue));
344 } 344 }
345 } 345 }
346 /** 346 /**
347 * Compute the content of a string with the given literal representation. 347 * Compute the content of a string with the given literal representation.
348 * @param lexeme the literal representation of the string 348 * @param lexeme the literal representation of the string
349 * @return the actual value of the string 349 * @return the actual value of the string
350 */ 350 */
351 String computeStringValue(String lexeme) { 351 String computeStringValue(String lexeme) {
(...skipping 22 matching lines...) Expand all
374 int index = start; 374 int index = start;
375 while (index < end) { 375 while (index < end) {
376 index = translateCharacter(builder, lexeme, index); 376 index = translateCharacter(builder, lexeme, index);
377 } 377 }
378 return builder.toString(); 378 return builder.toString();
379 } 379 }
380 /** 380 /**
381 * Create a synthetic identifier. 381 * Create a synthetic identifier.
382 * @return the synthetic identifier that was created 382 * @return the synthetic identifier that was created
383 */ 383 */
384 SimpleIdentifier createSyntheticIdentifier() => new SimpleIdentifier(createSyn theticToken(TokenType.IDENTIFIER)); 384 SimpleIdentifier createSyntheticIdentifier() => new SimpleIdentifier.full(crea teSyntheticToken(TokenType.IDENTIFIER));
385 /** 385 /**
386 * Create a synthetic string literal. 386 * Create a synthetic string literal.
387 * @return the synthetic string literal that was created 387 * @return the synthetic string literal that was created
388 */ 388 */
389 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral( createSyntheticToken(TokenType.STRING), ""); 389 SimpleStringLiteral createSyntheticStringLiteral() => new SimpleStringLiteral. full(createSyntheticToken(TokenType.STRING), "");
390 /** 390 /**
391 * Create a synthetic token with the given type. 391 * Create a synthetic token with the given type.
392 * @return the synthetic token that was created 392 * @return the synthetic token that was created
393 */ 393 */
394 Token createSyntheticToken(TokenType type) => new StringToken(type, "", _curre ntToken.offset); 394 Token createSyntheticToken(TokenType type) => new StringToken(type, "", _curre ntToken.offset);
395 /** 395 /**
396 * Check that the given expression is assignable and report an error if it isn 't. 396 * Check that the given expression is assignable and report an error if it isn 't.
397 * <pre> 397 * <pre>
398 * assignableExpression ::= 398 * assignableExpression ::=
399 * primary (arguments* assignableSelector)+ 399 * primary (arguments* assignableSelector)+
(...skipping 26 matching lines...) Expand all
426 /** 426 /**
427 * If the current token has the expected type, return it after advancing to th e next token. 427 * If the current token has the expected type, return it after advancing to th e next token.
428 * Otherwise report an error and return the current token without advancing. 428 * Otherwise report an error and return the current token without advancing.
429 * @param type the type of token that is expected 429 * @param type the type of token that is expected
430 * @return the token that matched the given type 430 * @return the token that matched the given type
431 */ 431 */
432 Token expect2(TokenType type) { 432 Token expect2(TokenType type) {
433 if (matches5(type)) { 433 if (matches5(type)) {
434 return andAdvance; 434 return andAdvance;
435 } 435 }
436 if (type == TokenType.SEMICOLON) { 436 if (identical(type, TokenType.SEMICOLON)) {
437 reportError4(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type .lexeme]); 437 reportError4(ParserErrorCode.EXPECTED_TOKEN, _currentToken.previous, [type .lexeme]);
438 } else { 438 } else {
439 reportError3(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]); 439 reportError3(ParserErrorCode.EXPECTED_TOKEN, [type.lexeme]);
440 } 440 }
441 return _currentToken; 441 return _currentToken;
442 } 442 }
443 /** 443 /**
444 * Advance to the next token in the token stream, making it the new current to ken. 444 * Advance to the next token in the token stream, making it the new current to ken.
445 * @return the token that was current before this method was invoked 445 * @return the token that was current before this method was invoked
446 */ 446 */
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 return true; 530 return true;
531 } 531 }
532 Token token = skipTypeName(_currentToken); 532 Token token = skipTypeName(_currentToken);
533 if (token == null) { 533 if (token == null) {
534 return false; 534 return false;
535 } 535 }
536 token = skipSimpleIdentifier(token); 536 token = skipSimpleIdentifier(token);
537 if (token == null) { 537 if (token == null) {
538 return false; 538 return false;
539 } 539 }
540 TokenType type17 = token.type; 540 TokenType type15 = token.type;
541 return type17 == TokenType.EQ || type17 == TokenType.COMMA || type17 == Toke nType.SEMICOLON || matches3(token, Keyword.IN); 541 return identical(type15, TokenType.EQ) || identical(type15, TokenType.COMMA) || identical(type15, TokenType.SEMICOLON) || matches3(token, Keyword.IN);
542 } 542 }
543 /** 543 /**
544 * Return {@code true} if the current token appears to be the beginning of a s witch member. 544 * Return {@code true} if the current token appears to be the beginning of a s witch member.
545 * @return {@code true} if the current token appears to be the beginning of a switch member 545 * @return {@code true} if the current token appears to be the beginning of a switch member
546 */ 546 */
547 bool isSwitchMember() { 547 bool isSwitchMember() {
548 Token token = _currentToken; 548 Token token = _currentToken;
549 while (matches4(token, TokenType.IDENTIFIER) && matches4(token.next, TokenTy pe.COLON)) { 549 while (matches4(token, TokenType.IDENTIFIER) && matches4(token.next, TokenTy pe.COLON)) {
550 token = token.next.next; 550 token = token.next.next;
551 } 551 }
552 if (token.type == TokenType.KEYWORD) { 552 if (identical(token.type, TokenType.KEYWORD)) {
553 Keyword keyword28 = (token as KeywordToken).keyword; 553 Keyword keyword27 = ((token as KeywordToken)).keyword;
554 return keyword28 == Keyword.CASE || keyword28 == Keyword.DEFAULT; 554 return identical(keyword27, Keyword.CASE) || identical(keyword27, Keyword. DEFAULT);
555 } 555 }
556 return false; 556 return false;
557 } 557 }
558 /** 558 /**
559 * Compare the given tokens to find the token that appears first in the source being parsed. That 559 * Compare the given tokens to find the token that appears first in the source being parsed. That
560 * is, return the left-most of all of the tokens. The arguments are allowed to be {@code null}. 560 * is, return the left-most of all of the tokens. The arguments are allowed to be {@code null}.
561 * Return the token with the smallest offset, or {@code null} if there are no arguments or if all 561 * Return the token with the smallest offset, or {@code null} if there are no arguments or if all
562 * of the arguments are {@code null}. 562 * of the arguments are {@code null}.
563 * @param tokens the tokens being compared 563 * @param tokens the tokens being compared
564 * @return the token with the smallest offset 564 * @return the token with the smallest offset
565 */ 565 */
566 Token lexicallyFirst(List<Token> tokens) { 566 Token lexicallyFirst(List<Token> tokens) {
567 Token first = null; 567 Token first = null;
568 int firstOffset = 2147483647; 568 int firstOffset = 2147483647;
569 for (Token token in tokens) { 569 for (Token token in tokens) {
570 if (token != null) { 570 if (token != null) {
571 int offset3 = token.offset; 571 int offset4 = token.offset;
572 if (offset3 < firstOffset) { 572 if (offset4 < firstOffset) {
573 first = token; 573 first = token;
574 } 574 }
575 } 575 }
576 } 576 }
577 return first; 577 return first;
578 } 578 }
579 /** 579 /**
580 * Return {@code true} if the current token matches the given keyword. 580 * Return {@code true} if the current token matches the given keyword.
581 * @param keyword the keyword that can optionally appear in the current locati on 581 * @param keyword the keyword that can optionally appear in the current locati on
582 * @return {@code true} if the current token matches the given keyword 582 * @return {@code true} if the current token matches the given keyword
583 */ 583 */
584 bool matches(Keyword keyword) => matches3(_currentToken, keyword); 584 bool matches(Keyword keyword) => matches3(_currentToken, keyword);
585 /** 585 /**
586 * Return {@code true} if the current token matches the given identifier. 586 * Return {@code true} if the current token matches the given identifier.
587 * @param identifier the identifier that can optionally appear in the current location 587 * @param identifier the identifier that can optionally appear in the current location
588 * @return {@code true} if the current token matches the given identifier 588 * @return {@code true} if the current token matches the given identifier
589 */ 589 */
590 bool matches2(String identifier) => _currentToken.type == TokenType.IDENTIFIER && _currentToken.lexeme == identifier; 590 bool matches2(String identifier) => identical(_currentToken.type, TokenType.ID ENTIFIER) && _currentToken.lexeme == identifier;
591 /** 591 /**
592 * Return {@code true} if the given token matches the given keyword. 592 * Return {@code true} if the given token matches the given keyword.
593 * @param token the token being tested 593 * @param token the token being tested
594 * @param keyword the keyword that is being tested for 594 * @param keyword the keyword that is being tested for
595 * @return {@code true} if the given token matches the given keyword 595 * @return {@code true} if the given token matches the given keyword
596 */ 596 */
597 bool matches3(Token token, Keyword keyword) => token.type == TokenType.KEYWORD && (token as KeywordToken).keyword == keyword; 597 bool matches3(Token token, Keyword keyword35) => identical(token.type, TokenTy pe.KEYWORD) && identical(((token as KeywordToken)).keyword, keyword35);
598 /** 598 /**
599 * Return {@code true} if the given token has the given type. 599 * Return {@code true} if the given token has the given type.
600 * @param token the token being tested 600 * @param token the token being tested
601 * @param type the type of token that is being tested for 601 * @param type the type of token that is being tested for
602 * @return {@code true} if the given token has the given type 602 * @return {@code true} if the given token has the given type
603 */ 603 */
604 bool matches4(Token token, TokenType type) => token.type == type; 604 bool matches4(Token token, TokenType type24) => identical(token.type, type24);
605 /** 605 /**
606 * Return {@code true} if the current token has the given type. Note that this method, unlike 606 * Return {@code true} if the current token has the given type. Note that this method, unlike
607 * other variants, will modify the token stream if possible to match a wider r ange of tokens. In 607 * other variants, will modify the token stream if possible to match a wider r ange of tokens. In
608 * particular, if we are attempting to match a '>' and the next token is eithe r a '>>' or '>>>', 608 * particular, if we are attempting to match a '>' and the next token is eithe r a '>>' or '>>>',
609 * the token stream will be re-written and {@code true} will be returned. 609 * the token stream will be re-written and {@code true} will be returned.
610 * @param type the type of token that can optionally appear in the current loc ation 610 * @param type the type of token that can optionally appear in the current loc ation
611 * @return {@code true} if the current token has the given type 611 * @return {@code true} if the current token has the given type
612 */ 612 */
613 bool matches5(TokenType type) { 613 bool matches5(TokenType type25) {
614 TokenType currentType = _currentToken.type; 614 TokenType currentType = _currentToken.type;
615 if (currentType != type) { 615 if (currentType != type25) {
616 if (type == TokenType.GT) { 616 if (identical(type25, TokenType.GT)) {
617 if (currentType == TokenType.GT_GT) { 617 if (identical(currentType, TokenType.GT_GT)) {
618 int offset4 = _currentToken.offset; 618 int offset5 = _currentToken.offset;
619 Token first = new Token(TokenType.GT, offset4); 619 Token first = new Token(TokenType.GT, offset5);
620 Token second = new Token(TokenType.GT, offset4 + 1); 620 Token second = new Token(TokenType.GT, offset5 + 1);
621 second.setNext(_currentToken.next); 621 second.setNext(_currentToken.next);
622 first.setNext(second); 622 first.setNext(second);
623 _currentToken.previous.setNext(first); 623 _currentToken.previous.setNext(first);
624 _currentToken = first; 624 _currentToken = first;
625 return true; 625 return true;
626 } else if (currentType == TokenType.GT_EQ) { 626 } else if (identical(currentType, TokenType.GT_EQ)) {
627 int offset5 = _currentToken.offset; 627 int offset6 = _currentToken.offset;
628 Token first = new Token(TokenType.GT, offset5); 628 Token first = new Token(TokenType.GT, offset6);
629 Token second = new Token(TokenType.EQ, offset5 + 1); 629 Token second = new Token(TokenType.EQ, offset6 + 1);
630 second.setNext(_currentToken.next); 630 second.setNext(_currentToken.next);
631 first.setNext(second); 631 first.setNext(second);
632 _currentToken.previous.setNext(first); 632 _currentToken.previous.setNext(first);
633 _currentToken = first; 633 _currentToken = first;
634 return true; 634 return true;
635 } else if (currentType == TokenType.GT_GT_EQ) { 635 } else if (identical(currentType, TokenType.GT_GT_EQ)) {
636 int offset6 = _currentToken.offset; 636 int offset7 = _currentToken.offset;
637 Token first = new Token(TokenType.GT, offset6); 637 Token first = new Token(TokenType.GT, offset7);
638 Token second = new Token(TokenType.GT, offset6 + 1); 638 Token second = new Token(TokenType.GT, offset7 + 1);
639 Token third = new Token(TokenType.EQ, offset6 + 2); 639 Token third = new Token(TokenType.EQ, offset7 + 2);
640 third.setNext(_currentToken.next); 640 third.setNext(_currentToken.next);
641 second.setNext(third); 641 second.setNext(third);
642 first.setNext(second); 642 first.setNext(second);
643 _currentToken.previous.setNext(first); 643 _currentToken.previous.setNext(first);
644 _currentToken = first; 644 _currentToken = first;
645 return true; 645 return true;
646 } 646 }
647 } 647 }
648 return false; 648 return false;
649 } 649 }
650 return true; 650 return true;
651 } 651 }
652 /** 652 /**
653 * Return {@code true} if the given token has any one of the given types. 653 * Return {@code true} if the given token has any one of the given types.
654 * @param token the token being tested 654 * @param token the token being tested
655 * @param types the types of token that are being tested for 655 * @param types the types of token that are being tested for
656 * @return {@code true} if the given token has any of the given types 656 * @return {@code true} if the given token has any of the given types
657 */ 657 */
658 bool matchesAny(Token token, List<TokenType> types) { 658 bool matchesAny(Token token, List<TokenType> types) {
659 TokenType actualType = token.type; 659 TokenType actualType = token.type;
660 for (TokenType type in types) { 660 for (TokenType type in types) {
661 if (actualType == type) { 661 if (identical(actualType, type)) {
662 return true; 662 return true;
663 } 663 }
664 } 664 }
665 return false; 665 return false;
666 } 666 }
667 /** 667 /**
668 * Return {@code true} if the current token is a valid identifier. Valid ident ifiers include 668 * Return {@code true} if the current token is a valid identifier. Valid ident ifiers include
669 * built-in identifiers (pseudo-keywords). 669 * built-in identifiers (pseudo-keywords).
670 * @return {@code true} if the current token is a valid identifier 670 * @return {@code true} if the current token is a valid identifier
671 */ 671 */
672 bool matchesIdentifier() => matchesIdentifier2(_currentToken); 672 bool matchesIdentifier() => matchesIdentifier2(_currentToken);
673 /** 673 /**
674 * Return {@code true} if the given token is a valid identifier. Valid identif iers include 674 * Return {@code true} if the given token is a valid identifier. Valid identif iers include
675 * built-in identifiers (pseudo-keywords). 675 * built-in identifiers (pseudo-keywords).
676 * @return {@code true} if the given token is a valid identifier 676 * @return {@code true} if the given token is a valid identifier
677 */ 677 */
678 bool matchesIdentifier2(Token token) => matches4(token, TokenType.IDENTIFIER) || (matches4(token, TokenType.KEYWORD) && (token as KeywordToken).keyword.isPseu doKeyword()); 678 bool matchesIdentifier2(Token token) => matches4(token, TokenType.IDENTIFIER) || (matches4(token, TokenType.KEYWORD) && ((token as KeywordToken)).keyword.isPs eudoKeyword());
679 /** 679 /**
680 * If the current token has the given type, then advance to the next token and return {@code true}. Otherwise, return {@code false} without advancing. 680 * If the current token has the given type, then advance to the next token and return {@code true}. Otherwise, return {@code false} without advancing.
681 * @param type the type of token that can optionally appear in the current loc ation 681 * @param type the type of token that can optionally appear in the current loc ation
682 * @return {@code true} if the current token has the given type 682 * @return {@code true} if the current token has the given type
683 */ 683 */
684 bool optional(TokenType type) { 684 bool optional(TokenType type) {
685 if (matches5(type)) { 685 if (matches5(type)) {
686 advance(); 686 advance();
687 return true; 687 return true;
688 } 688 }
689 return false; 689 return false;
690 } 690 }
691 /** 691 /**
692 * Parse an additive expression. 692 * Parse an additive expression.
693 * <pre> 693 * <pre>
694 * additiveExpression ::= 694 * additiveExpression ::=
695 * multiplicativeExpression (additiveOperator multiplicativeExpression) 695 * multiplicativeExpression (additiveOperator multiplicativeExpression)
696 * | 'super' (additiveOperator multiplicativeExpression)+ 696 * | 'super' (additiveOperator multiplicativeExpression)+
697 * </pre> 697 * </pre>
698 * @return the additive expression that was parsed 698 * @return the additive expression that was parsed
699 */ 699 */
700 Expression parseAdditiveExpression() { 700 Expression parseAdditiveExpression() {
701 Expression expression; 701 Expression expression;
702 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator()) { 702 if (matches(Keyword.SUPER) && _currentToken.next.type.isAdditiveOperator()) {
703 expression = new SuperExpression(andAdvance); 703 expression = new SuperExpression.full(andAdvance);
704 } else { 704 } else {
705 expression = parseMultiplicativeExpression(); 705 expression = parseMultiplicativeExpression();
706 } 706 }
707 while (_currentToken.type.isAdditiveOperator()) { 707 while (_currentToken.type.isAdditiveOperator()) {
708 Token operator = andAdvance; 708 Token operator = andAdvance;
709 expression = new BinaryExpression(expression, operator, parseMultiplicativ eExpression()); 709 expression = new BinaryExpression.full(expression, operator, parseMultipli cativeExpression());
710 } 710 }
711 return expression; 711 return expression;
712 } 712 }
713 /** 713 /**
714 * Parse an annotation. 714 * Parse an annotation.
715 * <pre> 715 * <pre>
716 * annotation ::= 716 * annotation ::=
717 * '@' qualified (‘.’ identifier)? arguments? 717 * '@' qualified (‘.’ identifier)? arguments?
718 * </pre> 718 * </pre>
719 * @return the annotation that was parsed 719 * @return the annotation that was parsed
720 */ 720 */
721 Annotation parseAnnotation() { 721 Annotation parseAnnotation() {
722 Token atSign = expect2(TokenType.AT); 722 Token atSign = expect2(TokenType.AT);
723 Identifier name = parsePrefixedIdentifier(); 723 Identifier name = parsePrefixedIdentifier();
724 Token period = null; 724 Token period = null;
725 SimpleIdentifier constructorName = null; 725 SimpleIdentifier constructorName = null;
726 if (matches5(TokenType.PERIOD)) { 726 if (matches5(TokenType.PERIOD)) {
727 period = andAdvance; 727 period = andAdvance;
728 constructorName = parseSimpleIdentifier(); 728 constructorName = parseSimpleIdentifier();
729 } 729 }
730 ArgumentList arguments = null; 730 ArgumentList arguments = null;
731 if (matches5(TokenType.OPEN_PAREN)) { 731 if (matches5(TokenType.OPEN_PAREN)) {
732 arguments = parseArgumentList(); 732 arguments = parseArgumentList();
733 } 733 }
734 return new Annotation(atSign, name, period, constructorName, arguments); 734 return new Annotation.full(atSign, name, period, constructorName, arguments) ;
735 } 735 }
736 /** 736 /**
737 * Parse an argument. 737 * Parse an argument.
738 * <pre> 738 * <pre>
739 * argument ::= 739 * argument ::=
740 * namedArgument 740 * namedArgument
741 * | expression 741 * | expression
742 * namedArgument ::= 742 * namedArgument ::=
743 * label expression 743 * label expression
744 * </pre> 744 * </pre>
745 * @return the argument that was parsed 745 * @return the argument that was parsed
746 */ 746 */
747 Expression parseArgument() { 747 Expression parseArgument() {
748 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 748 if (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
749 SimpleIdentifier label = new SimpleIdentifier(andAdvance); 749 SimpleIdentifier label = new SimpleIdentifier.full(andAdvance);
750 Label name = new Label(label, andAdvance); 750 Label name = new Label.full(label, andAdvance);
751 return new NamedExpression(name, parseExpression2()); 751 return new NamedExpression.full(name, parseExpression2());
752 } else { 752 } else {
753 return parseExpression2(); 753 return parseExpression2();
754 } 754 }
755 } 755 }
756 /** 756 /**
757 * Parse an argument definition test. 757 * Parse an argument definition test.
758 * <pre> 758 * <pre>
759 * argumentDefinitionTest ::= 759 * argumentDefinitionTest ::=
760 * '?' identifier 760 * '?' identifier
761 * </pre> 761 * </pre>
762 * @return the argument definition test that was parsed 762 * @return the argument definition test that was parsed
763 */ 763 */
764 ArgumentDefinitionTest parseArgumentDefinitionTest() { 764 ArgumentDefinitionTest parseArgumentDefinitionTest() {
765 Token question = expect2(TokenType.QUESTION); 765 Token question = expect2(TokenType.QUESTION);
766 SimpleIdentifier identifier = parseSimpleIdentifier(); 766 SimpleIdentifier identifier = parseSimpleIdentifier();
767 return new ArgumentDefinitionTest(question, identifier); 767 return new ArgumentDefinitionTest.full(question, identifier);
768 } 768 }
769 /** 769 /**
770 * Parse a list of arguments. 770 * Parse a list of arguments.
771 * <pre> 771 * <pre>
772 * arguments ::= 772 * arguments ::=
773 * '(' argumentList? ')' 773 * '(' argumentList? ')'
774 * argumentList ::= 774 * argumentList ::=
775 * namedArgument (',' namedArgument) 775 * namedArgument (',' namedArgument)
776 * | expressionList (',' namedArgument) 776 * | expressionList (',' namedArgument)
777 * </pre> 777 * </pre>
778 * @return the argument list that was parsed 778 * @return the argument list that was parsed
779 */ 779 */
780 ArgumentList parseArgumentList() { 780 ArgumentList parseArgumentList() {
781 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 781 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
782 List<Expression> arguments = new List<Expression>(); 782 List<Expression> arguments = new List<Expression>();
783 if (matches5(TokenType.CLOSE_PAREN)) { 783 if (matches5(TokenType.CLOSE_PAREN)) {
784 return new ArgumentList(leftParenthesis, arguments, andAdvance); 784 return new ArgumentList.full(leftParenthesis, arguments, andAdvance);
785 } 785 }
786 Expression argument = parseArgument(); 786 Expression argument = parseArgument();
787 arguments.add(argument); 787 arguments.add(argument);
788 bool foundNamedArgument = argument is NamedExpression; 788 bool foundNamedArgument = argument is NamedExpression;
789 bool generatedError = false; 789 bool generatedError = false;
790 while (optional(TokenType.COMMA)) { 790 while (optional(TokenType.COMMA)) {
791 argument = parseArgument(); 791 argument = parseArgument();
792 arguments.add(argument); 792 arguments.add(argument);
793 if (foundNamedArgument) { 793 if (foundNamedArgument) {
794 if (!generatedError && argument is! NamedExpression) { 794 if (!generatedError && argument is! NamedExpression) {
795 reportError3(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []); 795 reportError3(ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT, []);
796 generatedError = true; 796 generatedError = true;
797 } 797 }
798 } else if (argument is NamedExpression) { 798 } else if (argument is NamedExpression) {
799 foundNamedArgument = true; 799 foundNamedArgument = true;
800 } 800 }
801 } 801 }
802 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 802 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
803 return new ArgumentList(leftParenthesis, arguments, rightParenthesis); 803 return new ArgumentList.full(leftParenthesis, arguments, rightParenthesis);
804 } 804 }
805 /** 805 /**
806 * Parse an assert statement. 806 * Parse an assert statement.
807 * <pre> 807 * <pre>
808 * assertStatement ::= 808 * assertStatement ::=
809 * 'assert' '(' conditionalExpression ')' ';' 809 * 'assert' '(' conditionalExpression ')' ';'
810 * </pre> 810 * </pre>
811 * @return the assert statement 811 * @return the assert statement
812 */ 812 */
813 AssertStatement parseAssertStatement() { 813 AssertStatement parseAssertStatement() {
814 Token keyword = expect(Keyword.ASSERT); 814 Token keyword = expect(Keyword.ASSERT);
815 Token leftParen = expect2(TokenType.OPEN_PAREN); 815 Token leftParen = expect2(TokenType.OPEN_PAREN);
816 Expression expression = parseConditionalExpression(); 816 Expression expression = parseConditionalExpression();
817 Token rightParen = expect2(TokenType.CLOSE_PAREN); 817 Token rightParen = expect2(TokenType.CLOSE_PAREN);
818 Token semicolon = expect2(TokenType.SEMICOLON); 818 Token semicolon = expect2(TokenType.SEMICOLON);
819 return new AssertStatement(keyword, leftParen, expression, rightParen, semic olon); 819 return new AssertStatement.full(keyword, leftParen, expression, rightParen, semicolon);
820 } 820 }
821 /** 821 /**
822 * Parse an assignable expression. 822 * Parse an assignable expression.
823 * <pre> 823 * <pre>
824 * assignableExpression ::= 824 * assignableExpression ::=
825 * primary (arguments* assignableSelector)+ 825 * primary (arguments* assignableSelector)+
826 * | 'super' assignableSelector 826 * | 'super' assignableSelector
827 * | identifier 827 * | identifier
828 * </pre> 828 * </pre>
829 * @param primaryAllowed {@code true} if the expression is allowed to be a pri mary without any 829 * @param primaryAllowed {@code true} if the expression is allowed to be a pri mary without any
830 * assignable selector 830 * assignable selector
831 * @return the assignable expression that was parsed 831 * @return the assignable expression that was parsed
832 */ 832 */
833 Expression parseAssignableExpression(bool primaryAllowed) { 833 Expression parseAssignableExpression(bool primaryAllowed) {
834 if (matches(Keyword.SUPER)) { 834 if (matches(Keyword.SUPER)) {
835 return parseAssignableSelector(new SuperExpression(andAdvance), false); 835 return parseAssignableSelector(new SuperExpression.full(andAdvance), false );
836 } 836 }
837 Expression expression = parsePrimaryExpression(); 837 Expression expression = parsePrimaryExpression();
838 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 838 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
839 while (true) { 839 while (true) {
840 while (matches5(TokenType.OPEN_PAREN)) { 840 while (matches5(TokenType.OPEN_PAREN)) {
841 ArgumentList argumentList = parseArgumentList(); 841 ArgumentList argumentList = parseArgumentList();
842 if (expression is SimpleIdentifier) { 842 if (expression is SimpleIdentifier) {
843 expression = new MethodInvocation(null, null, expression as SimpleIden tifier, argumentList); 843 expression = new MethodInvocation.full(null, null, (expression as Simp leIdentifier), argumentList);
844 } else if (expression is PrefixedIdentifier) { 844 } else if (expression is PrefixedIdentifier) {
845 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 845 PrefixedIdentifier identifier = (expression as PrefixedIdentifier);
846 expression = new MethodInvocation(identifier.prefix, identifier.period , identifier.identifier, argumentList); 846 expression = new MethodInvocation.full(identifier.prefix, identifier.p eriod, identifier.identifier, argumentList);
847 } else if (expression is PropertyAccess) { 847 } else if (expression is PropertyAccess) {
848 PropertyAccess access = expression as PropertyAccess; 848 PropertyAccess access = (expression as PropertyAccess);
849 expression = new MethodInvocation(access.target, access.operator, acce ss.propertyName, argumentList); 849 expression = new MethodInvocation.full(access.target, access.operator, access.propertyName, argumentList);
850 } else { 850 } else {
851 expression = new FunctionExpressionInvocation(expression, argumentList ); 851 expression = new FunctionExpressionInvocation.full(expression, argumen tList);
852 } 852 }
853 if (!primaryAllowed) { 853 if (!primaryAllowed) {
854 isOptional = false; 854 isOptional = false;
855 } 855 }
856 } 856 }
857 Expression selectorExpression = parseAssignableSelector(expression, isOpti onal || (expression is PrefixedIdentifier)); 857 Expression selectorExpression = parseAssignableSelector(expression, isOpti onal || (expression is PrefixedIdentifier));
858 if (selectorExpression == expression) { 858 if (identical(selectorExpression, expression)) {
859 if (!isOptional && (expression is PrefixedIdentifier)) { 859 if (!isOptional && (expression is PrefixedIdentifier)) {
860 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 860 PrefixedIdentifier identifier = (expression as PrefixedIdentifier);
861 expression = new PropertyAccess(identifier.prefix, identifier.period, identifier.identifier); 861 expression = new PropertyAccess.full(identifier.prefix, identifier.per iod, identifier.identifier);
862 } 862 }
863 return expression; 863 return expression;
864 } 864 }
865 expression = selectorExpression; 865 expression = selectorExpression;
866 isOptional = true; 866 isOptional = true;
867 } 867 }
868 } 868 }
869 /** 869 /**
870 * Parse an assignable selector. 870 * Parse an assignable selector.
871 * <pre> 871 * <pre>
872 * assignableSelector ::= 872 * assignableSelector ::=
873 * '[' expression ']' 873 * '[' expression ']'
874 * | '.' identifier 874 * | '.' identifier
875 * </pre> 875 * </pre>
876 * @param prefix the expression preceding the selector 876 * @param prefix the expression preceding the selector
877 * @param optional {@code true} if the selector is optional 877 * @param optional {@code true} if the selector is optional
878 * @return the assignable selector that was parsed 878 * @return the assignable selector that was parsed
879 */ 879 */
880 Expression parseAssignableSelector(Expression prefix, bool optional) { 880 Expression parseAssignableSelector(Expression prefix, bool optional) {
881 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 881 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
882 Token leftBracket = andAdvance; 882 Token leftBracket = andAdvance;
883 Expression index = parseExpression2(); 883 Expression index = parseExpression2();
884 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 884 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
885 return new IndexExpression.con1(prefix, leftBracket, index, rightBracket); 885 return new IndexExpression.forTarget_full(prefix, leftBracket, index, righ tBracket);
886 } else if (matches5(TokenType.PERIOD)) { 886 } else if (matches5(TokenType.PERIOD)) {
887 Token period = andAdvance; 887 Token period = andAdvance;
888 return new PropertyAccess(prefix, period, parseSimpleIdentifier()); 888 return new PropertyAccess.full(prefix, period, parseSimpleIdentifier());
889 } else { 889 } else {
890 if (!optional) { 890 if (!optional) {
891 reportError3(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 891 reportError3(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
892 } 892 }
893 return prefix; 893 return prefix;
894 } 894 }
895 } 895 }
896 /** 896 /**
897 * Parse a bitwise and expression. 897 * Parse a bitwise and expression.
898 * <pre> 898 * <pre>
899 * bitwiseAndExpression ::= 899 * bitwiseAndExpression ::=
900 * equalityExpression ('&' equalityExpression) 900 * equalityExpression ('&' equalityExpression)
901 * | 'super' ('&' equalityExpression)+ 901 * | 'super' ('&' equalityExpression)+
902 * </pre> 902 * </pre>
903 * @return the bitwise and expression that was parsed 903 * @return the bitwise and expression that was parsed
904 */ 904 */
905 Expression parseBitwiseAndExpression() { 905 Expression parseBitwiseAndExpression() {
906 Expression expression; 906 Expression expression;
907 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) { 907 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.AMPERSAND)) {
908 expression = new SuperExpression(andAdvance); 908 expression = new SuperExpression.full(andAdvance);
909 } else { 909 } else {
910 expression = parseEqualityExpression(); 910 expression = parseEqualityExpression();
911 } 911 }
912 while (matches5(TokenType.AMPERSAND)) { 912 while (matches5(TokenType.AMPERSAND)) {
913 Token operator = andAdvance; 913 Token operator = andAdvance;
914 expression = new BinaryExpression(expression, operator, parseEqualityExpre ssion()); 914 expression = new BinaryExpression.full(expression, operator, parseEquality Expression());
915 } 915 }
916 return expression; 916 return expression;
917 } 917 }
918 /** 918 /**
919 * Parse a bitwise or expression. 919 * Parse a bitwise or expression.
920 * <pre> 920 * <pre>
921 * bitwiseOrExpression ::= 921 * bitwiseOrExpression ::=
922 * bitwiseXorExpression ('|' bitwiseXorExpression) 922 * bitwiseXorExpression ('|' bitwiseXorExpression)
923 * | 'super' ('|' bitwiseXorExpression)+ 923 * | 'super' ('|' bitwiseXorExpression)+
924 * </pre> 924 * </pre>
925 * @return the bitwise or expression that was parsed 925 * @return the bitwise or expression that was parsed
926 */ 926 */
927 Expression parseBitwiseOrExpression() { 927 Expression parseBitwiseOrExpression() {
928 Expression expression; 928 Expression expression;
929 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) { 929 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.BAR)) {
930 expression = new SuperExpression(andAdvance); 930 expression = new SuperExpression.full(andAdvance);
931 } else { 931 } else {
932 expression = parseBitwiseXorExpression(); 932 expression = parseBitwiseXorExpression();
933 } 933 }
934 while (matches5(TokenType.BAR)) { 934 while (matches5(TokenType.BAR)) {
935 Token operator = andAdvance; 935 Token operator = andAdvance;
936 expression = new BinaryExpression(expression, operator, parseBitwiseXorExp ression()); 936 expression = new BinaryExpression.full(expression, operator, parseBitwiseX orExpression());
937 } 937 }
938 return expression; 938 return expression;
939 } 939 }
940 /** 940 /**
941 * Parse a bitwise exclusive-or expression. 941 * Parse a bitwise exclusive-or expression.
942 * <pre> 942 * <pre>
943 * bitwiseXorExpression ::= 943 * bitwiseXorExpression ::=
944 * bitwiseAndExpression ('^' bitwiseAndExpression) 944 * bitwiseAndExpression ('^' bitwiseAndExpression)
945 * | 'super' ('^' bitwiseAndExpression)+ 945 * | 'super' ('^' bitwiseAndExpression)+
946 * </pre> 946 * </pre>
947 * @return the bitwise exclusive-or expression that was parsed 947 * @return the bitwise exclusive-or expression that was parsed
948 */ 948 */
949 Expression parseBitwiseXorExpression() { 949 Expression parseBitwiseXorExpression() {
950 Expression expression; 950 Expression expression;
951 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) { 951 if (matches(Keyword.SUPER) && matches4(peek(), TokenType.CARET)) {
952 expression = new SuperExpression(andAdvance); 952 expression = new SuperExpression.full(andAdvance);
953 } else { 953 } else {
954 expression = parseBitwiseAndExpression(); 954 expression = parseBitwiseAndExpression();
955 } 955 }
956 while (matches5(TokenType.CARET)) { 956 while (matches5(TokenType.CARET)) {
957 Token operator = andAdvance; 957 Token operator = andAdvance;
958 expression = new BinaryExpression(expression, operator, parseBitwiseAndExp ression()); 958 expression = new BinaryExpression.full(expression, operator, parseBitwiseA ndExpression());
959 } 959 }
960 return expression; 960 return expression;
961 } 961 }
962 /** 962 /**
963 * Parse a block. 963 * Parse a block.
964 * <pre> 964 * <pre>
965 * block ::= 965 * block ::=
966 * '{' statements '}' 966 * '{' statements '}'
967 * </pre> 967 * </pre>
968 * @return the block that was parsed 968 * @return the block that was parsed
969 */ 969 */
970 Block parseBlock() { 970 Block parseBlock() {
971 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 971 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
972 List<Statement> statements = new List<Statement>(); 972 List<Statement> statements = new List<Statement>();
973 Token statementStart = _currentToken; 973 Token statementStart = _currentToken;
974 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) { 974 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET)) {
975 Statement statement = parseStatement2(); 975 Statement statement = parseStatement2();
976 if (statement != null) { 976 if (statement != null) {
977 statements.add(statement); 977 statements.add(statement);
978 } 978 }
979 if (_currentToken == statementStart) { 979 if (identical(_currentToken, statementStart)) {
980 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 980 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
981 advance(); 981 advance();
982 } 982 }
983 statementStart = _currentToken; 983 statementStart = _currentToken;
984 } 984 }
985 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 985 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
986 return new Block(leftBracket, statements, rightBracket); 986 return new Block.full(leftBracket, statements, rightBracket);
987 } 987 }
988 /** 988 /**
989 * Parse a break statement. 989 * Parse a break statement.
990 * <pre> 990 * <pre>
991 * breakStatement ::= 991 * breakStatement ::=
992 * 'break' identifier? ';' 992 * 'break' identifier? ';'
993 * </pre> 993 * </pre>
994 * @return the break statement that was parsed 994 * @return the break statement that was parsed
995 */ 995 */
996 Statement parseBreakStatement() { 996 Statement parseBreakStatement() {
997 Token breakKeyword = expect(Keyword.BREAK); 997 Token breakKeyword = expect(Keyword.BREAK);
998 SimpleIdentifier label = null; 998 SimpleIdentifier label = null;
999 if (matchesIdentifier()) { 999 if (matchesIdentifier()) {
1000 label = parseSimpleIdentifier(); 1000 label = parseSimpleIdentifier();
1001 } 1001 }
1002 if (!_inLoop && !_inSwitch && label == null) { 1002 if (!_inLoop && !_inSwitch && label == null) {
1003 reportError4(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []); 1003 reportError4(ParserErrorCode.BREAK_OUTSIDE_OF_LOOP, breakKeyword, []);
1004 } 1004 }
1005 Token semicolon = expect2(TokenType.SEMICOLON); 1005 Token semicolon = expect2(TokenType.SEMICOLON);
1006 return new BreakStatement(breakKeyword, label, semicolon); 1006 return new BreakStatement.full(breakKeyword, label, semicolon);
1007 } 1007 }
1008 /** 1008 /**
1009 * Parse a cascade section. 1009 * Parse a cascade section.
1010 * <pre> 1010 * <pre>
1011 * cascadeSection ::= 1011 * cascadeSection ::=
1012 * '..' cascadeSelector arguments* (assignableSelector arguments*)* cascadeAss ignment? 1012 * '..' cascadeSelector arguments* (assignableSelector arguments*)* cascadeAss ignment?
1013 * cascadeSelector ::= 1013 * cascadeSelector ::=
1014 * '[' expression ']' 1014 * '[' expression ']'
1015 * | identifier 1015 * | identifier
1016 * cascadeAssignment ::= 1016 * cascadeAssignment ::=
1017 * assignmentOperator expressionWithoutCascade 1017 * assignmentOperator expressionWithoutCascade
1018 * </pre> 1018 * </pre>
1019 * @return the expression representing the cascaded method invocation 1019 * @return the expression representing the cascaded method invocation
1020 */ 1020 */
1021 Expression parseCascadeSection() { 1021 Expression parseCascadeSection() {
1022 Token period = expect2(TokenType.PERIOD_PERIOD); 1022 Token period = expect2(TokenType.PERIOD_PERIOD);
1023 Expression expression = null; 1023 Expression expression = null;
1024 SimpleIdentifier functionName = null; 1024 SimpleIdentifier functionName = null;
1025 if (matchesIdentifier()) { 1025 if (matchesIdentifier()) {
1026 functionName = parseSimpleIdentifier(); 1026 functionName = parseSimpleIdentifier();
1027 } else if (_currentToken.type == TokenType.OPEN_SQUARE_BRACKET) { 1027 } else if (identical(_currentToken.type, TokenType.OPEN_SQUARE_BRACKET)) {
1028 Token leftBracket = andAdvance; 1028 Token leftBracket = andAdvance;
1029 Expression index = parseExpression2(); 1029 Expression index = parseExpression2();
1030 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 1030 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
1031 expression = new IndexExpression.con2(period, leftBracket, index, rightBra cket); 1031 expression = new IndexExpression.forCascade_full(period, leftBracket, inde x, rightBracket);
1032 period = null; 1032 period = null;
1033 } else { 1033 } else {
1034 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentTok en.lexeme]); 1034 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentTok en.lexeme]);
1035 return expression; 1035 return expression;
1036 } 1036 }
1037 if (_currentToken.type == TokenType.OPEN_PAREN) { 1037 if (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
1038 while (_currentToken.type == TokenType.OPEN_PAREN) { 1038 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
1039 if (functionName != null) { 1039 if (functionName != null) {
1040 expression = new MethodInvocation(expression, period, functionName, pa rseArgumentList()); 1040 expression = new MethodInvocation.full(expression, period, functionNam e, parseArgumentList());
1041 period = null; 1041 period = null;
1042 functionName = null; 1042 functionName = null;
1043 } else if (expression == null) { 1043 } else if (expression == null) {
1044 return null; 1044 return null;
1045 } else { 1045 } else {
1046 expression = new FunctionExpressionInvocation(expression, parseArgumen tList()); 1046 expression = new FunctionExpressionInvocation.full(expression, parseAr gumentList());
1047 } 1047 }
1048 } 1048 }
1049 } else if (functionName != null) { 1049 } else if (functionName != null) {
1050 expression = new PropertyAccess(expression, period, functionName); 1050 expression = new PropertyAccess.full(expression, period, functionName);
1051 period = null; 1051 period = null;
1052 } 1052 }
1053 bool progress = true; 1053 bool progress = true;
1054 while (progress) { 1054 while (progress) {
1055 progress = false; 1055 progress = false;
1056 Expression selector = parseAssignableSelector(expression, true); 1056 Expression selector = parseAssignableSelector(expression, true);
1057 if (selector != expression) { 1057 if (selector != expression) {
1058 expression = selector; 1058 expression = selector;
1059 progress = true; 1059 progress = true;
1060 while (_currentToken.type == TokenType.OPEN_PAREN) { 1060 while (identical(_currentToken.type, TokenType.OPEN_PAREN)) {
1061 expression = new FunctionExpressionInvocation(expression, parseArgumen tList()); 1061 expression = new FunctionExpressionInvocation.full(expression, parseAr gumentList());
1062 } 1062 }
1063 } 1063 }
1064 } 1064 }
1065 if (_currentToken.type.isAssignmentOperator()) { 1065 if (_currentToken.type.isAssignmentOperator()) {
1066 Token operator = andAdvance; 1066 Token operator = andAdvance;
1067 ensureAssignable(expression); 1067 ensureAssignable(expression);
1068 expression = new AssignmentExpression(expression, operator, parseExpressio n2()); 1068 expression = new AssignmentExpression.full(expression, operator, parseExpr ession2());
1069 } 1069 }
1070 return expression; 1070 return expression;
1071 } 1071 }
1072 /** 1072 /**
1073 * Parse a class declaration. 1073 * Parse a class declaration.
1074 * <pre> 1074 * <pre>
1075 * classDeclaration ::= 1075 * classDeclaration ::=
1076 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause withCla use?)? implementsClause? '{' classMembers '}' 1076 * metadata 'abstract'? 'class' name typeParameterList? (extendsClause withCla use?)? implementsClause? '{' classMembers '}'
1077 * </pre> 1077 * </pre>
1078 * @param commentAndMetadata the metadata to be associated with the member 1078 * @param commentAndMetadata the metadata to be associated with the member
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 Token rightBracket = null; 1134 Token rightBracket = null;
1135 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 1135 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
1136 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 1136 leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
1137 members = parseClassMembers(className); 1137 members = parseClassMembers(className);
1138 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 1138 rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
1139 } else { 1139 } else {
1140 leftBracket = createSyntheticToken(TokenType.OPEN_CURLY_BRACKET); 1140 leftBracket = createSyntheticToken(TokenType.OPEN_CURLY_BRACKET);
1141 rightBracket = createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET); 1141 rightBracket = createSyntheticToken(TokenType.CLOSE_CURLY_BRACKET);
1142 reportError3(ParserErrorCode.MISSING_CLASS_BODY, []); 1142 reportError3(ParserErrorCode.MISSING_CLASS_BODY, []);
1143 } 1143 }
1144 return new ClassDeclaration(commentAndMetadata.comment, commentAndMetadata.m etadata, abstractKeyword, keyword, name, typeParameters, extendsClause, withClau se, implementsClause, leftBracket, members, rightBracket); 1144 return new ClassDeclaration.full(commentAndMetadata.comment, commentAndMetad ata.metadata, abstractKeyword, keyword, name, typeParameters, extendsClause, wit hClause, implementsClause, leftBracket, members, rightBracket);
1145 } 1145 }
1146 /** 1146 /**
1147 * Parse a class member. 1147 * Parse a class member.
1148 * <pre> 1148 * <pre>
1149 * classMemberDefinition ::= 1149 * classMemberDefinition ::=
1150 * declaration ';' 1150 * declaration ';'
1151 * | methodSignature functionBody 1151 * | methodSignature functionBody
1152 * </pre> 1152 * </pre>
1153 * @param className the name of the class containing the member being parsed 1153 * @param className the name of the class containing the member being parsed
1154 * @return the class member that was parsed 1154 * @return the class member that was parsed
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !matches(Keyword.CLASS) && !matches(Keyword.TYPEDEF)) { 1235 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !matches(Keyword.CLASS) && !matches(Keyword.TYPEDEF)) {
1236 if (matches5(TokenType.SEMICOLON)) { 1236 if (matches5(TokenType.SEMICOLON)) {
1237 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 1237 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
1238 advance(); 1238 advance();
1239 } else { 1239 } else {
1240 ClassMember member = parseClassMember(className); 1240 ClassMember member = parseClassMember(className);
1241 if (member != null) { 1241 if (member != null) {
1242 members.add(member); 1242 members.add(member);
1243 } 1243 }
1244 } 1244 }
1245 if (_currentToken == memberStart) { 1245 if (identical(_currentToken, memberStart)) {
1246 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 1246 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
1247 advance(); 1247 advance();
1248 } 1248 }
1249 memberStart = _currentToken; 1249 memberStart = _currentToken;
1250 } 1250 }
1251 return members; 1251 return members;
1252 } 1252 }
1253 /** 1253 /**
1254 * Parse a class type alias. 1254 * Parse a class type alias.
1255 * <pre> 1255 * <pre>
(...skipping 17 matching lines...) Expand all
1273 if (matches(Keyword.ABSTRACT)) { 1273 if (matches(Keyword.ABSTRACT)) {
1274 abstractKeyword = andAdvance; 1274 abstractKeyword = andAdvance;
1275 } 1275 }
1276 TypeName superclass = parseTypeName(); 1276 TypeName superclass = parseTypeName();
1277 WithClause withClause = parseWithClause(); 1277 WithClause withClause = parseWithClause();
1278 ImplementsClause implementsClause = null; 1278 ImplementsClause implementsClause = null;
1279 if (matches(Keyword.IMPLEMENTS)) { 1279 if (matches(Keyword.IMPLEMENTS)) {
1280 implementsClause = parseImplementsClause(); 1280 implementsClause = parseImplementsClause();
1281 } 1281 }
1282 Token semicolon = expect2(TokenType.SEMICOLON); 1282 Token semicolon = expect2(TokenType.SEMICOLON);
1283 return new ClassTypeAlias(commentAndMetadata.comment, commentAndMetadata.met adata, keyword, name, typeParameters, equals, abstractKeyword, superclass, withC lause, implementsClause, semicolon); 1283 return new ClassTypeAlias.full(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, name, typeParameters, equals, abstractKeyword, superclass, withClause, implementsClause, semicolon);
1284 } 1284 }
1285 /** 1285 /**
1286 * Parse a list of combinators in a directive. 1286 * Parse a list of combinators in a directive.
1287 * <pre> 1287 * <pre>
1288 * combinator ::= 1288 * combinator ::=
1289 * 'show' identifier (',' identifier) 1289 * 'show' identifier (',' identifier)
1290 * | 'hide' identifier (',' identifier) 1290 * | 'hide' identifier (',' identifier)
1291 * </pre> 1291 * </pre>
1292 * @return the combinators that were parsed 1292 * @return the combinators that were parsed
1293 */ 1293 */
1294 List<Combinator> parseCombinators() { 1294 List<Combinator> parseCombinators() {
1295 List<Combinator> combinators = new List<Combinator>(); 1295 List<Combinator> combinators = new List<Combinator>();
1296 while (matches2(Parser._SHOW) || matches2(Parser._HIDE)) { 1296 while (matches2(_SHOW) || matches2(_HIDE)) {
1297 Token keyword = expect2(TokenType.IDENTIFIER); 1297 Token keyword = expect2(TokenType.IDENTIFIER);
1298 if (keyword.lexeme == Parser._SHOW) { 1298 if (keyword.lexeme == _SHOW) {
1299 List<SimpleIdentifier> shownNames = parseIdentifierList(); 1299 List<SimpleIdentifier> shownNames = parseIdentifierList();
1300 combinators.add(new ShowCombinator(keyword, shownNames)); 1300 combinators.add(new ShowCombinator.full(keyword, shownNames));
1301 } else { 1301 } else {
1302 List<SimpleIdentifier> hiddenNames = parseIdentifierList(); 1302 List<SimpleIdentifier> hiddenNames = parseIdentifierList();
1303 combinators.add(new HideCombinator(keyword, hiddenNames)); 1303 combinators.add(new HideCombinator.full(keyword, hiddenNames));
1304 } 1304 }
1305 } 1305 }
1306 return combinators; 1306 return combinators;
1307 } 1307 }
1308 /** 1308 /**
1309 * Parse the documentation comment and metadata preceeding a declaration. This method allows any 1309 * Parse the documentation comment and metadata preceeding a declaration. This method allows any
1310 * number of documentation comments to occur before, after or between the meta data, but only 1310 * number of documentation comments to occur before, after or between the meta data, but only
1311 * returns the last (right-most) documentation comment that is found. 1311 * returns the last (right-most) documentation comment that is found.
1312 * <pre> 1312 * <pre>
1313 * metadata ::= 1313 * metadata ::=
(...skipping 23 matching lines...) Expand all
1337 * comment 1337 * comment
1338 * @param sourceOffset the offset of the first character of the reference sour ce 1338 * @param sourceOffset the offset of the first character of the reference sour ce
1339 * @return the comment reference that was parsed 1339 * @return the comment reference that was parsed
1340 */ 1340 */
1341 CommentReference parseCommentReference(String referenceSource, int sourceOffse t) { 1341 CommentReference parseCommentReference(String referenceSource, int sourceOffse t) {
1342 if (referenceSource.length == 0) { 1342 if (referenceSource.length == 0) {
1343 return null; 1343 return null;
1344 } 1344 }
1345 try { 1345 try {
1346 List<bool> errorFound = [false]; 1346 List<bool> errorFound = [false];
1347 AnalysisErrorListener listener = new AnalysisErrorListener_1(errorFound); 1347 AnalysisErrorListener listener = new AnalysisErrorListener_4(errorFound);
1348 StringScanner scanner = new StringScanner(null, referenceSource, listener) ; 1348 StringScanner scanner = new StringScanner(null, referenceSource, listener) ;
1349 scanner.setSourceStart(1, 1, sourceOffset); 1349 scanner.setSourceStart(1, 1, sourceOffset);
1350 Token firstToken = scanner.tokenize(); 1350 Token firstToken = scanner.tokenize();
1351 if (!errorFound[0]) { 1351 if (!errorFound[0]) {
1352 Token newKeyword = null; 1352 Token newKeyword = null;
1353 if (matches3(firstToken, Keyword.NEW)) { 1353 if (matches3(firstToken, Keyword.NEW)) {
1354 newKeyword = firstToken; 1354 newKeyword = firstToken;
1355 firstToken = firstToken.next; 1355 firstToken = firstToken.next;
1356 } 1356 }
1357 if (matchesIdentifier2(firstToken)) { 1357 if (matchesIdentifier2(firstToken)) {
1358 Token secondToken = firstToken.next; 1358 Token secondToken = firstToken.next;
1359 Token thirdToken = secondToken.next; 1359 Token thirdToken = secondToken.next;
1360 Token nextToken; 1360 Token nextToken;
1361 Identifier identifier; 1361 Identifier identifier;
1362 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thir dToken)) { 1362 if (matches4(secondToken, TokenType.PERIOD) && matchesIdentifier2(thir dToken)) {
1363 identifier = new PrefixedIdentifier(new SimpleIdentifier(firstToken) , secondToken, new SimpleIdentifier(thirdToken)); 1363 identifier = new PrefixedIdentifier.full(new SimpleIdentifier.full(f irstToken), secondToken, new SimpleIdentifier.full(thirdToken));
1364 nextToken = thirdToken.next; 1364 nextToken = thirdToken.next;
1365 } else { 1365 } else {
1366 identifier = new SimpleIdentifier(firstToken); 1366 identifier = new SimpleIdentifier.full(firstToken);
1367 nextToken = firstToken.next; 1367 nextToken = firstToken.next;
1368 } 1368 }
1369 if (nextToken.type != TokenType.EOF) { 1369 if (nextToken.type != TokenType.EOF) {
1370 } 1370 }
1371 return new CommentReference(newKeyword, identifier); 1371 return new CommentReference.full(newKeyword, identifier);
1372 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Ke yword.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keywor d.FALSE)) { 1372 } else if (matches3(firstToken, Keyword.THIS) || matches3(firstToken, Ke yword.NULL) || matches3(firstToken, Keyword.TRUE) || matches3(firstToken, Keywor d.FALSE)) {
1373 return null; 1373 return null;
1374 } else if (matches4(firstToken, TokenType.STRING)) { 1374 } else if (matches4(firstToken, TokenType.STRING)) {
1375 } else { 1375 } else {
1376 } 1376 }
1377 } 1377 }
1378 } on Exception catch (exception) { 1378 } on JavaException catch (exception) {
1379 } 1379 }
1380 return null; 1380 return null;
1381 } 1381 }
1382 /** 1382 /**
1383 * Parse all of the comment references occurring in the given array of documen tation comments. 1383 * Parse all of the comment references occurring in the given array of documen tation comments.
1384 * <pre> 1384 * <pre>
1385 * commentReference ::= 1385 * commentReference ::=
1386 * '[' 'new'? qualified ']' libraryReference? 1386 * '[' 'new'? qualified ']' libraryReference?
1387 * libraryReference ::= 1387 * libraryReference ::=
1388 * '(' stringLiteral ')' 1388 * '(' stringLiteral ')'
1389 * </pre> 1389 * </pre>
1390 * @param tokens the comment tokens representing the documentation comments to be parsed 1390 * @param tokens the comment tokens representing the documentation comments to be parsed
1391 * @return the comment references that were parsed 1391 * @return the comment references that were parsed
1392 */ 1392 */
1393 List<CommentReference> parseCommentReferences(List<Token> tokens) { 1393 List<CommentReference> parseCommentReferences(List<Token> tokens) {
1394 List<CommentReference> references = new List<CommentReference>(); 1394 List<CommentReference> references = new List<CommentReference>();
1395 for (Token token in tokens) { 1395 for (Token token in tokens) {
1396 String comment = token.lexeme; 1396 String comment = token.lexeme;
1397 int leftIndex = comment.indexOf('['); 1397 int leftIndex = comment.indexOf('[');
1398 while (leftIndex >= 0) { 1398 while (leftIndex >= 0) {
1399 int rightIndex = comment.indexOf(']', leftIndex); 1399 int rightIndex = comment.indexOf(']', leftIndex);
1400 if (rightIndex >= 0) { 1400 if (rightIndex >= 0) {
1401 int firstChar = comment.charCodeAt(leftIndex + 1); 1401 int firstChar = comment.codeUnitAt(leftIndex + 1);
1402 if (firstChar != 0x27 && firstChar != 0x22 && firstChar != 0x3a) { 1402 if (firstChar != 0x27 && firstChar != 0x22 && firstChar != 0x3A) {
1403 CommentReference reference = parseCommentReference(comment.substring (leftIndex + 1, rightIndex), token.offset + leftIndex + 1); 1403 CommentReference reference = parseCommentReference(comment.substring (leftIndex + 1, rightIndex), token.offset + leftIndex + 1);
1404 if (reference != null) { 1404 if (reference != null) {
1405 references.add(reference); 1405 references.add(reference);
1406 } 1406 }
1407 } 1407 }
1408 } else { 1408 } else {
1409 rightIndex = leftIndex + 1; 1409 rightIndex = leftIndex + 1;
1410 } 1410 }
1411 leftIndex = comment.indexOf('[', rightIndex); 1411 leftIndex = comment.indexOf('[', rightIndex);
1412 } 1412 }
(...skipping 18 matching lines...) Expand all
1431 * </pre> 1431 * </pre>
1432 * @return the compilation unit that was parsed 1432 * @return the compilation unit that was parsed
1433 */ 1433 */
1434 CompilationUnit parseCompilationUnit2() { 1434 CompilationUnit parseCompilationUnit2() {
1435 Token firstToken = _currentToken.precedingComments; 1435 Token firstToken = _currentToken.precedingComments;
1436 if (firstToken == null) { 1436 if (firstToken == null) {
1437 firstToken = _currentToken; 1437 firstToken = _currentToken;
1438 } 1438 }
1439 ScriptTag scriptTag = null; 1439 ScriptTag scriptTag = null;
1440 if (matches5(TokenType.SCRIPT_TAG)) { 1440 if (matches5(TokenType.SCRIPT_TAG)) {
1441 scriptTag = new ScriptTag(andAdvance); 1441 scriptTag = new ScriptTag.full(andAdvance);
1442 } 1442 }
1443 bool libraryDirectiveFound = false; 1443 bool libraryDirectiveFound = false;
1444 bool partOfDirectiveFound = false; 1444 bool partOfDirectiveFound = false;
1445 bool partDirectiveFound = false; 1445 bool partDirectiveFound = false;
1446 bool directiveFoundAfterDeclaration = false; 1446 bool directiveFoundAfterDeclaration = false;
1447 List<Directive> directives = new List<Directive>(); 1447 List<Directive> directives = new List<Directive>();
1448 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ; 1448 List<CompilationUnitMember> declarations = new List<CompilationUnitMember>() ;
1449 Token memberStart = _currentToken; 1449 Token memberStart = _currentToken;
1450 while (!matches5(TokenType.EOF)) { 1450 while (!matches5(TokenType.EOF)) {
1451 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 1451 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 directives.add(directive); 1490 directives.add(directive);
1491 } else if (matches5(TokenType.SEMICOLON)) { 1491 } else if (matches5(TokenType.SEMICOLON)) {
1492 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 1492 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
1493 advance(); 1493 advance();
1494 } else { 1494 } else {
1495 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data); 1495 CompilationUnitMember member = parseCompilationUnitMember(commentAndMeta data);
1496 if (member != null) { 1496 if (member != null) {
1497 declarations.add(member); 1497 declarations.add(member);
1498 } 1498 }
1499 } 1499 }
1500 if (_currentToken == memberStart) { 1500 if (identical(_currentToken, memberStart)) {
1501 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 1501 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
1502 advance(); 1502 advance();
1503 } 1503 }
1504 memberStart = _currentToken; 1504 memberStart = _currentToken;
1505 } 1505 }
1506 return new CompilationUnit(firstToken, scriptTag, directives, declarations, _currentToken); 1506 return new CompilationUnit.full(firstToken, scriptTag, directives, declarati ons, _currentToken);
1507 } 1507 }
1508 /** 1508 /**
1509 * Parse a compilation unit member. 1509 * Parse a compilation unit member.
1510 * <pre> 1510 * <pre>
1511 * compilationUnitMember ::= 1511 * compilationUnitMember ::=
1512 * classDefinition 1512 * classDefinition
1513 * | functionTypeAlias 1513 * | functionTypeAlias
1514 * | external functionSignature 1514 * | external functionSignature
1515 * | external getterSignature 1515 * | external getterSignature
1516 * | external setterSignature 1516 * | external setterSignature
(...skipping 20 matching lines...) Expand all
1537 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, null, false); 1537 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, null, false);
1538 } else if (matches(Keyword.OPERATOR) && peek().isOperator()) { 1538 } else if (matches(Keyword.OPERATOR) && peek().isOperator()) {
1539 return null; 1539 return null;
1540 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN , TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { 1540 } else if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN , TokenType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) {
1541 validateModifiersForTopLevelFunction(modifiers); 1541 validateModifiersForTopLevelFunction(modifiers);
1542 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, null, false); 1542 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKe yword, null, false);
1543 } else { 1543 } else {
1544 if (matchesIdentifier()) { 1544 if (matchesIdentifier()) {
1545 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) { 1545 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMIC OLON])) {
1546 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); 1546 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []);
1547 return new TopLevelVariableDeclaration(commentAndMetadata.comment, c ommentAndMetadata.metadata, parseVariableDeclarationList2(validateModifiersForTo pLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON)); 1547 return new TopLevelVariableDeclaration.full(commentAndMetadata.comme nt, commentAndMetadata.metadata, parseVariableDeclarationList2(validateModifiers ForTopLevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
1548 } 1548 }
1549 } 1549 }
1550 return null; 1550 return null;
1551 } 1551 }
1552 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) { 1552 } else if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifi er2(peek())) {
1553 validateModifiersForTopLevelFunction(modifiers); 1553 validateModifiersForTopLevelFunction(modifiers);
1554 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null, false); 1554 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null, false);
1555 } else if (matches(Keyword.OPERATOR) && peek().isOperator()) { 1555 } else if (matches(Keyword.OPERATOR) && peek().isOperator()) {
1556 return null; 1556 return null;
1557 } else if (!matchesIdentifier()) { 1557 } else if (!matchesIdentifier()) {
1558 return null; 1558 return null;
1559 } else if (matches4(peek(), TokenType.OPEN_PAREN)) { 1559 } else if (matches4(peek(), TokenType.OPEN_PAREN)) {
1560 validateModifiersForTopLevelFunction(modifiers); 1560 validateModifiersForTopLevelFunction(modifiers);
1561 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null, false); 1561 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, null, false);
1562 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) { 1562 } else if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEMI COLON])) {
1563 return new TopLevelVariableDeclaration(commentAndMetadata.comment, comment AndMetadata.metadata, parseVariableDeclarationList2(validateModifiersForTopLevel Variable(modifiers), null), expect2(TokenType.SEMICOLON)); 1563 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, co mmentAndMetadata.metadata, parseVariableDeclarationList2(validateModifiersForTop LevelVariable(modifiers), null), expect2(TokenType.SEMICOLON));
1564 } 1564 }
1565 TypeName returnType = parseReturnType(); 1565 TypeName returnType = parseReturnType();
1566 if (matches(Keyword.GET) || matches(Keyword.SET)) { 1566 if (matches(Keyword.GET) || matches(Keyword.SET)) {
1567 validateModifiersForTopLevelFunction(modifiers); 1567 validateModifiersForTopLevelFunction(modifiers);
1568 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType, false); 1568 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType, false);
1569 } else if (!matchesIdentifier()) { 1569 } else if (!matchesIdentifier()) {
1570 return null; 1570 return null;
1571 } 1571 }
1572 if (matchesAny(peek(), [TokenType.OPEN_PAREN, TokenType.FUNCTION, TokenType. OPEN_CURLY_BRACKET])) { 1572 if (matchesAny(peek(), [TokenType.OPEN_PAREN, TokenType.FUNCTION, TokenType. OPEN_CURLY_BRACKET])) {
1573 validateModifiersForTopLevelFunction(modifiers); 1573 validateModifiersForTopLevelFunction(modifiers);
1574 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType, false); 1574 return parseFunctionDeclaration(commentAndMetadata, modifiers.externalKeyw ord, returnType, false);
1575 } 1575 }
1576 return new TopLevelVariableDeclaration(commentAndMetadata.comment, commentAn dMetadata.metadata, parseVariableDeclarationList2(validateModifiersForTopLevelVa riable(modifiers), returnType), expect2(TokenType.SEMICOLON)); 1576 return new TopLevelVariableDeclaration.full(commentAndMetadata.comment, comm entAndMetadata.metadata, parseVariableDeclarationList2(validateModifiersForTopLe velVariable(modifiers), returnType), expect2(TokenType.SEMICOLON));
1577 } 1577 }
1578 /** 1578 /**
1579 * Parse a conditional expression. 1579 * Parse a conditional expression.
1580 * <pre> 1580 * <pre>
1581 * conditionalExpression ::= 1581 * conditionalExpression ::=
1582 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithoutCasc ade)? 1582 * logicalOrExpression ('?' expressionWithoutCascade ':' expressionWithoutCasc ade)?
1583 * </pre> 1583 * </pre>
1584 * @return the conditional expression that was parsed 1584 * @return the conditional expression that was parsed
1585 */ 1585 */
1586 Expression parseConditionalExpression() { 1586 Expression parseConditionalExpression() {
1587 Expression condition = parseLogicalOrExpression(); 1587 Expression condition = parseLogicalOrExpression();
1588 if (!matches5(TokenType.QUESTION)) { 1588 if (!matches5(TokenType.QUESTION)) {
1589 return condition; 1589 return condition;
1590 } 1590 }
1591 Token question = andAdvance; 1591 Token question = andAdvance;
1592 Expression thenExpression = parseExpressionWithoutCascade(); 1592 Expression thenExpression = parseExpressionWithoutCascade();
1593 Token colon = expect2(TokenType.COLON); 1593 Token colon = expect2(TokenType.COLON);
1594 Expression elseExpression = parseExpressionWithoutCascade(); 1594 Expression elseExpression = parseExpressionWithoutCascade();
1595 return new ConditionalExpression(condition, question, thenExpression, colon, elseExpression); 1595 return new ConditionalExpression.full(condition, question, thenExpression, c olon, elseExpression);
1596 } 1596 }
1597 /** 1597 /**
1598 * Parse a const expression. 1598 * Parse a const expression.
1599 * <pre> 1599 * <pre>
1600 * constExpression ::= 1600 * constExpression ::=
1601 * instanceCreationExpression 1601 * instanceCreationExpression
1602 * | listLiteral 1602 * | listLiteral
1603 * | mapLiteral 1603 * | mapLiteral
1604 * </pre> 1604 * </pre>
1605 * @return the const expression that was parsed 1605 * @return the const expression that was parsed
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 } else { 1638 } else {
1639 initializers.add(parseConstructorFieldInitializer()); 1639 initializers.add(parseConstructorFieldInitializer());
1640 } 1640 }
1641 } while (optional(TokenType.COMMA)); 1641 } while (optional(TokenType.COMMA));
1642 } 1642 }
1643 ConstructorName redirectedConstructor = null; 1643 ConstructorName redirectedConstructor = null;
1644 FunctionBody body; 1644 FunctionBody body;
1645 if (matches5(TokenType.EQ)) { 1645 if (matches5(TokenType.EQ)) {
1646 separator = andAdvance; 1646 separator = andAdvance;
1647 redirectedConstructor = parseConstructorName(); 1647 redirectedConstructor = parseConstructorName();
1648 body = new EmptyFunctionBody(expect2(TokenType.SEMICOLON)); 1648 body = new EmptyFunctionBody.full(expect2(TokenType.SEMICOLON));
1649 } else { 1649 } else {
1650 body = parseFunctionBody(true, false); 1650 body = parseFunctionBody(true, false);
1651 if (!bodyAllowed && body is! EmptyFunctionBody) { 1651 if (!bodyAllowed && body is! EmptyFunctionBody) {
1652 reportError3(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, []); 1652 reportError3(ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY, []);
1653 } 1653 }
1654 } 1654 }
1655 return new ConstructorDeclaration(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, period , name, parameters, separator, initializers, redirectedConstructor, body); 1655 return new ConstructorDeclaration.full(commentAndMetadata.comment, commentAn dMetadata.metadata, externalKeyword, constKeyword, factoryKeyword, returnType, p eriod, name, parameters, separator, initializers, redirectedConstructor, body);
1656 } 1656 }
1657 /** 1657 /**
1658 * Parse a field initializer within a constructor. 1658 * Parse a field initializer within a constructor.
1659 * <pre> 1659 * <pre>
1660 * fieldInitializer: 1660 * fieldInitializer:
1661 * ('this' '.')? identifier '=' conditionalExpression cascadeSection 1661 * ('this' '.')? identifier '=' conditionalExpression cascadeSection
1662 * </pre> 1662 * </pre>
1663 * @return the field initializer that was parsed 1663 * @return the field initializer that was parsed
1664 */ 1664 */
1665 ConstructorFieldInitializer parseConstructorFieldInitializer() { 1665 ConstructorFieldInitializer parseConstructorFieldInitializer() {
1666 Token keyword = null; 1666 Token keyword = null;
1667 Token period = null; 1667 Token period = null;
1668 if (matches(Keyword.THIS)) { 1668 if (matches(Keyword.THIS)) {
1669 keyword = andAdvance; 1669 keyword = andAdvance;
1670 period = expect2(TokenType.PERIOD); 1670 period = expect2(TokenType.PERIOD);
1671 } 1671 }
1672 SimpleIdentifier fieldName = parseSimpleIdentifier(); 1672 SimpleIdentifier fieldName = parseSimpleIdentifier();
1673 Token equals = expect2(TokenType.EQ); 1673 Token equals = expect2(TokenType.EQ);
1674 Expression expression = parseConditionalExpression(); 1674 Expression expression = parseConditionalExpression();
1675 TokenType tokenType = _currentToken.type; 1675 TokenType tokenType = _currentToken.type;
1676 if (tokenType == TokenType.PERIOD_PERIOD) { 1676 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1677 List<Expression> cascadeSections = new List<Expression>(); 1677 List<Expression> cascadeSections = new List<Expression>();
1678 while (tokenType == TokenType.PERIOD_PERIOD) { 1678 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1679 Expression section = parseCascadeSection(); 1679 Expression section = parseCascadeSection();
1680 if (section != null) { 1680 if (section != null) {
1681 cascadeSections.add(section); 1681 cascadeSections.add(section);
1682 } 1682 }
1683 tokenType = _currentToken.type; 1683 tokenType = _currentToken.type;
1684 } 1684 }
1685 expression = new CascadeExpression(expression, cascadeSections); 1685 expression = new CascadeExpression.full(expression, cascadeSections);
1686 } 1686 }
1687 return new ConstructorFieldInitializer(keyword, period, fieldName, equals, e xpression); 1687 return new ConstructorFieldInitializer.full(keyword, period, fieldName, equa ls, expression);
1688 } 1688 }
1689 /** 1689 /**
1690 * Parse the name of a constructor. 1690 * Parse the name of a constructor.
1691 * <pre> 1691 * <pre>
1692 * constructorName: 1692 * constructorName:
1693 * type ('.' identifier)? 1693 * type ('.' identifier)?
1694 * </pre> 1694 * </pre>
1695 * @return the constructor name that was parsed 1695 * @return the constructor name that was parsed
1696 */ 1696 */
1697 ConstructorName parseConstructorName() { 1697 ConstructorName parseConstructorName() {
1698 TypeName type = parseTypeName(); 1698 TypeName type = parseTypeName();
1699 Token period = null; 1699 Token period = null;
1700 SimpleIdentifier name = null; 1700 SimpleIdentifier name = null;
1701 if (matches5(TokenType.PERIOD)) { 1701 if (matches5(TokenType.PERIOD)) {
1702 period = andAdvance; 1702 period = andAdvance;
1703 name = parseSimpleIdentifier(); 1703 name = parseSimpleIdentifier();
1704 } 1704 }
1705 return new ConstructorName(type, period, name); 1705 return new ConstructorName.full(type, period, name);
1706 } 1706 }
1707 /** 1707 /**
1708 * Parse a continue statement. 1708 * Parse a continue statement.
1709 * <pre> 1709 * <pre>
1710 * continueStatement ::= 1710 * continueStatement ::=
1711 * 'continue' identifier? ';' 1711 * 'continue' identifier? ';'
1712 * </pre> 1712 * </pre>
1713 * @return the continue statement that was parsed 1713 * @return the continue statement that was parsed
1714 */ 1714 */
1715 Statement parseContinueStatement() { 1715 Statement parseContinueStatement() {
1716 Token continueKeyword = expect(Keyword.CONTINUE); 1716 Token continueKeyword = expect(Keyword.CONTINUE);
1717 if (!_inLoop && !_inSwitch) { 1717 if (!_inLoop && !_inSwitch) {
1718 reportError4(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [] ); 1718 reportError4(ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP, continueKeyword, [] );
1719 } 1719 }
1720 SimpleIdentifier label = null; 1720 SimpleIdentifier label = null;
1721 if (matchesIdentifier()) { 1721 if (matchesIdentifier()) {
1722 label = parseSimpleIdentifier(); 1722 label = parseSimpleIdentifier();
1723 } 1723 }
1724 if (_inSwitch && !_inLoop && label == null) { 1724 if (_inSwitch && !_inLoop && label == null) {
1725 reportError4(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeywo rd, []); 1725 reportError4(ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE, continueKeywo rd, []);
1726 } 1726 }
1727 Token semicolon = expect2(TokenType.SEMICOLON); 1727 Token semicolon = expect2(TokenType.SEMICOLON);
1728 return new ContinueStatement(continueKeyword, label, semicolon); 1728 return new ContinueStatement.full(continueKeyword, label, semicolon);
1729 } 1729 }
1730 /** 1730 /**
1731 * Parse a directive. 1731 * Parse a directive.
1732 * <pre> 1732 * <pre>
1733 * directive ::= 1733 * directive ::=
1734 * exportDirective 1734 * exportDirective
1735 * | libraryDirective 1735 * | libraryDirective
1736 * | importDirective 1736 * | importDirective
1737 * | partDirective 1737 * | partDirective
1738 * </pre> 1738 * </pre>
(...skipping 19 matching lines...) Expand all
1758 * documentationComment ::= 1758 * documentationComment ::=
1759 * multiLineComment? 1759 * multiLineComment?
1760 * | singleLineComment 1760 * | singleLineComment
1761 * </pre> 1761 * </pre>
1762 * @return the documentation comment that was parsed, or {@code null} if there was no comment 1762 * @return the documentation comment that was parsed, or {@code null} if there was no comment
1763 */ 1763 */
1764 Comment parseDocumentationComment() { 1764 Comment parseDocumentationComment() {
1765 List<Token> commentTokens = new List<Token>(); 1765 List<Token> commentTokens = new List<Token>();
1766 Token commentToken = _currentToken.precedingComments; 1766 Token commentToken = _currentToken.precedingComments;
1767 while (commentToken != null) { 1767 while (commentToken != null) {
1768 if (commentToken.type == TokenType.SINGLE_LINE_COMMENT) { 1768 if (identical(commentToken.type, TokenType.SINGLE_LINE_COMMENT)) {
1769 if (commentToken.lexeme.startsWith("///")) { 1769 if (commentToken.lexeme.startsWith("///")) {
1770 if (commentTokens.length == 1 && commentTokens[0].lexeme.startsWith("/ **")) { 1770 if (commentTokens.length == 1 && commentTokens[0].lexeme.startsWith("/ **")) {
1771 commentTokens.clear(); 1771 commentTokens.clear();
1772 } 1772 }
1773 commentTokens.add(commentToken); 1773 commentTokens.add(commentToken);
1774 } 1774 }
1775 } else { 1775 } else {
1776 if (commentToken.lexeme.startsWith("/**")) { 1776 if (commentToken.lexeme.startsWith("/**")) {
1777 commentTokens.clear(); 1777 commentTokens.clear();
1778 commentTokens.add(commentToken); 1778 commentTokens.add(commentToken);
(...skipping 20 matching lines...) Expand all
1799 bool wasInLoop = _inLoop; 1799 bool wasInLoop = _inLoop;
1800 _inLoop = true; 1800 _inLoop = true;
1801 try { 1801 try {
1802 Token doKeyword = expect(Keyword.DO); 1802 Token doKeyword = expect(Keyword.DO);
1803 Statement body = parseStatement2(); 1803 Statement body = parseStatement2();
1804 Token whileKeyword = expect(Keyword.WHILE); 1804 Token whileKeyword = expect(Keyword.WHILE);
1805 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 1805 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
1806 Expression condition = parseExpression2(); 1806 Expression condition = parseExpression2();
1807 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 1807 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
1808 Token semicolon = expect2(TokenType.SEMICOLON); 1808 Token semicolon = expect2(TokenType.SEMICOLON);
1809 return new DoStatement(doKeyword, body, whileKeyword, leftParenthesis, con dition, rightParenthesis, semicolon); 1809 return new DoStatement.full(doKeyword, body, whileKeyword, leftParenthesis , condition, rightParenthesis, semicolon);
1810 } finally { 1810 } finally {
1811 _inLoop = wasInLoop; 1811 _inLoop = wasInLoop;
1812 } 1812 }
1813 } 1813 }
1814 /** 1814 /**
1815 * Parse an empty statement. 1815 * Parse an empty statement.
1816 * <pre> 1816 * <pre>
1817 * emptyStatement ::= 1817 * emptyStatement ::=
1818 * ';' 1818 * ';'
1819 * </pre> 1819 * </pre>
1820 * @return the empty statement that was parsed 1820 * @return the empty statement that was parsed
1821 */ 1821 */
1822 Statement parseEmptyStatement() => new EmptyStatement(andAdvance); 1822 Statement parseEmptyStatement() => new EmptyStatement.full(andAdvance);
1823 /** 1823 /**
1824 * Parse an equality expression. 1824 * Parse an equality expression.
1825 * <pre> 1825 * <pre>
1826 * equalityExpression ::= 1826 * equalityExpression ::=
1827 * relationalExpression (equalityOperator relationalExpression)? 1827 * relationalExpression (equalityOperator relationalExpression)?
1828 * | 'super' equalityOperator relationalExpression 1828 * | 'super' equalityOperator relationalExpression
1829 * </pre> 1829 * </pre>
1830 * @return the equality expression that was parsed 1830 * @return the equality expression that was parsed
1831 */ 1831 */
1832 Expression parseEqualityExpression() { 1832 Expression parseEqualityExpression() {
1833 Expression expression; 1833 Expression expression;
1834 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator()) { 1834 if (matches(Keyword.SUPER) && _currentToken.next.type.isEqualityOperator()) {
1835 expression = new SuperExpression(andAdvance); 1835 expression = new SuperExpression.full(andAdvance);
1836 } else { 1836 } else {
1837 expression = parseRelationalExpression(); 1837 expression = parseRelationalExpression();
1838 } 1838 }
1839 while (_currentToken.type.isEqualityOperator()) { 1839 while (_currentToken.type.isEqualityOperator()) {
1840 Token operator = andAdvance; 1840 Token operator = andAdvance;
1841 expression = new BinaryExpression(expression, operator, parseRelationalExp ression()); 1841 expression = new BinaryExpression.full(expression, operator, parseRelation alExpression());
1842 } 1842 }
1843 return expression; 1843 return expression;
1844 } 1844 }
1845 /** 1845 /**
1846 * Parse an export directive. 1846 * Parse an export directive.
1847 * <pre> 1847 * <pre>
1848 * exportDirective ::= 1848 * exportDirective ::=
1849 * metadata 'export' stringLiteral combinator*';' 1849 * metadata 'export' stringLiteral combinator*';'
1850 * </pre> 1850 * </pre>
1851 * @param commentAndMetadata the metadata to be associated with the directive 1851 * @param commentAndMetadata the metadata to be associated with the directive
1852 * @return the export directive that was parsed 1852 * @return the export directive that was parsed
1853 */ 1853 */
1854 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) { 1854 ExportDirective parseExportDirective(CommentAndMetadata commentAndMetadata) {
1855 Token exportKeyword = expect(Keyword.EXPORT); 1855 Token exportKeyword = expect(Keyword.EXPORT);
1856 StringLiteral libraryUri = parseStringLiteral(); 1856 StringLiteral libraryUri = parseStringLiteral();
1857 List<Combinator> combinators = parseCombinators(); 1857 List<Combinator> combinators = parseCombinators();
1858 Token semicolon = expect2(TokenType.SEMICOLON); 1858 Token semicolon = expect2(TokenType.SEMICOLON);
1859 return new ExportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, exportKeyword, libraryUri, combinators, semicolon); 1859 return new ExportDirective.full(commentAndMetadata.comment, commentAndMetada ta.metadata, exportKeyword, libraryUri, combinators, semicolon);
1860 } 1860 }
1861 /** 1861 /**
1862 * Parse an expression that does not contain any cascades. 1862 * Parse an expression that does not contain any cascades.
1863 * <pre> 1863 * <pre>
1864 * expression ::= 1864 * expression ::=
1865 * assignableExpression assignmentOperator expression 1865 * assignableExpression assignmentOperator expression
1866 * | conditionalExpression cascadeSection 1866 * | conditionalExpression cascadeSection
1867 * | throwExpression 1867 * | throwExpression
1868 * </pre> 1868 * </pre>
1869 * @return the expression that was parsed 1869 * @return the expression that was parsed
1870 */ 1870 */
1871 Expression parseExpression2() { 1871 Expression parseExpression2() {
1872 if (matches(Keyword.THROW)) { 1872 if (matches(Keyword.THROW)) {
1873 return parseThrowExpression(); 1873 return parseThrowExpression();
1874 } 1874 }
1875 Expression expression = parseConditionalExpression(); 1875 Expression expression = parseConditionalExpression();
1876 TokenType tokenType = _currentToken.type; 1876 TokenType tokenType = _currentToken.type;
1877 if (tokenType == TokenType.PERIOD_PERIOD) { 1877 if (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1878 List<Expression> cascadeSections = new List<Expression>(); 1878 List<Expression> cascadeSections = new List<Expression>();
1879 while (tokenType == TokenType.PERIOD_PERIOD) { 1879 while (identical(tokenType, TokenType.PERIOD_PERIOD)) {
1880 Expression section = parseCascadeSection(); 1880 Expression section = parseCascadeSection();
1881 if (section != null) { 1881 if (section != null) {
1882 cascadeSections.add(section); 1882 cascadeSections.add(section);
1883 } 1883 }
1884 tokenType = _currentToken.type; 1884 tokenType = _currentToken.type;
1885 } 1885 }
1886 return new CascadeExpression(expression, cascadeSections); 1886 return new CascadeExpression.full(expression, cascadeSections);
1887 } else if (tokenType.isAssignmentOperator()) { 1887 } else if (tokenType.isAssignmentOperator()) {
1888 Token operator = andAdvance; 1888 Token operator = andAdvance;
1889 ensureAssignable(expression); 1889 ensureAssignable(expression);
1890 return new AssignmentExpression(expression, operator, parseExpression2()); 1890 return new AssignmentExpression.full(expression, operator, parseExpression 2());
1891 } 1891 }
1892 return expression; 1892 return expression;
1893 } 1893 }
1894 /** 1894 /**
1895 * Parse a list of expressions. 1895 * Parse a list of expressions.
1896 * <pre> 1896 * <pre>
1897 * expressionList ::= 1897 * expressionList ::=
1898 * expression (',' expression) 1898 * expression (',' expression)
1899 * </pre> 1899 * </pre>
1900 * @return the expression that was parsed 1900 * @return the expression that was parsed
(...skipping 17 matching lines...) Expand all
1918 * @return the expression that was parsed 1918 * @return the expression that was parsed
1919 */ 1919 */
1920 Expression parseExpressionWithoutCascade() { 1920 Expression parseExpressionWithoutCascade() {
1921 if (matches(Keyword.THROW)) { 1921 if (matches(Keyword.THROW)) {
1922 return parseThrowExpressionWithoutCascade(); 1922 return parseThrowExpressionWithoutCascade();
1923 } 1923 }
1924 Expression expression = parseConditionalExpression(); 1924 Expression expression = parseConditionalExpression();
1925 if (_currentToken.type.isAssignmentOperator()) { 1925 if (_currentToken.type.isAssignmentOperator()) {
1926 Token operator = andAdvance; 1926 Token operator = andAdvance;
1927 ensureAssignable(expression); 1927 ensureAssignable(expression);
1928 expression = new AssignmentExpression(expression, operator, parseExpressio nWithoutCascade()); 1928 expression = new AssignmentExpression.full(expression, operator, parseExpr essionWithoutCascade());
1929 } 1929 }
1930 return expression; 1930 return expression;
1931 } 1931 }
1932 /** 1932 /**
1933 * Parse a class extends clause. 1933 * Parse a class extends clause.
1934 * <pre> 1934 * <pre>
1935 * classExtendsClause ::= 1935 * classExtendsClause ::=
1936 * 'extends' type 1936 * 'extends' type
1937 * </pre> 1937 * </pre>
1938 * @return the class extends clause that was parsed 1938 * @return the class extends clause that was parsed
1939 */ 1939 */
1940 ExtendsClause parseExtendsClause() { 1940 ExtendsClause parseExtendsClause() {
1941 Token keyword = expect(Keyword.EXTENDS); 1941 Token keyword = expect(Keyword.EXTENDS);
1942 TypeName superclass = parseTypeName(); 1942 TypeName superclass = parseTypeName();
1943 return new ExtendsClause(keyword, superclass); 1943 return new ExtendsClause.full(keyword, superclass);
1944 } 1944 }
1945 /** 1945 /**
1946 * Parse the 'final', 'const', 'var' or type preceding a variable declaration. 1946 * Parse the 'final', 'const', 'var' or type preceding a variable declaration.
1947 * <pre> 1947 * <pre>
1948 * finalConstVarOrType ::= 1948 * finalConstVarOrType ::=
1949 * | 'final' type? 1949 * | 'final' type?
1950 * | 'const' type? 1950 * | 'const' type?
1951 * | 'var' 1951 * | 'var'
1952 * | type 1952 * | type
1953 * </pre> 1953 * </pre>
(...skipping 29 matching lines...) Expand all
1983 * </pre> 1983 * </pre>
1984 * @param kind the kind of parameter being expected based on the presence or a bsence of group 1984 * @param kind the kind of parameter being expected based on the presence or a bsence of group
1985 * delimiters 1985 * delimiters
1986 * @return the formal parameter that was parsed 1986 * @return the formal parameter that was parsed
1987 */ 1987 */
1988 FormalParameter parseFormalParameter(ParameterKind kind) { 1988 FormalParameter parseFormalParameter(ParameterKind kind) {
1989 NormalFormalParameter parameter = parseNormalFormalParameter(); 1989 NormalFormalParameter parameter = parseNormalFormalParameter();
1990 if (matches5(TokenType.EQ)) { 1990 if (matches5(TokenType.EQ)) {
1991 Token seperator = andAdvance; 1991 Token seperator = andAdvance;
1992 Expression defaultValue = parseExpression2(); 1992 Expression defaultValue = parseExpression2();
1993 if (kind == ParameterKind.NAMED) { 1993 if (identical(kind, ParameterKind.NAMED)) {
1994 reportError4(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, sepera tor, []); 1994 reportError4(ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER, sepera tor, []);
1995 } else if (kind == ParameterKind.REQUIRED) { 1995 } else if (identical(kind, ParameterKind.REQUIRED)) {
1996 reportError(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramete r, []); 1996 reportError(ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP, paramete r, []);
1997 } 1997 }
1998 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 1998 return new DefaultFormalParameter.full(parameter, kind, seperator, default Value);
1999 } else if (matches5(TokenType.COLON)) { 1999 } else if (matches5(TokenType.COLON)) {
2000 Token seperator = andAdvance; 2000 Token seperator = andAdvance;
2001 Expression defaultValue = parseExpression2(); 2001 Expression defaultValue = parseExpression2();
2002 if (kind == ParameterKind.POSITIONAL) { 2002 if (identical(kind, ParameterKind.POSITIONAL)) {
2003 reportError4(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, s eperator, []); 2003 reportError4(ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER, s eperator, []);
2004 } else if (kind == ParameterKind.REQUIRED) { 2004 } else if (identical(kind, ParameterKind.REQUIRED)) {
2005 reportError(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, [] ); 2005 reportError(ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP, parameter, [] );
2006 } 2006 }
2007 return new DefaultFormalParameter(parameter, kind, seperator, defaultValue ); 2007 return new DefaultFormalParameter.full(parameter, kind, seperator, default Value);
2008 } else if (kind != ParameterKind.REQUIRED) { 2008 } else if (kind != ParameterKind.REQUIRED) {
2009 return new DefaultFormalParameter(parameter, kind, null, null); 2009 return new DefaultFormalParameter.full(parameter, kind, null, null);
2010 } 2010 }
2011 return parameter; 2011 return parameter;
2012 } 2012 }
2013 /** 2013 /**
2014 * Parse a list of formal parameters. 2014 * Parse a list of formal parameters.
2015 * <pre> 2015 * <pre>
2016 * formalParameterList ::= 2016 * formalParameterList ::=
2017 * '(' ')' 2017 * '(' ')'
2018 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')' 2018 * | '(' normalFormalParameters (',' optionalFormalParameters)? ')'
2019 * | '(' optionalFormalParameters ')' 2019 * | '(' optionalFormalParameters ')'
2020 * normalFormalParameters ::= 2020 * normalFormalParameters ::=
2021 * normalFormalParameter (',' normalFormalParameter) 2021 * normalFormalParameter (',' normalFormalParameter)
2022 * optionalFormalParameters ::= 2022 * optionalFormalParameters ::=
2023 * optionalPositionalFormalParameters 2023 * optionalPositionalFormalParameters
2024 * | namedFormalParameters 2024 * | namedFormalParameters
2025 * optionalPositionalFormalParameters ::= 2025 * optionalPositionalFormalParameters ::=
2026 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']' 2026 * '[' defaultFormalParameter (',' defaultFormalParameter)* ']'
2027 * namedFormalParameters ::= 2027 * namedFormalParameters ::=
2028 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' 2028 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}'
2029 * </pre> 2029 * </pre>
2030 * @return the formal parameters that were parsed 2030 * @return the formal parameters that were parsed
2031 */ 2031 */
2032 FormalParameterList parseFormalParameterList() { 2032 FormalParameterList parseFormalParameterList() {
2033 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 2033 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
2034 if (matches5(TokenType.CLOSE_PAREN)) { 2034 if (matches5(TokenType.CLOSE_PAREN)) {
2035 return new FormalParameterList(leftParenthesis, null, null, null, andAdvan ce); 2035 return new FormalParameterList.full(leftParenthesis, null, null, null, and Advance);
2036 } 2036 }
2037 List<FormalParameter> parameters = new List<FormalParameter>(); 2037 List<FormalParameter> parameters = new List<FormalParameter>();
2038 List<FormalParameter> normalParameters = new List<FormalParameter>(); 2038 List<FormalParameter> normalParameters = new List<FormalParameter>();
2039 List<FormalParameter> positionalParameters = new List<FormalParameter>(); 2039 List<FormalParameter> positionalParameters = new List<FormalParameter>();
2040 List<FormalParameter> namedParameters = new List<FormalParameter>(); 2040 List<FormalParameter> namedParameters = new List<FormalParameter>();
2041 List<FormalParameter> currentParameters = normalParameters; 2041 List<FormalParameter> currentParameters = normalParameters;
2042 Token leftSquareBracket = null; 2042 Token leftSquareBracket = null;
2043 Token rightSquareBracket = null; 2043 Token rightSquareBracket = null;
2044 Token leftCurlyBracket = null; 2044 Token leftCurlyBracket = null;
2045 Token rightCurlyBracket = null; 2045 Token rightCurlyBracket = null;
2046 ParameterKind kind = ParameterKind.REQUIRED; 2046 ParameterKind kind = ParameterKind.REQUIRED;
2047 bool firstParameter = true; 2047 bool firstParameter = true;
2048 bool reportedMuliplePositionalGroups = false; 2048 bool reportedMuliplePositionalGroups = false;
2049 bool reportedMulipleNamedGroups = false; 2049 bool reportedMulipleNamedGroups = false;
2050 bool reportedMixedGroups = false; 2050 bool reportedMixedGroups = false;
2051 Token initialToken = null; 2051 Token initialToken = null;
2052 do { 2052 do {
2053 if (firstParameter) { 2053 if (firstParameter) {
2054 firstParameter = false; 2054 firstParameter = false;
2055 } else if (!optional(TokenType.COMMA)) { 2055 } else if (!optional(TokenType.COMMA)) {
2056 if ((leftParenthesis as BeginToken).endToken != null) { 2056 if (((leftParenthesis as BeginToken)).endToken != null) {
2057 reportError3(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme]) ; 2057 reportError3(ParserErrorCode.EXPECTED_TOKEN, [TokenType.COMMA.lexeme]) ;
2058 } else { 2058 } else {
2059 break; 2059 break;
2060 } 2060 }
2061 } 2061 }
2062 initialToken = _currentToken; 2062 initialToken = _currentToken;
2063 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) { 2063 if (matches5(TokenType.OPEN_SQUARE_BRACKET)) {
2064 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) { 2064 if (leftSquareBracket != null && !reportedMuliplePositionalGroups) {
2065 reportError3(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, []) ; 2065 reportError3(ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS, []) ;
2066 reportedMuliplePositionalGroups = true; 2066 reportedMuliplePositionalGroups = true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 if (leftSquareBracket != null && rightSquareBracket == null) { 2106 if (leftSquareBracket != null && rightSquareBracket == null) {
2107 } 2107 }
2108 if (leftCurlyBracket != null && rightCurlyBracket == null) { 2108 if (leftCurlyBracket != null && rightCurlyBracket == null) {
2109 } 2109 }
2110 if (leftSquareBracket == null) { 2110 if (leftSquareBracket == null) {
2111 leftSquareBracket = leftCurlyBracket; 2111 leftSquareBracket = leftCurlyBracket;
2112 } 2112 }
2113 if (rightSquareBracket == null) { 2113 if (rightSquareBracket == null) {
2114 rightSquareBracket = rightCurlyBracket; 2114 rightSquareBracket = rightCurlyBracket;
2115 } 2115 }
2116 return new FormalParameterList(leftParenthesis, parameters, leftSquareBracke t, rightSquareBracket, rightParenthesis); 2116 return new FormalParameterList.full(leftParenthesis, parameters, leftSquareB racket, rightSquareBracket, rightParenthesis);
2117 } 2117 }
2118 /** 2118 /**
2119 * Parse a for statement. 2119 * Parse a for statement.
2120 * <pre> 2120 * <pre>
2121 * forStatement ::= 2121 * forStatement ::=
2122 * 'for' '(' forLoopParts ')' statement 2122 * 'for' '(' forLoopParts ')' statement
2123 * forLoopParts ::= 2123 * forLoopParts ::=
2124 * forInitializerStatement expression? ';' expressionList? 2124 * forInitializerStatement expression? ';' expressionList?
2125 * | declaredIdentifier 'in' expression 2125 * | declaredIdentifier 'in' expression
2126 * | identifier 'in' expression 2126 * | identifier 'in' expression
2127 * forInitializerStatement ::= 2127 * forInitializerStatement ::=
2128 * variableDeclarationList ';' 2128 * variableDeclarationList ';'
2129 * | expression? ';' 2129 * | expression? ';'
2130 * </pre> 2130 * </pre>
2131 * @return the for statement that was parsed 2131 * @return the for statement that was parsed
2132 */ 2132 */
2133 Statement parseForStatement() { 2133 Statement parseForStatement() {
2134 bool wasInLoop = _inLoop; 2134 bool wasInLoop = _inLoop;
2135 _inLoop = true; 2135 _inLoop = true;
2136 try { 2136 try {
2137 Token forKeyword = expect(Keyword.FOR); 2137 Token forKeyword = expect(Keyword.FOR);
2138 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 2138 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
2139 VariableDeclarationList variableList = null; 2139 VariableDeclarationList variableList = null;
2140 Expression initialization = null; 2140 Expression initialization = null;
2141 if (!matches5(TokenType.SEMICOLON)) { 2141 if (!matches5(TokenType.SEMICOLON)) {
2142 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) { 2142 if (matchesIdentifier() && matches3(peek(), Keyword.IN)) {
2143 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 2143 List<VariableDeclaration> variables = new List<VariableDeclaration>();
2144 SimpleIdentifier variableName = parseSimpleIdentifier(); 2144 SimpleIdentifier variableName = parseSimpleIdentifier();
2145 variables.add(new VariableDeclaration(null, null, variableName, null, null)); 2145 variables.add(new VariableDeclaration.full(null, null, variableName, n ull, null));
2146 variableList = new VariableDeclarationList(null, null, variables); 2146 variableList = new VariableDeclarationList.full(null, null, variables) ;
2147 } else if (isInitializedVariableDeclaration()) { 2147 } else if (isInitializedVariableDeclaration()) {
2148 variableList = parseVariableDeclarationList(); 2148 variableList = parseVariableDeclarationList();
2149 } else { 2149 } else {
2150 initialization = parseExpression2(); 2150 initialization = parseExpression2();
2151 } 2151 }
2152 if (matches(Keyword.IN)) { 2152 if (matches(Keyword.IN)) {
2153 SimpleFormalParameter loopParameter = null; 2153 SimpleFormalParameter loopParameter = null;
2154 if (variableList == null) { 2154 if (variableList == null) {
2155 reportError3(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []); 2155 reportError3(ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH, []);
2156 } else { 2156 } else {
2157 NodeList<VariableDeclaration> variables5 = variableList.variables; 2157 NodeList<VariableDeclaration> variables3 = variableList.variables;
2158 if (variables5.length > 1) { 2158 if (variables3.length > 1) {
2159 reportError3(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [vari ables5.length.toString()]); 2159 reportError3(ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH, [vari ables3.length.toString()]);
2160 } 2160 }
2161 VariableDeclaration variable = variables5[0]; 2161 VariableDeclaration variable = variables3[0];
2162 if (variable.initializer != null) { 2162 if (variable.initializer != null) {
2163 reportError3(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, []) ; 2163 reportError3(ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH, []) ;
2164 } 2164 }
2165 loopParameter = new SimpleFormalParameter(null, null, variableList.k eyword, variableList.type, variable.name); 2165 loopParameter = new SimpleFormalParameter.full(null, null, variableL ist.keyword, variableList.type, variable.name);
2166 } 2166 }
2167 Token inKeyword = expect(Keyword.IN); 2167 Token inKeyword = expect(Keyword.IN);
2168 Expression iterator = parseExpression2(); 2168 Expression iterator = parseExpression2();
2169 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2169 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
2170 Statement body = parseStatement2(); 2170 Statement body = parseStatement2();
2171 return new ForEachStatement(forKeyword, leftParenthesis, loopParameter , inKeyword, iterator, rightParenthesis, body); 2171 return new ForEachStatement.full(forKeyword, leftParenthesis, loopPara meter, inKeyword, iterator, rightParenthesis, body);
2172 } 2172 }
2173 } 2173 }
2174 Token leftSeparator = expect2(TokenType.SEMICOLON); 2174 Token leftSeparator = expect2(TokenType.SEMICOLON);
2175 Expression condition = null; 2175 Expression condition = null;
2176 if (!matches5(TokenType.SEMICOLON)) { 2176 if (!matches5(TokenType.SEMICOLON)) {
2177 condition = parseExpression2(); 2177 condition = parseExpression2();
2178 } 2178 }
2179 Token rightSeparator = expect2(TokenType.SEMICOLON); 2179 Token rightSeparator = expect2(TokenType.SEMICOLON);
2180 List<Expression> updaters = null; 2180 List<Expression> updaters = null;
2181 if (!matches5(TokenType.CLOSE_PAREN)) { 2181 if (!matches5(TokenType.CLOSE_PAREN)) {
2182 updaters = parseExpressionList(); 2182 updaters = parseExpressionList();
2183 } 2183 }
2184 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2184 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
2185 Statement body = parseStatement2(); 2185 Statement body = parseStatement2();
2186 return new ForStatement(forKeyword, leftParenthesis, variableList, initial ization, leftSeparator, condition, rightSeparator, updaters, rightParenthesis, b ody); 2186 return new ForStatement.full(forKeyword, leftParenthesis, variableList, in itialization, leftSeparator, condition, rightSeparator, updaters, rightParenthes is, body);
2187 } finally { 2187 } finally {
2188 _inLoop = wasInLoop; 2188 _inLoop = wasInLoop;
2189 } 2189 }
2190 } 2190 }
2191 /** 2191 /**
2192 * Parse a function body. 2192 * Parse a function body.
2193 * <pre> 2193 * <pre>
2194 * functionBody ::= 2194 * functionBody ::=
2195 * '=>' expression ';' 2195 * '=>' expression ';'
2196 * | block 2196 * | block
2197 * functionExpressionBody ::= 2197 * functionExpressionBody ::=
2198 * '=>' expression 2198 * '=>' expression
2199 * | block 2199 * | block
2200 * </pre> 2200 * </pre>
2201 * @param mayBeEmpty {@code true} if the function body is allowed to be empty 2201 * @param mayBeEmpty {@code true} if the function body is allowed to be empty
2202 * @param inExpression {@code true} if the function body is being parsed as pa rt of an expression 2202 * @param inExpression {@code true} if the function body is being parsed as pa rt of an expression
2203 * and therefore does not have a terminating semicolon 2203 * and therefore does not have a terminating semicolon
2204 * @return the function body that was parsed 2204 * @return the function body that was parsed
2205 */ 2205 */
2206 FunctionBody parseFunctionBody(bool mayBeEmpty, bool inExpression) { 2206 FunctionBody parseFunctionBody(bool mayBeEmpty, bool inExpression) {
2207 bool wasInLoop = _inLoop; 2207 bool wasInLoop = _inLoop;
2208 bool wasInSwitch = _inSwitch; 2208 bool wasInSwitch = _inSwitch;
2209 _inLoop = false; 2209 _inLoop = false;
2210 _inSwitch = false; 2210 _inSwitch = false;
2211 try { 2211 try {
2212 if (matches5(TokenType.SEMICOLON)) { 2212 if (matches5(TokenType.SEMICOLON)) {
2213 if (!mayBeEmpty) { 2213 if (!mayBeEmpty) {
2214 reportError3(ParserErrorCode.MISSING_FUNCTION_BODY, []); 2214 reportError3(ParserErrorCode.MISSING_FUNCTION_BODY, []);
2215 } 2215 }
2216 return new EmptyFunctionBody(andAdvance); 2216 return new EmptyFunctionBody.full(andAdvance);
2217 } else if (matches5(TokenType.FUNCTION)) { 2217 } else if (matches5(TokenType.FUNCTION)) {
2218 Token functionDefinition = andAdvance; 2218 Token functionDefinition = andAdvance;
2219 Expression expression = parseExpression2(); 2219 Expression expression = parseExpression2();
2220 Token semicolon = null; 2220 Token semicolon = null;
2221 if (!inExpression) { 2221 if (!inExpression) {
2222 semicolon = expect2(TokenType.SEMICOLON); 2222 semicolon = expect2(TokenType.SEMICOLON);
2223 } 2223 }
2224 return new ExpressionFunctionBody(functionDefinition, expression, semico lon); 2224 return new ExpressionFunctionBody.full(functionDefinition, expression, s emicolon);
2225 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2225 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
2226 return new BlockFunctionBody(parseBlock()); 2226 return new BlockFunctionBody.full(parseBlock());
2227 } else if (matches2("native")) { 2227 } else if (matches2("native")) {
2228 advance(); 2228 advance();
2229 parseStringLiteral(); 2229 parseStringLiteral();
2230 return new EmptyFunctionBody(andAdvance); 2230 return new EmptyFunctionBody.full(andAdvance);
2231 } else { 2231 } else {
2232 reportError3(ParserErrorCode.MISSING_FUNCTION_BODY, []); 2232 reportError3(ParserErrorCode.MISSING_FUNCTION_BODY, []);
2233 return new EmptyFunctionBody(createSyntheticToken(TokenType.SEMICOLON)); 2233 return new EmptyFunctionBody.full(createSyntheticToken(TokenType.SEMICOL ON));
2234 } 2234 }
2235 } finally { 2235 } finally {
2236 _inLoop = wasInLoop; 2236 _inLoop = wasInLoop;
2237 _inSwitch = wasInSwitch; 2237 _inSwitch = wasInSwitch;
2238 } 2238 }
2239 } 2239 }
2240 /** 2240 /**
2241 * Parse a function declaration. 2241 * Parse a function declaration.
2242 * <pre> 2242 * <pre>
2243 * functionDeclaration ::= 2243 * functionDeclaration ::=
(...skipping 30 matching lines...) Expand all
2274 parseFormalParameterList(); 2274 parseFormalParameterList();
2275 } 2275 }
2276 FunctionBody body = null; 2276 FunctionBody body = null;
2277 if (externalKeyword == null) { 2277 if (externalKeyword == null) {
2278 body = parseFunctionBody(false, false); 2278 body = parseFunctionBody(false, false);
2279 } 2279 }
2280 if (!isStatement && matches5(TokenType.SEMICOLON)) { 2280 if (!isStatement && matches5(TokenType.SEMICOLON)) {
2281 reportError3(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 2281 reportError3(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
2282 advance(); 2282 advance();
2283 } 2283 }
2284 return new FunctionDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, externalKeyword, returnType, keyword, name, new FunctionExpression(p arameters, body)); 2284 return new FunctionDeclaration.full(commentAndMetadata.comment, commentAndMe tadata.metadata, externalKeyword, returnType, keyword, name, new FunctionExpress ion.full(parameters, body));
2285 } 2285 }
2286 /** 2286 /**
2287 * Parse a function declaration statement. 2287 * Parse a function declaration statement.
2288 * <pre> 2288 * <pre>
2289 * functionDeclarationStatement ::= 2289 * functionDeclarationStatement ::=
2290 * functionSignature functionBody 2290 * functionSignature functionBody
2291 * </pre> 2291 * </pre>
2292 * @return the function declaration statement that was parsed 2292 * @return the function declaration statement that was parsed
2293 */ 2293 */
2294 Statement parseFunctionDeclarationStatement() => parseFunctionDeclarationState ment2(parseCommentAndMetadata(), parseOptionalReturnType()); 2294 Statement parseFunctionDeclarationStatement() => parseFunctionDeclarationState ment2(parseCommentAndMetadata(), parseOptionalReturnType());
2295 /** 2295 /**
2296 * Parse a function declaration statement. 2296 * Parse a function declaration statement.
2297 * <pre> 2297 * <pre>
2298 * functionDeclarationStatement ::= 2298 * functionDeclarationStatement ::=
2299 * functionSignature functionBody 2299 * functionSignature functionBody
2300 * </pre> 2300 * </pre>
2301 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 2301 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
2302 * declaration 2302 * declaration
2303 * @param returnType the return type, or {@code null} if there is no return ty pe 2303 * @param returnType the return type, or {@code null} if there is no return ty pe
2304 * @return the function declaration statement that was parsed 2304 * @return the function declaration statement that was parsed
2305 */ 2305 */
2306 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) => new FunctionDeclarationStatement(parseFunctionDecl aration(commentAndMetadata, null, returnType, true)); 2306 Statement parseFunctionDeclarationStatement2(CommentAndMetadata commentAndMeta data, TypeName returnType) => new FunctionDeclarationStatement.full(parseFunctio nDeclaration(commentAndMetadata, null, returnType, true));
2307 /** 2307 /**
2308 * Parse a function expression. 2308 * Parse a function expression.
2309 * <pre> 2309 * <pre>
2310 * functionExpression ::= 2310 * functionExpression ::=
2311 * (returnType? identifier)? formalParameterList functionExpressionBody 2311 * (returnType? identifier)? formalParameterList functionExpressionBody
2312 * </pre> 2312 * </pre>
2313 * @return the function expression that was parsed 2313 * @return the function expression that was parsed
2314 */ 2314 */
2315 FunctionExpression parseFunctionExpression() { 2315 FunctionExpression parseFunctionExpression() {
2316 FormalParameterList parameters = parseFormalParameterList(); 2316 FormalParameterList parameters = parseFormalParameterList();
2317 validateFormalParameterList(parameters); 2317 validateFormalParameterList(parameters);
2318 FunctionBody body = parseFunctionBody(false, true); 2318 FunctionBody body = parseFunctionBody(false, true);
2319 return new FunctionExpression(parameters, body); 2319 return new FunctionExpression.full(parameters, body);
2320 } 2320 }
2321 /** 2321 /**
2322 * Parse a function type alias. 2322 * Parse a function type alias.
2323 * <pre> 2323 * <pre>
2324 * functionTypeAlias ::= 2324 * functionTypeAlias ::=
2325 * functionPrefix typeParameterList? formalParameterList ';' 2325 * functionPrefix typeParameterList? formalParameterList ';'
2326 * functionPrefix ::= 2326 * functionPrefix ::=
2327 * returnType? name 2327 * returnType? name
2328 * </pre> 2328 * </pre>
2329 * @param commentAndMetadata the metadata to be associated with the member 2329 * @param commentAndMetadata the metadata to be associated with the member
2330 * @param keyword the token representing the 'typedef' keyword 2330 * @param keyword the token representing the 'typedef' keyword
2331 * @return the function type alias that was parsed 2331 * @return the function type alias that was parsed
2332 */ 2332 */
2333 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) { 2333 FunctionTypeAlias parseFunctionTypeAlias(CommentAndMetadata commentAndMetadata , Token keyword) {
2334 TypeName returnType = null; 2334 TypeName returnType = null;
2335 if (hasReturnTypeInTypeAlias()) { 2335 if (hasReturnTypeInTypeAlias()) {
2336 returnType = parseReturnType(); 2336 returnType = parseReturnType();
2337 } 2337 }
2338 SimpleIdentifier name = parseSimpleIdentifier2(ParserErrorCode.BUILT_IN_IDEN TIFIER_AS_TYPEDEF_NAME); 2338 SimpleIdentifier name = parseSimpleIdentifier2(ParserErrorCode.BUILT_IN_IDEN TIFIER_AS_TYPEDEF_NAME);
2339 TypeParameterList typeParameters = null; 2339 TypeParameterList typeParameters = null;
2340 if (matches5(TokenType.LT)) { 2340 if (matches5(TokenType.LT)) {
2341 typeParameters = parseTypeParameterList(); 2341 typeParameters = parseTypeParameterList();
2342 } 2342 }
2343 if (matches5(TokenType.SEMICOLON)) { 2343 if (matches5(TokenType.SEMICOLON)) {
2344 reportError3(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []); 2344 reportError3(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS, []);
2345 FormalParameterList parameters = new FormalParameterList(createSyntheticTo ken(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken(TokenType.CLOS E_PAREN)); 2345 FormalParameterList parameters = new FormalParameterList.full(createSynthe ticToken(TokenType.OPEN_PAREN), null, null, null, createSyntheticToken(TokenType .CLOSE_PAREN));
2346 Token semicolon = expect2(TokenType.SEMICOLON); 2346 Token semicolon = expect2(TokenType.SEMICOLON);
2347 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadat a.metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 2347 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMe tadata.metadata, keyword, returnType, name, typeParameters, parameters, semicolo n);
2348 } else if (!matches5(TokenType.OPEN_PAREN)) { 2348 } else if (!matches5(TokenType.OPEN_PAREN)) {
2349 return null; 2349 return null;
2350 } 2350 }
2351 FormalParameterList parameters = parseFormalParameterList(); 2351 FormalParameterList parameters = parseFormalParameterList();
2352 validateFormalParameterList(parameters); 2352 validateFormalParameterList(parameters);
2353 Token semicolon = expect2(TokenType.SEMICOLON); 2353 Token semicolon = expect2(TokenType.SEMICOLON);
2354 return new FunctionTypeAlias(commentAndMetadata.comment, commentAndMetadata. metadata, keyword, returnType, name, typeParameters, parameters, semicolon); 2354 return new FunctionTypeAlias.full(commentAndMetadata.comment, commentAndMeta data.metadata, keyword, returnType, name, typeParameters, parameters, semicolon) ;
2355 } 2355 }
2356 /** 2356 /**
2357 * Parse a getter. 2357 * Parse a getter.
2358 * <pre> 2358 * <pre>
2359 * getter ::= 2359 * getter ::=
2360 * getterSignature functionBody? 2360 * getterSignature functionBody?
2361 * getterSignature ::= 2361 * getterSignature ::=
2362 * 'external'? 'static'? returnType? 'get' identifier 2362 * 'external'? 'static'? returnType? 'get' identifier
2363 * </pre> 2363 * </pre>
2364 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 2364 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
2365 * declaration 2365 * declaration
2366 * @param externalKeyword the 'external' token 2366 * @param externalKeyword the 'external' token
2367 * @param staticKeyword the static keyword, or {@code null} if the getter is n ot static 2367 * @param staticKeyword the static keyword, or {@code null} if the getter is n ot static
2368 * @param the return type that has already been parsed, or {@code null} if the re was no return 2368 * @param the return type that has already been parsed, or {@code null} if the re was no return
2369 * type 2369 * type
2370 * @return the getter that was parsed 2370 * @return the getter that was parsed
2371 */ 2371 */
2372 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 2372 MethodDeclaration parseGetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
2373 Token propertyKeyword = expect(Keyword.GET); 2373 Token propertyKeyword = expect(Keyword.GET);
2374 SimpleIdentifier name = parseSimpleIdentifier(); 2374 SimpleIdentifier name = parseSimpleIdentifier();
2375 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) { 2375 if (matches5(TokenType.OPEN_PAREN) && matches4(peek(), TokenType.CLOSE_PAREN )) {
2376 reportError3(ParserErrorCode.GETTER_WITH_PARAMETERS, []); 2376 reportError3(ParserErrorCode.GETTER_WITH_PARAMETERS, []);
2377 advance(); 2377 advance();
2378 advance(); 2378 advance();
2379 } 2379 }
2380 FunctionBody body = parseFunctionBody(true, false); 2380 FunctionBody body = parseFunctionBody(true, false);
2381 if (externalKeyword != null && body is! EmptyFunctionBody) { 2381 if (externalKeyword != null && body is! EmptyFunctionBody) {
2382 reportError3(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []); 2382 reportError3(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY, []);
2383 } 2383 }
2384 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, null, body); 2384 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null , name, null, body);
2385 } 2385 }
2386 /** 2386 /**
2387 * Parse a list of identifiers. 2387 * Parse a list of identifiers.
2388 * <pre> 2388 * <pre>
2389 * identifierList ::= 2389 * identifierList ::=
2390 * identifier (',' identifier) 2390 * identifier (',' identifier)
2391 * </pre> 2391 * </pre>
2392 * @return the list of identifiers that were parsed 2392 * @return the list of identifiers that were parsed
2393 */ 2393 */
2394 List<SimpleIdentifier> parseIdentifierList() { 2394 List<SimpleIdentifier> parseIdentifierList() {
(...skipping 18 matching lines...) Expand all
2413 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 2413 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
2414 Expression condition = parseExpression2(); 2414 Expression condition = parseExpression2();
2415 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 2415 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
2416 Statement thenStatement = parseStatement2(); 2416 Statement thenStatement = parseStatement2();
2417 Token elseKeyword = null; 2417 Token elseKeyword = null;
2418 Statement elseStatement = null; 2418 Statement elseStatement = null;
2419 if (matches(Keyword.ELSE)) { 2419 if (matches(Keyword.ELSE)) {
2420 elseKeyword = andAdvance; 2420 elseKeyword = andAdvance;
2421 elseStatement = parseStatement2(); 2421 elseStatement = parseStatement2();
2422 } 2422 }
2423 return new IfStatement(ifKeyword, leftParenthesis, condition, rightParenthes is, thenStatement, elseKeyword, elseStatement); 2423 return new IfStatement.full(ifKeyword, leftParenthesis, condition, rightPare nthesis, thenStatement, elseKeyword, elseStatement);
2424 } 2424 }
2425 /** 2425 /**
2426 * Parse an implements clause. 2426 * Parse an implements clause.
2427 * <pre> 2427 * <pre>
2428 * implementsClause ::= 2428 * implementsClause ::=
2429 * 'implements' type (',' type) 2429 * 'implements' type (',' type)
2430 * </pre> 2430 * </pre>
2431 * @return the implements clause that was parsed 2431 * @return the implements clause that was parsed
2432 */ 2432 */
2433 ImplementsClause parseImplementsClause() { 2433 ImplementsClause parseImplementsClause() {
2434 Token keyword = expect(Keyword.IMPLEMENTS); 2434 Token keyword = expect(Keyword.IMPLEMENTS);
2435 List<TypeName> interfaces = new List<TypeName>(); 2435 List<TypeName> interfaces = new List<TypeName>();
2436 interfaces.add(parseTypeName()); 2436 interfaces.add(parseTypeName());
2437 while (optional(TokenType.COMMA)) { 2437 while (optional(TokenType.COMMA)) {
2438 interfaces.add(parseTypeName()); 2438 interfaces.add(parseTypeName());
2439 } 2439 }
2440 return new ImplementsClause(keyword, interfaces); 2440 return new ImplementsClause.full(keyword, interfaces);
2441 } 2441 }
2442 /** 2442 /**
2443 * Parse an import directive. 2443 * Parse an import directive.
2444 * <pre> 2444 * <pre>
2445 * importDirective ::= 2445 * importDirective ::=
2446 * metadata 'import' stringLiteral ('as' identifier)? combinator*';' 2446 * metadata 'import' stringLiteral ('as' identifier)? combinator*';'
2447 * </pre> 2447 * </pre>
2448 * @param commentAndMetadata the metadata to be associated with the directive 2448 * @param commentAndMetadata the metadata to be associated with the directive
2449 * @return the import directive that was parsed 2449 * @return the import directive that was parsed
2450 */ 2450 */
2451 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) { 2451 ImportDirective parseImportDirective(CommentAndMetadata commentAndMetadata) {
2452 Token importKeyword = expect(Keyword.IMPORT); 2452 Token importKeyword = expect(Keyword.IMPORT);
2453 StringLiteral libraryUri = parseStringLiteral(); 2453 StringLiteral libraryUri = parseStringLiteral();
2454 Token asToken = null; 2454 Token asToken = null;
2455 SimpleIdentifier prefix = null; 2455 SimpleIdentifier prefix = null;
2456 if (matches(Keyword.AS)) { 2456 if (matches(Keyword.AS)) {
2457 asToken = andAdvance; 2457 asToken = andAdvance;
2458 prefix = parseSimpleIdentifier(); 2458 prefix = parseSimpleIdentifier();
2459 } 2459 }
2460 List<Combinator> combinators = parseCombinators(); 2460 List<Combinator> combinators = parseCombinators();
2461 Token semicolon = expect2(TokenType.SEMICOLON); 2461 Token semicolon = expect2(TokenType.SEMICOLON);
2462 return new ImportDirective(commentAndMetadata.comment, commentAndMetadata.me tadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon); 2462 return new ImportDirective.full(commentAndMetadata.comment, commentAndMetada ta.metadata, importKeyword, libraryUri, asToken, prefix, combinators, semicolon) ;
2463 } 2463 }
2464 /** 2464 /**
2465 * Parse a list of initialized identifiers. 2465 * Parse a list of initialized identifiers.
2466 * <pre> 2466 * <pre>
2467 * ?? ::= 2467 * ?? ::=
2468 * 'static'? ('var' | type) initializedIdentifierList ';' 2468 * 'static'? ('var' | type) initializedIdentifierList ';'
2469 * | 'final' type? initializedIdentifierList ';' 2469 * | 'final' type? initializedIdentifierList ';'
2470 * initializedIdentifierList ::= 2470 * initializedIdentifierList ::=
2471 * initializedIdentifier (',' initializedIdentifier) 2471 * initializedIdentifier (',' initializedIdentifier)
2472 * initializedIdentifier ::= 2472 * initializedIdentifier ::=
2473 * identifier ('=' expression)? 2473 * identifier ('=' expression)?
2474 * </pre> 2474 * </pre>
2475 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 2475 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
2476 * declaration 2476 * declaration
2477 * @param staticKeyword the static keyword, or {@code null} if the getter is n ot static 2477 * @param staticKeyword the static keyword, or {@code null} if the getter is n ot static
2478 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or {@code null} if 2478 * @param keyword the token representing the 'final', 'const' or 'var' keyword , or {@code null} if
2479 * there is no keyword 2479 * there is no keyword
2480 * @param type the type that has already been parsed, or {@code null} if 'var' was provided 2480 * @param type the type that has already been parsed, or {@code null} if 'var' was provided
2481 * @return the getter that was parsed 2481 * @return the getter that was parsed
2482 */ 2482 */
2483 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) { 2483 FieldDeclaration parseInitializedIdentifierList(CommentAndMetadata commentAndM etadata, Token staticKeyword, Token keyword, TypeName type) {
2484 VariableDeclarationList fieldList = parseVariableDeclarationList2(keyword, t ype); 2484 VariableDeclarationList fieldList = parseVariableDeclarationList2(keyword, t ype);
2485 return new FieldDeclaration(commentAndMetadata.comment, commentAndMetadata.m etadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON)); 2485 return new FieldDeclaration.full(commentAndMetadata.comment, commentAndMetad ata.metadata, staticKeyword, fieldList, expect2(TokenType.SEMICOLON));
2486 } 2486 }
2487 /** 2487 /**
2488 * Parse an instance creation expression. 2488 * Parse an instance creation expression.
2489 * <pre> 2489 * <pre>
2490 * instanceCreationExpression ::= 2490 * instanceCreationExpression ::=
2491 * ('new' | 'const') type ('.' identifier)? argumentList 2491 * ('new' | 'const') type ('.' identifier)? argumentList
2492 * </pre> 2492 * </pre>
2493 * @param keyword the 'new' or 'const' keyword that introduces the expression 2493 * @param keyword the 'new' or 'const' keyword that introduces the expression
2494 * @return the instance creation expression that was parsed 2494 * @return the instance creation expression that was parsed
2495 */ 2495 */
2496 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) { 2496 InstanceCreationExpression parseInstanceCreationExpression(Token keyword) {
2497 ConstructorName constructorName = parseConstructorName(); 2497 ConstructorName constructorName = parseConstructorName();
2498 ArgumentList argumentList = parseArgumentList(); 2498 ArgumentList argumentList = parseArgumentList();
2499 return new InstanceCreationExpression(keyword, constructorName, argumentList ); 2499 return new InstanceCreationExpression.full(keyword, constructorName, argumen tList);
2500 } 2500 }
2501 /** 2501 /**
2502 * Parse a library directive. 2502 * Parse a library directive.
2503 * <pre> 2503 * <pre>
2504 * libraryDirective ::= 2504 * libraryDirective ::=
2505 * metadata 'library' identifier ';' 2505 * metadata 'library' identifier ';'
2506 * </pre> 2506 * </pre>
2507 * @param commentAndMetadata the metadata to be associated with the directive 2507 * @param commentAndMetadata the metadata to be associated with the directive
2508 * @return the library directive that was parsed 2508 * @return the library directive that was parsed
2509 */ 2509 */
2510 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) { 2510 LibraryDirective parseLibraryDirective(CommentAndMetadata commentAndMetadata) {
2511 Token keyword = expect(Keyword.LIBRARY); 2511 Token keyword = expect(Keyword.LIBRARY);
2512 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword); 2512 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_NAM E_IN_LIBRARY_DIRECTIVE, keyword);
2513 Token semicolon = expect2(TokenType.SEMICOLON); 2513 Token semicolon = expect2(TokenType.SEMICOLON);
2514 return new LibraryDirective(commentAndMetadata.comment, commentAndMetadata.m etadata, keyword, libraryName, semicolon); 2514 return new LibraryDirective.full(commentAndMetadata.comment, commentAndMetad ata.metadata, keyword, libraryName, semicolon);
2515 } 2515 }
2516 /** 2516 /**
2517 * Parse a library identifier. 2517 * Parse a library identifier.
2518 * <pre> 2518 * <pre>
2519 * libraryIdentifier ::= 2519 * libraryIdentifier ::=
2520 * identifier ('.' identifier) 2520 * identifier ('.' identifier)
2521 * </pre> 2521 * </pre>
2522 * @return the library identifier that was parsed 2522 * @return the library identifier that was parsed
2523 */ 2523 */
2524 LibraryIdentifier parseLibraryIdentifier() { 2524 LibraryIdentifier parseLibraryIdentifier() {
2525 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 2525 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
2526 components.add(parseSimpleIdentifier()); 2526 components.add(parseSimpleIdentifier());
2527 while (matches5(TokenType.PERIOD)) { 2527 while (matches5(TokenType.PERIOD)) {
2528 advance(); 2528 advance();
2529 components.add(parseSimpleIdentifier()); 2529 components.add(parseSimpleIdentifier());
2530 } 2530 }
2531 return new LibraryIdentifier(components); 2531 return new LibraryIdentifier.full(components);
2532 } 2532 }
2533 /** 2533 /**
2534 * Parse a library name. 2534 * Parse a library name.
2535 * <pre> 2535 * <pre>
2536 * libraryName ::= 2536 * libraryName ::=
2537 * libraryIdentifier 2537 * libraryIdentifier
2538 * </pre> 2538 * </pre>
2539 * @param missingNameError the error code to be used if the library name is mi ssing 2539 * @param missingNameError the error code to be used if the library name is mi ssing
2540 * @param missingNameToken the token associated with the error produced if the library name is 2540 * @param missingNameToken the token associated with the error produced if the library name is
2541 * missing 2541 * missing
2542 * @return the library name that was parsed 2542 * @return the library name that was parsed
2543 */ 2543 */
2544 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) { 2544 LibraryIdentifier parseLibraryName(ParserErrorCode missingNameError, Token mis singNameToken) {
2545 if (matchesIdentifier()) { 2545 if (matchesIdentifier()) {
2546 return parseLibraryIdentifier(); 2546 return parseLibraryIdentifier();
2547 } else if (matches5(TokenType.STRING)) { 2547 } else if (matches5(TokenType.STRING)) {
2548 StringLiteral string = parseStringLiteral(); 2548 StringLiteral string = parseStringLiteral();
2549 reportError(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []); 2549 reportError(ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME, string, []);
2550 } else { 2550 } else {
2551 reportError4(missingNameError, missingNameToken, []); 2551 reportError4(missingNameError, missingNameToken, []);
2552 } 2552 }
2553 List<SimpleIdentifier> components = new List<SimpleIdentifier>(); 2553 List<SimpleIdentifier> components = new List<SimpleIdentifier>();
2554 components.add(createSyntheticIdentifier()); 2554 components.add(createSyntheticIdentifier());
2555 return new LibraryIdentifier(components); 2555 return new LibraryIdentifier.full(components);
2556 } 2556 }
2557 /** 2557 /**
2558 * Parse a list literal. 2558 * Parse a list literal.
2559 * <pre> 2559 * <pre>
2560 * listLiteral ::= 2560 * listLiteral ::=
2561 * 'const'? typeArguments? '[' (expressionList ','?)? ']' 2561 * 'const'? typeArguments? '[' (expressionList ','?)? ']'
2562 * </pre> 2562 * </pre>
2563 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is 2563 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is
2564 * no modifier 2564 * no modifier
2565 * @param typeArguments the type arguments appearing before the literal, or {@ code null} if there 2565 * @param typeArguments the type arguments appearing before the literal, or {@ code null} if there
2566 * are no type arguments 2566 * are no type arguments
2567 * @return the list literal that was parsed 2567 * @return the list literal that was parsed
2568 */ 2568 */
2569 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) { 2569 ListLiteral parseListLiteral(Token modifier, TypeArgumentList typeArguments) {
2570 if (matches5(TokenType.INDEX)) { 2570 if (matches5(TokenType.INDEX)) {
2571 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset); 2571 BeginToken leftBracket = new BeginToken(TokenType.OPEN_SQUARE_BRACKET, _cu rrentToken.offset);
2572 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1); 2572 Token rightBracket = new Token(TokenType.CLOSE_SQUARE_BRACKET, _currentTok en.offset + 1);
2573 leftBracket.endToken2 = rightBracket; 2573 leftBracket.endToken = rightBracket;
2574 rightBracket.setNext(_currentToken.next); 2574 rightBracket.setNext(_currentToken.next);
2575 leftBracket.setNext(rightBracket); 2575 leftBracket.setNext(rightBracket);
2576 _currentToken.previous.setNext(leftBracket); 2576 _currentToken.previous.setNext(leftBracket);
2577 _currentToken = _currentToken.next; 2577 _currentToken = _currentToken.next;
2578 return new ListLiteral(modifier, typeArguments, leftBracket, null, rightBr acket); 2578 return new ListLiteral.full(modifier, typeArguments, leftBracket, null, ri ghtBracket);
2579 } 2579 }
2580 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET); 2580 Token leftBracket = expect2(TokenType.OPEN_SQUARE_BRACKET);
2581 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 2581 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
2582 return new ListLiteral(modifier, typeArguments, leftBracket, null, andAdva nce); 2582 return new ListLiteral.full(modifier, typeArguments, leftBracket, null, an dAdvance);
2583 } 2583 }
2584 List<Expression> elements = new List<Expression>(); 2584 List<Expression> elements = new List<Expression>();
2585 elements.add(parseExpression2()); 2585 elements.add(parseExpression2());
2586 while (optional(TokenType.COMMA)) { 2586 while (optional(TokenType.COMMA)) {
2587 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) { 2587 if (matches5(TokenType.CLOSE_SQUARE_BRACKET)) {
2588 return new ListLiteral(modifier, typeArguments, leftBracket, elements, a ndAdvance); 2588 return new ListLiteral.full(modifier, typeArguments, leftBracket, elemen ts, andAdvance);
2589 } 2589 }
2590 elements.add(parseExpression2()); 2590 elements.add(parseExpression2());
2591 } 2591 }
2592 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET); 2592 Token rightBracket = expect2(TokenType.CLOSE_SQUARE_BRACKET);
2593 return new ListLiteral(modifier, typeArguments, leftBracket, elements, right Bracket); 2593 return new ListLiteral.full(modifier, typeArguments, leftBracket, elements, rightBracket);
2594 } 2594 }
2595 /** 2595 /**
2596 * Parse a list or map literal. 2596 * Parse a list or map literal.
2597 * <pre> 2597 * <pre>
2598 * listOrMapLiteral ::= 2598 * listOrMapLiteral ::=
2599 * listLiteral 2599 * listLiteral
2600 * | mapLiteral 2600 * | mapLiteral
2601 * </pre> 2601 * </pre>
2602 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is 2602 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is
2603 * no modifier 2603 * no modifier
2604 * @return the list or map literal that was parsed 2604 * @return the list or map literal that was parsed
2605 */ 2605 */
2606 TypedLiteral parseListOrMapLiteral(Token modifier) { 2606 TypedLiteral parseListOrMapLiteral(Token modifier) {
2607 TypeArgumentList typeArguments = null; 2607 TypeArgumentList typeArguments = null;
2608 if (matches5(TokenType.LT)) { 2608 if (matches5(TokenType.LT)) {
2609 typeArguments = parseTypeArgumentList(); 2609 typeArguments = parseTypeArgumentList();
2610 } 2610 }
2611 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2611 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
2612 return parseMapLiteral(modifier, typeArguments); 2612 return parseMapLiteral(modifier, typeArguments);
2613 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 2613 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
2614 return parseListLiteral(modifier, typeArguments); 2614 return parseListLiteral(modifier, typeArguments);
2615 } 2615 }
2616 reportError3(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []); 2616 reportError3(ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL, []);
2617 return new ListLiteral(modifier, typeArguments, createSyntheticToken(TokenTy pe.OPEN_SQUARE_BRACKET), null, createSyntheticToken(TokenType.CLOSE_SQUARE_BRACK ET)); 2617 return new ListLiteral.full(modifier, typeArguments, createSyntheticToken(To kenType.OPEN_SQUARE_BRACKET), null, createSyntheticToken(TokenType.CLOSE_SQUARE_ BRACKET));
2618 } 2618 }
2619 /** 2619 /**
2620 * Parse a logical and expression. 2620 * Parse a logical and expression.
2621 * <pre> 2621 * <pre>
2622 * logicalAndExpression ::= 2622 * logicalAndExpression ::=
2623 * bitwiseOrExpression ('&&' bitwiseOrExpression) 2623 * bitwiseOrExpression ('&&' bitwiseOrExpression)
2624 * </pre> 2624 * </pre>
2625 * @return the logical and expression that was parsed 2625 * @return the logical and expression that was parsed
2626 */ 2626 */
2627 Expression parseLogicalAndExpression() { 2627 Expression parseLogicalAndExpression() {
2628 Expression expression = parseBitwiseOrExpression(); 2628 Expression expression = parseBitwiseOrExpression();
2629 while (matches5(TokenType.AMPERSAND_AMPERSAND)) { 2629 while (matches5(TokenType.AMPERSAND_AMPERSAND)) {
2630 Token operator = andAdvance; 2630 Token operator = andAdvance;
2631 expression = new BinaryExpression(expression, operator, parseBitwiseOrExpr ession()); 2631 expression = new BinaryExpression.full(expression, operator, parseBitwiseO rExpression());
2632 } 2632 }
2633 return expression; 2633 return expression;
2634 } 2634 }
2635 /** 2635 /**
2636 * Parse a logical or expression. 2636 * Parse a logical or expression.
2637 * <pre> 2637 * <pre>
2638 * logicalOrExpression ::= 2638 * logicalOrExpression ::=
2639 * logicalAndExpression ('||' logicalAndExpression) 2639 * logicalAndExpression ('||' logicalAndExpression)
2640 * </pre> 2640 * </pre>
2641 * @return the logical or expression that was parsed 2641 * @return the logical or expression that was parsed
2642 */ 2642 */
2643 Expression parseLogicalOrExpression() { 2643 Expression parseLogicalOrExpression() {
2644 Expression expression = parseLogicalAndExpression(); 2644 Expression expression = parseLogicalAndExpression();
2645 while (matches5(TokenType.BAR_BAR)) { 2645 while (matches5(TokenType.BAR_BAR)) {
2646 Token operator = andAdvance; 2646 Token operator = andAdvance;
2647 expression = new BinaryExpression(expression, operator, parseLogicalAndExp ression()); 2647 expression = new BinaryExpression.full(expression, operator, parseLogicalA ndExpression());
2648 } 2648 }
2649 return expression; 2649 return expression;
2650 } 2650 }
2651 /** 2651 /**
2652 * Parse a map literal. 2652 * Parse a map literal.
2653 * <pre> 2653 * <pre>
2654 * mapLiteral ::= 2654 * mapLiteral ::=
2655 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)? '}' 2655 * 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)? '}'
2656 * </pre> 2656 * </pre>
2657 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is 2657 * @param modifier the 'const' modifier appearing before the literal, or {@cod e null} if there is
2658 * no modifier 2658 * no modifier
2659 * @param typeArguments the type arguments that were declared, or {@code null} if there are no 2659 * @param typeArguments the type arguments that were declared, or {@code null} if there are no
2660 * type arguments 2660 * type arguments
2661 * @return the map literal that was parsed 2661 * @return the map literal that was parsed
2662 */ 2662 */
2663 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) { 2663 MapLiteral parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
2664 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET); 2664 Token leftBracket = expect2(TokenType.OPEN_CURLY_BRACKET);
2665 List<MapLiteralEntry> entries = new List<MapLiteralEntry>(); 2665 List<MapLiteralEntry> entries = new List<MapLiteralEntry>();
2666 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 2666 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
2667 return new MapLiteral(modifier, typeArguments, leftBracket, entries, andAd vance); 2667 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, andAdvance);
2668 } 2668 }
2669 entries.add(parseMapLiteralEntry()); 2669 entries.add(parseMapLiteralEntry());
2670 while (optional(TokenType.COMMA)) { 2670 while (optional(TokenType.COMMA)) {
2671 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) { 2671 if (matches5(TokenType.CLOSE_CURLY_BRACKET)) {
2672 return new MapLiteral(modifier, typeArguments, leftBracket, entries, and Advance); 2672 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries , andAdvance);
2673 } 2673 }
2674 entries.add(parseMapLiteralEntry()); 2674 entries.add(parseMapLiteralEntry());
2675 } 2675 }
2676 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 2676 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
2677 return new MapLiteral(modifier, typeArguments, leftBracket, entries, rightBr acket); 2677 return new MapLiteral.full(modifier, typeArguments, leftBracket, entries, ri ghtBracket);
2678 } 2678 }
2679 /** 2679 /**
2680 * Parse a map literal entry. 2680 * Parse a map literal entry.
2681 * <pre> 2681 * <pre>
2682 * mapLiteralEntry ::= 2682 * mapLiteralEntry ::=
2683 * stringLiteral ':' expression 2683 * stringLiteral ':' expression
2684 * </pre> 2684 * </pre>
2685 * @return the map literal entry that was parsed 2685 * @return the map literal entry that was parsed
2686 */ 2686 */
2687 MapLiteralEntry parseMapLiteralEntry() { 2687 MapLiteralEntry parseMapLiteralEntry() {
2688 StringLiteral key = parseStringLiteral(); 2688 StringLiteral key = parseStringLiteral();
2689 Token separator = expect2(TokenType.COLON); 2689 Token separator = expect2(TokenType.COLON);
2690 Expression value = parseExpression2(); 2690 Expression value = parseExpression2();
2691 return new MapLiteralEntry(key, separator, value); 2691 return new MapLiteralEntry.full(key, separator, value);
2692 } 2692 }
2693 /** 2693 /**
2694 * Parse a method declaration. 2694 * Parse a method declaration.
2695 * <pre> 2695 * <pre>
2696 * functionDeclaration ::= 2696 * functionDeclaration ::=
2697 * 'external'? 'static'? functionSignature functionBody 2697 * 'external'? 'static'? functionSignature functionBody
2698 * | 'external'? functionSignature ';' 2698 * | 'external'? functionSignature ';'
2699 * </pre> 2699 * </pre>
2700 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 2700 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
2701 * declaration 2701 * declaration
(...skipping 28 matching lines...) Expand all
2730 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, false); 2730 FunctionBody body = parseFunctionBody(externalKeyword != null || staticKeywo rd == null, false);
2731 if (externalKeyword != null) { 2731 if (externalKeyword != null) {
2732 if (body is! EmptyFunctionBody) { 2732 if (body is! EmptyFunctionBody) {
2733 reportError(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []); 2733 reportError(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body, []);
2734 } 2734 }
2735 } else if (staticKeyword != null) { 2735 } else if (staticKeyword != null) {
2736 if (body is EmptyFunctionBody) { 2736 if (body is EmptyFunctionBody) {
2737 reportError(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []); 2737 reportError(ParserErrorCode.ABSTRACT_STATIC_METHOD, body, []);
2738 } 2738 }
2739 } 2739 }
2740 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, null, null, name, paramete rs, body); 2740 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, null, null, name, par ameters, body);
2741 } 2741 }
2742 /** 2742 /**
2743 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any 2743 * Parse the modifiers preceding a declaration. This method allows the modifie rs to appear in any
2744 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as 2744 * order but does generate errors for duplicated modifiers. Checks for other p roblems, such as
2745 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are 2745 * having the modifiers appear in the wrong order or specifying both 'const' a nd 'final', are
2746 * reported in one of the methods whose name is prefixed with {@code validateM odifiersFor}. 2746 * reported in one of the methods whose name is prefixed with {@code validateM odifiersFor}.
2747 * <pre> 2747 * <pre>
2748 * modifiers ::= 2748 * modifiers ::=
2749 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | 'var' ) 2749 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | 'var' )
2750 * </pre> 2750 * </pre>
2751 * @return the modifiers that were parsed 2751 * @return the modifiers that were parsed
2752 */ 2752 */
2753 Modifiers parseModifiers() { 2753 Modifiers parseModifiers() {
2754 Modifiers modifiers = new Modifiers(); 2754 Modifiers modifiers = new Modifiers();
2755 bool progress = true; 2755 bool progress = true;
2756 while (progress) { 2756 while (progress) {
2757 if (matches(Keyword.ABSTRACT)) { 2757 if (matches(Keyword.ABSTRACT)) {
2758 if (modifiers.abstractKeyword != null) { 2758 if (modifiers.abstractKeyword != null) {
2759 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2759 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2760 advance(); 2760 advance();
2761 } else { 2761 } else {
2762 modifiers.abstractKeyword4 = andAdvance; 2762 modifiers.abstractKeyword = andAdvance;
2763 } 2763 }
2764 } else if (matches(Keyword.CONST)) { 2764 } else if (matches(Keyword.CONST)) {
2765 if (modifiers.constKeyword != null) { 2765 if (modifiers.constKeyword != null) {
2766 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2766 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2767 advance(); 2767 advance();
2768 } else { 2768 } else {
2769 modifiers.constKeyword3 = andAdvance; 2769 modifiers.constKeyword = andAdvance;
2770 } 2770 }
2771 } else if (matches(Keyword.EXTERNAL)) { 2771 } else if (matches(Keyword.EXTERNAL)) {
2772 if (modifiers.externalKeyword != null) { 2772 if (modifiers.externalKeyword != null) {
2773 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2773 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2774 advance(); 2774 advance();
2775 } else { 2775 } else {
2776 modifiers.externalKeyword5 = andAdvance; 2776 modifiers.externalKeyword = andAdvance;
2777 } 2777 }
2778 } else if (matches(Keyword.FACTORY)) { 2778 } else if (matches(Keyword.FACTORY)) {
2779 if (modifiers.factoryKeyword != null) { 2779 if (modifiers.factoryKeyword != null) {
2780 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2780 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2781 advance(); 2781 advance();
2782 } else { 2782 } else {
2783 modifiers.factoryKeyword3 = andAdvance; 2783 modifiers.factoryKeyword = andAdvance;
2784 } 2784 }
2785 } else if (matches(Keyword.FINAL)) { 2785 } else if (matches(Keyword.FINAL)) {
2786 if (modifiers.finalKeyword != null) { 2786 if (modifiers.finalKeyword != null) {
2787 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2787 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2788 advance(); 2788 advance();
2789 } else { 2789 } else {
2790 modifiers.finalKeyword2 = andAdvance; 2790 modifiers.finalKeyword = andAdvance;
2791 } 2791 }
2792 } else if (matches(Keyword.STATIC)) { 2792 } else if (matches(Keyword.STATIC)) {
2793 if (modifiers.staticKeyword != null) { 2793 if (modifiers.staticKeyword != null) {
2794 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2794 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2795 advance(); 2795 advance();
2796 } else { 2796 } else {
2797 modifiers.staticKeyword2 = andAdvance; 2797 modifiers.staticKeyword = andAdvance;
2798 } 2798 }
2799 } else if (matches(Keyword.VAR)) { 2799 } else if (matches(Keyword.VAR)) {
2800 if (modifiers.varKeyword != null) { 2800 if (modifiers.varKeyword != null) {
2801 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]); 2801 reportError3(ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexem e]);
2802 advance(); 2802 advance();
2803 } else { 2803 } else {
2804 modifiers.varKeyword2 = andAdvance; 2804 modifiers.varKeyword = andAdvance;
2805 } 2805 }
2806 } else { 2806 } else {
2807 progress = false; 2807 progress = false;
2808 } 2808 }
2809 } 2809 }
2810 return modifiers; 2810 return modifiers;
2811 } 2811 }
2812 /** 2812 /**
2813 * Parse a multiplicative expression. 2813 * Parse a multiplicative expression.
2814 * <pre> 2814 * <pre>
2815 * multiplicativeExpression ::= 2815 * multiplicativeExpression ::=
2816 * unaryExpression (multiplicativeOperator unaryExpression) 2816 * unaryExpression (multiplicativeOperator unaryExpression)
2817 * | 'super' (multiplicativeOperator unaryExpression)+ 2817 * | 'super' (multiplicativeOperator unaryExpression)+
2818 * </pre> 2818 * </pre>
2819 * @return the multiplicative expression that was parsed 2819 * @return the multiplicative expression that was parsed
2820 */ 2820 */
2821 Expression parseMultiplicativeExpression() { 2821 Expression parseMultiplicativeExpression() {
2822 Expression expression; 2822 Expression expression;
2823 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat or()) { 2823 if (matches(Keyword.SUPER) && _currentToken.next.type.isMultiplicativeOperat or()) {
2824 expression = new SuperExpression(andAdvance); 2824 expression = new SuperExpression.full(andAdvance);
2825 } else { 2825 } else {
2826 expression = parseUnaryExpression(); 2826 expression = parseUnaryExpression();
2827 } 2827 }
2828 while (_currentToken.type.isMultiplicativeOperator()) { 2828 while (_currentToken.type.isMultiplicativeOperator()) {
2829 Token operator = andAdvance; 2829 Token operator = andAdvance;
2830 expression = new BinaryExpression(expression, operator, parseUnaryExpressi on()); 2830 expression = new BinaryExpression.full(expression, operator, parseUnaryExp ression());
2831 } 2831 }
2832 return expression; 2832 return expression;
2833 } 2833 }
2834 /** 2834 /**
2835 * Parse a new expression. 2835 * Parse a new expression.
2836 * <pre> 2836 * <pre>
2837 * newExpression ::= 2837 * newExpression ::=
2838 * instanceCreationExpression 2838 * instanceCreationExpression
2839 * </pre> 2839 * </pre>
2840 * @return the new expression that was parsed 2840 * @return the new expression that was parsed
(...skipping 18 matching lines...) Expand all
2859 * | expressionStatement 2859 * | expressionStatement
2860 * | functionSignature functionBody 2860 * | functionSignature functionBody
2861 * </pre> 2861 * </pre>
2862 * @return the non-labeled statement that was parsed 2862 * @return the non-labeled statement that was parsed
2863 */ 2863 */
2864 Statement parseNonLabeledStatement() { 2864 Statement parseNonLabeledStatement() {
2865 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 2865 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
2866 if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 2866 if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
2867 if (matches4(peek(), TokenType.STRING)) { 2867 if (matches4(peek(), TokenType.STRING)) {
2868 Token afterString = skipStringLiteral(_currentToken.next); 2868 Token afterString = skipStringLiteral(_currentToken.next);
2869 if (afterString != null && afterString.type == TokenType.COLON) { 2869 if (afterString != null && identical(afterString.type, TokenType.COLON)) {
2870 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON)); 2870 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT ype.SEMICOLON));
2871 } 2871 }
2872 } 2872 }
2873 return parseBlock(); 2873 return parseBlock();
2874 } else if (matches5(TokenType.KEYWORD) && !(_currentToken as KeywordToken).k eyword.isPseudoKeyword()) { 2874 } else if (matches5(TokenType.KEYWORD) && !((_currentToken as KeywordToken)) .keyword.isPseudoKeyword()) {
2875 Keyword keyword29 = (_currentToken as KeywordToken).keyword; 2875 Keyword keyword28 = ((_currentToken as KeywordToken)).keyword;
2876 if (keyword29 == Keyword.ASSERT) { 2876 if (identical(keyword28, Keyword.ASSERT)) {
2877 return parseAssertStatement(); 2877 return parseAssertStatement();
2878 } else if (keyword29 == Keyword.BREAK) { 2878 } else if (identical(keyword28, Keyword.BREAK)) {
2879 return parseBreakStatement(); 2879 return parseBreakStatement();
2880 } else if (keyword29 == Keyword.CONTINUE) { 2880 } else if (identical(keyword28, Keyword.CONTINUE)) {
2881 return parseContinueStatement(); 2881 return parseContinueStatement();
2882 } else if (keyword29 == Keyword.DO) { 2882 } else if (identical(keyword28, Keyword.DO)) {
2883 return parseDoStatement(); 2883 return parseDoStatement();
2884 } else if (keyword29 == Keyword.FOR) { 2884 } else if (identical(keyword28, Keyword.FOR)) {
2885 return parseForStatement(); 2885 return parseForStatement();
2886 } else if (keyword29 == Keyword.IF) { 2886 } else if (identical(keyword28, Keyword.IF)) {
2887 return parseIfStatement(); 2887 return parseIfStatement();
2888 } else if (keyword29 == Keyword.RETURN) { 2888 } else if (identical(keyword28, Keyword.RETURN)) {
2889 return parseReturnStatement(); 2889 return parseReturnStatement();
2890 } else if (keyword29 == Keyword.SWITCH) { 2890 } else if (identical(keyword28, Keyword.SWITCH)) {
2891 return parseSwitchStatement(); 2891 return parseSwitchStatement();
2892 } else if (keyword29 == Keyword.THROW) { 2892 } else if (identical(keyword28, Keyword.THROW)) {
2893 return new ExpressionStatement(parseThrowExpression(), expect2(TokenType .SEMICOLON)); 2893 return new ExpressionStatement.full(parseThrowExpression(), expect2(Toke nType.SEMICOLON));
2894 } else if (keyword29 == Keyword.TRY) { 2894 } else if (identical(keyword28, Keyword.TRY)) {
2895 return parseTryStatement(); 2895 return parseTryStatement();
2896 } else if (keyword29 == Keyword.WHILE) { 2896 } else if (identical(keyword28, Keyword.WHILE)) {
2897 return parseWhileStatement(); 2897 return parseWhileStatement();
2898 } else if (keyword29 == Keyword.VAR || keyword29 == Keyword.FINAL) { 2898 } else if (identical(keyword28, Keyword.VAR) || identical(keyword28, Keywo rd.FINAL)) {
2899 return parseVariableDeclarationStatement(); 2899 return parseVariableDeclarationStatement();
2900 } else if (keyword29 == Keyword.VOID) { 2900 } else if (identical(keyword28, Keyword.VOID)) {
2901 TypeName returnType = parseReturnType(); 2901 TypeName returnType = parseReturnType();
2902 if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN, Tok enType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) { 2902 if (matchesIdentifier() && matchesAny(peek(), [TokenType.OPEN_PAREN, Tok enType.OPEN_CURLY_BRACKET, TokenType.FUNCTION])) {
2903 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe); 2903 return parseFunctionDeclarationStatement2(commentAndMetadata, returnTy pe);
2904 } else { 2904 } else {
2905 if (matchesIdentifier()) { 2905 if (matchesIdentifier()) {
2906 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) { 2906 if (matchesAny(peek(), [TokenType.EQ, TokenType.COMMA, TokenType.SEM ICOLON])) {
2907 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []); 2907 reportError(ParserErrorCode.VOID_VARIABLE, returnType, []);
2908 return parseVariableDeclarationStatement(); 2908 return parseVariableDeclarationStatement();
2909 } 2909 }
2910 } 2910 }
2911 return null; 2911 return null;
2912 } 2912 }
2913 } else if (keyword29 == Keyword.CONST) { 2913 } else if (identical(keyword28, Keyword.CONST)) {
2914 if (matchesAny(peek(), [TokenType.LT, TokenType.OPEN_CURLY_BRACKET, Toke nType.OPEN_SQUARE_BRACKET, TokenType.INDEX])) { 2914 if (matchesAny(peek(), [TokenType.LT, TokenType.OPEN_CURLY_BRACKET, Toke nType.OPEN_SQUARE_BRACKET, TokenType.INDEX])) {
2915 return new ExpressionStatement(parseExpression2(), expect2(TokenType.S EMICOLON)); 2915 return new ExpressionStatement.full(parseExpression2(), expect2(TokenT ype.SEMICOLON));
2916 } else if (matches4(peek(), TokenType.IDENTIFIER)) { 2916 } else if (matches4(peek(), TokenType.IDENTIFIER)) {
2917 Token afterType = skipTypeName(peek()); 2917 Token afterType = skipTypeName(peek());
2918 if (afterType != null) { 2918 if (afterType != null) {
2919 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) { 2919 if (matches4(afterType, TokenType.OPEN_PAREN) || (matches4(afterType , TokenType.PERIOD) && matches4(afterType.next, TokenType.IDENTIFIER) && matches 4(afterType.next.next, TokenType.OPEN_PAREN))) {
2920 return new ExpressionStatement(parseExpression2(), expect2(TokenTy pe.SEMICOLON)); 2920 return new ExpressionStatement.full(parseExpression2(), expect2(To kenType.SEMICOLON));
2921 } 2921 }
2922 } 2922 }
2923 } 2923 }
2924 return parseVariableDeclarationStatement(); 2924 return parseVariableDeclarationStatement();
2925 } else if (keyword29 == Keyword.NEW || keyword29 == Keyword.TRUE || keywor d29 == Keyword.FALSE || keyword29 == Keyword.NULL || keyword29 == Keyword.SUPER || keyword29 == Keyword.THIS) { 2925 } else if (identical(keyword28, Keyword.NEW) || identical(keyword28, Keywo rd.TRUE) || identical(keyword28, Keyword.FALSE) || identical(keyword28, Keyword. NULL) || identical(keyword28, Keyword.SUPER) || identical(keyword28, Keyword.THI S)) {
2926 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEM ICOLON)); 2926 return new ExpressionStatement.full(parseExpression2(), expect2(TokenTyp e.SEMICOLON));
2927 } else { 2927 } else {
2928 return null; 2928 return null;
2929 } 2929 }
2930 } else if (matches5(TokenType.SEMICOLON)) { 2930 } else if (matches5(TokenType.SEMICOLON)) {
2931 return parseEmptyStatement(); 2931 return parseEmptyStatement();
2932 } else if (isInitializedVariableDeclaration()) { 2932 } else if (isInitializedVariableDeclaration()) {
2933 return parseVariableDeclarationStatement(); 2933 return parseVariableDeclarationStatement();
2934 } else if (isFunctionDeclaration()) { 2934 } else if (isFunctionDeclaration()) {
2935 return parseFunctionDeclarationStatement(); 2935 return parseFunctionDeclarationStatement();
2936 } else { 2936 } else {
2937 return new ExpressionStatement(parseExpression2(), expect2(TokenType.SEMIC OLON)); 2937 return new ExpressionStatement.full(parseExpression2(), expect2(TokenType. SEMICOLON));
2938 } 2938 }
2939 } 2939 }
2940 /** 2940 /**
2941 * Parse a normal formal parameter. 2941 * Parse a normal formal parameter.
2942 * <pre> 2942 * <pre>
2943 * normalFormalParameter ::= 2943 * normalFormalParameter ::=
2944 * functionSignature 2944 * functionSignature
2945 * | fieldFormalParameter 2945 * | fieldFormalParameter
2946 * | simpleFormalParameter 2946 * | simpleFormalParameter
2947 * functionSignature: 2947 * functionSignature:
(...skipping 13 matching lines...) Expand all
2961 Token period = null; 2961 Token period = null;
2962 if (matches(Keyword.THIS)) { 2962 if (matches(Keyword.THIS)) {
2963 thisKeyword = andAdvance; 2963 thisKeyword = andAdvance;
2964 period = expect2(TokenType.PERIOD); 2964 period = expect2(TokenType.PERIOD);
2965 } 2965 }
2966 SimpleIdentifier identifier = parseSimpleIdentifier(); 2966 SimpleIdentifier identifier = parseSimpleIdentifier();
2967 if (matches5(TokenType.OPEN_PAREN)) { 2967 if (matches5(TokenType.OPEN_PAREN)) {
2968 if (thisKeyword != null) { 2968 if (thisKeyword != null) {
2969 } 2969 }
2970 FormalParameterList parameters = parseFormalParameterList(); 2970 FormalParameterList parameters = parseFormalParameterList();
2971 return new FunctionTypedFormalParameter(commentAndMetadata.comment, commen tAndMetadata.metadata, holder.type, identifier, parameters); 2971 return new FunctionTypedFormalParameter.full(commentAndMetadata.comment, c ommentAndMetadata.metadata, holder.type, identifier, parameters);
2972 } 2972 }
2973 TypeName type18 = holder.type; 2973 TypeName type16 = holder.type;
2974 if (type18 != null && matches3(type18.name.beginToken, Keyword.VOID)) { 2974 if (type16 != null && matches3(type16.name.beginToken, Keyword.VOID)) {
2975 reportError4(ParserErrorCode.VOID_PARAMETER, type18.name.beginToken, []); 2975 reportError4(ParserErrorCode.VOID_PARAMETER, type16.name.beginToken, []);
2976 } 2976 }
2977 if (thisKeyword != null) { 2977 if (thisKeyword != null) {
2978 return new FieldFormalParameter(commentAndMetadata.comment, commentAndMeta data.metadata, holder.keyword, holder.type, thisKeyword, period, identifier); 2978 return new FieldFormalParameter.full(commentAndMetadata.comment, commentAn dMetadata.metadata, holder.keyword, holder.type, thisKeyword, period, identifier );
2979 } 2979 }
2980 return new SimpleFormalParameter(commentAndMetadata.comment, commentAndMetad ata.metadata, holder.keyword, holder.type, identifier); 2980 return new SimpleFormalParameter.full(commentAndMetadata.comment, commentAnd Metadata.metadata, holder.keyword, holder.type, identifier);
2981 } 2981 }
2982 /** 2982 /**
2983 * Parse an operator declaration. 2983 * Parse an operator declaration.
2984 * <pre> 2984 * <pre>
2985 * operatorDeclaration ::= 2985 * operatorDeclaration ::=
2986 * operatorSignature (';' | functionBody) 2986 * operatorSignature (';' | functionBody)
2987 * operatorSignature ::= 2987 * operatorSignature ::=
2988 * 'external'? returnType? 'operator' operator formalParameterList 2988 * 'external'? returnType? 'operator' operator formalParameterList
2989 * </pre> 2989 * </pre>
2990 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 2990 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
2991 * declaration 2991 * declaration
2992 * @param externalKeyword the 'external' token 2992 * @param externalKeyword the 'external' token
2993 * @param the return type that has already been parsed, or {@code null} if the re was no return 2993 * @param the return type that has already been parsed, or {@code null} if the re was no return
2994 * type 2994 * type
2995 * @return the operator declaration that was parsed 2995 * @return the operator declaration that was parsed
2996 */ 2996 */
2997 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) { 2997 MethodDeclaration parseOperator(CommentAndMetadata commentAndMetadata, Token e xternalKeyword, TypeName returnType) {
2998 Token operatorKeyword = expect(Keyword.OPERATOR); 2998 Token operatorKeyword = expect(Keyword.OPERATOR);
2999 if (!_currentToken.isUserDefinableOperator()) { 2999 if (!_currentToken.isUserDefinableOperator()) {
3000 reportError3(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.l exeme]); 3000 reportError3(ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.l exeme]);
3001 } 3001 }
3002 SimpleIdentifier name = new SimpleIdentifier(andAdvance); 3002 SimpleIdentifier name = new SimpleIdentifier.full(andAdvance);
3003 FormalParameterList parameters = parseFormalParameterList(); 3003 FormalParameterList parameters = parseFormalParameterList();
3004 validateFormalParameterList(parameters); 3004 validateFormalParameterList(parameters);
3005 FunctionBody body = parseFunctionBody(true, false); 3005 FunctionBody body = parseFunctionBody(true, false);
3006 if (externalKeyword != null && body is! EmptyFunctionBody) { 3006 if (externalKeyword != null && body is! EmptyFunctionBody) {
3007 reportError3(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []); 3007 reportError3(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY, []);
3008 } 3008 }
3009 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, null, returnType, null, operatorKeyword, name, parame ters, body); 3009 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, null, returnType, null, operatorKeyword, name, p arameters, body);
3010 } 3010 }
3011 /** 3011 /**
3012 * Parse a return type if one is given, otherwise return {@code null} without advancing. 3012 * Parse a return type if one is given, otherwise return {@code null} without advancing.
3013 * @return the return type that was parsed 3013 * @return the return type that was parsed
3014 */ 3014 */
3015 TypeName parseOptionalReturnType() { 3015 TypeName parseOptionalReturnType() {
3016 if (matches(Keyword.VOID)) { 3016 if (matches(Keyword.VOID)) {
3017 return parseReturnType(); 3017 return parseReturnType();
3018 } else if (matchesIdentifier() && !matches(Keyword.GET) && !matches(Keyword. SET) && !matches(Keyword.OPERATOR) && (matchesIdentifier2(peek()) || matches4(pe ek(), TokenType.LT))) { 3018 } else if (matchesIdentifier() && !matches(Keyword.GET) && !matches(Keyword. SET) && !matches(Keyword.OPERATOR) && (matchesIdentifier2(peek()) || matches4(pe ek(), TokenType.LT))) {
3019 return parseReturnType(); 3019 return parseReturnType();
3020 } else if (matchesIdentifier() && matches4(peek(), TokenType.PERIOD) && matc hesIdentifier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType.LT))) { 3020 } else if (matchesIdentifier() && matches4(peek(), TokenType.PERIOD) && matc hesIdentifier2(peek2(2)) && (matchesIdentifier2(peek2(3)) || matches4(peek2(3), TokenType.LT))) {
3021 return parseReturnType(); 3021 return parseReturnType();
3022 } 3022 }
3023 return null; 3023 return null;
3024 } 3024 }
3025 /** 3025 /**
3026 * Parse a part or part-of directive. 3026 * Parse a part or part-of directive.
3027 * <pre> 3027 * <pre>
3028 * partDirective ::= 3028 * partDirective ::=
3029 * metadata 'part' stringLiteral ';' 3029 * metadata 'part' stringLiteral ';'
3030 * partOfDirective ::= 3030 * partOfDirective ::=
3031 * metadata 'part' 'of' identifier ';' 3031 * metadata 'part' 'of' identifier ';'
3032 * </pre> 3032 * </pre>
3033 * @param commentAndMetadata the metadata to be associated with the directive 3033 * @param commentAndMetadata the metadata to be associated with the directive
3034 * @return the part or part-of directive that was parsed 3034 * @return the part or part-of directive that was parsed
3035 */ 3035 */
3036 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) { 3036 Directive parsePartDirective(CommentAndMetadata commentAndMetadata) {
3037 Token partKeyword = expect(Keyword.PART); 3037 Token partKeyword = expect(Keyword.PART);
3038 if (matches2(Parser._OF)) { 3038 if (matches2(_OF)) {
3039 Token ofKeyword = andAdvance; 3039 Token ofKeyword = andAdvance;
3040 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword); 3040 LibraryIdentifier libraryName = parseLibraryName(ParserErrorCode.MISSING_N AME_IN_PART_OF_DIRECTIVE, ofKeyword);
3041 Token semicolon = expect2(TokenType.SEMICOLON); 3041 Token semicolon = expect2(TokenType.SEMICOLON);
3042 return new PartOfDirective(commentAndMetadata.comment, commentAndMetadata. metadata, partKeyword, ofKeyword, libraryName, semicolon); 3042 return new PartOfDirective.full(commentAndMetadata.comment, commentAndMeta data.metadata, partKeyword, ofKeyword, libraryName, semicolon);
3043 } 3043 }
3044 StringLiteral partUri = parseStringLiteral(); 3044 StringLiteral partUri = parseStringLiteral();
3045 Token semicolon = expect2(TokenType.SEMICOLON); 3045 Token semicolon = expect2(TokenType.SEMICOLON);
3046 return new PartDirective(commentAndMetadata.comment, commentAndMetadata.meta data, partKeyword, partUri, semicolon); 3046 return new PartDirective.full(commentAndMetadata.comment, commentAndMetadata .metadata, partKeyword, partUri, semicolon);
3047 } 3047 }
3048 /** 3048 /**
3049 * Parse a postfix expression. 3049 * Parse a postfix expression.
3050 * <pre> 3050 * <pre>
3051 * postfixExpression ::= 3051 * postfixExpression ::=
3052 * assignableExpression postfixOperator 3052 * assignableExpression postfixOperator
3053 * | primary selector 3053 * | primary selector
3054 * selector ::= 3054 * selector ::=
3055 * assignableSelector 3055 * assignableSelector
3056 * | argumentList 3056 * | argumentList
3057 * </pre> 3057 * </pre>
3058 * @return the postfix expression that was parsed 3058 * @return the postfix expression that was parsed
3059 */ 3059 */
3060 Expression parsePostfixExpression() { 3060 Expression parsePostfixExpression() {
3061 Expression operand = parseAssignableExpression(true); 3061 Expression operand = parseAssignableExpression(true);
3062 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PERIOD) || matches5(TokenType.OPEN_PAREN)) { 3062 if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PERIOD) || matches5(TokenType.OPEN_PAREN)) {
3063 do { 3063 do {
3064 if (matches5(TokenType.OPEN_PAREN)) { 3064 if (matches5(TokenType.OPEN_PAREN)) {
3065 ArgumentList argumentList = parseArgumentList(); 3065 ArgumentList argumentList = parseArgumentList();
3066 if (operand is PropertyAccess) { 3066 if (operand is PropertyAccess) {
3067 PropertyAccess access = operand as PropertyAccess; 3067 PropertyAccess access = (operand as PropertyAccess);
3068 operand = new MethodInvocation(access.target, access.operator, acces s.propertyName, argumentList); 3068 operand = new MethodInvocation.full(access.target, access.operator, access.propertyName, argumentList);
3069 } else { 3069 } else {
3070 operand = new FunctionExpressionInvocation(operand, argumentList); 3070 operand = new FunctionExpressionInvocation.full(operand, argumentLis t);
3071 } 3071 }
3072 } else { 3072 } else {
3073 operand = parseAssignableSelector(operand, true); 3073 operand = parseAssignableSelector(operand, true);
3074 } 3074 }
3075 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN)); 3075 } while (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.PER IOD) || matches5(TokenType.OPEN_PAREN));
3076 return operand; 3076 return operand;
3077 } 3077 }
3078 if (!_currentToken.type.isIncrementOperator()) { 3078 if (!_currentToken.type.isIncrementOperator()) {
3079 return operand; 3079 return operand;
3080 } 3080 }
3081 if (operand is FunctionExpressionInvocation) { 3081 if (operand is FunctionExpressionInvocation) {
3082 reportError3(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []); 3082 reportError3(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, []);
3083 } 3083 }
3084 Token operator = andAdvance; 3084 Token operator = andAdvance;
3085 return new PostfixExpression(operand, operator); 3085 return new PostfixExpression.full(operand, operator);
3086 } 3086 }
3087 /** 3087 /**
3088 * Parse a prefixed identifier. 3088 * Parse a prefixed identifier.
3089 * <pre> 3089 * <pre>
3090 * prefixedIdentifier ::= 3090 * prefixedIdentifier ::=
3091 * identifier ('.' identifier)? 3091 * identifier ('.' identifier)?
3092 * </pre> 3092 * </pre>
3093 * @return the prefixed identifier that was parsed 3093 * @return the prefixed identifier that was parsed
3094 */ 3094 */
3095 Identifier parsePrefixedIdentifier() { 3095 Identifier parsePrefixedIdentifier() {
3096 SimpleIdentifier qualifier = parseSimpleIdentifier(); 3096 SimpleIdentifier qualifier = parseSimpleIdentifier();
3097 if (!matches5(TokenType.PERIOD)) { 3097 if (!matches5(TokenType.PERIOD)) {
3098 return qualifier; 3098 return qualifier;
3099 } 3099 }
3100 Token period = andAdvance; 3100 Token period = andAdvance;
3101 SimpleIdentifier qualified = parseSimpleIdentifier(); 3101 SimpleIdentifier qualified = parseSimpleIdentifier();
3102 return new PrefixedIdentifier(qualifier, period, qualified); 3102 return new PrefixedIdentifier.full(qualifier, period, qualified);
3103 } 3103 }
3104 /** 3104 /**
3105 * Parse a primary expression. 3105 * Parse a primary expression.
3106 * <pre> 3106 * <pre>
3107 * primary ::= 3107 * primary ::=
3108 * thisExpression 3108 * thisExpression
3109 * | 'super' assignableSelector 3109 * | 'super' assignableSelector
3110 * | functionExpression 3110 * | functionExpression
3111 * | literal 3111 * | literal
3112 * | identifier 3112 * | identifier
3113 * | newExpression 3113 * | newExpression
3114 * | constObjectExpression 3114 * | constObjectExpression
3115 * | '(' expression ')' 3115 * | '(' expression ')'
3116 * | argumentDefinitionTest 3116 * | argumentDefinitionTest
3117 * literal ::= 3117 * literal ::=
3118 * nullLiteral 3118 * nullLiteral
3119 * | booleanLiteral 3119 * | booleanLiteral
3120 * | numericLiteral 3120 * | numericLiteral
3121 * | stringLiteral 3121 * | stringLiteral
3122 * | mapLiteral 3122 * | mapLiteral
3123 * | listLiteral 3123 * | listLiteral
3124 * </pre> 3124 * </pre>
3125 * @return the primary expression that was parsed 3125 * @return the primary expression that was parsed
3126 */ 3126 */
3127 Expression parsePrimaryExpression() { 3127 Expression parsePrimaryExpression() {
3128 if (matches(Keyword.THIS)) { 3128 if (matches(Keyword.THIS)) {
3129 return new ThisExpression(andAdvance); 3129 return new ThisExpression.full(andAdvance);
3130 } else if (matches(Keyword.SUPER)) { 3130 } else if (matches(Keyword.SUPER)) {
3131 return parseAssignableSelector(new SuperExpression(andAdvance), false); 3131 return parseAssignableSelector(new SuperExpression.full(andAdvance), false );
3132 } else if (matches(Keyword.NULL)) { 3132 } else if (matches(Keyword.NULL)) {
3133 return new NullLiteral(andAdvance); 3133 return new NullLiteral.full(andAdvance);
3134 } else if (matches(Keyword.FALSE)) { 3134 } else if (matches(Keyword.FALSE)) {
3135 return new BooleanLiteral(andAdvance, false); 3135 return new BooleanLiteral.full(andAdvance, false);
3136 } else if (matches(Keyword.TRUE)) { 3136 } else if (matches(Keyword.TRUE)) {
3137 return new BooleanLiteral(andAdvance, true); 3137 return new BooleanLiteral.full(andAdvance, true);
3138 } else if (matches5(TokenType.DOUBLE)) { 3138 } else if (matches5(TokenType.DOUBLE)) {
3139 Token token = andAdvance; 3139 Token token = andAdvance;
3140 double value = 0.0; 3140 double value = 0.0;
3141 try { 3141 try {
3142 value = double.parse(token.lexeme); 3142 value = double.parse(token.lexeme);
3143 } on NumberFormatException catch (exception) { 3143 } on NumberFormatException catch (exception) {
3144 } 3144 }
3145 return new DoubleLiteral(token, value); 3145 return new DoubleLiteral.full(token, value);
3146 } else if (matches5(TokenType.HEXADECIMAL)) { 3146 } else if (matches5(TokenType.HEXADECIMAL)) {
3147 Token token = andAdvance; 3147 Token token = andAdvance;
3148 int value = null; 3148 int value = null;
3149 try { 3149 try {
3150 value = int.parse(token.lexeme.substring(2), radix: 16); 3150 value = int.parse(token.lexeme.substring(2), radix: 16);
3151 } on NumberFormatException catch (exception) { 3151 } on NumberFormatException catch (exception) {
3152 } 3152 }
3153 return new IntegerLiteral.con1(token, value); 3153 return new IntegerLiteral.full(token, value);
3154 } else if (matches5(TokenType.INT)) { 3154 } else if (matches5(TokenType.INT)) {
3155 Token token = andAdvance; 3155 Token token = andAdvance;
3156 int value = null; 3156 int value = null;
3157 try { 3157 try {
3158 value = int.parse(token.lexeme); 3158 value = int.parse(token.lexeme);
3159 } on NumberFormatException catch (exception) { 3159 } on NumberFormatException catch (exception) {
3160 } 3160 }
3161 return new IntegerLiteral.con1(token, value); 3161 return new IntegerLiteral.full(token, value);
3162 } else if (matches5(TokenType.STRING)) { 3162 } else if (matches5(TokenType.STRING)) {
3163 return parseStringLiteral(); 3163 return parseStringLiteral();
3164 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) { 3164 } else if (matches5(TokenType.OPEN_CURLY_BRACKET)) {
3165 return parseMapLiteral(null, null); 3165 return parseMapLiteral(null, null);
3166 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) { 3166 } else if (matches5(TokenType.OPEN_SQUARE_BRACKET) || matches5(TokenType.IND EX)) {
3167 return parseListLiteral(null, null); 3167 return parseListLiteral(null, null);
3168 } else if (matchesIdentifier()) { 3168 } else if (matchesIdentifier()) {
3169 return parsePrefixedIdentifier(); 3169 return parsePrefixedIdentifier();
3170 } else if (matches(Keyword.NEW)) { 3170 } else if (matches(Keyword.NEW)) {
3171 return parseNewExpression(); 3171 return parseNewExpression();
3172 } else if (matches(Keyword.CONST)) { 3172 } else if (matches(Keyword.CONST)) {
3173 return parseConstExpression(); 3173 return parseConstExpression();
3174 } else if (matches5(TokenType.OPEN_PAREN)) { 3174 } else if (matches5(TokenType.OPEN_PAREN)) {
3175 if (isFunctionExpression(_currentToken)) { 3175 if (isFunctionExpression(_currentToken)) {
3176 return parseFunctionExpression(); 3176 return parseFunctionExpression();
3177 } 3177 }
3178 Token leftParenthesis = andAdvance; 3178 Token leftParenthesis = andAdvance;
3179 Expression expression = parseExpression2(); 3179 Expression expression = parseExpression2();
3180 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 3180 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
3181 return new ParenthesizedExpression(leftParenthesis, expression, rightParen thesis); 3181 return new ParenthesizedExpression.full(leftParenthesis, expression, right Parenthesis);
3182 } else if (matches5(TokenType.LT)) { 3182 } else if (matches5(TokenType.LT)) {
3183 return parseListOrMapLiteral(null); 3183 return parseListOrMapLiteral(null);
3184 } else if (matches5(TokenType.QUESTION)) { 3184 } else if (matches5(TokenType.QUESTION)) {
3185 return parseArgumentDefinitionTest(); 3185 return parseArgumentDefinitionTest();
3186 } else if (matches(Keyword.VOID)) { 3186 } else if (matches(Keyword.VOID)) {
3187 reportError3(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]); 3187 reportError3(ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
3188 advance(); 3188 advance();
3189 return parsePrimaryExpression(); 3189 return parsePrimaryExpression();
3190 } else { 3190 } else {
3191 return createSyntheticIdentifier(); 3191 return createSyntheticIdentifier();
3192 } 3192 }
3193 } 3193 }
3194 /** 3194 /**
3195 * Parse a redirecting constructor invocation. 3195 * Parse a redirecting constructor invocation.
3196 * <pre> 3196 * <pre>
3197 * redirectingConstructorInvocation ::= 3197 * redirectingConstructorInvocation ::=
3198 * 'this' ('.' identifier)? arguments 3198 * 'this' ('.' identifier)? arguments
3199 * </pre> 3199 * </pre>
3200 * @return the redirecting constructor invocation that was parsed 3200 * @return the redirecting constructor invocation that was parsed
3201 */ 3201 */
3202 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() { 3202 RedirectingConstructorInvocation parseRedirectingConstructorInvocation() {
3203 Token keyword = expect(Keyword.THIS); 3203 Token keyword = expect(Keyword.THIS);
3204 Token period = null; 3204 Token period = null;
3205 SimpleIdentifier constructorName = null; 3205 SimpleIdentifier constructorName = null;
3206 if (matches5(TokenType.PERIOD)) { 3206 if (matches5(TokenType.PERIOD)) {
3207 period = andAdvance; 3207 period = andAdvance;
3208 constructorName = parseSimpleIdentifier(); 3208 constructorName = parseSimpleIdentifier();
3209 } 3209 }
3210 ArgumentList argumentList = parseArgumentList(); 3210 ArgumentList argumentList = parseArgumentList();
3211 return new RedirectingConstructorInvocation(keyword, period, constructorName , argumentList); 3211 return new RedirectingConstructorInvocation.full(keyword, period, constructo rName, argumentList);
3212 } 3212 }
3213 /** 3213 /**
3214 * Parse a relational expression. 3214 * Parse a relational expression.
3215 * <pre> 3215 * <pre>
3216 * relationalExpression ::= 3216 * relationalExpression ::=
3217 * shiftExpression ('is' type | 'as' type | relationalOperator shiftExpression )? 3217 * shiftExpression ('is' type | 'as' type | relationalOperator shiftExpression )?
3218 * | 'super' relationalOperator shiftExpression 3218 * | 'super' relationalOperator shiftExpression
3219 * </pre> 3219 * </pre>
3220 * @return the relational expression that was parsed 3220 * @return the relational expression that was parsed
3221 */ 3221 */
3222 Expression parseRelationalExpression() { 3222 Expression parseRelationalExpression() {
3223 if (matches(Keyword.SUPER) && _currentToken.next.type.isRelationalOperator() ) { 3223 if (matches(Keyword.SUPER) && _currentToken.next.type.isRelationalOperator() ) {
3224 Expression expression = new SuperExpression(andAdvance); 3224 Expression expression = new SuperExpression.full(andAdvance);
3225 Token operator = andAdvance; 3225 Token operator = andAdvance;
3226 expression = new BinaryExpression(expression, operator, parseShiftExpressi on()); 3226 expression = new BinaryExpression.full(expression, operator, parseShiftExp ression());
3227 return expression; 3227 return expression;
3228 } 3228 }
3229 Expression expression = parseShiftExpression(); 3229 Expression expression = parseShiftExpression();
3230 if (matches(Keyword.AS)) { 3230 if (matches(Keyword.AS)) {
3231 Token isOperator = andAdvance; 3231 Token isOperator = andAdvance;
3232 expression = new AsExpression(expression, isOperator, parseTypeName()); 3232 expression = new AsExpression.full(expression, isOperator, parseTypeName() );
3233 } else if (matches(Keyword.IS)) { 3233 } else if (matches(Keyword.IS)) {
3234 Token isOperator = andAdvance; 3234 Token isOperator = andAdvance;
3235 Token notOperator = null; 3235 Token notOperator = null;
3236 if (matches5(TokenType.BANG)) { 3236 if (matches5(TokenType.BANG)) {
3237 notOperator = andAdvance; 3237 notOperator = andAdvance;
3238 } 3238 }
3239 expression = new IsExpression(expression, isOperator, notOperator, parseTy peName()); 3239 expression = new IsExpression.full(expression, isOperator, notOperator, pa rseTypeName());
3240 } else if (_currentToken.type.isRelationalOperator()) { 3240 } else if (_currentToken.type.isRelationalOperator()) {
3241 Token operator = andAdvance; 3241 Token operator = andAdvance;
3242 expression = new BinaryExpression(expression, operator, parseShiftExpressi on()); 3242 expression = new BinaryExpression.full(expression, operator, parseShiftExp ression());
3243 } 3243 }
3244 return expression; 3244 return expression;
3245 } 3245 }
3246 /** 3246 /**
3247 * Parse a return statement. 3247 * Parse a return statement.
3248 * <pre> 3248 * <pre>
3249 * returnStatement ::= 3249 * returnStatement ::=
3250 * 'return' expression? ';' 3250 * 'return' expression? ';'
3251 * </pre> 3251 * </pre>
3252 * @return the return statement that was parsed 3252 * @return the return statement that was parsed
3253 */ 3253 */
3254 Statement parseReturnStatement() { 3254 Statement parseReturnStatement() {
3255 Token returnKeyword = expect(Keyword.RETURN); 3255 Token returnKeyword = expect(Keyword.RETURN);
3256 if (matches5(TokenType.SEMICOLON)) { 3256 if (matches5(TokenType.SEMICOLON)) {
3257 return new ReturnStatement(returnKeyword, null, andAdvance); 3257 return new ReturnStatement.full(returnKeyword, null, andAdvance);
3258 } 3258 }
3259 Expression expression = parseExpression2(); 3259 Expression expression = parseExpression2();
3260 Token semicolon = expect2(TokenType.SEMICOLON); 3260 Token semicolon = expect2(TokenType.SEMICOLON);
3261 return new ReturnStatement(returnKeyword, expression, semicolon); 3261 return new ReturnStatement.full(returnKeyword, expression, semicolon);
3262 } 3262 }
3263 /** 3263 /**
3264 * Parse a return type. 3264 * Parse a return type.
3265 * <pre> 3265 * <pre>
3266 * returnType ::= 3266 * returnType ::=
3267 * 'void' 3267 * 'void'
3268 * | type 3268 * | type
3269 * </pre> 3269 * </pre>
3270 * @return the return type that was parsed 3270 * @return the return type that was parsed
3271 */ 3271 */
3272 TypeName parseReturnType() { 3272 TypeName parseReturnType() {
3273 if (matches(Keyword.VOID)) { 3273 if (matches(Keyword.VOID)) {
3274 return new TypeName(new SimpleIdentifier(andAdvance), null); 3274 return new TypeName.full(new SimpleIdentifier.full(andAdvance), null);
3275 } else { 3275 } else {
3276 return parseTypeName(); 3276 return parseTypeName();
3277 } 3277 }
3278 } 3278 }
3279 /** 3279 /**
3280 * Parse a setter. 3280 * Parse a setter.
3281 * <pre> 3281 * <pre>
3282 * setter ::= 3282 * setter ::=
3283 * setterSignature functionBody? 3283 * setterSignature functionBody?
3284 * setterSignature ::= 3284 * setterSignature ::=
3285 * 'external'? 'static'? returnType? 'set' identifier formalParameterList 3285 * 'external'? 'static'? returnType? 'set' identifier formalParameterList
3286 * </pre> 3286 * </pre>
3287 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the 3287 * @param commentAndMetadata the documentation comment and metadata to be asso ciated with the
3288 * declaration 3288 * declaration
3289 * @param externalKeyword the 'external' token 3289 * @param externalKeyword the 'external' token
3290 * @param staticKeyword the static keyword, or {@code null} if the setter is n ot static 3290 * @param staticKeyword the static keyword, or {@code null} if the setter is n ot static
3291 * @param the return type that has already been parsed, or {@code null} if the re was no return 3291 * @param the return type that has already been parsed, or {@code null} if the re was no return
3292 * type 3292 * type
3293 * @return the setter that was parsed 3293 * @return the setter that was parsed
3294 */ 3294 */
3295 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) { 3295 MethodDeclaration parseSetter(CommentAndMetadata commentAndMetadata, Token ext ernalKeyword, Token staticKeyword, TypeName returnType) {
3296 Token propertyKeyword = expect(Keyword.SET); 3296 Token propertyKeyword = expect(Keyword.SET);
3297 SimpleIdentifier name = parseSimpleIdentifier(); 3297 SimpleIdentifier name = parseSimpleIdentifier();
3298 FormalParameterList parameters = parseFormalParameterList(); 3298 FormalParameterList parameters = parseFormalParameterList();
3299 validateFormalParameterList(parameters); 3299 validateFormalParameterList(parameters);
3300 FunctionBody body = parseFunctionBody(true, false); 3300 FunctionBody body = parseFunctionBody(true, false);
3301 if (externalKeyword != null && body is! EmptyFunctionBody) { 3301 if (externalKeyword != null && body is! EmptyFunctionBody) {
3302 reportError3(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []); 3302 reportError3(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY, []);
3303 } 3303 }
3304 return new MethodDeclaration(commentAndMetadata.comment, commentAndMetadata. metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null, nam e, parameters, body); 3304 return new MethodDeclaration.full(commentAndMetadata.comment, commentAndMeta data.metadata, externalKeyword, staticKeyword, returnType, propertyKeyword, null , name, parameters, body);
3305 } 3305 }
3306 /** 3306 /**
3307 * Parse a shift expression. 3307 * Parse a shift expression.
3308 * <pre> 3308 * <pre>
3309 * shiftExpression ::= 3309 * shiftExpression ::=
3310 * additiveExpression (shiftOperator additiveExpression) 3310 * additiveExpression (shiftOperator additiveExpression)
3311 * | 'super' (shiftOperator additiveExpression)+ 3311 * | 'super' (shiftOperator additiveExpression)+
3312 * </pre> 3312 * </pre>
3313 * @return the shift expression that was parsed 3313 * @return the shift expression that was parsed
3314 */ 3314 */
3315 Expression parseShiftExpression() { 3315 Expression parseShiftExpression() {
3316 Expression expression; 3316 Expression expression;
3317 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator()) { 3317 if (matches(Keyword.SUPER) && _currentToken.next.type.isShiftOperator()) {
3318 expression = new SuperExpression(andAdvance); 3318 expression = new SuperExpression.full(andAdvance);
3319 } else { 3319 } else {
3320 expression = parseAdditiveExpression(); 3320 expression = parseAdditiveExpression();
3321 } 3321 }
3322 while (_currentToken.type.isShiftOperator()) { 3322 while (_currentToken.type.isShiftOperator()) {
3323 Token operator = andAdvance; 3323 Token operator = andAdvance;
3324 expression = new BinaryExpression(expression, operator, parseAdditiveExpre ssion()); 3324 expression = new BinaryExpression.full(expression, operator, parseAdditive Expression());
3325 } 3325 }
3326 return expression; 3326 return expression;
3327 } 3327 }
3328 /** 3328 /**
3329 * Parse a simple identifier. 3329 * Parse a simple identifier.
3330 * <pre> 3330 * <pre>
3331 * identifier ::= 3331 * identifier ::=
3332 * IDENTIFIER 3332 * IDENTIFIER
3333 * </pre> 3333 * </pre>
3334 * @return the simple identifier that was parsed 3334 * @return the simple identifier that was parsed
3335 */ 3335 */
3336 SimpleIdentifier parseSimpleIdentifier() { 3336 SimpleIdentifier parseSimpleIdentifier() {
3337 if (matchesIdentifier()) { 3337 if (matchesIdentifier()) {
3338 return new SimpleIdentifier(andAdvance); 3338 return new SimpleIdentifier.full(andAdvance);
3339 } 3339 }
3340 reportError3(ParserErrorCode.MISSING_IDENTIFIER, []); 3340 reportError3(ParserErrorCode.MISSING_IDENTIFIER, []);
3341 return createSyntheticIdentifier(); 3341 return createSyntheticIdentifier();
3342 } 3342 }
3343 /** 3343 /**
3344 * Parse a simple identifier and validate that it is not a built-in identifier . 3344 * Parse a simple identifier and validate that it is not a built-in identifier .
3345 * <pre> 3345 * <pre>
3346 * identifier ::= 3346 * identifier ::=
3347 * IDENTIFIER 3347 * IDENTIFIER
3348 * </pre> 3348 * </pre>
3349 * @param errorCode the error code to be used to report a built-in identifier if one is found 3349 * @param errorCode the error code to be used to report a built-in identifier if one is found
3350 * @return the simple identifier that was parsed 3350 * @return the simple identifier that was parsed
3351 */ 3351 */
3352 SimpleIdentifier parseSimpleIdentifier2(ParserErrorCode errorCode) { 3352 SimpleIdentifier parseSimpleIdentifier2(ParserErrorCode errorCode) {
3353 if (matchesIdentifier()) { 3353 if (matchesIdentifier()) {
3354 Token token = andAdvance; 3354 Token token = andAdvance;
3355 if (token.type == TokenType.KEYWORD) { 3355 if (identical(token.type, TokenType.KEYWORD)) {
3356 reportError4(errorCode, token, [token.lexeme]); 3356 reportError4(errorCode, token, [token.lexeme]);
3357 } 3357 }
3358 return new SimpleIdentifier(token); 3358 return new SimpleIdentifier.full(token);
3359 } 3359 }
3360 reportError3(ParserErrorCode.MISSING_IDENTIFIER, []); 3360 reportError3(ParserErrorCode.MISSING_IDENTIFIER, []);
3361 return createSyntheticIdentifier(); 3361 return createSyntheticIdentifier();
3362 } 3362 }
3363 /** 3363 /**
3364 * Parse a statement. 3364 * Parse a statement.
3365 * <pre> 3365 * <pre>
3366 * statement ::= 3366 * statement ::=
3367 * label* nonLabeledStatement 3367 * label* nonLabeledStatement
3368 * </pre> 3368 * </pre>
3369 * @return the statement that was parsed 3369 * @return the statement that was parsed
3370 */ 3370 */
3371 Statement parseStatement2() { 3371 Statement parseStatement2() {
3372 List<Label> labels = new List<Label>(); 3372 List<Label> labels = new List<Label>();
3373 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 3373 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
3374 SimpleIdentifier label = parseSimpleIdentifier(); 3374 SimpleIdentifier label = parseSimpleIdentifier();
3375 Token colon = expect2(TokenType.COLON); 3375 Token colon = expect2(TokenType.COLON);
3376 labels.add(new Label(label, colon)); 3376 labels.add(new Label.full(label, colon));
3377 } 3377 }
3378 Statement statement = parseNonLabeledStatement(); 3378 Statement statement = parseNonLabeledStatement();
3379 if (labels.isEmpty) { 3379 if (labels.isEmpty) {
3380 return statement; 3380 return statement;
3381 } 3381 }
3382 return new LabeledStatement(labels, statement); 3382 return new LabeledStatement.full(labels, statement);
3383 } 3383 }
3384 /** 3384 /**
3385 * Parse a list of statements within a switch statement. 3385 * Parse a list of statements within a switch statement.
3386 * <pre> 3386 * <pre>
3387 * statements ::= 3387 * statements ::=
3388 * statement 3388 * statement
3389 * </pre> 3389 * </pre>
3390 * @return the statements that were parsed 3390 * @return the statements that were parsed
3391 */ 3391 */
3392 List<Statement> parseStatements2() { 3392 List<Statement> parseStatements2() {
3393 List<Statement> statements = new List<Statement>(); 3393 List<Statement> statements = new List<Statement>();
3394 Token statementStart = _currentToken; 3394 Token statementStart = _currentToken;
3395 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) { 3395 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRACKET) && !isSwitchMember()) {
3396 statements.add(parseStatement2()); 3396 statements.add(parseStatement2());
3397 if (_currentToken == statementStart) { 3397 if (identical(_currentToken, statementStart)) {
3398 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]); 3398 reportError4(ParserErrorCode.UNEXPECTED_TOKEN, _currentToken, [_currentT oken.lexeme]);
3399 advance(); 3399 advance();
3400 } 3400 }
3401 statementStart = _currentToken; 3401 statementStart = _currentToken;
3402 } 3402 }
3403 return statements; 3403 return statements;
3404 } 3404 }
3405 /** 3405 /**
3406 * Parse a string literal that contains interpolations. 3406 * Parse a string literal that contains interpolations.
3407 * @return the string literal that was parsed 3407 * @return the string literal that was parsed
3408 */ 3408 */
3409 StringInterpolation parseStringInterpolation(Token string) { 3409 StringInterpolation parseStringInterpolation(Token string) {
3410 List<InterpolationElement> elements = new List<InterpolationElement>(); 3410 List<InterpolationElement> elements = new List<InterpolationElement>();
3411 elements.add(new InterpolationString(string, computeStringValue(string.lexem e))); 3411 elements.add(new InterpolationString.full(string, computeStringValue(string. lexeme)));
3412 while (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(Token Type.STRING_INTERPOLATION_IDENTIFIER)) { 3412 while (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(Token Type.STRING_INTERPOLATION_IDENTIFIER)) {
3413 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) { 3413 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION)) {
3414 Token openToken = andAdvance; 3414 Token openToken = andAdvance;
3415 Expression expression = parseExpression2(); 3415 Expression expression = parseExpression2();
3416 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3416 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
3417 elements.add(new InterpolationExpression(openToken, expression, rightBra cket)); 3417 elements.add(new InterpolationExpression.full(openToken, expression, rig htBracket));
3418 } else { 3418 } else {
3419 Token openToken = andAdvance; 3419 Token openToken = andAdvance;
3420 Expression expression = null; 3420 Expression expression = null;
3421 if (matches(Keyword.THIS)) { 3421 if (matches(Keyword.THIS)) {
3422 expression = new ThisExpression(andAdvance); 3422 expression = new ThisExpression.full(andAdvance);
3423 } else { 3423 } else {
3424 expression = parseSimpleIdentifier(); 3424 expression = parseSimpleIdentifier();
3425 } 3425 }
3426 elements.add(new InterpolationExpression(openToken, expression, null)); 3426 elements.add(new InterpolationExpression.full(openToken, expression, nul l));
3427 } 3427 }
3428 if (matches5(TokenType.STRING)) { 3428 if (matches5(TokenType.STRING)) {
3429 string = andAdvance; 3429 string = andAdvance;
3430 elements.add(new InterpolationString(string, computeStringValue(string.l exeme))); 3430 elements.add(new InterpolationString.full(string, computeStringValue(str ing.lexeme)));
3431 } 3431 }
3432 } 3432 }
3433 return new StringInterpolation(elements); 3433 return new StringInterpolation.full(elements);
3434 } 3434 }
3435 /** 3435 /**
3436 * Parse a string literal. 3436 * Parse a string literal.
3437 * <pre> 3437 * <pre>
3438 * stringLiteral ::= 3438 * stringLiteral ::=
3439 * MULTI_LINE_STRING+ 3439 * MULTI_LINE_STRING+
3440 * | SINGLE_LINE_STRING+ 3440 * | SINGLE_LINE_STRING+
3441 * </pre> 3441 * </pre>
3442 * @return the string literal that was parsed 3442 * @return the string literal that was parsed
3443 */ 3443 */
3444 StringLiteral parseStringLiteral() { 3444 StringLiteral parseStringLiteral() {
3445 List<StringLiteral> strings = new List<StringLiteral>(); 3445 List<StringLiteral> strings = new List<StringLiteral>();
3446 while (matches5(TokenType.STRING)) { 3446 while (matches5(TokenType.STRING)) {
3447 Token string = andAdvance; 3447 Token string = andAdvance;
3448 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) { 3448 if (matches5(TokenType.STRING_INTERPOLATION_EXPRESSION) || matches5(TokenT ype.STRING_INTERPOLATION_IDENTIFIER)) {
3449 strings.add(parseStringInterpolation(string)); 3449 strings.add(parseStringInterpolation(string));
3450 } else { 3450 } else {
3451 strings.add(new SimpleStringLiteral(string, computeStringValue(string.le xeme))); 3451 strings.add(new SimpleStringLiteral.full(string, computeStringValue(stri ng.lexeme)));
3452 } 3452 }
3453 } 3453 }
3454 if (strings.length < 1) { 3454 if (strings.length < 1) {
3455 reportError3(ParserErrorCode.EXPECTED_STRING_LITERAL, []); 3455 reportError3(ParserErrorCode.EXPECTED_STRING_LITERAL, []);
3456 return createSyntheticStringLiteral(); 3456 return createSyntheticStringLiteral();
3457 } else if (strings.length == 1) { 3457 } else if (strings.length == 1) {
3458 return strings[0]; 3458 return strings[0];
3459 } else { 3459 } else {
3460 return new AdjacentStrings(strings); 3460 return new AdjacentStrings.full(strings);
3461 } 3461 }
3462 } 3462 }
3463 /** 3463 /**
3464 * Parse a super constructor invocation. 3464 * Parse a super constructor invocation.
3465 * <pre> 3465 * <pre>
3466 * superConstructorInvocation ::= 3466 * superConstructorInvocation ::=
3467 * 'super' ('.' identifier)? arguments 3467 * 'super' ('.' identifier)? arguments
3468 * </pre> 3468 * </pre>
3469 * @return the super constructor invocation that was parsed 3469 * @return the super constructor invocation that was parsed
3470 */ 3470 */
3471 SuperConstructorInvocation parseSuperConstructorInvocation() { 3471 SuperConstructorInvocation parseSuperConstructorInvocation() {
3472 Token keyword = expect(Keyword.SUPER); 3472 Token keyword = expect(Keyword.SUPER);
3473 Token period = null; 3473 Token period = null;
3474 SimpleIdentifier constructorName = null; 3474 SimpleIdentifier constructorName = null;
3475 if (matches5(TokenType.PERIOD)) { 3475 if (matches5(TokenType.PERIOD)) {
3476 period = andAdvance; 3476 period = andAdvance;
3477 constructorName = parseSimpleIdentifier(); 3477 constructorName = parseSimpleIdentifier();
3478 } 3478 }
3479 ArgumentList argumentList = parseArgumentList(); 3479 ArgumentList argumentList = parseArgumentList();
3480 return new SuperConstructorInvocation(keyword, period, constructorName, argu mentList); 3480 return new SuperConstructorInvocation.full(keyword, period, constructorName, argumentList);
3481 } 3481 }
3482 /** 3482 /**
3483 * Parse a switch statement. 3483 * Parse a switch statement.
3484 * <pre> 3484 * <pre>
3485 * switchStatement ::= 3485 * switchStatement ::=
3486 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}' 3486 * 'switch' '(' expression ')' '{' switchCase* defaultCase? '}'
3487 * switchCase ::= 3487 * switchCase ::=
3488 * label* ('case' expression ':') statements 3488 * label* ('case' expression ':') statements
3489 * defaultCase ::= 3489 * defaultCase ::=
3490 * label* 'default' ':' statements 3490 * label* 'default' ':' statements
(...skipping 15 matching lines...) Expand all
3506 List<Label> labels = new List<Label>(); 3506 List<Label> labels = new List<Label>();
3507 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) { 3507 while (matchesIdentifier() && matches4(peek(), TokenType.COLON)) {
3508 SimpleIdentifier identifier = parseSimpleIdentifier(); 3508 SimpleIdentifier identifier = parseSimpleIdentifier();
3509 String label = identifier.token.lexeme; 3509 String label = identifier.token.lexeme;
3510 if (definedLabels.contains(label)) { 3510 if (definedLabels.contains(label)) {
3511 reportError4(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, id entifier.token, [label]); 3511 reportError4(ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT, id entifier.token, [label]);
3512 } else { 3512 } else {
3513 javaSetAdd(definedLabels, label); 3513 javaSetAdd(definedLabels, label);
3514 } 3514 }
3515 Token colon = expect2(TokenType.COLON); 3515 Token colon = expect2(TokenType.COLON);
3516 labels.add(new Label(identifier, colon)); 3516 labels.add(new Label.full(identifier, colon));
3517 } 3517 }
3518 if (matches(Keyword.CASE)) { 3518 if (matches(Keyword.CASE)) {
3519 Token caseKeyword = andAdvance; 3519 Token caseKeyword = andAdvance;
3520 Expression caseExpression = parseExpression2(); 3520 Expression caseExpression = parseExpression2();
3521 Token colon = expect2(TokenType.COLON); 3521 Token colon = expect2(TokenType.COLON);
3522 members.add(new SwitchCase(labels, caseKeyword, caseExpression, colon, parseStatements2())); 3522 members.add(new SwitchCase.full(labels, caseKeyword, caseExpression, c olon, parseStatements2()));
3523 } else if (matches(Keyword.DEFAULT)) { 3523 } else if (matches(Keyword.DEFAULT)) {
3524 Token defaultKeyword = andAdvance; 3524 Token defaultKeyword = andAdvance;
3525 Token colon = expect2(TokenType.COLON); 3525 Token colon = expect2(TokenType.COLON);
3526 members.add(new SwitchDefault(labels, defaultKeyword, colon, parseStat ements2())); 3526 members.add(new SwitchDefault.full(labels, defaultKeyword, colon, pars eStatements2()));
3527 } else { 3527 } else {
3528 reportError3(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []); 3528 reportError3(ParserErrorCode.EXPECTED_CASE_OR_DEFAULT, []);
3529 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) { 3529 while (!matches5(TokenType.EOF) && !matches5(TokenType.CLOSE_CURLY_BRA CKET) && !matches(Keyword.CASE) && !matches(Keyword.DEFAULT)) {
3530 advance(); 3530 advance();
3531 } 3531 }
3532 } 3532 }
3533 } 3533 }
3534 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET); 3534 Token rightBracket = expect2(TokenType.CLOSE_CURLY_BRACKET);
3535 return new SwitchStatement(keyword, leftParenthesis, expression, rightPare nthesis, leftBracket, members, rightBracket); 3535 return new SwitchStatement.full(keyword, leftParenthesis, expression, righ tParenthesis, leftBracket, members, rightBracket);
3536 } finally { 3536 } finally {
3537 _inSwitch = wasInSwitch; 3537 _inSwitch = wasInSwitch;
3538 } 3538 }
3539 } 3539 }
3540 /** 3540 /**
3541 * Parse a throw expression. 3541 * Parse a throw expression.
3542 * <pre> 3542 * <pre>
3543 * throwExpression ::= 3543 * throwExpression ::=
3544 * 'throw' expression? ';' 3544 * 'throw' expression? ';'
3545 * </pre> 3545 * </pre>
3546 * @return the throw expression that was parsed 3546 * @return the throw expression that was parsed
3547 */ 3547 */
3548 Expression parseThrowExpression() { 3548 Expression parseThrowExpression() {
3549 Token keyword = expect(Keyword.THROW); 3549 Token keyword = expect(Keyword.THROW);
3550 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 3550 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
3551 return new ThrowExpression(keyword, null); 3551 return new ThrowExpression.full(keyword, null);
3552 } 3552 }
3553 Expression expression = parseExpression2(); 3553 Expression expression = parseExpression2();
3554 return new ThrowExpression(keyword, expression); 3554 return new ThrowExpression.full(keyword, expression);
3555 } 3555 }
3556 /** 3556 /**
3557 * Parse a throw expression. 3557 * Parse a throw expression.
3558 * <pre> 3558 * <pre>
3559 * throwExpressionWithoutCascade ::= 3559 * throwExpressionWithoutCascade ::=
3560 * 'throw' expressionWithoutCascade? ';' 3560 * 'throw' expressionWithoutCascade? ';'
3561 * </pre> 3561 * </pre>
3562 * @return the throw expression that was parsed 3562 * @return the throw expression that was parsed
3563 */ 3563 */
3564 Expression parseThrowExpressionWithoutCascade() { 3564 Expression parseThrowExpressionWithoutCascade() {
3565 Token keyword = expect(Keyword.THROW); 3565 Token keyword = expect(Keyword.THROW);
3566 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) { 3566 if (matches5(TokenType.SEMICOLON) || matches5(TokenType.CLOSE_PAREN)) {
3567 return new ThrowExpression(keyword, null); 3567 return new ThrowExpression.full(keyword, null);
3568 } 3568 }
3569 Expression expression = parseExpressionWithoutCascade(); 3569 Expression expression = parseExpressionWithoutCascade();
3570 return new ThrowExpression(keyword, expression); 3570 return new ThrowExpression.full(keyword, expression);
3571 } 3571 }
3572 /** 3572 /**
3573 * Parse a try statement. 3573 * Parse a try statement.
3574 * <pre> 3574 * <pre>
3575 * tryStatement ::= 3575 * tryStatement ::=
3576 * 'try' block (onPart+ finallyPart? | finallyPart) 3576 * 'try' block (onPart+ finallyPart? | finallyPart)
3577 * onPart ::= 3577 * onPart ::=
3578 * catchPart block 3578 * catchPart block
3579 * | 'on' qualified catchPart? block 3579 * | 'on' qualified catchPart? block
3580 * catchPart ::= 3580 * catchPart ::=
3581 * 'catch' '(' identifier (',' identifier)? ')' 3581 * 'catch' '(' identifier (',' identifier)? ')'
3582 * finallyPart ::= 3582 * finallyPart ::=
3583 * 'finally' block 3583 * 'finally' block
3584 * </pre> 3584 * </pre>
3585 * @return the try statement that was parsed 3585 * @return the try statement that was parsed
3586 */ 3586 */
3587 Statement parseTryStatement() { 3587 Statement parseTryStatement() {
3588 Token tryKeyword = expect(Keyword.TRY); 3588 Token tryKeyword = expect(Keyword.TRY);
3589 Block body = parseBlock(); 3589 Block body = parseBlock();
3590 List<CatchClause> catchClauses = new List<CatchClause>(); 3590 List<CatchClause> catchClauses = new List<CatchClause>();
3591 Block finallyClause = null; 3591 Block finallyClause = null;
3592 while (matches2(Parser._ON) || matches(Keyword.CATCH)) { 3592 while (matches2(_ON) || matches(Keyword.CATCH)) {
3593 Token onKeyword = null; 3593 Token onKeyword = null;
3594 TypeName exceptionType = null; 3594 TypeName exceptionType = null;
3595 if (matches2(Parser._ON)) { 3595 if (matches2(_ON)) {
3596 onKeyword = andAdvance; 3596 onKeyword = andAdvance;
3597 exceptionType = new TypeName(parsePrefixedIdentifier(), null); 3597 exceptionType = new TypeName.full(parsePrefixedIdentifier(), null);
3598 } 3598 }
3599 Token catchKeyword = null; 3599 Token catchKeyword = null;
3600 Token leftParenthesis = null; 3600 Token leftParenthesis = null;
3601 SimpleIdentifier exceptionParameter = null; 3601 SimpleIdentifier exceptionParameter = null;
3602 Token comma = null; 3602 Token comma = null;
3603 SimpleIdentifier stackTraceParameter = null; 3603 SimpleIdentifier stackTraceParameter = null;
3604 Token rightParenthesis = null; 3604 Token rightParenthesis = null;
3605 if (matches(Keyword.CATCH)) { 3605 if (matches(Keyword.CATCH)) {
3606 catchKeyword = andAdvance; 3606 catchKeyword = andAdvance;
3607 leftParenthesis = expect2(TokenType.OPEN_PAREN); 3607 leftParenthesis = expect2(TokenType.OPEN_PAREN);
3608 exceptionParameter = parseSimpleIdentifier(); 3608 exceptionParameter = parseSimpleIdentifier();
3609 if (matches5(TokenType.COMMA)) { 3609 if (matches5(TokenType.COMMA)) {
3610 comma = andAdvance; 3610 comma = andAdvance;
3611 stackTraceParameter = parseSimpleIdentifier(); 3611 stackTraceParameter = parseSimpleIdentifier();
3612 } 3612 }
3613 rightParenthesis = expect2(TokenType.CLOSE_PAREN); 3613 rightParenthesis = expect2(TokenType.CLOSE_PAREN);
3614 } 3614 }
3615 Block catchBody = parseBlock(); 3615 Block catchBody = parseBlock();
3616 catchClauses.add(new CatchClause(onKeyword, exceptionType, catchKeyword, l eftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParenthesis , catchBody)); 3616 catchClauses.add(new CatchClause.full(onKeyword, exceptionType, catchKeywo rd, leftParenthesis, exceptionParameter, comma, stackTraceParameter, rightParent hesis, catchBody));
3617 } 3617 }
3618 Token finallyKeyword = null; 3618 Token finallyKeyword = null;
3619 if (matches(Keyword.FINALLY)) { 3619 if (matches(Keyword.FINALLY)) {
3620 finallyKeyword = andAdvance; 3620 finallyKeyword = andAdvance;
3621 finallyClause = parseBlock(); 3621 finallyClause = parseBlock();
3622 } else { 3622 } else {
3623 if (catchClauses.isEmpty) { 3623 if (catchClauses.isEmpty) {
3624 reportError3(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []); 3624 reportError3(ParserErrorCode.MISSING_CATCH_OR_FINALLY, []);
3625 } 3625 }
3626 } 3626 }
3627 return new TryStatement(tryKeyword, body, catchClauses, finallyKeyword, fina llyClause); 3627 return new TryStatement.full(tryKeyword, body, catchClauses, finallyKeyword, finallyClause);
3628 } 3628 }
3629 /** 3629 /**
3630 * Parse a type alias. 3630 * Parse a type alias.
3631 * <pre> 3631 * <pre>
3632 * typeAlias ::= 3632 * typeAlias ::=
3633 * 'typedef' typeAliasBody 3633 * 'typedef' typeAliasBody
3634 * typeAliasBody ::= 3634 * typeAliasBody ::=
3635 * classTypeAlias 3635 * classTypeAlias
3636 * | functionTypeAlias 3636 * | functionTypeAlias
3637 * classTypeAlias ::= 3637 * classTypeAlias ::=
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3672 * @return the type argument list that was parsed 3672 * @return the type argument list that was parsed
3673 */ 3673 */
3674 TypeArgumentList parseTypeArgumentList() { 3674 TypeArgumentList parseTypeArgumentList() {
3675 Token leftBracket = expect2(TokenType.LT); 3675 Token leftBracket = expect2(TokenType.LT);
3676 List<TypeName> arguments = new List<TypeName>(); 3676 List<TypeName> arguments = new List<TypeName>();
3677 arguments.add(parseTypeName()); 3677 arguments.add(parseTypeName());
3678 while (optional(TokenType.COMMA)) { 3678 while (optional(TokenType.COMMA)) {
3679 arguments.add(parseTypeName()); 3679 arguments.add(parseTypeName());
3680 } 3680 }
3681 Token rightBracket = expect2(TokenType.GT); 3681 Token rightBracket = expect2(TokenType.GT);
3682 return new TypeArgumentList(leftBracket, arguments, rightBracket); 3682 return new TypeArgumentList.full(leftBracket, arguments, rightBracket);
3683 } 3683 }
3684 /** 3684 /**
3685 * Parse a type name. 3685 * Parse a type name.
3686 * <pre> 3686 * <pre>
3687 * type ::= 3687 * type ::=
3688 * qualified typeArguments? 3688 * qualified typeArguments?
3689 * </pre> 3689 * </pre>
3690 * @return the type name that was parsed 3690 * @return the type name that was parsed
3691 */ 3691 */
3692 TypeName parseTypeName() { 3692 TypeName parseTypeName() {
3693 Identifier typeName = parsePrefixedIdentifier(); 3693 Identifier typeName = parsePrefixedIdentifier();
3694 TypeArgumentList typeArguments = null; 3694 TypeArgumentList typeArguments = null;
3695 if (matches5(TokenType.LT)) { 3695 if (matches5(TokenType.LT)) {
3696 typeArguments = parseTypeArgumentList(); 3696 typeArguments = parseTypeArgumentList();
3697 } 3697 }
3698 return new TypeName(typeName, typeArguments); 3698 return new TypeName.full(typeName, typeArguments);
3699 } 3699 }
3700 /** 3700 /**
3701 * Parse a type parameter. 3701 * Parse a type parameter.
3702 * <pre> 3702 * <pre>
3703 * typeParameter ::= 3703 * typeParameter ::=
3704 * metadata name ('extends' bound)? 3704 * metadata name ('extends' bound)?
3705 * </pre> 3705 * </pre>
3706 * @return the type parameter that was parsed 3706 * @return the type parameter that was parsed
3707 */ 3707 */
3708 TypeParameter parseTypeParameter() { 3708 TypeParameter parseTypeParameter() {
3709 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 3709 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
3710 SimpleIdentifier name = parseSimpleIdentifier2(ParserErrorCode.BUILT_IN_IDEN TIFIER_AS_TYPE_VARIABLE_NAME); 3710 SimpleIdentifier name = parseSimpleIdentifier2(ParserErrorCode.BUILT_IN_IDEN TIFIER_AS_TYPE_VARIABLE_NAME);
3711 if (matches(Keyword.EXTENDS)) { 3711 if (matches(Keyword.EXTENDS)) {
3712 Token keyword = andAdvance; 3712 Token keyword = andAdvance;
3713 TypeName bound = parseTypeName(); 3713 TypeName bound = parseTypeName();
3714 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.me tadata, name, keyword, bound); 3714 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetada ta.metadata, name, keyword, bound);
3715 } 3715 }
3716 return new TypeParameter(commentAndMetadata.comment, commentAndMetadata.meta data, name, null, null); 3716 return new TypeParameter.full(commentAndMetadata.comment, commentAndMetadata .metadata, name, null, null);
3717 } 3717 }
3718 /** 3718 /**
3719 * Parse a list of type parameters. 3719 * Parse a list of type parameters.
3720 * <pre> 3720 * <pre>
3721 * typeParameterList ::= 3721 * typeParameterList ::=
3722 * '<' typeParameter (',' typeParameter)* '>' 3722 * '<' typeParameter (',' typeParameter)* '>'
3723 * </pre> 3723 * </pre>
3724 * @return the list of type parameters that were parsed 3724 * @return the list of type parameters that were parsed
3725 */ 3725 */
3726 TypeParameterList parseTypeParameterList() { 3726 TypeParameterList parseTypeParameterList() {
3727 Token leftBracket = expect2(TokenType.LT); 3727 Token leftBracket = expect2(TokenType.LT);
3728 List<TypeParameter> typeParameters = new List<TypeParameter>(); 3728 List<TypeParameter> typeParameters = new List<TypeParameter>();
3729 typeParameters.add(parseTypeParameter()); 3729 typeParameters.add(parseTypeParameter());
3730 while (optional(TokenType.COMMA)) { 3730 while (optional(TokenType.COMMA)) {
3731 typeParameters.add(parseTypeParameter()); 3731 typeParameters.add(parseTypeParameter());
3732 } 3732 }
3733 Token rightBracket = expect2(TokenType.GT); 3733 Token rightBracket = expect2(TokenType.GT);
3734 return new TypeParameterList(leftBracket, typeParameters, rightBracket); 3734 return new TypeParameterList.full(leftBracket, typeParameters, rightBracket) ;
3735 } 3735 }
3736 /** 3736 /**
3737 * Parse a unary expression. 3737 * Parse a unary expression.
3738 * <pre> 3738 * <pre>
3739 * unaryExpression ::= 3739 * unaryExpression ::=
3740 * prefixOperator unaryExpression 3740 * prefixOperator unaryExpression
3741 * | postfixExpression 3741 * | postfixExpression
3742 * | unaryOperator 'super' 3742 * | unaryOperator 'super'
3743 * | '-' 'super' 3743 * | '-' 'super'
3744 * | incrementOperator assignableExpression 3744 * | incrementOperator assignableExpression
3745 * </pre> 3745 * </pre>
3746 * @return the unary expression that was parsed 3746 * @return the unary expression that was parsed
3747 */ 3747 */
3748 Expression parseUnaryExpression() { 3748 Expression parseUnaryExpression() {
3749 if (matches5(TokenType.MINUS) || matches5(TokenType.BANG) || matches5(TokenT ype.TILDE)) { 3749 if (matches5(TokenType.MINUS) || matches5(TokenType.BANG) || matches5(TokenT ype.TILDE)) {
3750 Token operator = andAdvance; 3750 Token operator = andAdvance;
3751 if (matches(Keyword.SUPER)) { 3751 if (matches(Keyword.SUPER)) {
3752 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) { 3752 if (matches4(peek(), TokenType.OPEN_SQUARE_BRACKET) || matches4(peek(), TokenType.PERIOD)) {
3753 return new PrefixExpression(operator, parseUnaryExpression()); 3753 return new PrefixExpression.full(operator, parseUnaryExpression());
3754 } 3754 }
3755 return new PrefixExpression(operator, new SuperExpression(andAdvance)); 3755 return new PrefixExpression.full(operator, new SuperExpression.full(andA dvance));
3756 } 3756 }
3757 return new PrefixExpression(operator, parseUnaryExpression()); 3757 return new PrefixExpression.full(operator, parseUnaryExpression());
3758 } else if (_currentToken.type.isIncrementOperator()) { 3758 } else if (_currentToken.type.isIncrementOperator()) {
3759 Token operator = andAdvance; 3759 Token operator = andAdvance;
3760 if (matches(Keyword.SUPER)) { 3760 if (matches(Keyword.SUPER)) {
3761 if (operator.type == TokenType.MINUS_MINUS) { 3761 if (identical(operator.type, TokenType.MINUS_MINUS)) {
3762 int offset7 = operator.offset; 3762 int offset8 = operator.offset;
3763 Token firstOperator = new Token(TokenType.MINUS, offset7); 3763 Token firstOperator = new Token(TokenType.MINUS, offset8);
3764 Token secondOperator = new Token(TokenType.MINUS, offset7 + 1); 3764 Token secondOperator = new Token(TokenType.MINUS, offset8 + 1);
3765 secondOperator.setNext(_currentToken); 3765 secondOperator.setNext(_currentToken);
3766 firstOperator.setNext(secondOperator); 3766 firstOperator.setNext(secondOperator);
3767 operator.previous.setNext(firstOperator); 3767 operator.previous.setNext(firstOperator);
3768 return new PrefixExpression(firstOperator, new PrefixExpression(second Operator, new SuperExpression(andAdvance))); 3768 return new PrefixExpression.full(firstOperator, new PrefixExpression.f ull(secondOperator, new SuperExpression.full(andAdvance)));
3769 } else { 3769 } else {
3770 reportError3(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lex eme]); 3770 reportError3(ParserErrorCode.INVALID_OPERATOR_FOR_SUPER, [operator.lex eme]);
3771 return new PrefixExpression(operator, new SuperExpression(andAdvance)) ; 3771 return new PrefixExpression.full(operator, new SuperExpression.full(an dAdvance));
3772 } 3772 }
3773 } 3773 }
3774 return new PrefixExpression(operator, parseAssignableExpression(false)); 3774 return new PrefixExpression.full(operator, parseAssignableExpression(false ));
3775 } else if (matches5(TokenType.PLUS)) { 3775 } else if (matches5(TokenType.PLUS)) {
3776 reportError3(ParserErrorCode.USE_OF_UNARY_PLUS_OPERATOR, []); 3776 reportError3(ParserErrorCode.USE_OF_UNARY_PLUS_OPERATOR, []);
3777 } 3777 }
3778 return parsePostfixExpression(); 3778 return parsePostfixExpression();
3779 } 3779 }
3780 /** 3780 /**
3781 * Parse a variable declaration. 3781 * Parse a variable declaration.
3782 * <pre> 3782 * <pre>
3783 * variableDeclaration ::= 3783 * variableDeclaration ::=
3784 * identifier ('=' expression)? 3784 * identifier ('=' expression)?
3785 * </pre> 3785 * </pre>
3786 * @return the variable declaration that was parsed 3786 * @return the variable declaration that was parsed
3787 */ 3787 */
3788 VariableDeclaration parseVariableDeclaration() { 3788 VariableDeclaration parseVariableDeclaration() {
3789 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 3789 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
3790 SimpleIdentifier name = parseSimpleIdentifier(); 3790 SimpleIdentifier name = parseSimpleIdentifier();
3791 Token equals = null; 3791 Token equals = null;
3792 Expression initializer = null; 3792 Expression initializer = null;
3793 if (matches5(TokenType.EQ)) { 3793 if (matches5(TokenType.EQ)) {
3794 equals = andAdvance; 3794 equals = andAdvance;
3795 initializer = parseExpression2(); 3795 initializer = parseExpression2();
3796 } 3796 }
3797 return new VariableDeclaration(commentAndMetadata.comment, commentAndMetadat a.metadata, name, equals, initializer); 3797 return new VariableDeclaration.full(commentAndMetadata.comment, commentAndMe tadata.metadata, name, equals, initializer);
3798 } 3798 }
3799 /** 3799 /**
3800 * Parse a variable declaration list. 3800 * Parse a variable declaration list.
3801 * <pre> 3801 * <pre>
3802 * variableDeclarationList ::= 3802 * variableDeclarationList ::=
3803 * finalConstVarOrType variableDeclaration (',' variableDeclaration) 3803 * finalConstVarOrType variableDeclaration (',' variableDeclaration)
3804 * </pre> 3804 * </pre>
3805 * @return the variable declaration list that was parsed 3805 * @return the variable declaration list that was parsed
3806 */ 3806 */
3807 VariableDeclarationList parseVariableDeclarationList() { 3807 VariableDeclarationList parseVariableDeclarationList() {
(...skipping 11 matching lines...) Expand all
3819 * @param type the type of the variables in the list 3819 * @param type the type of the variables in the list
3820 * @return the variable declaration list that was parsed 3820 * @return the variable declaration list that was parsed
3821 */ 3821 */
3822 VariableDeclarationList parseVariableDeclarationList2(Token keyword, TypeName type) { 3822 VariableDeclarationList parseVariableDeclarationList2(Token keyword, TypeName type) {
3823 List<VariableDeclaration> variables = new List<VariableDeclaration>(); 3823 List<VariableDeclaration> variables = new List<VariableDeclaration>();
3824 variables.add(parseVariableDeclaration()); 3824 variables.add(parseVariableDeclaration());
3825 while (matches5(TokenType.COMMA)) { 3825 while (matches5(TokenType.COMMA)) {
3826 advance(); 3826 advance();
3827 variables.add(parseVariableDeclaration()); 3827 variables.add(parseVariableDeclaration());
3828 } 3828 }
3829 return new VariableDeclarationList(keyword, type, variables); 3829 return new VariableDeclarationList.full(keyword, type, variables);
3830 } 3830 }
3831 /** 3831 /**
3832 * Parse a variable declaration statement. 3832 * Parse a variable declaration statement.
3833 * <pre> 3833 * <pre>
3834 * variableDeclarationStatement ::= 3834 * variableDeclarationStatement ::=
3835 * variableDeclarationList ';' 3835 * variableDeclarationList ';'
3836 * </pre> 3836 * </pre>
3837 * @return the variable declaration statement that was parsed 3837 * @return the variable declaration statement that was parsed
3838 */ 3838 */
3839 VariableDeclarationStatement parseVariableDeclarationStatement() { 3839 VariableDeclarationStatement parseVariableDeclarationStatement() {
3840 VariableDeclarationList variableList = parseVariableDeclarationList(); 3840 VariableDeclarationList variableList = parseVariableDeclarationList();
3841 Token semicolon = expect2(TokenType.SEMICOLON); 3841 Token semicolon = expect2(TokenType.SEMICOLON);
3842 return new VariableDeclarationStatement(variableList, semicolon); 3842 return new VariableDeclarationStatement.full(variableList, semicolon);
3843 } 3843 }
3844 /** 3844 /**
3845 * Parse a while statement. 3845 * Parse a while statement.
3846 * <pre> 3846 * <pre>
3847 * whileStatement ::= 3847 * whileStatement ::=
3848 * 'while' '(' expression ')' statement 3848 * 'while' '(' expression ')' statement
3849 * </pre> 3849 * </pre>
3850 * @return the while statement that was parsed 3850 * @return the while statement that was parsed
3851 */ 3851 */
3852 Statement parseWhileStatement() { 3852 Statement parseWhileStatement() {
3853 bool wasInLoop = _inLoop; 3853 bool wasInLoop = _inLoop;
3854 _inLoop = true; 3854 _inLoop = true;
3855 try { 3855 try {
3856 Token keyword = expect(Keyword.WHILE); 3856 Token keyword = expect(Keyword.WHILE);
3857 Token leftParenthesis = expect2(TokenType.OPEN_PAREN); 3857 Token leftParenthesis = expect2(TokenType.OPEN_PAREN);
3858 Expression condition = parseExpression2(); 3858 Expression condition = parseExpression2();
3859 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN); 3859 Token rightParenthesis = expect2(TokenType.CLOSE_PAREN);
3860 Statement body = parseStatement2(); 3860 Statement body = parseStatement2();
3861 return new WhileStatement(keyword, leftParenthesis, condition, rightParent hesis, body); 3861 return new WhileStatement.full(keyword, leftParenthesis, condition, rightP arenthesis, body);
3862 } finally { 3862 } finally {
3863 _inLoop = wasInLoop; 3863 _inLoop = wasInLoop;
3864 } 3864 }
3865 } 3865 }
3866 /** 3866 /**
3867 * Parse a with clause. 3867 * Parse a with clause.
3868 * <pre> 3868 * <pre>
3869 * withClause ::= 3869 * withClause ::=
3870 * 'with' typeName (',' typeName) 3870 * 'with' typeName (',' typeName)
3871 * </pre> 3871 * </pre>
3872 * @return the with clause that was parsed 3872 * @return the with clause that was parsed
3873 */ 3873 */
3874 WithClause parseWithClause() { 3874 WithClause parseWithClause() {
3875 Token with6 = expect(Keyword.WITH); 3875 Token with6 = expect(Keyword.WITH);
3876 List<TypeName> types = new List<TypeName>(); 3876 List<TypeName> types = new List<TypeName>();
3877 types.add(parseTypeName()); 3877 types.add(parseTypeName());
3878 while (optional(TokenType.COMMA)) { 3878 while (optional(TokenType.COMMA)) {
3879 types.add(parseTypeName()); 3879 types.add(parseTypeName());
3880 } 3880 }
3881 return new WithClause(with6, types); 3881 return new WithClause.full(with6, types);
3882 } 3882 }
3883 /** 3883 /**
3884 * Return the token that is immediately after the current token. This is equiv alent to{@link #peek(int) peek(1)}. 3884 * Return the token that is immediately after the current token. This is equiv alent to{@link #peek(int) peek(1)}.
3885 * @return the token that is immediately after the current token 3885 * @return the token that is immediately after the current token
3886 */ 3886 */
3887 Token peek() => _currentToken.next; 3887 Token peek() => _currentToken.next;
3888 /** 3888 /**
3889 * Return the token that is the given distance after the current token. 3889 * Return the token that is the given distance after the current token.
3890 * @param distance the number of tokens to look ahead, where {@code 0} is the current token,{@code 1} is the next token, etc. 3890 * @param distance the number of tokens to look ahead, where {@code 0} is the current token,{@code 1} is the next token, etc.
3891 * @return the token that is the given distance after the current token 3891 * @return the token that is the given distance after the current token
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3933 * | 'final' type? 3933 * | 'final' type?
3934 * | 'const' type? 3934 * | 'const' type?
3935 * | 'var' 3935 * | 'var'
3936 * | type 3936 * | type
3937 * </pre> 3937 * </pre>
3938 * @param startToken the token at which parsing is to begin 3938 * @param startToken the token at which parsing is to begin
3939 * @return the token following the type that was parsed 3939 * @return the token following the type that was parsed
3940 */ 3940 */
3941 Token skipFinalConstVarOrType(Token startToken) { 3941 Token skipFinalConstVarOrType(Token startToken) {
3942 if (matches3(startToken, Keyword.FINAL) || matches3(startToken, Keyword.CONS T)) { 3942 if (matches3(startToken, Keyword.FINAL) || matches3(startToken, Keyword.CONS T)) {
3943 Token next2 = startToken.next; 3943 Token next3 = startToken.next;
3944 if (matchesIdentifier2(next2.next) || matches4(next2.next, TokenType.LT) | | matches3(next2.next, Keyword.THIS)) { 3944 if (matchesIdentifier2(next3.next) || matches4(next3.next, TokenType.LT) | | matches3(next3.next, Keyword.THIS)) {
3945 return skipTypeName(next2); 3945 return skipTypeName(next3);
3946 } 3946 }
3947 } else if (matches3(startToken, Keyword.VAR)) { 3947 } else if (matches3(startToken, Keyword.VAR)) {
3948 return startToken.next; 3948 return startToken.next;
3949 } else if (matchesIdentifier2(startToken)) { 3949 } else if (matchesIdentifier2(startToken)) {
3950 Token next3 = startToken.next; 3950 Token next4 = startToken.next;
3951 if (matchesIdentifier2(next3) || matches4(next3, TokenType.LT) || matches3 (next3, Keyword.THIS) || (matches4(next3, TokenType.PERIOD) && matchesIdentifier 2(next3.next) && (matchesIdentifier2(next3.next.next) || matches4(next3.next.nex t, TokenType.LT) || matches3(next3.next.next, Keyword.THIS)))) { 3951 if (matchesIdentifier2(next4) || matches4(next4, TokenType.LT) || matches3 (next4, Keyword.THIS) || (matches4(next4, TokenType.PERIOD) && matchesIdentifier 2(next4.next) && (matchesIdentifier2(next4.next.next) || matches4(next4.next.nex t, TokenType.LT) || matches3(next4.next.next, Keyword.THIS)))) {
3952 return skipReturnType(startToken); 3952 return skipReturnType(startToken);
3953 } 3953 }
3954 } 3954 }
3955 return null; 3955 return null;
3956 } 3956 }
3957 /** 3957 /**
3958 * Parse a list of formal parameters, starting at the given token, without act ually creating a 3958 * Parse a list of formal parameters, starting at the given token, without act ually creating a
3959 * formal parameter list or changing the current token. Return the token follo wing the formal 3959 * formal parameter list or changing the current token. Return the token follo wing the formal
3960 * parameter list that was parsed, or {@code null} if the given token is not t he first token in a 3960 * parameter list that was parsed, or {@code null} if the given token is not t he first token in a
3961 * valid list of formal parameter. 3961 * valid list of formal parameter.
(...skipping 20 matching lines...) Expand all
3982 * namedFormalParameters ::= 3982 * namedFormalParameters ::=
3983 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}' 3983 * '{' defaultNamedParameter (',' defaultNamedParameter)* '}'
3984 * </pre> 3984 * </pre>
3985 * @param startToken the token at which parsing is to begin 3985 * @param startToken the token at which parsing is to begin
3986 * @return the token following the formal parameter list that was parsed 3986 * @return the token following the formal parameter list that was parsed
3987 */ 3987 */
3988 Token skipFormalParameterList(Token startToken) { 3988 Token skipFormalParameterList(Token startToken) {
3989 if (!matches4(startToken, TokenType.OPEN_PAREN)) { 3989 if (!matches4(startToken, TokenType.OPEN_PAREN)) {
3990 return null; 3990 return null;
3991 } 3991 }
3992 Token next4 = startToken.next; 3992 Token next5 = startToken.next;
3993 if (matches4(next4, TokenType.CLOSE_PAREN)) { 3993 if (matches4(next5, TokenType.CLOSE_PAREN)) {
3994 return next4.next; 3994 return next5.next;
3995 } 3995 }
3996 if (matchesAny(next4, [TokenType.AT, TokenType.OPEN_SQUARE_BRACKET, TokenTyp e.OPEN_CURLY_BRACKET]) || matches3(next4, Keyword.VOID) || (matchesIdentifier2(n ext4) && (matchesAny(next4.next, [TokenType.COMMA, TokenType.CLOSE_PAREN])))) { 3996 if (matchesAny(next5, [TokenType.AT, TokenType.OPEN_SQUARE_BRACKET, TokenTyp e.OPEN_CURLY_BRACKET]) || matches3(next5, Keyword.VOID) || (matchesIdentifier2(n ext5) && (matchesAny(next5.next, [TokenType.COMMA, TokenType.CLOSE_PAREN])))) {
3997 return skipPastMatchingToken(startToken); 3997 return skipPastMatchingToken(startToken);
3998 } 3998 }
3999 if (matchesIdentifier2(next4) && matches4(next4.next, TokenType.OPEN_PAREN)) { 3999 if (matchesIdentifier2(next5) && matches4(next5.next, TokenType.OPEN_PAREN)) {
4000 Token afterParameters = skipFormalParameterList(next4.next); 4000 Token afterParameters = skipFormalParameterList(next5.next);
4001 if (afterParameters != null && (matchesAny(afterParameters, [TokenType.COM MA, TokenType.CLOSE_PAREN]))) { 4001 if (afterParameters != null && (matchesAny(afterParameters, [TokenType.COM MA, TokenType.CLOSE_PAREN]))) {
4002 return skipPastMatchingToken(startToken); 4002 return skipPastMatchingToken(startToken);
4003 } 4003 }
4004 } 4004 }
4005 Token afterType = skipFinalConstVarOrType(next4); 4005 Token afterType = skipFinalConstVarOrType(next5);
4006 if (afterType == null) { 4006 if (afterType == null) {
4007 return null; 4007 return null;
4008 } 4008 }
4009 if (skipSimpleIdentifier(afterType) == null) { 4009 if (skipSimpleIdentifier(afterType) == null) {
4010 return null; 4010 return null;
4011 } 4011 }
4012 return skipPastMatchingToken(startToken); 4012 return skipPastMatchingToken(startToken);
4013 } 4013 }
4014 /** 4014 /**
4015 * If the given token is a begin token with an associated end token, then retu rn the token 4015 * If the given token is a begin token with an associated end token, then retu rn the token
4016 * following the end token. Otherwise, return {@code null}. 4016 * following the end token. Otherwise, return {@code null}.
4017 * @param startToken the token that is assumed to be a being token 4017 * @param startToken the token that is assumed to be a being token
4018 * @return the token following the matching end token 4018 * @return the token following the matching end token
4019 */ 4019 */
4020 Token skipPastMatchingToken(Token startToken) { 4020 Token skipPastMatchingToken(Token startToken) {
4021 if (startToken is! BeginToken) { 4021 if (startToken is! BeginToken) {
4022 return null; 4022 return null;
4023 } 4023 }
4024 Token closeParen = (startToken as BeginToken).endToken; 4024 Token closeParen = ((startToken as BeginToken)).endToken;
4025 if (closeParen == null) { 4025 if (closeParen == null) {
4026 return null; 4026 return null;
4027 } 4027 }
4028 return closeParen.next; 4028 return closeParen.next;
4029 } 4029 }
4030 /** 4030 /**
4031 * Parse a prefixed identifier, starting at the given token, without actually creating a prefixed 4031 * Parse a prefixed identifier, starting at the given token, without actually creating a prefixed
4032 * identifier or changing the current token. Return the token following the pr efixed identifier 4032 * identifier or changing the current token. Return the token following the pr efixed identifier
4033 * that was parsed, or {@code null} if the given token is not the first token in a valid prefixed 4033 * that was parsed, or {@code null} if the given token is not the first token in a valid prefixed
4034 * identifier. 4034 * identifier.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4078 * <p> 4078 * <p>
4079 * This method must be kept in sync with {@link #parseSimpleIdentifier()}. 4079 * This method must be kept in sync with {@link #parseSimpleIdentifier()}.
4080 * <pre> 4080 * <pre>
4081 * identifier ::= 4081 * identifier ::=
4082 * IDENTIFIER 4082 * IDENTIFIER
4083 * </pre> 4083 * </pre>
4084 * @param startToken the token at which parsing is to begin 4084 * @param startToken the token at which parsing is to begin
4085 * @return the token following the simple identifier that was parsed 4085 * @return the token following the simple identifier that was parsed
4086 */ 4086 */
4087 Token skipSimpleIdentifier(Token startToken) { 4087 Token skipSimpleIdentifier(Token startToken) {
4088 if (matches4(startToken, TokenType.IDENTIFIER) || (matches4(startToken, Toke nType.KEYWORD) && (startToken as KeywordToken).keyword.isPseudoKeyword())) { 4088 if (matches4(startToken, TokenType.IDENTIFIER) || (matches4(startToken, Toke nType.KEYWORD) && ((startToken as KeywordToken)).keyword.isPseudoKeyword())) {
4089 return startToken.next; 4089 return startToken.next;
4090 } 4090 }
4091 return null; 4091 return null;
4092 } 4092 }
4093 /** 4093 /**
4094 * Parse a string literal that contains interpolations, starting at the given token, without 4094 * Parse a string literal that contains interpolations, starting at the given token, without
4095 * actually creating a string literal or changing the current token. Return th e token following 4095 * actually creating a string literal or changing the current token. Return th e token following
4096 * the string literal that was parsed, or {@code null} if the given token is n ot the first token 4096 * the string literal that was parsed, or {@code null} if the given token is n ot the first token
4097 * in a valid string literal. 4097 * in a valid string literal.
4098 * <p> 4098 * <p>
4099 * This method must be kept in sync with {@link #parseStringInterpolation(Toke n)}. 4099 * This method must be kept in sync with {@link #parseStringInterpolation(Toke n)}.
4100 * @param startToken the token at which parsing is to begin 4100 * @param startToken the token at which parsing is to begin
4101 * @return the string literal that was parsed 4101 * @return the string literal that was parsed
4102 */ 4102 */
4103 Token skipStringInterpolation(Token startToken) { 4103 Token skipStringInterpolation(Token startToken) {
4104 Token token = startToken; 4104 Token token = startToken;
4105 TokenType type19 = token.type; 4105 TokenType type17 = token.type;
4106 while (type19 == TokenType.STRING_INTERPOLATION_EXPRESSION || type19 == Toke nType.STRING_INTERPOLATION_IDENTIFIER) { 4106 while (identical(type17, TokenType.STRING_INTERPOLATION_EXPRESSION) || ident ical(type17, TokenType.STRING_INTERPOLATION_IDENTIFIER)) {
4107 if (type19 == TokenType.STRING_INTERPOLATION_EXPRESSION) { 4107 if (identical(type17, TokenType.STRING_INTERPOLATION_EXPRESSION)) {
4108 token = token.next; 4108 token = token.next;
4109 type19 = token.type; 4109 type17 = token.type;
4110 int bracketNestingLevel = 1; 4110 int bracketNestingLevel = 1;
4111 while (bracketNestingLevel > 0) { 4111 while (bracketNestingLevel > 0) {
4112 if (type19 == TokenType.EOF) { 4112 if (identical(type17, TokenType.EOF)) {
4113 return null; 4113 return null;
4114 } else if (type19 == TokenType.OPEN_CURLY_BRACKET) { 4114 } else if (identical(type17, TokenType.OPEN_CURLY_BRACKET)) {
4115 bracketNestingLevel++; 4115 bracketNestingLevel++;
4116 } else if (type19 == TokenType.CLOSE_CURLY_BRACKET) { 4116 } else if (identical(type17, TokenType.CLOSE_CURLY_BRACKET)) {
4117 bracketNestingLevel--; 4117 bracketNestingLevel--;
4118 } else if (type19 == TokenType.STRING) { 4118 } else if (identical(type17, TokenType.STRING)) {
4119 token = skipStringLiteral(token); 4119 token = skipStringLiteral(token);
4120 if (token == null) { 4120 if (token == null) {
4121 return null; 4121 return null;
4122 } 4122 }
4123 } else { 4123 } else {
4124 token = token.next; 4124 token = token.next;
4125 } 4125 }
4126 type19 = token.type; 4126 type17 = token.type;
4127 } 4127 }
4128 token = token.next; 4128 token = token.next;
4129 type19 = token.type; 4129 type17 = token.type;
4130 } else { 4130 } else {
4131 token = token.next; 4131 token = token.next;
4132 if (token.type != TokenType.IDENTIFIER) { 4132 if (token.type != TokenType.IDENTIFIER) {
4133 return null; 4133 return null;
4134 } 4134 }
4135 token = token.next; 4135 token = token.next;
4136 } 4136 }
4137 type19 = token.type; 4137 type17 = token.type;
4138 if (type19 == TokenType.STRING) { 4138 if (identical(type17, TokenType.STRING)) {
4139 token = token.next; 4139 token = token.next;
4140 type19 = token.type; 4140 type17 = token.type;
4141 } 4141 }
4142 } 4142 }
4143 return token; 4143 return token;
4144 } 4144 }
4145 /** 4145 /**
4146 * Parse a string literal, starting at the given token, without actually creat ing a string literal 4146 * Parse a string literal, starting at the given token, without actually creat ing a string literal
4147 * or changing the current token. Return the token following the string litera l that was parsed, 4147 * or changing the current token. Return the token following the string litera l that was parsed,
4148 * or {@code null} if the given token is not the first token in a valid string literal. 4148 * or {@code null} if the given token is not the first token in a valid string literal.
4149 * <p> 4149 * <p>
4150 * This method must be kept in sync with {@link #parseStringLiteral()}. 4150 * This method must be kept in sync with {@link #parseStringLiteral()}.
4151 * <pre> 4151 * <pre>
4152 * stringLiteral ::= 4152 * stringLiteral ::=
4153 * MULTI_LINE_STRING+ 4153 * MULTI_LINE_STRING+
4154 * | SINGLE_LINE_STRING+ 4154 * | SINGLE_LINE_STRING+
4155 * </pre> 4155 * </pre>
4156 * @param startToken the token at which parsing is to begin 4156 * @param startToken the token at which parsing is to begin
4157 * @return the token following the string literal that was parsed 4157 * @return the token following the string literal that was parsed
4158 */ 4158 */
4159 Token skipStringLiteral(Token startToken) { 4159 Token skipStringLiteral(Token startToken) {
4160 Token token = startToken; 4160 Token token = startToken;
4161 while (token != null && matches4(token, TokenType.STRING)) { 4161 while (token != null && matches4(token, TokenType.STRING)) {
4162 token = token.next; 4162 token = token.next;
4163 TokenType type20 = token.type; 4163 TokenType type18 = token.type;
4164 if (type20 == TokenType.STRING_INTERPOLATION_EXPRESSION || type20 == Token Type.STRING_INTERPOLATION_IDENTIFIER) { 4164 if (identical(type18, TokenType.STRING_INTERPOLATION_EXPRESSION) || identi cal(type18, TokenType.STRING_INTERPOLATION_IDENTIFIER)) {
4165 token = skipStringInterpolation(token); 4165 token = skipStringInterpolation(token);
4166 } 4166 }
4167 } 4167 }
4168 if (token == startToken) { 4168 if (identical(token, startToken)) {
4169 return null; 4169 return null;
4170 } 4170 }
4171 return token; 4171 return token;
4172 } 4172 }
4173 /** 4173 /**
4174 * Parse a list of type arguments, starting at the given token, without actual ly creating a type argument list 4174 * Parse a list of type arguments, starting at the given token, without actual ly creating a type argument list
4175 * or changing the current token. Return the token following the type argument list that was parsed, 4175 * or changing the current token. Return the token following the type argument list that was parsed,
4176 * or {@code null} if the given token is not the first token in a valid type a rgument list. 4176 * or {@code null} if the given token is not the first token in a valid type a rgument list.
4177 * <p> 4177 * <p>
4178 * This method must be kept in sync with {@link #parseTypeArgumentList()}. 4178 * This method must be kept in sync with {@link #parseTypeArgumentList()}.
(...skipping 14 matching lines...) Expand all
4193 token = skipTypeName(token.next); 4193 token = skipTypeName(token.next);
4194 if (token == null) { 4194 if (token == null) {
4195 return null; 4195 return null;
4196 } 4196 }
4197 while (matches4(token, TokenType.COMMA)) { 4197 while (matches4(token, TokenType.COMMA)) {
4198 token = skipTypeName(token.next); 4198 token = skipTypeName(token.next);
4199 if (token == null) { 4199 if (token == null) {
4200 return null; 4200 return null;
4201 } 4201 }
4202 } 4202 }
4203 if (token.type == TokenType.GT) { 4203 if (identical(token.type, TokenType.GT)) {
4204 return token.next; 4204 return token.next;
4205 } else if (token.type == TokenType.GT_GT) { 4205 } else if (identical(token.type, TokenType.GT_GT)) {
4206 Token second = new Token(TokenType.GT, token.offset + 1); 4206 Token second = new Token(TokenType.GT, token.offset + 1);
4207 second.setNextWithoutSettingPrevious(token.next); 4207 second.setNextWithoutSettingPrevious(token.next);
4208 return second; 4208 return second;
4209 } 4209 }
4210 return null; 4210 return null;
4211 } 4211 }
4212 /** 4212 /**
4213 * Parse a type name, starting at the given token, without actually creating a type name or 4213 * Parse a type name, starting at the given token, without actually creating a type name or
4214 * changing the current token. Return the token following the type name that w as parsed, or{@code null} if the given token is not the first token in a valid t ype name. 4214 * changing the current token. Return the token following the type name that w as parsed, or{@code null} if the given token is not the first token in a valid t ype name.
4215 * <p> 4215 * <p>
(...skipping 27 matching lines...) Expand all
4243 * '<' typeParameter (',' typeParameter)* '>' 4243 * '<' typeParameter (',' typeParameter)* '>'
4244 * </pre> 4244 * </pre>
4245 * @param startToken the token at which parsing is to begin 4245 * @param startToken the token at which parsing is to begin
4246 * @return the token following the type parameter list that was parsed 4246 * @return the token following the type parameter list that was parsed
4247 */ 4247 */
4248 Token skipTypeParameterList(Token startToken) { 4248 Token skipTypeParameterList(Token startToken) {
4249 if (!matches4(startToken, TokenType.LT)) { 4249 if (!matches4(startToken, TokenType.LT)) {
4250 return null; 4250 return null;
4251 } 4251 }
4252 int depth = 1; 4252 int depth = 1;
4253 Token next5 = startToken.next; 4253 Token next6 = startToken.next;
4254 while (depth > 0) { 4254 while (depth > 0) {
4255 if (matches4(next5, TokenType.EOF)) { 4255 if (matches4(next6, TokenType.EOF)) {
4256 return null; 4256 return null;
4257 } else if (matches4(next5, TokenType.LT)) { 4257 } else if (matches4(next6, TokenType.LT)) {
4258 depth++; 4258 depth++;
4259 } else if (matches4(next5, TokenType.GT)) { 4259 } else if (matches4(next6, TokenType.GT)) {
4260 depth--; 4260 depth--;
4261 } else if (matches4(next5, TokenType.GT_EQ)) { 4261 } else if (matches4(next6, TokenType.GT_EQ)) {
4262 if (depth == 1) { 4262 if (depth == 1) {
4263 Token fakeEquals = new Token(TokenType.EQ, next5.offset + 2); 4263 Token fakeEquals = new Token(TokenType.EQ, next6.offset + 2);
4264 fakeEquals.setNextWithoutSettingPrevious(next5.next); 4264 fakeEquals.setNextWithoutSettingPrevious(next6.next);
4265 return fakeEquals; 4265 return fakeEquals;
4266 } 4266 }
4267 depth--; 4267 depth--;
4268 } else if (matches4(next5, TokenType.GT_GT)) { 4268 } else if (matches4(next6, TokenType.GT_GT)) {
4269 depth -= 2; 4269 depth -= 2;
4270 } else if (matches4(next5, TokenType.GT_GT_EQ)) { 4270 } else if (matches4(next6, TokenType.GT_GT_EQ)) {
4271 if (depth < 2) { 4271 if (depth < 2) {
4272 return null; 4272 return null;
4273 } else if (depth == 2) { 4273 } else if (depth == 2) {
4274 Token fakeEquals = new Token(TokenType.EQ, next5.offset + 2); 4274 Token fakeEquals = new Token(TokenType.EQ, next6.offset + 2);
4275 fakeEquals.setNextWithoutSettingPrevious(next5.next); 4275 fakeEquals.setNextWithoutSettingPrevious(next6.next);
4276 return fakeEquals; 4276 return fakeEquals;
4277 } 4277 }
4278 depth -= 2; 4278 depth -= 2;
4279 } 4279 }
4280 next5 = next5.next; 4280 next6 = next6.next;
4281 } 4281 }
4282 return next5; 4282 return next6;
4283 } 4283 }
4284 /** 4284 /**
4285 * Translate the characters at the given index in the given string, appending the translated 4285 * Translate the characters at the given index in the given string, appending the translated
4286 * character to the given builder. The index is assumed to be valid. 4286 * character to the given builder. The index is assumed to be valid.
4287 * @param builder the builder to which the translated character is to be appen ded 4287 * @param builder the builder to which the translated character is to be appen ded
4288 * @param lexeme the string containing the character(s) to be translated 4288 * @param lexeme the string containing the character(s) to be translated
4289 * @param index the index of the character to be translated 4289 * @param index the index of the character to be translated
4290 * @return the index of the next character to be translated 4290 * @return the index of the next character to be translated
4291 */ 4291 */
4292 int translateCharacter(StringBuffer builder, String lexeme, int index) { 4292 int translateCharacter(StringBuffer builder, String lexeme, int index) {
4293 int currentChar = lexeme.charCodeAt(index); 4293 int currentChar = lexeme.codeUnitAt(index);
4294 if (currentChar != 0x5c) { 4294 if (currentChar != 0x5C) {
4295 builder.addCharCode(currentChar); 4295 builder.addCharCode(currentChar);
4296 return index + 1; 4296 return index + 1;
4297 } 4297 }
4298 int length8 = lexeme.length; 4298 int length8 = lexeme.length;
4299 int currentIndex = index + 1; 4299 int currentIndex = index + 1;
4300 if (currentIndex >= length8) { 4300 if (currentIndex >= length8) {
4301 return length8; 4301 return length8;
4302 } 4302 }
4303 currentChar = lexeme.charCodeAt(currentIndex); 4303 currentChar = lexeme.codeUnitAt(currentIndex);
4304 if (currentChar == 0x6e) { 4304 if (currentChar == 0x6E) {
4305 builder.addCharCode(0xa); 4305 builder.addCharCode(0xA);
4306 } else if (currentChar == 0x72) { 4306 } else if (currentChar == 0x72) {
4307 builder.addCharCode(0xd); 4307 builder.addCharCode(0xD);
4308 } else if (currentChar == 0x66) { 4308 } else if (currentChar == 0x66) {
4309 builder.addCharCode(0xc); 4309 builder.addCharCode(0xC);
4310 } else if (currentChar == 0x62) { 4310 } else if (currentChar == 0x62) {
4311 builder.addCharCode(0x8); 4311 builder.addCharCode(0x8);
4312 } else if (currentChar == 0x74) { 4312 } else if (currentChar == 0x74) {
4313 builder.addCharCode(0x9); 4313 builder.addCharCode(0x9);
4314 } else if (currentChar == 0x76) { 4314 } else if (currentChar == 0x76) {
4315 builder.addCharCode(0xb); 4315 builder.addCharCode(0xB);
4316 } else if (currentChar == 0x78) { 4316 } else if (currentChar == 0x78) {
4317 if (currentIndex + 2 >= length8) { 4317 if (currentIndex + 2 >= length8) {
4318 reportError3(ParserErrorCode.INVALID_HEX_ESCAPE, []); 4318 reportError3(ParserErrorCode.INVALID_HEX_ESCAPE, []);
4319 return length8; 4319 return length8;
4320 } 4320 }
4321 int firstDigit = lexeme.charCodeAt(currentIndex + 1); 4321 int firstDigit = lexeme.codeUnitAt(currentIndex + 1);
4322 int secondDigit = lexeme.charCodeAt(currentIndex + 2); 4322 int secondDigit = lexeme.codeUnitAt(currentIndex + 2);
4323 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) { 4323 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit)) {
4324 reportError3(ParserErrorCode.INVALID_HEX_ESCAPE, []); 4324 reportError3(ParserErrorCode.INVALID_HEX_ESCAPE, []);
4325 } else { 4325 } else {
4326 builder.addCharCode(((Character.digit(firstDigit, 16) << 4) + Character. digit(secondDigit, 16)) as int); 4326 builder.addCharCode((((Character.digit(firstDigit, 16) << 4) + Character .digit(secondDigit, 16)) as int));
4327 } 4327 }
4328 return currentIndex + 3; 4328 return currentIndex + 3;
4329 } else if (currentChar == 0x75) { 4329 } else if (currentChar == 0x75) {
4330 currentIndex++; 4330 currentIndex++;
4331 if (currentIndex >= length8) { 4331 if (currentIndex >= length8) {
4332 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4332 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4333 return length8; 4333 return length8;
4334 } 4334 }
4335 currentChar = lexeme.charCodeAt(currentIndex); 4335 currentChar = lexeme.codeUnitAt(currentIndex);
4336 if (currentChar == 0x7b) { 4336 if (currentChar == 0x7B) {
4337 currentIndex++; 4337 currentIndex++;
4338 if (currentIndex >= length8) { 4338 if (currentIndex >= length8) {
4339 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4339 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4340 return length8; 4340 return length8;
4341 } 4341 }
4342 currentChar = lexeme.charCodeAt(currentIndex); 4342 currentChar = lexeme.codeUnitAt(currentIndex);
4343 int digitCount = 0; 4343 int digitCount = 0;
4344 int value = 0; 4344 int value = 0;
4345 while (currentChar != 0x7d) { 4345 while (currentChar != 0x7D) {
4346 if (!isHexDigit(currentChar)) { 4346 if (!isHexDigit(currentChar)) {
4347 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4347 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4348 currentIndex++; 4348 currentIndex++;
4349 while (currentIndex < length8 && lexeme.charCodeAt(currentIndex) != 0x7d) { 4349 while (currentIndex < length8 && lexeme.codeUnitAt(currentIndex) != 0x7D) {
4350 currentIndex++; 4350 currentIndex++;
4351 } 4351 }
4352 return currentIndex + 1; 4352 return currentIndex + 1;
4353 } 4353 }
4354 digitCount++; 4354 digitCount++;
4355 value = (value << 4) + Character.digit(currentChar, 16); 4355 value = (value << 4) + Character.digit(currentChar, 16);
4356 currentIndex++; 4356 currentIndex++;
4357 if (currentIndex >= length8) { 4357 if (currentIndex >= length8) {
4358 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4358 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4359 return length8; 4359 return length8;
4360 } 4360 }
4361 currentChar = lexeme.charCodeAt(currentIndex); 4361 currentChar = lexeme.codeUnitAt(currentIndex);
4362 } 4362 }
4363 if (digitCount < 1 || digitCount > 6) { 4363 if (digitCount < 1 || digitCount > 6) {
4364 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4364 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4365 } 4365 }
4366 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex); 4366 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), va lue, index, currentIndex);
4367 return currentIndex + 1; 4367 return currentIndex + 1;
4368 } else { 4368 } else {
4369 if (currentIndex + 3 >= length8) { 4369 if (currentIndex + 3 >= length8) {
4370 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4370 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4371 return length8; 4371 return length8;
4372 } 4372 }
4373 int firstDigit = currentChar; 4373 int firstDigit = currentChar;
4374 int secondDigit = lexeme.charCodeAt(currentIndex + 1); 4374 int secondDigit = lexeme.codeUnitAt(currentIndex + 1);
4375 int thirdDigit = lexeme.charCodeAt(currentIndex + 2); 4375 int thirdDigit = lexeme.codeUnitAt(currentIndex + 2);
4376 int fourthDigit = lexeme.charCodeAt(currentIndex + 3); 4376 int fourthDigit = lexeme.codeUnitAt(currentIndex + 3);
4377 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) { 4377 if (!isHexDigit(firstDigit) || !isHexDigit(secondDigit) || !isHexDigit(t hirdDigit) || !isHexDigit(fourthDigit)) {
4378 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []); 4378 reportError3(ParserErrorCode.INVALID_UNICODE_ESCAPE, []);
4379 } else { 4379 } else {
4380 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), ((((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) << 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16 )), index, currentIndex + 3); 4380 appendScalarValue(builder, lexeme.substring(index, currentIndex + 1), ((((((Character.digit(firstDigit, 16) << 4) + Character.digit(secondDigit, 16)) << 4) + Character.digit(thirdDigit, 16)) << 4) + Character.digit(fourthDigit, 16 )), index, currentIndex + 3);
4381 } 4381 }
4382 return currentIndex + 4; 4382 return currentIndex + 4;
4383 } 4383 }
4384 } else { 4384 } else {
4385 builder.addCharCode(currentChar); 4385 builder.addCharCode(currentChar);
4386 } 4386 }
4387 return currentIndex + 1; 4387 return currentIndex + 1;
4388 } 4388 }
4389 /** 4389 /**
4390 * Validate that the given parameter list does not contain any field initializ ers. 4390 * Validate that the given parameter list does not contain any field initializ ers.
4391 * @param parameterList the parameter list to be validated 4391 * @param parameterList the parameter list to be validated
4392 */ 4392 */
4393 void validateFormalParameterList(FormalParameterList parameterList) { 4393 void validateFormalParameterList(FormalParameterList parameterList) {
4394 for (FormalParameter parameter in parameterList.parameters) { 4394 for (FormalParameter parameter in parameterList.parameters) {
4395 if (parameter is FieldFormalParameter) { 4395 if (parameter is FieldFormalParameter) {
4396 reportError(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, (para meter as FieldFormalParameter).identifier, []); 4396 reportError(ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, ((par ameter as FieldFormalParameter)).identifier, []);
4397 } 4397 }
4398 } 4398 }
4399 } 4399 }
4400 /** 4400 /**
4401 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract' 4401 * Validate that the given set of modifiers is appropriate for a class and ret urn the 'abstract'
4402 * keyword if there is one. 4402 * keyword if there is one.
4403 * @param modifiers the modifiers being validated 4403 * @param modifiers the modifiers being validated
4404 */ 4404 */
4405 Token validateModifiersForClass(Modifiers modifiers) { 4405 Token validateModifiersForClass(Modifiers modifiers) {
4406 validateModifiersForTopLevelDeclaration(modifiers); 4406 validateModifiersForTopLevelDeclaration(modifiers);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
4619 reportError4(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []); 4619 reportError4(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.externalKeyword, []);
4620 } 4620 }
4621 if (modifiers.finalKeyword != null) { 4621 if (modifiers.finalKeyword != null) {
4622 reportError4(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []); 4622 reportError4(ParserErrorCode.FINAL_TYPEDEF, modifiers.finalKeyword, []);
4623 } 4623 }
4624 if (modifiers.varKeyword != null) { 4624 if (modifiers.varKeyword != null) {
4625 reportError4(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []); 4625 reportError4(ParserErrorCode.VAR_TYPEDEF, modifiers.varKeyword, []);
4626 } 4626 }
4627 } 4627 }
4628 } 4628 }
4629 class AnalysisErrorListener_1 implements AnalysisErrorListener { 4629 class AnalysisErrorListener_4 implements AnalysisErrorListener {
4630 List<bool> errorFound; 4630 List<bool> errorFound;
4631 AnalysisErrorListener_1(this.errorFound); 4631 AnalysisErrorListener_4(this.errorFound);
4632 void onError(AnalysisError error) { 4632 void onError(AnalysisError error) {
4633 errorFound[0] = true; 4633 errorFound[0] = true;
4634 } 4634 }
4635 } 4635 }
4636 /** 4636 /**
4637 * The enumeration {@code ParserErrorCode} defines the error codes used for erro rs detected by the 4637 * The enumeration {@code ParserErrorCode} defines the error codes used for erro rs detected by the
4638 * parser. The convention for this class is for the name of the error code to in dicate the problem 4638 * parser. The convention for this class is for the name of the error code to in dicate the problem
4639 * that caused the error to be generated and for the error message to explain wh at is wrong and, 4639 * that caused the error to be generated and for the error message to explain wh at is wrong and,
4640 * when appropriate, how the problem can be corrected. 4640 * when appropriate, how the problem can be corrected.
4641 */ 4641 */
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
4748 ErrorSeverity _severity; 4748 ErrorSeverity _severity;
4749 /** 4749 /**
4750 * The message template used to create the message to be displayed for this er ror. 4750 * The message template used to create the message to be displayed for this er ror.
4751 */ 4751 */
4752 String _message; 4752 String _message;
4753 /** 4753 /**
4754 * Initialize a newly created error code to have the given severity and messag e. 4754 * Initialize a newly created error code to have the given severity and messag e.
4755 * @param severity the severity of the error 4755 * @param severity the severity of the error
4756 * @param message the message template used to create the message to be displa yed for the error 4756 * @param message the message template used to create the message to be displa yed for the error
4757 */ 4757 */
4758 ParserErrorCode.con1(String ___name, int ___ordinal, ErrorSeverity severity, S tring message) { 4758 ParserErrorCode.con1(String ___name, int ___ordinal, ErrorSeverity severity2, String message2) {
4759 _jtd_constructor_208_impl(___name, ___ordinal, severity, message); 4759 _jtd_constructor_217_impl(___name, ___ordinal, severity2, message2);
4760 } 4760 }
4761 _jtd_constructor_208_impl(String ___name, int ___ordinal, ErrorSeverity severi ty, String message) { 4761 _jtd_constructor_217_impl(String ___name, int ___ordinal, ErrorSeverity severi ty2, String message2) {
4762 __name = ___name; 4762 __name = ___name;
4763 __ordinal = ___ordinal; 4763 __ordinal = ___ordinal;
4764 this._severity = severity; 4764 this._severity = severity2;
4765 this._message = message; 4765 this._message = message2;
4766 } 4766 }
4767 /** 4767 /**
4768 * Initialize a newly created error code to have the given message and a sever ity of ERROR. 4768 * Initialize a newly created error code to have the given message and a sever ity of ERROR.
4769 * @param message the message template used to create the message to be displa yed for the error 4769 * @param message the message template used to create the message to be displa yed for the error
4770 */ 4770 */
4771 ParserErrorCode.con2(String ___name, int ___ordinal, String message) { 4771 ParserErrorCode.con2(String ___name, int ___ordinal, String message) {
4772 _jtd_constructor_209_impl(___name, ___ordinal, message); 4772 _jtd_constructor_218_impl(___name, ___ordinal, message);
4773 } 4773 }
4774 _jtd_constructor_209_impl(String ___name, int ___ordinal, String message) { 4774 _jtd_constructor_218_impl(String ___name, int ___ordinal, String message) {
4775 _jtd_constructor_208_impl(___name, ___ordinal, ErrorSeverity.ERROR, message) ; 4775 _jtd_constructor_217_impl(___name, ___ordinal, ErrorSeverity.ERROR, message) ;
4776 } 4776 }
4777 ErrorSeverity get errorSeverity => _severity; 4777 ErrorSeverity get errorSeverity => _severity;
4778 String get message => _message; 4778 String get message => _message;
4779 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 4779 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
4780 bool needsRecompilation() => true; 4780 bool needsRecompilation() => true;
4781 String toString() => __name; 4781 String toString() => __name;
4782 } 4782 }
4783 /** 4783 /**
4784 * Instances of the class {link ToFormattedSourceVisitor} write a source represe ntation of a visited 4784 * Instances of the class {link ToFormattedSourceVisitor} write a source represe ntation of a visited
4785 * AST node (and all of it's children) to a writer. 4785 * AST node (and all of it's children) to a writer.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
4935 for (String line in StringUtils.split(token.lexeme, "\n")) { 4935 for (String line in StringUtils.split(token.lexeme, "\n")) {
4936 if (firstLine) { 4936 if (firstLine) {
4937 firstLine = false; 4937 firstLine = false;
4938 } else { 4938 } else {
4939 line = " ${line.trim()}"; 4939 line = " ${line.trim()}";
4940 line = StringUtils.replace(line, "/*", "/ *"); 4940 line = StringUtils.replace(line, "/*", "/ *");
4941 } 4941 }
4942 _writer.print(line); 4942 _writer.print(line);
4943 nl2(); 4943 nl2();
4944 } 4944 }
4945 if (token == node.endToken) { 4945 if (identical(token, node.endToken)) {
4946 break; 4946 break;
4947 } 4947 }
4948 } 4948 }
4949 return null; 4949 return null;
4950 } 4950 }
4951 Object visitCommentReference(CommentReference node) => null; 4951 Object visitCommentReference(CommentReference node) => null;
4952 Object visitCompilationUnit(CompilationUnit node) { 4952 Object visitCompilationUnit(CompilationUnit node) {
4953 ScriptTag scriptTag5 = node.scriptTag; 4953 ScriptTag scriptTag7 = node.scriptTag;
4954 NodeList<Directive> directives4 = node.directives; 4954 NodeList<Directive> directives4 = node.directives;
4955 visit(scriptTag5); 4955 visit(scriptTag7);
4956 String prefix = scriptTag5 == null ? "" : " "; 4956 String prefix = scriptTag7 == null ? "" : " ";
4957 visitList7(prefix, directives4, "\n"); 4957 visitList7(prefix, directives4, "\n");
4958 prefix = scriptTag5 == null && directives4.isEmpty ? "" : "\n\n"; 4958 prefix = scriptTag7 == null && directives4.isEmpty ? "" : "\n\n";
4959 visitList7(prefix, node.declarations, "\n"); 4959 visitList7(prefix, node.declarations, "\n");
4960 return null; 4960 return null;
4961 } 4961 }
4962 Object visitConditionalExpression(ConditionalExpression node) { 4962 Object visitConditionalExpression(ConditionalExpression node) {
4963 visit(node.condition); 4963 visit(node.condition);
4964 _writer.print(" ? "); 4964 _writer.print(" ? ");
4965 visit(node.thenExpression); 4965 visit(node.thenExpression);
4966 _writer.print(" : "); 4966 _writer.print(" : ");
4967 visit(node.elseExpression); 4967 visit(node.elseExpression);
4968 return null; 4968 return null;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
5025 Object visitEmptyFunctionBody(EmptyFunctionBody node) { 5025 Object visitEmptyFunctionBody(EmptyFunctionBody node) {
5026 _writer.print(';'); 5026 _writer.print(';');
5027 return null; 5027 return null;
5028 } 5028 }
5029 Object visitEmptyStatement(EmptyStatement node) { 5029 Object visitEmptyStatement(EmptyStatement node) {
5030 _writer.print(';'); 5030 _writer.print(';');
5031 return null; 5031 return null;
5032 } 5032 }
5033 Object visitExportDirective(ExportDirective node) { 5033 Object visitExportDirective(ExportDirective node) {
5034 _writer.print("export "); 5034 _writer.print("export ");
5035 visit(node.libraryUri); 5035 visit(node.uri);
5036 visitList7(" ", node.combinators, " "); 5036 visitList7(" ", node.combinators, " ");
5037 _writer.print(';'); 5037 _writer.print(';');
5038 return null; 5038 return null;
5039 } 5039 }
5040 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 5040 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
5041 _writer.print("=> "); 5041 _writer.print("=> ");
5042 visit(node.expression); 5042 visit(node.expression);
5043 if (node.semicolon != null) { 5043 if (node.semicolon != null) {
5044 _writer.print(';'); 5044 _writer.print(';');
5045 } 5045 }
(...skipping 29 matching lines...) Expand all
5075 _writer.print(" in "); 5075 _writer.print(" in ");
5076 visit(node.iterator); 5076 visit(node.iterator);
5077 _writer.print(") "); 5077 _writer.print(") ");
5078 visit(node.body); 5078 visit(node.body);
5079 return null; 5079 return null;
5080 } 5080 }
5081 Object visitFormalParameterList(FormalParameterList node) { 5081 Object visitFormalParameterList(FormalParameterList node) {
5082 String groupEnd = null; 5082 String groupEnd = null;
5083 _writer.print('('); 5083 _writer.print('(');
5084 NodeList<FormalParameter> parameters11 = node.parameters; 5084 NodeList<FormalParameter> parameters11 = node.parameters;
5085 int size6 = parameters11.length; 5085 int size7 = parameters11.length;
5086 for (int i = 0; i < size6; i++) { 5086 for (int i = 0; i < size7; i++) {
5087 FormalParameter parameter = parameters11[i]; 5087 FormalParameter parameter = parameters11[i];
5088 if (i > 0) { 5088 if (i > 0) {
5089 _writer.print(", "); 5089 _writer.print(", ");
5090 } 5090 }
5091 if (groupEnd == null && parameter is DefaultFormalParameter) { 5091 if (groupEnd == null && parameter is DefaultFormalParameter) {
5092 if (parameter.kind == ParameterKind.NAMED) { 5092 if (identical(parameter.kind, ParameterKind.NAMED)) {
5093 groupEnd = "}"; 5093 groupEnd = "}";
5094 _writer.print('{'); 5094 _writer.print('{');
5095 } else { 5095 } else {
5096 groupEnd = "]"; 5096 groupEnd = "]";
5097 _writer.print('['); 5097 _writer.print('[');
5098 } 5098 }
5099 } 5099 }
5100 parameter.accept(this); 5100 parameter.accept(this);
5101 } 5101 }
5102 if (groupEnd != null) { 5102 if (groupEnd != null) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
5172 visit7(" else ", node.elseStatement); 5172 visit7(" else ", node.elseStatement);
5173 return null; 5173 return null;
5174 } 5174 }
5175 Object visitImplementsClause(ImplementsClause node) { 5175 Object visitImplementsClause(ImplementsClause node) {
5176 _writer.print("implements "); 5176 _writer.print("implements ");
5177 visitList5(node.interfaces, ", "); 5177 visitList5(node.interfaces, ", ");
5178 return null; 5178 return null;
5179 } 5179 }
5180 Object visitImportDirective(ImportDirective node) { 5180 Object visitImportDirective(ImportDirective node) {
5181 _writer.print("import "); 5181 _writer.print("import ");
5182 visit(node.libraryUri); 5182 visit(node.uri);
5183 visit7(" as ", node.prefix); 5183 visit7(" as ", node.prefix);
5184 visitList7(" ", node.combinators, " "); 5184 visitList7(" ", node.combinators, " ");
5185 _writer.print(';'); 5185 _writer.print(';');
5186 return null; 5186 return null;
5187 } 5187 }
5188 Object visitIndexExpression(IndexExpression node) { 5188 Object visitIndexExpression(IndexExpression node) {
5189 if (node.isCascaded()) { 5189 if (node.isCascaded()) {
5190 _writer.print(".."); 5190 _writer.print("..");
5191 } else { 5191 } else {
5192 visit(node.array); 5192 visit(node.array);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5317 return null; 5317 return null;
5318 } 5318 }
5319 Object visitParenthesizedExpression(ParenthesizedExpression node) { 5319 Object visitParenthesizedExpression(ParenthesizedExpression node) {
5320 _writer.print('('); 5320 _writer.print('(');
5321 visit(node.expression); 5321 visit(node.expression);
5322 _writer.print(')'); 5322 _writer.print(')');
5323 return null; 5323 return null;
5324 } 5324 }
5325 Object visitPartDirective(PartDirective node) { 5325 Object visitPartDirective(PartDirective node) {
5326 _writer.print("part "); 5326 _writer.print("part ");
5327 visit(node.partUri); 5327 visit(node.uri);
5328 _writer.print(';'); 5328 _writer.print(';');
5329 return null; 5329 return null;
5330 } 5330 }
5331 Object visitPartOfDirective(PartOfDirective node) { 5331 Object visitPartOfDirective(PartOfDirective node) {
5332 _writer.print("part of "); 5332 _writer.print("part of ");
5333 visit(node.libraryName); 5333 visit(node.libraryName);
5334 _writer.print(';'); 5334 _writer.print(';');
5335 return null; 5335 return null;
5336 } 5336 }
5337 Object visitPostfixExpression(PostfixExpression node) { 5337 Object visitPostfixExpression(PostfixExpression node) {
(...skipping 21 matching lines...) Expand all
5359 visit(node.propertyName); 5359 visit(node.propertyName);
5360 return null; 5360 return null;
5361 } 5361 }
5362 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) { 5362 Object visitRedirectingConstructorInvocation(RedirectingConstructorInvocation node) {
5363 _writer.print("this"); 5363 _writer.print("this");
5364 visit7(".", node.constructorName); 5364 visit7(".", node.constructorName);
5365 visit(node.argumentList); 5365 visit(node.argumentList);
5366 return null; 5366 return null;
5367 } 5367 }
5368 Object visitReturnStatement(ReturnStatement node) { 5368 Object visitReturnStatement(ReturnStatement node) {
5369 Expression expression15 = node.expression; 5369 Expression expression16 = node.expression;
5370 if (expression15 == null) { 5370 if (expression16 == null) {
5371 _writer.print("return;"); 5371 _writer.print("return;");
5372 } else { 5372 } else {
5373 _writer.print("return "); 5373 _writer.print("return ");
5374 expression15.accept(this); 5374 expression16.accept(this);
5375 _writer.print(";"); 5375 _writer.print(";");
5376 } 5376 }
5377 return null; 5377 return null;
5378 } 5378 }
5379 Object visitScriptTag(ScriptTag node) { 5379 Object visitScriptTag(ScriptTag node) {
5380 _writer.print(node.scriptTag.lexeme); 5380 _writer.print(node.scriptTag.lexeme);
5381 return null; 5381 return null;
5382 } 5382 }
5383 Object visitShowCombinator(ShowCombinator node) { 5383 Object visitShowCombinator(ShowCombinator node) {
5384 _writer.print("show "); 5384 _writer.print("show ");
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
5587 void visitList(NodeList<ASTNode> nodes) { 5587 void visitList(NodeList<ASTNode> nodes) {
5588 visitList5(nodes, ""); 5588 visitList5(nodes, "");
5589 } 5589 }
5590 /** 5590 /**
5591 * Print a list of nodes, separated by the given separator. 5591 * Print a list of nodes, separated by the given separator.
5592 * @param nodes the nodes to be printed 5592 * @param nodes the nodes to be printed
5593 * @param separator the separator to be printed between adjacent nodes 5593 * @param separator the separator to be printed between adjacent nodes
5594 */ 5594 */
5595 void visitList5(NodeList<ASTNode> nodes, String separator) { 5595 void visitList5(NodeList<ASTNode> nodes, String separator) {
5596 if (nodes != null) { 5596 if (nodes != null) {
5597 int size7 = nodes.length; 5597 int size8 = nodes.length;
5598 for (int i = 0; i < size7; i++) { 5598 for (int i = 0; i < size8; i++) {
5599 if ("\n" == separator) { 5599 if ("\n" == separator) {
5600 _writer.print("\n"); 5600 _writer.print("\n");
5601 indent(); 5601 indent();
5602 } else if (i > 0) { 5602 } else if (i > 0) {
5603 _writer.print(separator); 5603 _writer.print(separator);
5604 } 5604 }
5605 nodes[i].accept(this); 5605 nodes[i].accept(this);
5606 } 5606 }
5607 } 5607 }
5608 } 5608 }
5609 /** 5609 /**
5610 * Print a list of nodes, separated by the given separator. 5610 * Print a list of nodes, separated by the given separator.
5611 * @param nodes the nodes to be printed 5611 * @param nodes the nodes to be printed
5612 * @param separator the separator to be printed between adjacent nodes 5612 * @param separator the separator to be printed between adjacent nodes
5613 * @param suffix the suffix to be printed if the list is not empty 5613 * @param suffix the suffix to be printed if the list is not empty
5614 */ 5614 */
5615 void visitList6(NodeList<ASTNode> nodes, String separator, String suffix) { 5615 void visitList6(NodeList<ASTNode> nodes, String separator, String suffix) {
5616 if (nodes != null) { 5616 if (nodes != null) {
5617 int size8 = nodes.length; 5617 int size9 = nodes.length;
5618 if (size8 > 0) { 5618 if (size9 > 0) {
5619 for (int i = 0; i < size8; i++) { 5619 for (int i = 0; i < size9; i++) {
5620 if (i > 0) { 5620 if (i > 0) {
5621 _writer.print(separator); 5621 _writer.print(separator);
5622 } 5622 }
5623 nodes[i].accept(this); 5623 nodes[i].accept(this);
5624 } 5624 }
5625 _writer.print(suffix); 5625 _writer.print(suffix);
5626 } 5626 }
5627 } 5627 }
5628 } 5628 }
5629 /** 5629 /**
5630 * Print a list of nodes, separated by the given separator. 5630 * Print a list of nodes, separated by the given separator.
5631 * @param prefix the prefix to be printed if the list is not empty 5631 * @param prefix the prefix to be printed if the list is not empty
5632 * @param nodes the nodes to be printed 5632 * @param nodes the nodes to be printed
5633 * @param separator the separator to be printed between adjacent nodes 5633 * @param separator the separator to be printed between adjacent nodes
5634 */ 5634 */
5635 void visitList7(String prefix, NodeList<ASTNode> nodes, String separator) { 5635 void visitList7(String prefix, NodeList<ASTNode> nodes, String separator) {
5636 if (nodes != null) { 5636 if (nodes != null) {
5637 int size9 = nodes.length; 5637 int size10 = nodes.length;
5638 if (size9 > 0) { 5638 if (size10 > 0) {
5639 _writer.print(prefix); 5639 _writer.print(prefix);
5640 for (int i = 0; i < size9; i++) { 5640 for (int i = 0; i < size10; i++) {
5641 if (i > 0) { 5641 if (i > 0) {
5642 _writer.print(separator); 5642 _writer.print(separator);
5643 } 5643 }
5644 nodes[i].accept(this); 5644 nodes[i].accept(this);
5645 } 5645 }
5646 } 5646 }
5647 } 5647 }
5648 } 5648 }
5649 } 5649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698