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

Unified Diff: dart/lib/compiler/implementation/scanner/parser.dart

Issue 10911298: Parse new library syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update status file after rebasing. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: dart/lib/compiler/implementation/scanner/parser.dart
diff --git a/dart/lib/compiler/implementation/scanner/parser.dart b/dart/lib/compiler/implementation/scanner/parser.dart
index 8f31c7b262d377287e0392099684deca7e82bd46..3ffe95749e9a7721d38f0638d1b1e4eedd3e9939 100644
--- a/dart/lib/compiler/implementation/scanner/parser.dart
+++ b/dart/lib/compiler/implementation/scanner/parser.dart
@@ -48,11 +48,113 @@ class Parser {
return parseNamedFunctionAlias(token);
} else if (value === '#') {
return parseScriptTags(token);
+ } else if (value === 'library') {
+ return parseLibraryName(token);
+ } else if (value === 'import') {
+ return parseImport(token);
+ } else if (value === 'export') {
+ return parseExport(token);
} else {
return parseTopLevelMember(token);
}
}
+ /// library qualified ';'
+ Token parseLibraryName(Token token) {
+ Token libraryKeyword = token;
+ listener.beginLibraryName(libraryKeyword);
+ assert(optional('library', token));
+ token = parseIdentifier(token.next);
+ while (optional('.', token)) {
+ token = parseQualifiedRest(token);
+ }
+ Token semicolon = token;
+ token = expect(';', token);
+ listener.endLibraryName(libraryKeyword, semicolon);
+ return token;
+ }
+
+ /// import uri (as identifier)? combinator* ';'
+ Token parseImport(Token token) {
+ Token importKeyword = token;
+ listener.beginImport(importKeyword);
+ assert(optional('import', token));
+ token = parseLiteralStringOrRecoverExpression(token.next);
+ Token asKeyword;
+ if (optional('as', token)) {
+ asKeyword = token;
+ token = parseIdentifier(token.next);
+ }
+ token = parseCombinators(token);
+ Token semicolon = token;
+ token = expect(';', token);
+ listener.endImport(importKeyword, asKeyword, semicolon);
+ return token;
+ }
+
+ /// export uri combinator* ';'
+ Token parseExport(Token token) {
+ Token exportKeyword = token;
+ listener.beginExport(exportKeyword);
+ assert(optional('export', token));
+ token = parseLiteralStringOrRecoverExpression(token.next);
+ token = parseCombinators(token);
+ Token semicolon = token;
+ token = expect(';', token);
+ listener.endExport(exportKeyword, semicolon);
+ return token;
+ }
+
+ Token parseCombinators(Token token) {
+ listener.beginCombinators(token);
+ int count = 0;
+ while (true) {
+ String value = token.stringValue;
+ if ('hide' === value) {
+ token = parseHide(token);
+ } else if ('show' === value) {
+ token = parseShow(token);
+ } else {
+ listener.endCombinators(count);
+ return token;
+ }
+ count++;
+ }
+ }
+
+ /// hide identifierList
+ Token parseHide(Token token) {
+ Token hideKeyword = token;
+ listener.beginHide(hideKeyword);
+ assert(optional('hide', token));
+ token = parseIdentifierList(token.next);
+ listener.endHide(hideKeyword);
+ return token;
+ }
+
+ /// show identifierList
+ Token parseShow(Token token) {
+ Token showKeyword = token;
+ listener.beginShow(showKeyword);
+ assert(optional('show', token));
+ token = parseIdentifierList(token.next);
+ listener.endShow(showKeyword);
+ return token;
+ }
+
+ /// identifier (, identifier)*
+ Token parseIdentifierList(Token token) {
+ listener.beginIdentifierList(token);
+ token = parseIdentifier(token);
+ int count = 1;
+ while (optional(',', token)) {
+ token = parseIdentifier(token.next);
+ count++;
+ }
+ listener.endIdentifierList(count);
+ return token;
+ }
+
Token parseMetadataStar(Token token) {
while (optional('@', token)) {
token = parseMetadata(token);
@@ -242,10 +344,17 @@ class Parser {
Token parseQualifiedRestOpt(Token token) {
if (optional('.', token)) {
- Token period = token;
- token = parseIdentifier(token.next);
- listener.handleQualified(period);
+ return parseQualifiedRest(token);
+ } else {
+ return token;
}
+ }
+
+ Token parseQualifiedRest(Token token) {
+ assert(optional('.', token));
+ Token period = token;
+ token = parseIdentifier(token.next);
+ listener.handleQualified(period);
return token;
}
« no previous file with comments | « dart/lib/compiler/implementation/scanner/listener.dart ('k') | dart/lib/compiler/implementation/scanner/scanner_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698