| OLD | NEW |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 import '../../scanner/token.dart' | 61 import '../../scanner/token.dart' |
| 62 show | 62 show |
| 63 ASSIGNMENT_PRECEDENCE, | 63 ASSIGNMENT_PRECEDENCE, |
| 64 CASCADE_PRECEDENCE, | 64 CASCADE_PRECEDENCE, |
| 65 EQUALITY_PRECEDENCE, | 65 EQUALITY_PRECEDENCE, |
| 66 Keyword, | 66 Keyword, |
| 67 POSTFIX_PRECEDENCE, | 67 POSTFIX_PRECEDENCE, |
| 68 RELATIONAL_PRECEDENCE, | 68 RELATIONAL_PRECEDENCE, |
| 69 TokenType; | 69 TokenType; |
| 70 | 70 |
| 71 import '../scanner/precedence.dart' | |
| 72 show | |
| 73 AS_INFO, | |
| 74 GT_INFO, | |
| 75 IS_INFO, | |
| 76 MINUS_MINUS_INFO, | |
| 77 OPEN_PAREN_INFO, | |
| 78 OPEN_SQUARE_BRACKET_INFO, | |
| 79 PERIOD_INFO, | |
| 80 PLUS_PLUS_INFO, | |
| 81 QUESTION_INFO, | |
| 82 QUESTION_PERIOD_INFO, | |
| 83 SCRIPT_INFO; | |
| 84 | |
| 85 import '../scanner/token.dart' | 71 import '../scanner/token.dart' |
| 86 show | 72 show |
| 87 BeginGroupToken, | 73 BeginGroupToken, |
| 88 KeywordToken, | 74 KeywordToken, |
| 89 SymbolToken, | 75 SymbolToken, |
| 90 Token, | 76 Token, |
| 91 isUserDefinableOperator; | 77 isUserDefinableOperator; |
| 92 | 78 |
| 93 import '../scanner/token_constants.dart' | 79 import '../scanner/token_constants.dart' |
| 94 show | 80 show |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 return token; | 286 return token; |
| 301 } | 287 } |
| 302 | 288 |
| 303 Token parseTopLevelDeclaration(Token token) { | 289 Token parseTopLevelDeclaration(Token token) { |
| 304 token = _parseTopLevelDeclaration(token); | 290 token = _parseTopLevelDeclaration(token); |
| 305 listener.endTopLevelDeclaration(token); | 291 listener.endTopLevelDeclaration(token); |
| 306 return token; | 292 return token; |
| 307 } | 293 } |
| 308 | 294 |
| 309 Token _parseTopLevelDeclaration(Token token) { | 295 Token _parseTopLevelDeclaration(Token token) { |
| 310 if (identical(token.info, SCRIPT_INFO)) { | 296 if (identical(token.info, TokenType.SCRIPT_TAG)) { |
| 311 return parseScript(token); | 297 return parseScript(token); |
| 312 } | 298 } |
| 313 token = parseMetadataStar(token); | 299 token = parseMetadataStar(token); |
| 314 final String value = token.stringValue; | 300 final String value = token.stringValue; |
| 315 if ((identical(value, 'abstract') && optional('class', token.next)) || | 301 if ((identical(value, 'abstract') && optional('class', token.next)) || |
| 316 identical(value, 'class')) { | 302 identical(value, 'class')) { |
| 317 return parseClassOrNamedMixinApplication(token); | 303 return parseClassOrNamedMixinApplication(token); |
| 318 } else if (identical(value, 'enum')) { | 304 } else if (identical(value, 'enum')) { |
| 319 return parseEnum(token); | 305 return parseEnum(token); |
| 320 } else if (identical(value, 'typedef')) { | 306 } else if (identical(value, 'typedef')) { |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 token = tryParseType(token.next); | 876 token = tryParseType(token.next); |
| 891 while (token != null && identical(token.kind, COMMA_TOKEN)) { | 877 while (token != null && identical(token.kind, COMMA_TOKEN)) { |
| 892 token = tryParseType(token.next); | 878 token = tryParseType(token.next); |
| 893 } | 879 } |
| 894 if (token == null) return null; | 880 if (token == null) return null; |
| 895 if (identical(token.kind, GT_TOKEN)) return token.next; | 881 if (identical(token.kind, GT_TOKEN)) return token.next; |
| 896 if (!identical(token.kind, GT_GT_TOKEN)) return null; | 882 if (!identical(token.kind, GT_GT_TOKEN)) return null; |
| 897 // [token] is '>>' of which the final '>' that we are parsing is the first | 883 // [token] is '>>' of which the final '>' that we are parsing is the first |
| 898 // character. In order to keep the parsing process on track we must return | 884 // character. In order to keep the parsing process on track we must return |
| 899 // a synthetic '>' corresponding to the second character of that '>>'. | 885 // a synthetic '>' corresponding to the second character of that '>>'. |
| 900 Token syntheticToken = new SymbolToken(GT_INFO, token.charOffset + 1); | 886 Token syntheticToken = new SymbolToken(TokenType.GT, token.charOffset + 1); |
| 901 syntheticToken.next = token.next; | 887 syntheticToken.next = token.next; |
| 902 return syntheticToken; | 888 return syntheticToken; |
| 903 } | 889 } |
| 904 | 890 |
| 905 Token parseQualified(Token token, IdentifierContext context, | 891 Token parseQualified(Token token, IdentifierContext context, |
| 906 IdentifierContext continuationContext) { | 892 IdentifierContext continuationContext) { |
| 907 token = parseIdentifier(token, context); | 893 token = parseIdentifier(token, context); |
| 908 while (optional('.', token)) { | 894 while (optional('.', token)) { |
| 909 token = parseQualifiedRest(token, continuationContext); | 895 token = parseQualifiedRest(token, continuationContext); |
| 910 } | 896 } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 if (optional('<', token)) { | 1188 if (optional('<', token)) { |
| 1203 Token begin = token; | 1189 Token begin = token; |
| 1204 beginStuff(begin); | 1190 beginStuff(begin); |
| 1205 int count = 0; | 1191 int count = 0; |
| 1206 do { | 1192 do { |
| 1207 token = stuffParser(token.next); | 1193 token = stuffParser(token.next); |
| 1208 ++count; | 1194 ++count; |
| 1209 } while (optional(',', token)); | 1195 } while (optional(',', token)); |
| 1210 Token next = token.next; | 1196 Token next = token.next; |
| 1211 if (identical(token.stringValue, '>>')) { | 1197 if (identical(token.stringValue, '>>')) { |
| 1212 token = new SymbolToken(GT_INFO, token.charOffset); | 1198 token = new SymbolToken(TokenType.GT, token.charOffset); |
| 1213 token.next = new SymbolToken(GT_INFO, token.charOffset + 1); | 1199 token.next = new SymbolToken(TokenType.GT, token.charOffset + 1); |
| 1214 token.next.next = next; | 1200 token.next.next = next; |
| 1215 } | 1201 } |
| 1216 endStuff(count, begin, token); | 1202 endStuff(count, begin, token); |
| 1217 return expect('>', token); | 1203 return expect('>', token); |
| 1218 } | 1204 } |
| 1219 handleNoStuff(token); | 1205 handleNoStuff(token); |
| 1220 return token; | 1206 return token; |
| 1221 } | 1207 } |
| 1222 | 1208 |
| 1223 Token parseTopLevelMember(Token token) { | 1209 Token parseTopLevelMember(Token token) { |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2738 return token; | 2724 return token; |
| 2739 } | 2725 } |
| 2740 token = parseCascadeExpression(token); | 2726 token = parseCascadeExpression(token); |
| 2741 } else if (identical(tokenLevel, ASSIGNMENT_PRECEDENCE)) { | 2727 } else if (identical(tokenLevel, ASSIGNMENT_PRECEDENCE)) { |
| 2742 // Right associative, so we recurse at the same precedence | 2728 // Right associative, so we recurse at the same precedence |
| 2743 // level. | 2729 // level. |
| 2744 listener.beginExpression(token.next); | 2730 listener.beginExpression(token.next); |
| 2745 token = parsePrecedenceExpression(token.next, level, allowCascades); | 2731 token = parsePrecedenceExpression(token.next, level, allowCascades); |
| 2746 listener.handleAssignmentExpression(operator); | 2732 listener.handleAssignmentExpression(operator); |
| 2747 } else if (identical(tokenLevel, POSTFIX_PRECEDENCE)) { | 2733 } else if (identical(tokenLevel, POSTFIX_PRECEDENCE)) { |
| 2748 if (identical(info, PERIOD_INFO) || | 2734 if (identical(info, TokenType.PERIOD) || |
| 2749 identical(info, QUESTION_PERIOD_INFO)) { | 2735 identical(info, TokenType.QUESTION_PERIOD)) { |
| 2750 // Left associative, so we recurse at the next higher precedence | 2736 // Left associative, so we recurse at the next higher precedence |
| 2751 // level. However, POSTFIX_PRECEDENCE is the highest level, so we | 2737 // level. However, POSTFIX_PRECEDENCE is the highest level, so we |
| 2752 // should just call [parseUnaryExpression] directly. However, a | 2738 // should just call [parseUnaryExpression] directly. However, a |
| 2753 // unary expression isn't legal after a period, so we call | 2739 // unary expression isn't legal after a period, so we call |
| 2754 // [parsePrimary] instead. | 2740 // [parsePrimary] instead. |
| 2755 token = parsePrimary( | 2741 token = parsePrimary( |
| 2756 token.next, IdentifierContext.expressionContinuation); | 2742 token.next, IdentifierContext.expressionContinuation); |
| 2757 listener.handleBinaryExpression(operator); | 2743 listener.handleBinaryExpression(operator); |
| 2758 } else if ((identical(info, OPEN_PAREN_INFO)) || | 2744 } else if ((identical(info, TokenType.OPEN_PAREN)) || |
| 2759 (identical(info, OPEN_SQUARE_BRACKET_INFO))) { | 2745 (identical(info, TokenType.OPEN_SQUARE_BRACKET))) { |
| 2760 token = parseArgumentOrIndexStar(token); | 2746 token = parseArgumentOrIndexStar(token); |
| 2761 } else if ((identical(info, PLUS_PLUS_INFO)) || | 2747 } else if ((identical(info, TokenType.PLUS_PLUS)) || |
| 2762 (identical(info, MINUS_MINUS_INFO))) { | 2748 (identical(info, TokenType.MINUS_MINUS))) { |
| 2763 listener.handleUnaryPostfixAssignmentExpression(token); | 2749 listener.handleUnaryPostfixAssignmentExpression(token); |
| 2764 token = token.next; | 2750 token = token.next; |
| 2765 } else { | 2751 } else { |
| 2766 token = reportUnexpectedToken(token).next; | 2752 token = reportUnexpectedToken(token).next; |
| 2767 } | 2753 } |
| 2768 } else if (identical(info, IS_INFO)) { | 2754 } else if (identical(info, TokenType.IS)) { |
| 2769 token = parseIsOperatorRest(token); | 2755 token = parseIsOperatorRest(token); |
| 2770 } else if (identical(info, AS_INFO)) { | 2756 } else if (identical(info, TokenType.AS)) { |
| 2771 token = parseAsOperatorRest(token); | 2757 token = parseAsOperatorRest(token); |
| 2772 } else if (identical(info, QUESTION_INFO)) { | 2758 } else if (identical(info, TokenType.QUESTION)) { |
| 2773 token = parseConditionalExpressionRest(token); | 2759 token = parseConditionalExpressionRest(token); |
| 2774 } else { | 2760 } else { |
| 2775 // Left associative, so we recurse at the next higher | 2761 // Left associative, so we recurse at the next higher |
| 2776 // precedence level. | 2762 // precedence level. |
| 2777 listener.beginExpression(token.next); | 2763 listener.beginExpression(token.next); |
| 2778 token = | 2764 token = |
| 2779 parsePrecedenceExpression(token.next, level + 1, allowCascades); | 2765 parsePrecedenceExpression(token.next, level + 1, allowCascades); |
| 2780 listener.handleBinaryExpression(operator); | 2766 listener.handleBinaryExpression(operator); |
| 2781 } | 2767 } |
| 2782 info = token.info; | 2768 info = token.info; |
| (...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3907 return reportUnrecoverableError( | 3893 return reportUnrecoverableError( |
| 3908 token, () => code.format(uri, token.charOffset, string)); | 3894 token, () => code.format(uri, token.charOffset, string)); |
| 3909 } | 3895 } |
| 3910 } | 3896 } |
| 3911 | 3897 |
| 3912 typedef FastaMessage NoArgument(Uri uri, int charOffset); | 3898 typedef FastaMessage NoArgument(Uri uri, int charOffset); |
| 3913 | 3899 |
| 3914 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); | 3900 typedef FastaMessage TokenArgument(Uri uri, int charOffset, Token token); |
| 3915 | 3901 |
| 3916 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); | 3902 typedef FastaMessage StringArgument(Uri uri, int charOffset, String string); |
| OLD | NEW |