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

Side by Side Diff: utils/template/tool.dart

Issue 9695048: Template parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Siggi's comments Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/template/tokenkind.dart ('k') | utils/template/tree.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 #library('templatetool');
6
7 #import('dart:io');
8 #import('template.dart');
9 #import('../lib/file_system.dart');
10 #import('../lib/file_system_vm.dart');
11
12
13 FileSystem files;
14
15 /** Invokes [callback] and returns how long it took to execute in ms. */
16 num time(callback()) {
17 final watch = new Stopwatch();
18 watch.start();
19 callback();
20 watch.stop();
21 return watch.elapsedInMs();
22 }
23
24 String GREEN_COLOR = '\u001b[32m';
25 String NO_COLOR = '\u001b[0m';
26
27 printStats(String phase, num elapsed, [String filename = '']) {
28 print('${phase} ${GREEN_COLOR}${filename}${NO_COLOR} in ${elapsed} msec.');
29 }
30
31 /**
32 * Run from the `utils/css` directory.
33 */
34 void main() {
35 // argument 0 - sourcefile full path
36 // argument 1 - outputfile full path
37 var optionArgs = new Options().arguments;
38
39 String sourceFullFn = optionArgs[0];
40 String outputFullFn = optionArgs[1];
41
42 String sourcePath;
43 String sourceFilename;
44 int idxBeforeFilename = sourceFullFn.lastIndexOf('/');
45 if (idxBeforeFilename >= 0) {
46 sourcePath = sourceFullFn.substring(0, idxBeforeFilename + 1);
47 sourceFilename = sourceFullFn.substring(idxBeforeFilename + 1);
48 }
49
50 String outPath;
51 String outFilename;
52 idxBeforeFilename = outputFullFn.lastIndexOf('/');
53 if (idxBeforeFilename >= 0) {
54 outPath = outputFullFn.substring(0, idxBeforeFilename + 1);
55 outFilename = outputFullFn.substring(idxBeforeFilename + 1);
56 }
57
58 if (sourceFilename.length == 0 || outFilename.length == 0) {
59 print("Unknown command:\r");
60 print(" Format: sourcefile outputfile [--options]");
61 print(" outputfile - template file filename.tmpl");
62 print(" outputfile - generated dart source file filename.dart");
63 return;
64 }
65
66 // files = new NodeFileSystem();
67 files = new VMFileSystem();
68
69 // TODO(terry): Cleanup options handling need common options between template
70 // and CSS parsers also cleanup above cruft.
71
72 // TODO(terry): Pass on switches.
73 var args = [];
74 parseOptions(args, files);
75
76 initHtmlWorld(false);
77
78 if (!files.fileExists(sourceFullFn)) {
79 // Display colored error message if file is missing.
80 print(world.fatal("CSS source file missing - ${sourceFullFn}"));
81 } else {
82
83 String source = files.readAll(sourceFullFn);
84
85 List<Template> templates;
86 final parsedElapsed = time(() {
87 templates = templateParseAndValidate(source);
88 });
89
90 StringBuffer code = new StringBuffer();
91
92 num codegenElapsed;
93 if (world.errors == 0) {
94 // Generate the Dart class(es) for all template(s).
95 codegenElapsed = time(() {
96 code.add(Codegen.generate(templates, outFilename));
97 });
98 }
99
100 printStats("Parsed", parsedElapsed, sourceFullFn);
101 printStats("Codegen", codegenElapsed, sourceFullFn);
102
103 final outputElapsed = time(() {
104 files.writeString(outputFullFn, code.toString());
105 });
106
107 printStats("Wrote file", codegenElapsed, outputFullFn);
108 }
109 }
OLDNEW
« no previous file with comments | « utils/template/tokenkind.dart ('k') | utils/template/tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698