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

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: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../common.dart'; 7 import '../common.dart';
8 import '../tokens/keyword.dart' show 8 import '../tokens/keyword.dart' show
9 Keyword; 9 Keyword;
10 import '../tokens/precedence.dart' show 10 import '../tokens/precedence.dart' show
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 * 91 *
92 * Parse methods are generally named parseGrammarProductionSuffix. The 92 * Parse methods are generally named parseGrammarProductionSuffix. The
93 * suffix can be one of "opt", or "star". "opt" means zero or one 93 * suffix can be one of "opt", or "star". "opt" means zero or one
94 * matches, "star" means zero or more matches. For example, 94 * matches, "star" means zero or more matches. For example,
95 * [parseMetadataStar] corresponds to this grammar snippet: [: 95 * [parseMetadataStar] corresponds to this grammar snippet: [:
96 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :]. 96 * metadata* :], and [parseTypeOpt] corresponds to: [: type? :].
97 */ 97 */
98 class Parser { 98 class Parser {
99 final Listener listener; 99 final Listener listener;
100 bool mayParseFunctionExpressions = true; 100 bool mayParseFunctionExpressions = true;
101 final bool enableConditionalDirectives;
101 bool asyncAwaitKeywordsEnabled; 102 bool asyncAwaitKeywordsEnabled;
102 103
103 Parser(this.listener, 104 Parser(this.listener,
104 {this.asyncAwaitKeywordsEnabled: false}); 105 {this.enableConditionalDirectives: false,
106 this.asyncAwaitKeywordsEnabled: false});
105 107
106 Token parseUnit(Token token) { 108 Token parseUnit(Token token) {
107 listener.beginCompilationUnit(token); 109 listener.beginCompilationUnit(token);
108 int count = 0; 110 int count = 0;
109 while (!identical(token.kind, EOF_TOKEN)) { 111 while (!identical(token.kind, EOF_TOKEN)) {
110 token = parseTopLevelDeclaration(token); 112 token = parseTopLevelDeclaration(token);
111 listener.endTopLevelDeclaration(token); 113 listener.endTopLevelDeclaration(token);
112 count++; 114 count++;
113 } 115 }
114 listener.endCompilationUnit(count, token); 116 listener.endCompilationUnit(count, token);
(...skipping 28 matching lines...) Expand all
143 Token libraryKeyword = token; 145 Token libraryKeyword = token;
144 listener.beginLibraryName(libraryKeyword); 146 listener.beginLibraryName(libraryKeyword);
145 assert(optional('library', token)); 147 assert(optional('library', token));
146 token = parseQualified(token.next); 148 token = parseQualified(token.next);
147 Token semicolon = token; 149 Token semicolon = token;
148 token = expect(';', token); 150 token = expect(';', token);
149 listener.endLibraryName(libraryKeyword, semicolon); 151 listener.endLibraryName(libraryKeyword, semicolon);
150 return token; 152 return token;
151 } 153 }
152 154
153 /// import uri (as identifier)? combinator* ';' 155 /// import uri (if (test) uri)* (as identifier)? combinator* ';'
154 Token parseImport(Token token) { 156 Token parseImport(Token token) {
155 Token importKeyword = token; 157 Token importKeyword = token;
156 listener.beginImport(importKeyword); 158 listener.beginImport(importKeyword);
157 assert(optional('import', token)); 159 assert(optional('import', token));
158 token = parseLiteralStringOrRecoverExpression(token.next); 160 token = parseLiteralStringOrRecoverExpression(token.next);
161 token = parseConditionalUris(token);
159 Token deferredKeyword; 162 Token deferredKeyword;
160 if (optional('deferred', token)) { 163 if (optional('deferred', token)) {
161 deferredKeyword = token; 164 deferredKeyword = token;
162 token = token.next; 165 token = token.next;
163 } 166 }
164 Token asKeyword; 167 Token asKeyword;
165 if (optional('as', token)) { 168 if (optional('as', token)) {
166 asKeyword = token; 169 asKeyword = token;
167 token = parseIdentifier(token.next); 170 token = parseIdentifier(token.next);
168 } 171 }
169 token = parseCombinators(token); 172 token = parseCombinators(token);
170 Token semicolon = token; 173 Token semicolon = token;
171 token = expect(';', token); 174 token = expect(';', token);
172 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon); 175 listener.endImport(importKeyword, deferredKeyword, asKeyword, semicolon);
173 return token; 176 return token;
174 } 177 }
175 178
176 /// export uri combinator* ';' 179 /// if (test) uri
180 Token parseConditionalUris(Token token) {
181 listener.beginConditionalUris(token);
182 int count = 0;
183 if (enableConditionalDirectives) {
184 while (optional('if', token)) {
185 count++;
186 token = parseConditionalUri(token);
187 }
188 }
189 listener.endConditionalUris(count);
190 return token;
191 }
192
193 Token parseConditionalUri(Token token) {
194 listener.beginConditionalUri(token);
195 Token ifKeyword = token;
196 token = expect('if', token);
197 token = expect('(', token);
198 token = parseDottedName(token);
199 Token equalitySign;
200 if (optional('==', token)) {
201 equalitySign = token;
202 token = parseLiteralStringOrRecoverExpression(token.next);
203 }
204 token = expect(')', token);
205 token = parseLiteralStringOrRecoverExpression(token);
206 listener.endConditionalUri(ifKeyword, equalitySign);
207 return token;
208 }
209
210 Token parseDottedName(Token token) {
211 listener.beginDottedName(token);
212 Token firstIdentifier = token;
213 token = parseIdentifier(token);
214 int count = 1;
215 while (optional('.', token)) {
216 token = parseIdentifier(token.next);
217 count++;
218 }
219 listener.endDottedName(count, firstIdentifier);
220 return token;
221 }
222
223 /// export uri conditional-uris* combinator* ';'
177 Token parseExport(Token token) { 224 Token parseExport(Token token) {
178 Token exportKeyword = token; 225 Token exportKeyword = token;
179 listener.beginExport(exportKeyword); 226 listener.beginExport(exportKeyword);
180 assert(optional('export', token)); 227 assert(optional('export', token));
181 token = parseLiteralStringOrRecoverExpression(token.next); 228 token = parseLiteralStringOrRecoverExpression(token.next);
229 token = parseConditionalUris(token);
182 token = parseCombinators(token); 230 token = parseCombinators(token);
183 Token semicolon = token; 231 Token semicolon = token;
184 token = expect(';', token); 232 token = expect(';', token);
185 listener.endExport(exportKeyword, semicolon); 233 listener.endExport(exportKeyword, semicolon);
186 return token; 234 return token;
187 } 235 }
188 236
189 Token parseCombinators(Token token) { 237 Token parseCombinators(Token token) {
190 listener.beginCombinators(token); 238 listener.beginCombinators(token);
191 int count = 0; 239 int count = 0;
(...skipping 2542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2734 } 2782 }
2735 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2783 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2736 return expectSemicolon(token); 2784 return expectSemicolon(token);
2737 } 2785 }
2738 2786
2739 Token parseEmptyStatement(Token token) { 2787 Token parseEmptyStatement(Token token) {
2740 listener.handleEmptyStatement(token); 2788 listener.handleEmptyStatement(token);
2741 return expectSemicolon(token); 2789 return expectSemicolon(token);
2742 } 2790 }
2743 } 2791 }
OLDNEW
« 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