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

Side by Side Diff: pkg/front_end/lib/src/fasta/parser/parser.dart

Issue 2839403004: change fasta.Token.isIdentifier() from method to getter (Closed)
Patch Set: rebase Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.parser.parser; 5 library fasta.parser.parser;
6 6
7 import '../fasta_codes.dart' 7 import '../fasta_codes.dart'
8 show 8 show
9 FastaCode, 9 FastaCode,
10 FastaMessage, 10 FastaMessage,
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 listener.endPart(partKeyword, semicolon); 496 listener.endPart(partKeyword, semicolon);
497 return token; 497 return token;
498 } 498 }
499 499
500 Token parsePartOf(Token token) { 500 Token parsePartOf(Token token) {
501 listener.beginPartOf(token); 501 listener.beginPartOf(token);
502 assert(optional('part', token)); 502 assert(optional('part', token));
503 assert(optional('of', token.next)); 503 assert(optional('of', token.next));
504 Token partKeyword = token; 504 Token partKeyword = token;
505 token = token.next.next; 505 token = token.next.next;
506 bool hasName = token.isIdentifier(); 506 bool hasName = token.isIdentifier;
507 if (hasName) { 507 if (hasName) {
508 token = parseQualified(token, IdentifierContext.partName, 508 token = parseQualified(token, IdentifierContext.partName,
509 IdentifierContext.partNameContinuation); 509 IdentifierContext.partNameContinuation);
510 } else { 510 } else {
511 token = parseLiteralStringOrRecoverExpression(token); 511 token = parseLiteralStringOrRecoverExpression(token);
512 } 512 }
513 Token semicolon = token; 513 Token semicolon = token;
514 token = expect(';', token); 514 token = expect(';', token);
515 listener.endPartOf(partKeyword, semicolon, hasName); 515 listener.endPartOf(partKeyword, semicolon, hasName);
516 return token; 516 return token;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 {bool inFunctionType: false}) { 663 {bool inFunctionType: false}) {
664 token = parseMetadataStar(token, forParameter: true); 664 token = parseMetadataStar(token, forParameter: true);
665 listener.beginFormalParameter(token); 665 listener.beginFormalParameter(token);
666 666
667 // Skip over `covariant` token, if the next token is an identifier or 667 // Skip over `covariant` token, if the next token is an identifier or
668 // modifier. 668 // modifier.
669 // This enables the case where `covariant` is the name of the parameter: 669 // This enables the case where `covariant` is the name of the parameter:
670 // void foo(covariant); 670 // void foo(covariant);
671 Token covariantKeyword; 671 Token covariantKeyword;
672 if (identical(token.stringValue, 'covariant') && 672 if (identical(token.stringValue, 'covariant') &&
673 (token.next.isIdentifier() || isModifier(token.next))) { 673 (token.next.isIdentifier || isModifier(token.next))) {
674 covariantKeyword = token; 674 covariantKeyword = token;
675 token = token.next; 675 token = token.next;
676 } 676 }
677 token = parseModifiers(token); 677 token = parseModifiers(token);
678 bool isNamedParameter = kind == FormalParameterType.NAMED; 678 bool isNamedParameter = kind == FormalParameterType.NAMED;
679 679
680 Token thisKeyword = null; 680 Token thisKeyword = null;
681 Token nameToken; 681 Token nameToken;
682 if (inFunctionType && isNamedParameter) { 682 if (inFunctionType && isNamedParameter) {
683 token = parseType(token); 683 token = parseType(token);
684 token = 684 token =
685 parseIdentifier(token, IdentifierContext.formalParameterDeclaration); 685 parseIdentifier(token, IdentifierContext.formalParameterDeclaration);
686 } else if (inFunctionType) { 686 } else if (inFunctionType) {
687 token = parseType(token); 687 token = parseType(token);
688 if (token.isIdentifier()) { 688 if (token.isIdentifier) {
689 token = parseIdentifier( 689 token = parseIdentifier(
690 token, IdentifierContext.formalParameterDeclaration); 690 token, IdentifierContext.formalParameterDeclaration);
691 } else { 691 } else {
692 listener.handleNoName(token); 692 listener.handleNoName(token);
693 } 693 }
694 } else { 694 } else {
695 token = parseReturnTypeOpt(token); 695 token = parseReturnTypeOpt(token);
696 if (optional('this', token)) { 696 if (optional('this', token)) {
697 thisKeyword = token; 697 thisKeyword = token;
698 token = expect('.', token.next); 698 token = expect('.', token.next);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 } 786 }
787 } 787 }
788 788
789 Token parseTypeOpt(Token token) { 789 Token parseTypeOpt(Token token) {
790 if (isGeneralizedFunctionType(token)) { 790 if (isGeneralizedFunctionType(token)) {
791 // Function type without return type. 791 // Function type without return type.
792 return parseType(token); 792 return parseType(token);
793 } 793 }
794 token = listener.injectGenericCommentTypeAssign(token); 794 token = listener.injectGenericCommentTypeAssign(token);
795 Token peek = peekAfterIfType(token); 795 Token peek = peekAfterIfType(token);
796 if (peek != null && (peek.isIdentifier() || optional('this', peek))) { 796 if (peek != null && (peek.isIdentifier || optional('this', peek))) {
797 return parseType(token); 797 return parseType(token);
798 } 798 }
799 listener.handleNoType(token); 799 listener.handleNoType(token);
800 return token; 800 return token;
801 } 801 }
802 802
803 bool isValidTypeReference(Token token) { 803 bool isValidTypeReference(Token token) {
804 final kind = token.kind; 804 final kind = token.kind;
805 if (identical(kind, IDENTIFIER_TOKEN)) return true; 805 if (identical(kind, IDENTIFIER_TOKEN)) return true;
806 if (identical(kind, KEYWORD_TOKEN)) { 806 if (identical(kind, KEYWORD_TOKEN)) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 Token parseStringPart(Token token) { 1031 Token parseStringPart(Token token) {
1032 if (token.kind != STRING_TOKEN) { 1032 if (token.kind != STRING_TOKEN) {
1033 token = 1033 token =
1034 reportUnrecoverableErrorCodeWithToken(token, codeExpectedString).next; 1034 reportUnrecoverableErrorCodeWithToken(token, codeExpectedString).next;
1035 } 1035 }
1036 listener.handleStringPart(token); 1036 listener.handleStringPart(token);
1037 return token.next; 1037 return token.next;
1038 } 1038 }
1039 1039
1040 Token parseIdentifier(Token token, IdentifierContext context) { 1040 Token parseIdentifier(Token token, IdentifierContext context) {
1041 if (!token.isIdentifier()) { 1041 if (!token.isIdentifier) {
1042 token = 1042 token =
1043 reportUnrecoverableErrorCodeWithToken(token, codeExpectedIdentifier) 1043 reportUnrecoverableErrorCodeWithToken(token, codeExpectedIdentifier)
1044 .next; 1044 .next;
1045 } else if (token.isBuiltInIdentifier && 1045 } else if (token.isBuiltInIdentifier &&
1046 !context.isBuiltInIdentifierAllowed) { 1046 !context.isBuiltInIdentifierAllowed) {
1047 if (context.inDeclaration) { 1047 if (context.inDeclaration) {
1048 reportRecoverableErrorCodeWithToken( 1048 reportRecoverableErrorCodeWithToken(
1049 token, codeBuiltInIdentifierInDeclaration); 1049 token, codeBuiltInIdentifierInDeclaration);
1050 } else if (!optional("dynamic", token)) { 1050 } else if (!optional("dynamic", token)) {
1051 reportRecoverableErrorCodeWithToken(token, codeBuiltInIdentifierAsType); 1051 reportRecoverableErrorCodeWithToken(token, codeBuiltInIdentifierAsType);
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 hasName = true; 1546 hasName = true;
1547 } 1547 }
1548 identifiers = identifiers.prepend(token); 1548 identifiers = identifiers.prepend(token);
1549 1549
1550 if (!isGeneralizedFunctionType(token)) { 1550 if (!isGeneralizedFunctionType(token)) {
1551 // Read a potential return type. 1551 // Read a potential return type.
1552 if (isValidTypeReference(token)) { 1552 if (isValidTypeReference(token)) {
1553 // type ... 1553 // type ...
1554 if (optional('.', token.next)) { 1554 if (optional('.', token.next)) {
1555 // type '.' ... 1555 // type '.' ...
1556 if (token.next.next.isIdentifier()) { 1556 if (token.next.next.isIdentifier) {
1557 // type '.' identifier 1557 // type '.' identifier
1558 token = token.next.next; 1558 token = token.next.next;
1559 } 1559 }
1560 } 1560 }
1561 if (optional('<', token.next)) { 1561 if (optional('<', token.next)) {
1562 if (token.next is BeginGroupToken) { 1562 if (token.next is BeginGroupToken) {
1563 BeginGroupToken beginGroup = token.next; 1563 BeginGroupToken beginGroup = token.next;
1564 if (beginGroup.endGroup == null) { 1564 if (beginGroup.endGroup == null) {
1565 token = reportUnmatchedToken(beginGroup).next; 1565 token = reportUnmatchedToken(beginGroup).next;
1566 } else { 1566 } else {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1733 }
1734 return peek; 1734 return peek;
1735 } 1735 }
1736 1736
1737 /// Returns the first token after the nominal type starting at [token]. 1737 /// Returns the first token after the nominal type starting at [token].
1738 /// 1738 ///
1739 /// This method assumes that [token] is an identifier (or void). 1739 /// This method assumes that [token] is an identifier (or void).
1740 Token peekAfterNominalType(Token token) { 1740 Token peekAfterNominalType(Token token) {
1741 Token peek = token.next; 1741 Token peek = token.next;
1742 if (identical(peek.kind, PERIOD_TOKEN)) { 1742 if (identical(peek.kind, PERIOD_TOKEN)) {
1743 if (peek.next.isIdentifier()) { 1743 if (peek.next.isIdentifier) {
1744 // Look past a library prefix. 1744 // Look past a library prefix.
1745 peek = peek.next.next; 1745 peek = peek.next.next;
1746 } 1746 }
1747 } 1747 }
1748 // We are looking at "qualified ...". 1748 // We are looking at "qualified ...".
1749 if (identical(peek.kind, LT_TOKEN)) { 1749 if (identical(peek.kind, LT_TOKEN)) {
1750 // Possibly generic type. 1750 // Possibly generic type.
1751 // We are looking at "qualified '<'". 1751 // We are looking at "qualified '<'".
1752 BeginGroupToken beginGroupToken = peek; 1752 BeginGroupToken beginGroupToken = peek;
1753 Token gtToken = beginGroupToken.endGroup; 1753 Token gtToken = beginGroupToken.endGroup;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 if (closeToken != null) { 1799 if (closeToken != null) {
1800 peek = closeToken.next; 1800 peek = closeToken.next;
1801 } 1801 }
1802 1802
1803 return peek; 1803 return peek;
1804 } 1804 }
1805 1805
1806 /// If [token] is the start of a type, returns the token after that type. 1806 /// If [token] is the start of a type, returns the token after that type.
1807 /// If [token] is not the start of a type, null is returned. 1807 /// If [token] is not the start of a type, null is returned.
1808 Token peekAfterIfType(Token token) { 1808 Token peekAfterIfType(Token token) {
1809 if (!optional('void', token) && !token.isIdentifier()) { 1809 if (!optional('void', token) && !token.isIdentifier) {
1810 return null; 1810 return null;
1811 } 1811 }
1812 return peekAfterType(token); 1812 return peekAfterType(token);
1813 } 1813 }
1814 1814
1815 Token skipClassBody(Token token) { 1815 Token skipClassBody(Token token) {
1816 if (!optional('{', token)) { 1816 if (!optional('{', token)) {
1817 return reportUnrecoverableErrorCodeWithToken( 1817 return reportUnrecoverableErrorCodeWithToken(
1818 token, codeExpectedClassBodyToSkip) 1818 token, codeExpectedClassBodyToSkip)
1819 .next; 1819 .next;
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 case AsyncModifier.AsyncStar: 2394 case AsyncModifier.AsyncStar:
2395 return parseYieldStatement(token); 2395 return parseYieldStatement(token);
2396 2396
2397 case AsyncModifier.Async: 2397 case AsyncModifier.Async:
2398 reportRecoverableErrorCode(token, codeYieldNotGenerator); 2398 reportRecoverableErrorCode(token, codeYieldNotGenerator);
2399 return parseYieldStatement(token); 2399 return parseYieldStatement(token);
2400 } 2400 }
2401 throw "Internal error: Unknown asyncState: '$asyncState'."; 2401 throw "Internal error: Unknown asyncState: '$asyncState'.";
2402 } else if (identical(value, 'const')) { 2402 } else if (identical(value, 'const')) {
2403 return parseExpressionStatementOrConstDeclaration(token); 2403 return parseExpressionStatementOrConstDeclaration(token);
2404 } else if (token.isIdentifier()) { 2404 } else if (token.isIdentifier) {
2405 return parseExpressionStatementOrDeclaration(token); 2405 return parseExpressionStatementOrDeclaration(token);
2406 } else { 2406 } else {
2407 return parseExpressionStatement(token); 2407 return parseExpressionStatement(token);
2408 } 2408 }
2409 } 2409 }
2410 2410
2411 Token parseYieldStatement(Token token) { 2411 Token parseYieldStatement(Token token) {
2412 Token begin = token; 2412 Token begin = token;
2413 listener.beginYieldStatement(begin); 2413 listener.beginYieldStatement(begin);
2414 assert(identical('yield', token.stringValue)); 2414 assert(identical('yield', token.stringValue));
(...skipping 20 matching lines...) Expand all
2435 if (inGenerator) { 2435 if (inGenerator) {
2436 reportRecoverableErrorCode(begin.next, codeGeneratorReturnsValue); 2436 reportRecoverableErrorCode(begin.next, codeGeneratorReturnsValue);
2437 } 2437 }
2438 listener.endReturnStatement(true, begin, token); 2438 listener.endReturnStatement(true, begin, token);
2439 } 2439 }
2440 return expectSemicolon(token); 2440 return expectSemicolon(token);
2441 } 2441 }
2442 2442
2443 Token peekIdentifierAfterType(Token token) { 2443 Token peekIdentifierAfterType(Token token) {
2444 Token peek = peekAfterType(token); 2444 Token peek = peekAfterType(token);
2445 if (peek != null && peek.isIdentifier()) { 2445 if (peek != null && peek.isIdentifier) {
2446 // We are looking at "type identifier". 2446 // We are looking at "type identifier".
2447 return peek; 2447 return peek;
2448 } else { 2448 } else {
2449 return null; 2449 return null;
2450 } 2450 }
2451 } 2451 }
2452 2452
2453 Token peekIdentifierAfterOptionalType(Token token) { 2453 Token peekIdentifierAfterOptionalType(Token token) {
2454 Token peek = peekAfterIfType(token); 2454 Token peek = peekAfterIfType(token);
2455 if (peek != null && peek.isIdentifier()) { 2455 if (peek != null && peek.isIdentifier) {
2456 // We are looking at "type identifier". 2456 // We are looking at "type identifier".
2457 return peek; 2457 return peek;
2458 } else if (token.isIdentifier()) { 2458 } else if (token.isIdentifier) {
2459 // We are looking at "identifier". 2459 // We are looking at "identifier".
2460 return token; 2460 return token;
2461 } else { 2461 } else {
2462 return null; 2462 return null;
2463 } 2463 }
2464 } 2464 }
2465 2465
2466 Token parseExpressionStatementOrDeclaration(Token token) { 2466 Token parseExpressionStatementOrDeclaration(Token token) {
2467 if (!inPlainSync && optional("await", token)) { 2467 if (!inPlainSync && optional("await", token)) {
2468 return parseExpressionStatement(token); 2468 return parseExpressionStatement(token);
2469 } 2469 }
2470 assert(token.isIdentifier() || identical(token.stringValue, 'void')); 2470 assert(token.isIdentifier || identical(token.stringValue, 'void'));
2471 Token identifier = peekIdentifierAfterType(token); 2471 Token identifier = peekIdentifierAfterType(token);
2472 if (identifier != null) { 2472 if (identifier != null) {
2473 assert(identifier.isIdentifier()); 2473 assert(identifier.isIdentifier);
2474 2474
2475 // If the identifier token has a type substitution comment /*=T*/, 2475 // If the identifier token has a type substitution comment /*=T*/,
2476 // then the set of tokens type tokens should be replaced with the 2476 // then the set of tokens type tokens should be replaced with the
2477 // tokens parsed from the comment. 2477 // tokens parsed from the comment.
2478 token = 2478 token =
2479 listener.replaceTokenWithGenericCommentTypeAssign(token, identifier); 2479 listener.replaceTokenWithGenericCommentTypeAssign(token, identifier);
2480 2480
2481 Token afterId = identifier.next; 2481 Token afterId = identifier.next;
2482 int afterIdKind = afterId.kind; 2482 int afterIdKind = afterId.kind;
2483 if (identical(afterIdKind, EQ_TOKEN) || 2483 if (identical(afterIdKind, EQ_TOKEN) ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 } 2558 }
2559 2559
2560 Token parseExpressionStatementOrConstDeclaration(Token token) { 2560 Token parseExpressionStatementOrConstDeclaration(Token token) {
2561 assert(identical(token.stringValue, 'const')); 2561 assert(identical(token.stringValue, 'const'));
2562 if (isModifier(token.next)) { 2562 if (isModifier(token.next)) {
2563 return parseVariablesDeclaration(token); 2563 return parseVariablesDeclaration(token);
2564 } 2564 }
2565 listener.injectGenericCommentTypeAssign(token.next); 2565 listener.injectGenericCommentTypeAssign(token.next);
2566 Token identifier = peekIdentifierAfterOptionalType(token.next); 2566 Token identifier = peekIdentifierAfterOptionalType(token.next);
2567 if (identifier != null) { 2567 if (identifier != null) {
2568 assert(identifier.isIdentifier()); 2568 assert(identifier.isIdentifier);
2569 Token afterId = identifier.next; 2569 Token afterId = identifier.next;
2570 int afterIdKind = afterId.kind; 2570 int afterIdKind = afterId.kind;
2571 if (identical(afterIdKind, EQ_TOKEN) || 2571 if (identical(afterIdKind, EQ_TOKEN) ||
2572 identical(afterIdKind, SEMICOLON_TOKEN) || 2572 identical(afterIdKind, SEMICOLON_TOKEN) ||
2573 identical(afterIdKind, COMMA_TOKEN)) { 2573 identical(afterIdKind, COMMA_TOKEN)) {
2574 // We are looking at "const type identifier" followed by '=', ';', or 2574 // We are looking at "const type identifier" followed by '=', ';', or
2575 // ','. 2575 // ','.
2576 return parseVariablesDeclaration(token); 2576 return parseVariablesDeclaration(token);
2577 } 2577 }
2578 // Fall-through to expression statement. 2578 // Fall-through to expression statement.
2579 } 2579 }
2580 2580
2581 return parseExpressionStatement(token); 2581 return parseExpressionStatement(token);
2582 } 2582 }
2583 2583
2584 Token parseLabel(Token token) { 2584 Token parseLabel(Token token) {
2585 token = parseIdentifier(token, IdentifierContext.labelDeclaration); 2585 token = parseIdentifier(token, IdentifierContext.labelDeclaration);
2586 Token colon = token; 2586 Token colon = token;
2587 token = expect(':', token); 2587 token = expect(':', token);
2588 listener.handleLabel(colon); 2588 listener.handleLabel(colon);
2589 return token; 2589 return token;
2590 } 2590 }
2591 2591
2592 Token parseLabeledStatement(Token token) { 2592 Token parseLabeledStatement(Token token) {
2593 int labelCount = 0; 2593 int labelCount = 0;
2594 do { 2594 do {
2595 token = parseLabel(token); 2595 token = parseLabel(token);
2596 labelCount++; 2596 labelCount++;
2597 } while (token.isIdentifier() && optional(':', token.next)); 2597 } while (token.isIdentifier && optional(':', token.next));
2598 listener.beginLabeledStatement(token, labelCount); 2598 listener.beginLabeledStatement(token, labelCount);
2599 token = parseStatement(token); 2599 token = parseStatement(token);
2600 listener.endLabeledStatement(labelCount); 2600 listener.endLabeledStatement(labelCount);
2601 return token; 2601 return token;
2602 } 2602 }
2603 2603
2604 Token parseExpressionStatement(Token token) { 2604 Token parseExpressionStatement(Token token) {
2605 listener.beginExpressionStatement(token); 2605 listener.beginExpressionStatement(token);
2606 token = parseExpression(token); 2606 token = parseExpression(token);
2607 listener.endExpressionStatement(token); 2607 listener.endExpressionStatement(token);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2778 return token; 2778 return token;
2779 } 2779 }
2780 2780
2781 Token parseCascadeExpression(Token token) { 2781 Token parseCascadeExpression(Token token) {
2782 listener.beginCascade(token); 2782 listener.beginCascade(token);
2783 assert(optional('..', token)); 2783 assert(optional('..', token));
2784 Token cascadeOperator = token; 2784 Token cascadeOperator = token;
2785 token = token.next; 2785 token = token.next;
2786 if (optional('[', token)) { 2786 if (optional('[', token)) {
2787 token = parseArgumentOrIndexStar(token); 2787 token = parseArgumentOrIndexStar(token);
2788 } else if (token.isIdentifier()) { 2788 } else if (token.isIdentifier) {
2789 token = parseSend(token, IdentifierContext.expressionContinuation); 2789 token = parseSend(token, IdentifierContext.expressionContinuation);
2790 listener.handleBinaryExpression(cascadeOperator); 2790 listener.handleBinaryExpression(cascadeOperator);
2791 } else { 2791 } else {
2792 return reportUnexpectedToken(token).next; 2792 return reportUnexpectedToken(token).next;
2793 } 2793 }
2794 Token mark; 2794 Token mark;
2795 do { 2795 do {
2796 mark = token; 2796 mark = token;
2797 if (optional('.', token)) { 2797 if (optional('.', token)) {
2798 Token period = token; 2798 Token period = token;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 return parseSuperExpression(token, context); 2895 return parseSuperExpression(token, context);
2896 } else if (identical(value, "new")) { 2896 } else if (identical(value, "new")) {
2897 return parseNewExpression(token); 2897 return parseNewExpression(token);
2898 } else if (identical(value, "const")) { 2898 } else if (identical(value, "const")) {
2899 return parseConstExpression(token); 2899 return parseConstExpression(token);
2900 } else if (identical(value, "void")) { 2900 } else if (identical(value, "void")) {
2901 return parseFunctionExpression(token); 2901 return parseFunctionExpression(token);
2902 } else if (!inPlainSync && 2902 } else if (!inPlainSync &&
2903 (identical(value, "yield") || identical(value, "async"))) { 2903 (identical(value, "yield") || identical(value, "async"))) {
2904 return expressionExpected(token); 2904 return expressionExpected(token);
2905 } else if (token.isIdentifier()) { 2905 } else if (token.isIdentifier) {
2906 return parseSendOrFunctionLiteral(token, context); 2906 return parseSendOrFunctionLiteral(token, context);
2907 } else { 2907 } else {
2908 return expressionExpected(token); 2908 return expressionExpected(token);
2909 } 2909 }
2910 } else if (kind == OPEN_PAREN_TOKEN) { 2910 } else if (kind == OPEN_PAREN_TOKEN) {
2911 return parseParenthesizedExpressionOrFunctionLiteral(token); 2911 return parseParenthesizedExpressionOrFunctionLiteral(token);
2912 } else if (kind == OPEN_SQUARE_BRACKET_TOKEN || optional('[]', token)) { 2912 } else if (kind == OPEN_SQUARE_BRACKET_TOKEN || optional('[]', token)) {
2913 listener.handleNoTypeArguments(token); 2913 listener.handleNoTypeArguments(token);
2914 return parseLiteralListSuffix(token, null); 2914 return parseLiteralListSuffix(token, null);
2915 } else if (kind == OPEN_CURLY_BRACKET_TOKEN) { 2915 } else if (kind == OPEN_CURLY_BRACKET_TOKEN) {
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
3468 Token parseVariablesDeclarationOrExpressionOpt(Token token) { 3468 Token parseVariablesDeclarationOrExpressionOpt(Token token) {
3469 final String value = token.stringValue; 3469 final String value = token.stringValue;
3470 if (identical(value, ';')) { 3470 if (identical(value, ';')) {
3471 listener.handleNoExpression(token); 3471 listener.handleNoExpression(token);
3472 return token; 3472 return token;
3473 } else if (isOneOf4(token, '@', 'var', 'final', 'const')) { 3473 } else if (isOneOf4(token, '@', 'var', 'final', 'const')) {
3474 return parseVariablesDeclarationNoSemicolon(token); 3474 return parseVariablesDeclarationNoSemicolon(token);
3475 } 3475 }
3476 Token identifier = peekIdentifierAfterType(token); 3476 Token identifier = peekIdentifierAfterType(token);
3477 if (identifier != null) { 3477 if (identifier != null) {
3478 assert(identifier.isIdentifier()); 3478 assert(identifier.isIdentifier);
3479 if (isOneOf4(identifier.next, '=', ';', ',', 'in')) { 3479 if (isOneOf4(identifier.next, '=', ';', ',', 'in')) {
3480 return parseVariablesDeclarationNoSemicolon(token); 3480 return parseVariablesDeclarationNoSemicolon(token);
3481 } 3481 }
3482 } 3482 }
3483 return parseExpression(token); 3483 return parseExpression(token);
3484 } 3484 }
3485 3485
3486 Token parseForRest(Token forToken, Token leftParenthesis, Token token) { 3486 Token parseForRest(Token forToken, Token leftParenthesis, Token token) {
3487 Token leftSeparator = token; 3487 Token leftSeparator = token;
3488 token = expectSemicolon(token); 3488 token = expectSemicolon(token);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 } 3671 }
3672 listener.endSwitchBlock(caseCount, begin, token); 3672 listener.endSwitchBlock(caseCount, begin, token);
3673 expect('}', token); 3673 expect('}', token);
3674 return token; 3674 return token;
3675 } 3675 }
3676 3676
3677 /// Peek after the following labels (if any). The following token 3677 /// Peek after the following labels (if any). The following token
3678 /// is used to determine if the labels belong to a statement or a 3678 /// is used to determine if the labels belong to a statement or a
3679 /// switch case. 3679 /// switch case.
3680 Token peekPastLabels(Token token) { 3680 Token peekPastLabels(Token token) {
3681 while (token.isIdentifier() && optional(':', token.next)) { 3681 while (token.isIdentifier && optional(':', token.next)) {
3682 token = token.next.next; 3682 token = token.next.next;
3683 } 3683 }
3684 return token; 3684 return token;
3685 } 3685 }
3686 3686
3687 /// Parse a group of labels, cases and possibly a default keyword and the 3687 /// Parse a group of labels, cases and possibly a default keyword and the
3688 /// statements that they select. 3688 /// statements that they select.
3689 Token parseSwitchCase(Token token) { 3689 Token parseSwitchCase(Token token) {
3690 Token begin = token; 3690 Token begin = token;
3691 Token defaultKeyword = null; 3691 Token defaultKeyword = null;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3744 listener.handleSwitchCase(labelCount, expressionCount, defaultKeyword, 3744 listener.handleSwitchCase(labelCount, expressionCount, defaultKeyword,
3745 statementCount, begin, token); 3745 statementCount, begin, token);
3746 return token; 3746 return token;
3747 } 3747 }
3748 3748
3749 Token parseBreakStatement(Token token) { 3749 Token parseBreakStatement(Token token) {
3750 assert(optional('break', token)); 3750 assert(optional('break', token));
3751 Token breakKeyword = token; 3751 Token breakKeyword = token;
3752 token = token.next; 3752 token = token.next;
3753 bool hasTarget = false; 3753 bool hasTarget = false;
3754 if (token.isIdentifier()) { 3754 if (token.isIdentifier) {
3755 token = parseIdentifier(token, IdentifierContext.labelReference); 3755 token = parseIdentifier(token, IdentifierContext.labelReference);
3756 hasTarget = true; 3756 hasTarget = true;
3757 } 3757 }
3758 listener.handleBreakStatement(hasTarget, breakKeyword, token); 3758 listener.handleBreakStatement(hasTarget, breakKeyword, token);
3759 return expectSemicolon(token); 3759 return expectSemicolon(token);
3760 } 3760 }
3761 3761
3762 Token parseAssertStatement(Token token) { 3762 Token parseAssertStatement(Token token) {
3763 Token assertKeyword = token; 3763 Token assertKeyword = token;
3764 Token commaToken = null; 3764 Token commaToken = null;
(...skipping 14 matching lines...) Expand all
3779 listener.handleAssertStatement( 3779 listener.handleAssertStatement(
3780 assertKeyword, leftParenthesis, commaToken, rightParenthesis, token); 3780 assertKeyword, leftParenthesis, commaToken, rightParenthesis, token);
3781 return expectSemicolon(token); 3781 return expectSemicolon(token);
3782 } 3782 }
3783 3783
3784 Token parseContinueStatement(Token token) { 3784 Token parseContinueStatement(Token token) {
3785 assert(optional('continue', token)); 3785 assert(optional('continue', token));
3786 Token continueKeyword = token; 3786 Token continueKeyword = token;
3787 token = token.next; 3787 token = token.next;
3788 bool hasTarget = false; 3788 bool hasTarget = false;
3789 if (token.isIdentifier()) { 3789 if (token.isIdentifier) {
3790 token = parseIdentifier(token, IdentifierContext.labelReference); 3790 token = parseIdentifier(token, IdentifierContext.labelReference);
3791 hasTarget = true; 3791 hasTarget = true;
3792 } 3792 }
3793 listener.handleContinueStatement(hasTarget, continueKeyword, token); 3793 listener.handleContinueStatement(hasTarget, continueKeyword, token);
3794 return expectSemicolon(token); 3794 return expectSemicolon(token);
3795 } 3795 }
3796 3796
3797 Token parseEmptyStatement(Token token) { 3797 Token parseEmptyStatement(Token token) {
3798 listener.handleEmptyStatement(token); 3798 listener.handleEmptyStatement(token);
3799 return expectSemicolon(token); 3799 return expectSemicolon(token);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 return reportUnrecoverableError( 3893 return reportUnrecoverableError(
3894 token, () => code.format(uri, token.charOffset, string)); 3894 token, () => code.format(uri, token.charOffset, string));
3895 } 3895 }
3896 } 3896 }
3897 3897
3898 typedef FastaMessage NoArgument(Uri uri, int charOffset); 3898 typedef FastaMessage NoArgument(Uri uri, int charOffset);
3899 3899
3900 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); 3900 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token);
3901 3901
3902 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); 3902 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string);
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/native/resolver.dart ('k') | pkg/front_end/lib/src/fasta/scanner/error_token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698