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

Side by Side Diff: pkg/compiler/lib/src/parser/parser.dart

Issue 1388523002: dart2js: add support for configuration-specific imports. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments and add flag. Created 5 years, 2 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 dart2js.parser; 5 library dart2js.parser;
6 6
7 import '../diagnostics/messages.dart' show 7 import '../diagnostics/messages.dart' show
8 MessageKind; 8 MessageKind;
9 import '../tokens/keyword.dart' show 9 import '../tokens/keyword.dart' show
10 Keyword; 10 Keyword;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 * 92 *
93 * Parse methods are generally named parseGrammarProductionSuffix. The 93 * Parse methods are generally named parseGrammarProductionSuffix. The
94 * suffix can be one of "opt", or "star". "opt" means zero or one 94 * suffix can be one of "opt", or "star". "opt" means zero or one
95 * matches, "star" means zero or more matches. For example, 95 * matches, "star" means zero or more matches. For example,
96 * [parseMetadataStar] corresponds to this grammar snippet: [: 96 * [parseMetadataStar] corresponds to this grammar snippet: [:
97 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :]. 97 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :].
98 */ 98 */
99 class Parser { 99 class Parser {
100 final Listener listener; 100 final Listener listener;
101 bool mayParseFunctionExpressions = true; 101 bool mayParseFunctionExpressions = true;
102 final bool enableConditionalDirectives;
102 bool yieldIsKeyword; 103 bool yieldIsKeyword;
103 bool awaitIsKeyword; 104 bool awaitIsKeyword;
104 105
105 Parser(this.listener, 106 Parser(this.listener,
106 {this.yieldIsKeyword: false, this.awaitIsKeyword: false}); 107 {this.enableConditionalDirectives: false,
108 this.yieldIsKeyword: false,
109 this.awaitIsKeyword: false});
107 110
108 Token parseUnit(Token token) { 111 Token parseUnit(Token token) {
109 listener.beginCompilationUnit(token); 112 listener.beginCompilationUnit(token);
110 int count = 0; 113 int count = 0;
111 while (!identical(token.kind, EOF_TOKEN)) { 114 while (!identical(token.kind, EOF_TOKEN)) {
112 token = parseTopLevelDeclaration(token); 115 token = parseTopLevelDeclaration(token);
113 listener.endTopLevelDeclaration(token); 116 listener.endTopLevelDeclaration(token);
114 count++; 117 count++;
115 } 118 }
116 listener.endCompilationUnit(count, token); 119 listener.endCompilationUnit(count, token);
(...skipping 28 matching lines...) Expand all
145 Token libraryKeyword = token; 148 Token libraryKeyword = token;
146 listener.beginLibraryName(libraryKeyword); 149 listener.beginLibraryName(libraryKeyword);
147 assert(optional('library', token)); 150 assert(optional('library', token));
148 token = parseQualified(token.next); 151 token = parseQualified(token.next);
149 Token semicolon = token; 152 Token semicolon = token;
150 token = expect(';', token); 153 token = expect(';', token);
151 listener.endLibraryName(libraryKeyword, semicolon); 154 listener.endLibraryName(libraryKeyword, semicolon);
152 return token; 155 return token;
153 } 156 }
154 157
155 /// import uri (as identifier)? combinator* ';' 158 /// import uri (if (test) uri)* (as identifier)? combinator* ';'
156 Token parseImport(Token token) { 159 Token parseImport(Token token) {
157 Token importKeyword = token; 160 Token importKeyword = token;
158 listener.beginImport(importKeyword); 161 listener.beginImport(importKeyword);
159 assert(optional('import', token)); 162 assert(optional('import', token));
160 token = parseLiteralStringOrRecoverExpression(token.next); 163 token = parseLiteralStringOrRecoverExpression(token.next);
164 token = parseConditionalUris(token);
161 Token deferredKeyword; 165 Token deferredKeyword;
162 if (optional('deferred', token)) { 166 if (optional('deferred', token)) {
163 deferredKeyword = token; 167 deferredKeyword = token;
164 token = token.next; 168 token = token.next;
165 } 169 }
166 Token asKeyword; 170 Token asKeyword;
167 if (optional('as', token)) { 171 if (optional('as', token)) {
168 asKeyword = token; 172 asKeyword = token;
169 token = parseIdentifier(token.next); 173 token = parseIdentifier(token.next);
170 } 174 }
171 token = parseCombinators(token); 175 token = parseCombinators(token);
172 Token semicolon = token; 176 Token semicolon = token;
173 token = expect(';', token); 177 token = expect(';', token);
174 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon); 178 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon);
175 return token; 179 return token;
176 } 180 }
177 181
178 /// export uri combinator* ';' 182 /// if (test) uri
183 Token parseConditionalUris(Token token) {
184 listener.beginConditionalUris(token);
185 int count = 0;
186 if (enableConditionalDirectives) {
187 while (optional('if', token)) {
188 count++;
189 token = parseConditionalUri(token);
190 }
191 }
192 listener.endConditionalUris(count);
193 return token;
194 }
195
196 Token parseConditionalUri(Token token) {
197 listener.beginConditionalUri(token);
198 Token ifKeyword = token;
199 token = expect('if', token);
200 token = expect('(', token);
201 token = parseDottedName(token);
202 Token equalitySign;
203 if (optional('==', token)) {
204 equalitySign = token;
205 token = parseLiteralStringOrRecoverExpression(token.next);
206 }
207 token = expect(')', token);
208 token = parseLiteralStringOrRecoverExpression(token);
209 listener.endConditionalUri(ifKeyword, equalitySign);
210 return token;
211 }
212
213 Token parseDottedName(Token token) {
214 listener.beginDottedName(token);
215 Token firstIdentifier = token;
216 token = parseIdentifier(token);
217 int count = 1;
218 while (optional('.', token)) {
219 token = parseIdentifier(token.next);
220 count++;
221 }
222 listener.endDottedName(count, firstIdentifier);
223 return token;
224 }
225
226 /// export uri conditional-uris* combinator* ';'
179 Token parseExport(Token token) { 227 Token parseExport(Token token) {
180 Token exportKeyword = token; 228 Token exportKeyword = token;
181 listener.beginExport(exportKeyword); 229 listener.beginExport(exportKeyword);
182 assert(optional('export', token)); 230 assert(optional('export', token));
183 token = parseLiteralStringOrRecoverExpression(token.next); 231 token = parseLiteralStringOrRecoverExpression(token.next);
232 token = parseConditionalUris(token);
184 token = parseCombinators(token); 233 token = parseCombinators(token);
185 Token semicolon = token; 234 Token semicolon = token;
186 token = expect(';', token); 235 token = expect(';', token);
187 listener.endExport(exportKeyword, semicolon); 236 listener.endExport(exportKeyword, semicolon);
188 return token; 237 return token;
189 } 238 }
190 239
191 Token parseCombinators(Token token) { 240 Token parseCombinators(Token token) {
192 listener.beginCombinators(token); 241 listener.beginCombinators(token);
193 int count = 0; 242 int count = 0;
(...skipping 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2725 } 2774 }
2726 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2775 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2727 return expectSemicolon(token); 2776 return expectSemicolon(token);
2728 } 2777 }
2729 2778
2730 Token parseEmptyStatement(Token token) { 2779 Token parseEmptyStatement(Token token) {
2731 listener.handleEmptyStatement(token); 2780 listener.handleEmptyStatement(token);
2732 return expectSemicolon(token); 2781 return expectSemicolon(token);
2733 } 2782 }
2734 } 2783 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698