| 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 6ed2657b74a53e158e607f8e2b38a95ab8db671c..c88f20df9519930d39fc782a8d9e41e17899fca2 100644
|
| --- a/pkg/compiler/lib/src/parser/parser.dart
|
| +++ b/pkg/compiler/lib/src/parser/parser.dart
|
| @@ -99,11 +99,14 @@ class FormalParameterType {
|
| class Parser {
|
| final Listener listener;
|
| bool mayParseFunctionExpressions = true;
|
| + final bool enableConditionalDirectives;
|
| bool yieldIsKeyword;
|
| bool awaitIsKeyword;
|
|
|
| Parser(this.listener,
|
| - {this.yieldIsKeyword: false, this.awaitIsKeyword: false});
|
| + {this.enableConditionalDirectives: false,
|
| + this.yieldIsKeyword: false,
|
| + this.awaitIsKeyword: false});
|
|
|
| Token parseUnit(Token token) {
|
| listener.beginCompilationUnit(token);
|
| @@ -152,12 +155,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;
|
| @@ -175,12 +179,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);
|
|
|