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

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

Issue 10911298: Parse new library syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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/listener.dart
diff --git a/dart/lib/compiler/implementation/scanner/listener.dart b/dart/lib/compiler/implementation/scanner/listener.dart
index da74a9c70226cbfc6b9aad571c0db2899cab3d42..648cecbe9ba16e698c8254058f09f9fa313d07ac 100644
--- a/dart/lib/compiler/implementation/scanner/listener.dart
+++ b/dart/lib/compiler/implementation/scanner/listener.dart
@@ -47,6 +47,12 @@ class Listener {
Token endToken) {
}
+ void beginCombinators(Token token) {
+ }
+
+ void endCombinators(int count) {
+ }
+
void beginDoWhileStatement(Token token) {
}
@@ -54,6 +60,12 @@ class Listener {
Token endToken) {
}
+ void beginExport(Token token) {
+ }
+
+ void endExport(Token exportKeyword, Token semicolon) {
+ }
+
void beginExpressionStatement(Token token) {
}
@@ -137,12 +149,30 @@ class Listener {
void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
}
+ void beginHide(Token hideKeyword) {
+ }
+
+ void endHide(Token hideKeyword) {
+ }
+
+ void beginIdentifierList(Token token) {
+ }
+
+ void endIdentifierList(int count) {
+ }
+
void beginIfStatement(Token token) {
}
void endIfStatement(Token ifToken, Token elseToken) {
}
+ void beginImport(Token importKeyword) {
+ }
+
+ void endImport(Token importKeyword, Token asKeyword, Token semicolon) {
+ }
+
void beginInitializedIdentifier(Token token) {
}
@@ -180,6 +210,12 @@ class Listener {
void endLabeledStatement(int labelCount) {
}
+ void beginLibraryName(Token token) {
+ }
+
+ void endLibraryName(Token libraryKeyword, Token semicolon) {
+ }
+
void beginLiteralMapEntry(Token token) {
}
@@ -233,6 +269,12 @@ class Listener {
void endSend(Token token) {
}
+ void beginShow(Token showKeyword) {
+ }
+
+ void endShow(Token showKeyword) {
+ }
+
void beginSwitchStatement(Token token) {
}
@@ -569,29 +611,75 @@ class ElementListener extends Listener {
return node;
}
- bool allowScriptTags() {
+ bool allowLibraryTags() {
// Script tags are only allowed in the library file itself, not in
Lasse Reichstein Nielsen 2012/09/14 09:36:09 Script -> Library?
ahe 2012/09/14 12:13:53 Done.
// sourced files.
LibraryElement library = compilationUnitElement.getLibrary();
- return library.entryCompilationUnit == compilationUnitElement;
+ return compilationUnitElement.localMembers.isEmpty()
+ && library.entryCompilationUnit == compilationUnitElement;
+ }
+
+ void endLibraryName(Token libraryKeyword, Token semicolon) {
+ Expression name = popNode();
+ addLibraryTag(new LibraryName(libraryKeyword, name));
+ }
+
+ void endImport(Token importKeyword, Token asKeyword, Token semicolon) {
+ NodeList combinators = popNode();
+ Identifier prefix;
+ if (asKeyword !== null) {
+ prefix = popNode();
+ }
+ LiteralString uri = popLiteralString();
+ addLibraryTag(new Import(importKeyword, uri, prefix, combinators));
+ }
+
+ void endExport(Token exportKeyword, Token semicolon) {
+ NodeList combinators = popNode();
+ LiteralString uri = popNode();
+ addLibraryTag(new Export(exportKeyword, uri, combinators));
+ }
+
+ void endCombinators(int count) {
+ if (0 == count) {
+ pushNode(null);
+ } else {
+ pushNode(makeNodeList(count, null, null, " "));
+ }
+ }
+
+ void endHide(Token hideKeyword) {
+ recoverableError('hide is not implemented', token: hideKeyword);
+ // TODO(ahe): Do not ignore.
+ }
+
+ void endShow(Token showKeyword) {
+ recoverableError('show is not implemented', token: showKeyword);
+ // TODO(ahe): Do not ignore.
+ }
+
+ void endIdentifierList(int count) {
+ pushNode(makeNodeList(count, null, null, " "));
}
void endScriptTag(bool hasPrefix, Token beginToken, Token endToken) {
- StringNode prefix = null;
+ LiteralString prefix = null;
Identifier argumentName = null;
if (hasPrefix) {
prefix = popLiteralString();
argumentName = popNode();
}
- StringNode firstArgument = popLiteralString();
+ LiteralString firstArgument = popLiteralString();
Identifier tag = popNode();
- if (!allowScriptTags()) {
- // Only allow script tags in the entry compilation unit.
- listener.cancel("script tags not allowed here", node: tag);
- }
ScriptTag scriptTag = new ScriptTag(tag, firstArgument, argumentName,
prefix, beginToken, endToken);
- addScriptTag(scriptTag);
+ if (const SourceString('import') == tag.source ||
+ const SourceString('source') == tag.source ||
+ const SourceString('library') == tag.source) {
+ addScriptTag(scriptTag);
+ } else {
+ recoverableError('unknown tag: ${tag.source.slowToString()}', node: tag);
+ }
}
void endMetadata(Token beginToken, Token endToken) {
@@ -853,6 +941,14 @@ class ElementListener extends Listener {
}
void addScriptTag(ScriptTag tag) {
+ // TODO(ahe): Remove this method.
+ addLibraryTag(tag.toLibraryTag());
+ }
+
+ void addLibraryTag(LibraryTag tag) {
+ if (!allowLibraryTags()) {
+ recoverableError('library tags not allowed here', node: tag);
+ }
compilationUnitElement.getLibrary().addTag(tag, listener);
Lasse Reichstein Nielsen 2012/09/14 09:36:09 Why is this not using addLibraryTag?
ahe 2012/09/14 12:13:53 This is the implementation of addLibraryTag.
}

Powered by Google App Engine
This is Rietveld 408576698