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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: utils/css/generate.dart
diff --git a/utils/css/generate.dart b/utils/css/generate.dart
new file mode 100644
index 0000000000000000000000000000000000000000..18c19909a7ba841cd8e68d19b532408d488453dc
--- /dev/null
+++ b/utils/css/generate.dart
@@ -0,0 +1,92 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class Generate {
nweiz 2012/01/04 19:05:41 A class full of static methods seems like it wants
+
+ // Build up list of all known class selectors in all CSS files.
+ 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
+ for (var selector in ruleset.selectorGroup.selectors) {
+ var selSeqs = selector.simpleSelectorSequences;
+ for (selSeq in selSeqs) {
+ var simpleSelector = selSeq.simpleSelector;
+ if (simpleSelector is ClassSelector) {
+ String className = simpleSelector.name;
+ if (classes.indexOf(className) == -1) { // Class name already known?
+ // No, expose it.
+ classes.add(className);
+ }
+ }
+ }
+ }
+
+ return classes;
+ }
+
+ 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
+ String filename) {
+
+ List<String> knownClasses = [];
nweiz 2012/01/04 19:05:41 Set?
+
+ StringBuffer buff = new StringBuffer(
+ '// File generated by Dart CSS from source file ${filename}\n' +
nweiz 2012/01/04 19:05:41 Style nit: $filename
+ '// Do not edit.\n\n');
+
+ // Emit class for any @stylet directive.
nweiz 2012/01/04 19:05:41 Shouldn't this comment be attached to the StyletDi
+ for (var production in stylesheet._topLevels) {
+ if (production is Directive) {
nweiz 2012/01/04 19:05:41 Looks like you can just check for StyletDirective
+ if (production is StyletDirective) {
+ // TODO(terry): Need safer mechanism for stylets in different files
+ // and stylets with colliding names.
+ buff.add('class ${production.dartClassName} {\n');
+ buff.add(' // selector, properties<propertyName, value>\n');
+ buff.add(' static final selectors = const {\n');
+
+ for (var ruleset in production.rulesets) {
+ for (var selector in ruleset.selectorGroup.selectors) {
nweiz 2012/01/04 19:05:41 I'm having trouble understanding this loop. Why ar
+ var selSeq = selector.simpleSelectorSquences;
nweiz 2012/01/04 19:05:41 s/Squences/Sequences/
+ if (selSeq.length == 1) {
+ buff.add(' \'${selSeq.toString()}\' : const {\n');
nweiz 2012/01/04 19:05:41 $selSeq; toString will be called automatically.
+ }
+ }
+
+ for (var decl in ruleset.declarationGroup.declarations) {
+ buff.add(' \'${decl.property}\' : ' +
+ '\'${decl.expression.toString()}\',\n');
nweiz 2012/01/04 19:05:41 ${decl.expression}
+ }
+ buff.add(' },\n'); // End of declarations for stylet class.
+ }
+ buff.add(' };\n'); // End of static selectors constant.
+ buff.add('}\n\n'); // End of stylet class
+ } else if (production is IncludeDirective) {
+ for (var topLevel in production.styleSheet._topLevels) {
+ if (topLevel is RuleSet) {
+ knownClasses = computeClassSelectors(topLevel, knownClasses);
+ }
+ }
+ }
+ } else if (production is RuleSet) {
+ knownClasses = computeClassSelectors(production, knownClasses);
+ }
+ }
+
+ // Generate all known classes encountered in all processed CSS files.
+ StringBuffer classSelectors = new StringBuffer(
nweiz 2012/01/04 19:05:41 Why is this a separate StringBuffer? Why not use t
+ 'class CSS {\n' +
+ ' // CSS class selectors:\n');
+ for (var className in knownClasses) {
+ String classAsDart = className.replaceAll('-', '_').toUpperCase();
+ classSelectors.add(' static final String ${classAsDart} = ' +
+ '\'${className}\';\n');
+ }
+ classSelectors.add('}\n'); // End of class selectors.
+ buff.add(classSelectors.toString());
+
+ // Write Dart file.
+ String outFile = '${outPath}CSS.dart';
+ files.writeString(outFile, buff.toString());
+
+ return outFile;
+ }
+}
+
« 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