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

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. 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 Token libraryKeyword = token; 145 Token libraryKeyword = token;
146 listener.beginLibraryName(libraryKeyword); 146 listener.beginLibraryName(libraryKeyword);
147 assert(optional('library', token)); 147 assert(optional('library', token));
148 token = parseQualified(token.next); 148 token = parseQualified(token.next);
149 Token semicolon = token; 149 Token semicolon = token;
150 token = expect(';', token); 150 token = expect(';', token);
151 listener.endLibraryName(libraryKeyword, semicolon); 151 listener.endLibraryName(libraryKeyword, semicolon);
152 return token; 152 return token;
153 } 153 }
154 154
155 /// import uri (as identifier)? combinator* ';' 155 /// import uri (if (test) uri)* (as identifier)? combinator* ';'
156 Token parseImport(Token token) { 156 Token parseImport(Token token) {
157 Token importKeyword = token; 157 Token importKeyword = token;
158 listener.beginImport(importKeyword); 158 listener.beginImport(importKeyword);
159 assert(optional('import', token)); 159 assert(optional('import', token));
160 token = parseLiteralStringOrRecoverExpression(token.next); 160 token = parseLiteralStringOrRecoverExpression(token.next);
161 token = parseConditionalUris(token);
161 Token deferredKeyword; 162 Token deferredKeyword;
162 if (optional('deferred', token)) { 163 if (optional('deferred', token)) {
163 deferredKeyword = token; 164 deferredKeyword = token;
164 token = token.next; 165 token = token.next;
165 } 166 }
166 Token asKeyword; 167 Token asKeyword;
167 if (optional('as', token)) { 168 if (optional('as', token)) {
168 asKeyword = token; 169 asKeyword = token;
169 token = parseIdentifier(token.next); 170 token = parseIdentifier(token.next);
170 } 171 }
171 token = parseCombinators(token); 172 token = parseCombinators(token);
172 Token semicolon = token; 173 Token semicolon = token;
173 token = expect(';', token); 174 token = expect(';', token);
174 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon); 175 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon);
175 return token; 176 return token;
176 } 177 }
177 178
179 /// if (test) uri
180 Token parseConditionalUris(Token token) {
181 listener.beginConditionalUris(token);
182 int count = 0;
183 while (optional('if', token)) {
184 count++;
185 token = parseConditionalUri(token);
186 }
187 listener.endConditionalUris(count);
188 return token;
189 }
190
191 Token parseConditionalUri(Token token) {
192 listener.beginConditionalUri(token);
193 Token ifKeyword = token;
194 token = expect('if', token);
195 token = expect('(', token);
196 token = parseDottedName(token);
197 Token equalitySign;
198 if (optional('==', token)) {
199 equalitySign = token;
200 token = parseLiteralStringOrRecoverExpression(token.next);
201 }
202 token = expect(')', token);
203 token = parseLiteralStringOrRecoverExpression(token);
204 listener.endConditionalUri(ifKeyword, equalitySign);
205 return token;
206 }
207
208 Token parseDottedName(Token token) {
209 listener.beginDottedName(token);
210 Token firstIdentifier = token;
211 token = parseIdentifier(token);
212 int count = 1;
213 while (optional('.', token)) {
214 token = parseIdentifier(token.next);
215 count++;
216 }
217 listener.endDottedName(count, firstIdentifier);
218 return token;
219 }
220
178 /// export uri combinator* ';' 221 /// export uri combinator* ';'
Johnni Winther 2015/10/13 08:44:29 Update comment.
floitsch 2015/10/13 21:01:44 Done.
179 Token parseExport(Token token) { 222 Token parseExport(Token token) {
180 Token exportKeyword = token; 223 Token exportKeyword = token;
181 listener.beginExport(exportKeyword); 224 listener.beginExport(exportKeyword);
182 assert(optional('export', token)); 225 assert(optional('export', token));
183 token = parseLiteralStringOrRecoverExpression(token.next); 226 token = parseLiteralStringOrRecoverExpression(token.next);
227 token = parseConditionalUris(token);
184 token = parseCombinators(token); 228 token = parseCombinators(token);
185 Token semicolon = token; 229 Token semicolon = token;
186 token = expect(';', token); 230 token = expect(';', token);
187 listener.endExport(exportKeyword, semicolon); 231 listener.endExport(exportKeyword, semicolon);
188 return token; 232 return token;
189 } 233 }
190 234
191 Token parseCombinators(Token token) { 235 Token parseCombinators(Token token) {
192 listener.beginCombinators(token); 236 listener.beginCombinators(token);
193 int count = 0; 237 int count = 0;
(...skipping 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2725 } 2769 }
2726 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2770 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2727 return expectSemicolon(token); 2771 return expectSemicolon(token);
2728 } 2772 }
2729 2773
2730 Token parseEmptyStatement(Token token) { 2774 Token parseEmptyStatement(Token token) {
2731 listener.handleEmptyStatement(token); 2775 listener.handleEmptyStatement(token);
2732 return expectSemicolon(token); 2776 return expectSemicolon(token);
2733 } 2777 }
2734 } 2778 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698