| 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 dart2js.parser; | 5 library dart2js.parser; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../tokens/keyword.dart' show | 8 import '../tokens/keyword.dart' show |
| 9 Keyword; | 9 Keyword; |
| 10 import '../tokens/precedence.dart' show | 10 import '../tokens/precedence.dart' show |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 * | 91 * |
| 92 * Parse methods are generally named parseGrammarProductionSuffix. The | 92 * Parse methods are generally named parseGrammarProductionSuffix. The |
| 93 * suffix can be one of "opt", or "star". "opt" means zero or one | 93 * suffix can be one of "opt", or "star". "opt" means zero or one |
| 94 * matches, "star" means zero or more matches. For example, | 94 * matches, "star" means zero or more matches. For example, |
| 95 * [parseMetadataStar] corresponds to this grammar snippet: [: | 95 * [parseMetadataStar] corresponds to this grammar snippet: [: |
| 96 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :]. | 96 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :]. |
| 97 */ | 97 */ |
| 98 class Parser { | 98 class Parser { |
| 99 final Listener listener; | 99 final Listener listener; |
| 100 bool mayParseFunctionExpressions = true; | 100 bool mayParseFunctionExpressions = true; |
| 101 final bool enableConditionalDirectives; | |
| 102 bool asyncAwaitKeywordsEnabled; | 101 bool asyncAwaitKeywordsEnabled; |
| 103 | 102 |
| 104 Parser(this.listener, | 103 Parser(this.listener, |
| 105 {this.enableConditionalDirectives: false, | 104 {this.asyncAwaitKeywordsEnabled: false}); |
| 106 this.asyncAwaitKeywordsEnabled: false}); | |
| 107 | 105 |
| 108 Token parseUnit(Token token) { | 106 Token parseUnit(Token token) { |
| 109 listener.beginCompilationUnit(token); | 107 listener.beginCompilationUnit(token); |
| 110 int count = 0; | 108 int count = 0; |
| 111 while (!identical(token.kind, EOF_TOKEN)) { | 109 while (!identical(token.kind, EOF_TOKEN)) { |
| 112 token = parseTopLevelDeclaration(token); | 110 token = parseTopLevelDeclaration(token); |
| 113 listener.endTopLevelDeclaration(token); | 111 listener.endTopLevelDeclaration(token); |
| 114 count++; | 112 count++; |
| 115 } | 113 } |
| 116 listener.endCompilationUnit(count, token); | 114 listener.endCompilationUnit(count, token); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 Token semicolon = token; | 171 Token semicolon = token; |
| 174 token = expect(';', token); | 172 token = expect(';', token); |
| 175 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon); | 173 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon); |
| 176 return token; | 174 return token; |
| 177 } | 175 } |
| 178 | 176 |
| 179 /// if (test) uri | 177 /// if (test) uri |
| 180 Token parseConditionalUris(Token token) { | 178 Token parseConditionalUris(Token token) { |
| 181 listener.beginConditionalUris(token); | 179 listener.beginConditionalUris(token); |
| 182 int count = 0; | 180 int count = 0; |
| 183 if (enableConditionalDirectives) { | 181 while (optional('if', token)) { |
| 184 while (optional('if', token)) { | 182 count++; |
| 185 count++; | 183 token = parseConditionalUri(token); |
| 186 token = parseConditionalUri(token); | |
| 187 } | |
| 188 } | 184 } |
| 189 listener.endConditionalUris(count); | 185 listener.endConditionalUris(count); |
| 190 return token; | 186 return token; |
| 191 } | 187 } |
| 192 | 188 |
| 193 Token parseConditionalUri(Token token) { | 189 Token parseConditionalUri(Token token) { |
| 194 listener.beginConditionalUri(token); | 190 listener.beginConditionalUri(token); |
| 195 Token ifKeyword = token; | 191 Token ifKeyword = token; |
| 196 token = expect('if', token); | 192 token = expect('if', token); |
| 197 token = expect('(', token); | 193 token = expect('(', token); |
| (...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2778 } | 2774 } |
| 2779 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 2775 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 2780 return expectSemicolon(token); | 2776 return expectSemicolon(token); |
| 2781 } | 2777 } |
| 2782 | 2778 |
| 2783 Token parseEmptyStatement(Token token) { | 2779 Token parseEmptyStatement(Token token) { |
| 2784 listener.handleEmptyStatement(token); | 2780 listener.handleEmptyStatement(token); |
| 2785 return expectSemicolon(token); | 2781 return expectSemicolon(token); |
| 2786 } | 2782 } |
| 2787 } | 2783 } |
| OLD | NEW |