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

Side by Side Diff: utils/css/generate.dart

Issue 8937017: New CSS parser written in Dart to replace pyparser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Put back for DartC Created 9 years 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
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 class Generate {
nweiz 2012/01/04 19:05:41 A class full of static methods seems like it wants
6
7 // Build up list of all known class selectors in all CSS files.
8 static List<String> computeClassSelectors(RuleSet ruleset, classes) {
nweiz 2012/01/04 19:05:41 Shouldn't this be a Set rather than a List? That w
9 for (var selector in ruleset.selectorGroup.selectors) {
10 var selSeqs = selector.simpleSelectorSequences;
11 for (selSeq in selSeqs) {
12 var simpleSelector = selSeq.simpleSelector;
13 if (simpleSelector is ClassSelector) {
14 String className = simpleSelector.name;
15 if (classes.indexOf(className) == -1) { // Class name already known?
16 // No, expose it.
17 classes.add(className);
18 }
19 }
20 }
21 }
22
23 return classes;
24 }
25
26 static dartClass(FileSystem files, String outPath, Stylesheet stylesheet,
nweiz 2012/01/04 19:05:41 This should either list the return type or not ret
27 String filename) {
28
29 List<String> knownClasses = [];
nweiz 2012/01/04 19:05:41 Set?
30
31 StringBuffer buff = new StringBuffer(
32 '// File generated by Dart CSS from source file ${filename}\n' +
nweiz 2012/01/04 19:05:41 Style nit: $filename
33 '// Do not edit.\n\n');
34
35 // Emit class for any @stylet directive.
nweiz 2012/01/04 19:05:41 Shouldn't this comment be attached to the StyletDi
36 for (var production in stylesheet._topLevels) {
37 if (production is Directive) {
nweiz 2012/01/04 19:05:41 Looks like you can just check for StyletDirective
38 if (production is StyletDirective) {
39 // TODO(terry): Need safer mechanism for stylets in different files
40 // and stylets with colliding names.
41 buff.add('class ${production.dartClassName} {\n');
42 buff.add(' // selector, properties<propertyName, value>\n');
43 buff.add(' static final selectors = const {\n');
44
45 for (var ruleset in production.rulesets) {
46 for (var selector in ruleset.selectorGroup.selectors) {
nweiz 2012/01/04 19:05:41 I'm having trouble understanding this loop. Why ar
47 var selSeq = selector.simpleSelectorSquences;
nweiz 2012/01/04 19:05:41 s/Squences/Sequences/
48 if (selSeq.length == 1) {
49 buff.add(' \'${selSeq.toString()}\' : const {\n');
nweiz 2012/01/04 19:05:41 $selSeq; toString will be called automatically.
50 }
51 }
52
53 for (var decl in ruleset.declarationGroup.declarations) {
54 buff.add(' \'${decl.property}\' : ' +
55 '\'${decl.expression.toString()}\',\n');
nweiz 2012/01/04 19:05:41 ${decl.expression}
56 }
57 buff.add(' },\n'); // End of declarations for stylet class.
58 }
59 buff.add(' };\n'); // End of static selectors constant.
60 buff.add('}\n\n'); // End of stylet class
61 } else if (production is IncludeDirective) {
62 for (var topLevel in production.styleSheet._topLevels) {
63 if (topLevel is RuleSet) {
64 knownClasses = computeClassSelectors(topLevel, knownClasses);
65 }
66 }
67 }
68 } else if (production is RuleSet) {
69 knownClasses = computeClassSelectors(production, knownClasses);
70 }
71 }
72
73 // Generate all known classes encountered in all processed CSS files.
74 StringBuffer classSelectors = new StringBuffer(
nweiz 2012/01/04 19:05:41 Why is this a separate StringBuffer? Why not use t
75 'class CSS {\n' +
76 ' // CSS class selectors:\n');
77 for (var className in knownClasses) {
78 String classAsDart = className.replaceAll('-', '_').toUpperCase();
79 classSelectors.add(' static final String ${classAsDart} = ' +
80 '\'${className}\';\n');
81 }
82 classSelectors.add('}\n'); // End of class selectors.
83 buff.add(classSelectors.toString());
84
85 // Write Dart file.
86 String outFile = '${outPath}CSS.dart';
87 files.writeString(outFile, buff.toString());
88
89 return outFile;
90 }
91 }
92
OLDNEW
« no previous file with comments | « utils/css/cssworld.dart ('k') | utils/css/parser.dart » ('j') | utils/css/parser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698