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

Side by Side Diff: utils/css/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/css/tokenkind.dart ('k') | utils/css/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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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('csstool'); 5 #library('csstool');
6 6
7 #import('../../frog/lang.dart', prefix:'lang'); 7 #import('dart:io');
8 #import('../../frog/file_system.dart');
9 #import('../../frog/file_system_node.dart');
10 #import('../../frog/lib/node/node.dart');
11 #import('css.dart'); 8 #import('css.dart');
9 #import('../lib/file_system.dart');
10 #import('../lib/file_system_vm.dart');
11
12 12
13 FileSystem files; 13 FileSystem files;
14 14
15 /** Invokes [callback] and returns how long it took to execute in ms. */ 15 /** Invokes [callback] and returns how long it took to execute in ms. */
16 num time(callback()) { 16 num time(callback()) {
17 final watch = new Stopwatch(); 17 final watch = new Stopwatch();
18 watch.start(); 18 watch.start();
19 callback(); 19 callback();
20 watch.stop(); 20 watch.stop();
21 return watch.elapsedInMs(); 21 return watch.elapsedInMs();
22 } 22 }
23 23
24 printStats(num elapsed, [String filename = '']) { 24 printStats(num elapsed, [String filename = '']) {
25 print('Parsed\033[32m ${filename}\033[0m in ${elapsed} msec.'); 25 print('Parsed ${_GREEN_COLOR}${filename}${_NO_COLOR} in ${elapsed} msec.');
26 } 26 }
27 27
28 /** 28 /**
29 * Run from the `utils/css` directory. 29 * Run from the `utils/css` directory.
30 */ 30 */
31 void main() { 31 void main() {
32 // process.argv[0] == node and process.argv[1] == minfrog 32 var optionArgs = new Options().arguments;
33 assert(process.argv.length == 4); 33 assert(optionArgs.length == 2);
34 34
35 String sourceFullFn = process.argv[2]; 35 String sourceFullFn = optionArgs[0];
36 String outputFullFn = process.argv[3]; 36 String outputFullFn = optionArgs[1];
37 37
38 String sourcePath; 38 String sourcePath;
39 String sourceFilename; 39 String sourceFilename;
40 int idxBeforeFilename = sourceFullFn.lastIndexOf('/'); 40 int idxBeforeFilename = sourceFullFn.lastIndexOf('/');
41 if (idxBeforeFilename >= 0) { 41 if (idxBeforeFilename >= 0) {
42 sourcePath = sourceFullFn.substring(0, idxBeforeFilename + 1); 42 sourcePath = sourceFullFn.substring(0, idxBeforeFilename + 1);
43 sourceFilename = sourceFullFn.substring(idxBeforeFilename + 1); 43 sourceFilename = sourceFullFn.substring(idxBeforeFilename + 1);
44 } 44 }
45 45
46 String outPath; 46 String outPath;
47 idxBeforeFilename = outputFullFn.lastIndexOf('/'); 47 idxBeforeFilename = outputFullFn.lastIndexOf('/');
48 if (idxBeforeFilename >= 0) { 48 if (idxBeforeFilename >= 0) {
49 outPath = outputFullFn.substring(0, idxBeforeFilename + 1); 49 outPath = outputFullFn.substring(0, idxBeforeFilename + 1);
50 } 50 }
51 51
52 initCssWorld(); 52 initCssWorld();
53 53
54 files = new NodeFileSystem(); 54 files = new VMFileSystem();
55 if (!files.fileExists(sourceFullFn)) { 55 if (!files.fileExists(sourceFullFn)) {
56 // Display colored error message if file is missing. 56 // Display colored error message if file is missing.
57 print("\033[31mCSS source file missing - ${sourceFullFn}\033[0m"); 57 print("\033[31mCSS source file missing - ${sourceFullFn}\033[0m");
58 } else { 58 } else {
59 String source = files.readAll(sourceFullFn); 59 String source = files.readAll(sourceFullFn);
60 60
61 Stylesheet stylesheet; 61 Stylesheet stylesheet;
62 62
63 final elapsed = time(() { 63 final elapsed = time(() {
64 Parser parser = new Parser( 64 Parser parser = new Parser(
65 new lang.SourceFile(sourceFullFn, source), 0, files, sourcePath); 65 new SourceFile(sourceFullFn, source), 0, files, sourcePath);
66 stylesheet = parser.parse(); 66 stylesheet = parser.parse();
67 }); 67 });
68 68
69 printStats(elapsed, sourceFullFn); 69 printStats(elapsed, sourceFullFn);
70 70
71 StringBuffer buff = new StringBuffer( 71 StringBuffer buff = new StringBuffer(
72 '/* File generated by SCSS from source ${sourceFilename}\n' + 72 '/* File generated by SCSS from source ${sourceFilename}\n' +
73 ' * Do not edit.\n' + 73 ' * Do not edit.\n' +
74 ' */\n\n'); 74 ' */\n\n');
75 buff.add(stylesheet.toString()); 75 buff.add(stylesheet.toString());
76 76
77 files.writeString(outputFullFn, buff.toString()); 77 files.writeString(outputFullFn, buff.toString());
78 print("Generated file ${outputFullFn}"); 78 print("Generated file ${outputFullFn}");
79 79
80 // Generate CSS.dart file. 80 // Generate CSS.dart file.
81 String genDartClassFile = Generate.dartClass(files, outPath, stylesheet, 81 String genDartClassFile = Generate.dartClass(files, outPath, stylesheet,
82 sourceFilename); 82 sourceFilename);
83 print("Generated file ${genDartClassFile}"); 83 print("Generated file ${genDartClassFile}");
84 } 84 }
85 } 85 }
OLDNEW
« no previous file with comments | « utils/css/tokenkind.dart ('k') | utils/css/tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698