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

Unified Diff: dart/frog/leg/scanner/scanner_task.dart

Issue 9309061: Implement script tags. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 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
« no previous file with comments | « dart/frog/leg/resolver.dart ('k') | dart/frog/leg/scanner/scannerlib.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/scanner/scanner_task.dart
diff --git a/dart/frog/leg/scanner/scanner_task.dart b/dart/frog/leg/scanner/scanner_task.dart
index 139da0be3c6ce7f6ce37429788d944d68dd0cdcb..33c02e771517a7f80391ed112b5f7e7464c24043 100644
--- a/dart/frog/leg/scanner/scanner_task.dart
+++ b/dart/frog/leg/scanner/scanner_task.dart
@@ -16,8 +16,27 @@ class ScannerTask extends CompilerTask {
}
void processScriptTags(LibraryElement library) {
- for (ScriptTag tag in library.tags) {
- compiler.reportWarning(tag, "library tags are not implemented");
+ for (ScriptTag tag in library.tags.reverse()) {
+ SourceString argument = tag.argument.value.copyWithoutQuotes(1, 1);
+ Uri cwd = new Uri(scheme: 'file', path: compiler.currentDirectory);
+ Uri base = cwd.resolve(library.script.name.toString());
+ Uri resolved = base.resolve(argument.toString());
+ if (tag.isImport()) {
+ importLibrary(library, loadLibrary(resolved, tag), tag.prefix);
+ } else if (tag.isLibrary()) {
+ if (library.libraryTag !== null) {
+ compiler.cancel("duplicated library declaration", node: tag);
+ } else {
+ library.libraryTag = tag;
+ }
+ } else if (tag.isSource()) {
+ Script script = compiler.readScript(resolved, tag);
+ CompilationUnitElement unit =
+ new CompilationUnitElement(script, library);
+ compiler.withCurrentElement(unit, () => scan(unit));
+ } else {
+ compiler.cancel("illegal script tag: ${tag.tag}", node: tag);
+ }
}
if (library !== compiler.coreLibrary) {
importLibrary(library, compiler.coreLibrary, null);
@@ -46,12 +65,24 @@ class ScannerTask extends CompilerTask {
parser.parseUnit(tokens);
}
+ LibraryElement loadLibrary(Uri uri, ScriptTag node) {
+ bool newLibrary = false;
+ LibraryElement library =
+ compiler.universe.libraries.putIfAbsent(uri.toString(), () {
+ newLibrary = true;
kasperl 2012/02/03 11:51:37 Weird indentation.
ahe 2012/02/03 17:36:19 This is what Dart mode in Emacs does. What would y
kasperl 2012/02/05 07:58:29 I'd much prefer something like this: xxx.yyy.z
sra1 2012/02/05 19:01:38 Emacs is closer to the style guide. Style guide s
+ Script script = compiler.readScript(uri, node);
+ return new LibraryElement(script);
+ });
+ if (newLibrary) {
+ compiler.withCurrentElement(library, () => scan(library));
+ }
+ return library;
+ }
+
void importLibrary(LibraryElement library, LibraryElement imported,
LiteralString prefix) {
if (prefix !== null) {
- withCurrentElement(library, () {
- compiler.cancel("prefixes are not implemented", node: prefix);
- });
+ library.define(new PrefixElement(prefix, imported, library), compiler);
} else {
for (Link<Element> link = imported.topLevelElements; !link.isEmpty();
link = link.tail) {
« no previous file with comments | « dart/frog/leg/resolver.dart ('k') | dart/frog/leg/scanner/scannerlib.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698