| 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 '../scanner.dart' show ErrorToken; | 7 import '../scanner.dart' show ErrorToken; |
| 8 | 8 |
| 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; | 9 import '../scanner/recover.dart' show closeBraceFor, skipToEof; |
| 10 | 10 |
| 11 import '../scanner/keyword.dart' show Keyword; | 11 import '../scanner/keyword.dart' show Keyword; |
| 12 | 12 |
| 13 import '../scanner/precedence.dart' | 13 import '../scanner/precedence.dart' |
| 14 show | 14 show |
| 15 ASSIGNMENT_PRECEDENCE, | 15 ASSIGNMENT_PRECEDENCE, |
| 16 AS_INFO, | 16 AS_INFO, |
| 17 CASCADE_PRECEDENCE, | 17 CASCADE_PRECEDENCE, |
| 18 EQUALITY_PRECEDENCE, | 18 EQUALITY_PRECEDENCE, |
| 19 GT_INFO, | 19 GT_INFO, |
| 20 IS_INFO, | 20 IS_INFO, |
| 21 MINUS_MINUS_INFO, | 21 MINUS_MINUS_INFO, |
| 22 OPEN_PAREN_INFO, | 22 OPEN_PAREN_INFO, |
| 23 OPEN_SQUARE_BRACKET_INFO, | 23 OPEN_SQUARE_BRACKET_INFO, |
| 24 PERIOD_INFO, | 24 PERIOD_INFO, |
| 25 PLUS_PLUS_INFO, | 25 PLUS_PLUS_INFO, |
| 26 POSTFIX_PRECEDENCE, | 26 POSTFIX_PRECEDENCE, |
| 27 PrecedenceInfo, | 27 PrecedenceInfo, |
| 28 QUESTION_INFO, | 28 QUESTION_INFO, |
| 29 QUESTION_PERIOD_INFO, | 29 QUESTION_PERIOD_INFO, |
| 30 RELATIONAL_PRECEDENCE; | 30 RELATIONAL_PRECEDENCE, |
| 31 SCRIPT_INFO; |
| 31 | 32 |
| 32 import '../scanner/token.dart' | 33 import '../scanner/token.dart' |
| 33 show | 34 show |
| 34 BeginGroupToken, | 35 BeginGroupToken, |
| 35 KeywordToken, | 36 KeywordToken, |
| 36 SymbolToken, | 37 SymbolToken, |
| 37 Token, | 38 Token, |
| 38 isUserDefinableOperator; | 39 isUserDefinableOperator; |
| 39 | 40 |
| 40 import '../scanner/token_constants.dart' | 41 import '../scanner/token_constants.dart' |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return token; | 131 return token; |
| 131 } | 132 } |
| 132 | 133 |
| 133 Token parseTopLevelDeclaration(Token token) { | 134 Token parseTopLevelDeclaration(Token token) { |
| 134 token = _parseTopLevelDeclaration(token); | 135 token = _parseTopLevelDeclaration(token); |
| 135 listener.endTopLevelDeclaration(token); | 136 listener.endTopLevelDeclaration(token); |
| 136 return token; | 137 return token; |
| 137 } | 138 } |
| 138 | 139 |
| 139 Token _parseTopLevelDeclaration(Token token) { | 140 Token _parseTopLevelDeclaration(Token token) { |
| 141 if (identical(token.info, SCRIPT_INFO)) { |
| 142 return parseScript(token); |
| 143 } |
| 140 token = parseMetadataStar(token); | 144 token = parseMetadataStar(token); |
| 141 final String value = token.stringValue; | 145 final String value = token.stringValue; |
| 142 if ((identical(value, 'abstract') && optional('class', token.next)) || | 146 if ((identical(value, 'abstract') && optional('class', token.next)) || |
| 143 identical(value, 'class')) { | 147 identical(value, 'class')) { |
| 144 return parseClassOrNamedMixinApplication(token); | 148 return parseClassOrNamedMixinApplication(token); |
| 145 } else if (identical(value, 'enum')) { | 149 } else if (identical(value, 'enum')) { |
| 146 return parseEnum(token); | 150 return parseEnum(token); |
| 147 } else if (identical(value, 'typedef')) { | 151 } else if (identical(value, 'typedef')) { |
| 148 return parseTypedef(token); | 152 return parseTypedef(token); |
| 149 } else if (identical(value, 'library')) { | 153 } else if (identical(value, 'library')) { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 if (optional('.', token)) { | 387 if (optional('.', token)) { |
| 384 period = token; | 388 period = token; |
| 385 token = parseIdentifier( | 389 token = parseIdentifier( |
| 386 token.next, IdentifierContext.metadataContinuationAfterTypeArguments); | 390 token.next, IdentifierContext.metadataContinuationAfterTypeArguments); |
| 387 } | 391 } |
| 388 token = parseArgumentsOpt(token); | 392 token = parseArgumentsOpt(token); |
| 389 listener.endMetadata(atToken, period, token); | 393 listener.endMetadata(atToken, period, token); |
| 390 return token; | 394 return token; |
| 391 } | 395 } |
| 392 | 396 |
| 397 Token parseScript(Token token) { |
| 398 listener.handleScript(token); |
| 399 return token.next; |
| 400 } |
| 401 |
| 393 Token parseTypedef(Token token) { | 402 Token parseTypedef(Token token) { |
| 394 Token typedefKeyword = token; | 403 Token typedefKeyword = token; |
| 395 listener.beginFunctionTypeAlias(token); | 404 listener.beginFunctionTypeAlias(token); |
| 396 Token equals; | 405 Token equals; |
| 397 if (optional('=', peekAfterNominalType(token.next))) { | 406 if (optional('=', peekAfterNominalType(token.next))) { |
| 398 token = parseIdentifier(token.next, IdentifierContext.typedefDeclaration); | 407 token = parseIdentifier(token.next, IdentifierContext.typedefDeclaration); |
| 399 token = parseTypeVariablesOpt(token); | 408 token = parseTypeVariablesOpt(token); |
| 400 equals = token; | 409 equals = token; |
| 401 token = expect('=', token); | 410 token = expect('=', token); |
| 402 token = parseType(token); | 411 token = parseType(token); |
| (...skipping 3160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3563 break; | 3572 break; |
| 3564 } | 3573 } |
| 3565 if (isRecoverable) { | 3574 if (isRecoverable) { |
| 3566 listener.handleRecoverableError(token, kind, arguments); | 3575 listener.handleRecoverableError(token, kind, arguments); |
| 3567 return null; | 3576 return null; |
| 3568 } else { | 3577 } else { |
| 3569 return listener.handleUnrecoverableError(token, kind, arguments); | 3578 return listener.handleUnrecoverableError(token, kind, arguments); |
| 3570 } | 3579 } |
| 3571 } | 3580 } |
| 3572 } | 3581 } |
| OLD | NEW |