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); |