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

Unified 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: Update and fix status files. Implement missing functions. Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/parser/listener.dart ('k') | pkg/compiler/lib/src/parser/parser_task.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/parser/parser.dart
diff --git a/pkg/compiler/lib/src/parser/parser.dart b/pkg/compiler/lib/src/parser/parser.dart
index 942e121cf718045a5c552f5d3c18de42b64af2f4..f2e0577937e91946b398e1e8040ae978ff95a8ae 100644
--- a/pkg/compiler/lib/src/parser/parser.dart
+++ b/pkg/compiler/lib/src/parser/parser.dart
@@ -98,10 +98,12 @@ class FormalParameterType {
class Parser {
final Listener listener;
bool mayParseFunctionExpressions = true;
+ final bool enableConditionalDirectives;
bool asyncAwaitKeywordsEnabled;
Parser(this.listener,
- {this.asyncAwaitKeywordsEnabled: false});
+ {this.enableConditionalDirectives: false,
+ this.asyncAwaitKeywordsEnabled: false});
Token parseUnit(Token token) {
listener.beginCompilationUnit(token);
@@ -150,12 +152,13 @@ class Parser {
return token;
}
- /// import uri (as identifier)? combinator* ';'
+ /// import uri (if (test) uri)* (as identifier)? combinator* ';'
Token parseImport(Token token) {
Token importKeyword = token;
listener.beginImport(importKeyword);
assert(optional('import', token));
token = parseLiteralStringOrRecoverExpression(token.next);
+ token = parseConditionalUris(token);
Token deferredKeyword;
if (optional('deferred', token)) {
deferredKeyword = token;
@@ -173,12 +176,57 @@ class Parser {
return token;
}
- /// export uri combinator* ';'
+ /// if (test) uri
+ Token parseConditionalUris(Token token) {
+ listener.beginConditionalUris(token);
+ int count = 0;
+ if (enableConditionalDirectives) {
+ while (optional('if', token)) {
+ count++;
+ token = parseConditionalUri(token);
+ }
+ }
+ listener.endConditionalUris(count);
+ return token;
+ }
+
+ Token parseConditionalUri(Token token) {
+ listener.beginConditionalUri(token);
+ Token ifKeyword = token;
+ token = expect('if', token);
+ token = expect('(', token);
+ token = parseDottedName(token);
+ Token equalitySign;
+ if (optional('==', token)) {
+ equalitySign = token;
+ token = parseLiteralStringOrRecoverExpression(token.next);
+ }
+ token = expect(')', token);
+ token = parseLiteralStringOrRecoverExpression(token);
+ listener.endConditionalUri(ifKeyword, equalitySign);
+ return token;
+ }
+
+ Token parseDottedName(Token token) {
+ listener.beginDottedName(token);
+ Token firstIdentifier = token;
+ token = parseIdentifier(token);
+ int count = 1;
+ while (optional('.', token)) {
+ token = parseIdentifier(token.next);
+ count++;
+ }
+ listener.endDottedName(count, firstIdentifier);
+ return token;
+ }
+
+ /// export uri conditional-uris* combinator* ';'
Token parseExport(Token token) {
Token exportKeyword = token;
listener.beginExport(exportKeyword);
assert(optional('export', token));
token = parseLiteralStringOrRecoverExpression(token.next);
+ token = parseConditionalUris(token);
token = parseCombinators(token);
Token semicolon = token;
token = expect(';', token);
« no previous file with comments | « pkg/compiler/lib/src/parser/listener.dart ('k') | pkg/compiler/lib/src/parser/parser_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698