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

Side by Side Diff: utils/css/test.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 //#import('../file_system.dart');
6
7 #import("dart:dom");
8 #import('css.dart');
9 #import('../../frog/lang.dart', prefix:'lang');
10
11
12 void runCss([bool debug = false, bool parseOnly = false]) {
13 final HTMLTextAreaElement classes = document.getElementById('classes');
14 final HTMLTextAreaElement expression = document.getElementById('expression');
15 final HTMLDivElement result = document.getElementById('result');
16
17 List<String> knownWorld = classes.value.split("\n");
18 List<String> knownClasses = [];
19 List<String> knownIds = [];
20 for (name in knownWorld) {
21 if (name.startsWith('.')) {
22 knownClasses.add(name.substring(1));
23 } else if (name.startsWith('#')) {
24 knownIds.add(name.substring(1));
25 }
26 }
27
28 CssWorld cssWorld = new CssWorld(knownClasses, knownIds);
29 bool templateValid = true;
30 String dumpTree = "";
31
32 String cssExpr = expression.value;
33 if (!debug) {
34 try {
35 cssParseAndValidate(cssExpr, cssWorld);
36 } catch (var cssException) {
37 templateValid = false;
38 dumpTree = cssException.toString();
39 }
40 } else if (parseOnly) {
41 try {
42 Parser parser = new Parser(new lang.SourceFile(
43 lang.SourceFile.IN_MEMORY_FILE, cssExpr));
44 List<SelectorGroup> groups = parser.preprocess();
45 StringBuffer groupTree = new StringBuffer();
46 for (group in groups) {
47 String prettySelector = group.toString();
48 groupTree.add("${prettySelector}\n");
49 groupTree.add("-----\n");
50 groupTree.add(group.toDebugString());
51 }
52 dumpTree = groupTree.toString();
53 } catch (var cssParseException) {
54 templateValid = false;
55 dumpTree = cssParseException.toString();
56 }
57 } else {
58 try {
59 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld);
60 } catch (var cssException) {
61 templateValid = false;
62 dumpTree = cssException.toString();
63 }
64 }
65
66 final var bgcolor = templateValid ? "white" : "red";
67 final var color = templateValid ? "black" : "white";
68 final var valid = templateValid ? "VALID" : "NOT VALID";
69 String resultStyle = 'margin: 0; height: 138px; width: 100%; border: 0; border -top: 1px solid black;';
70 result.innerHTML = '''
71 <div style="font-weight: bold; background-color: $bgcolor; color: $color;">
72 Expression: $cssExpr is $valid
73 </div>
74 <textarea style="$resultStyle">$dumpTree</textarea>
75 ''';
76 }
77
78 void main() {
79 var element = document.createElement('div');
80 element.innerHTML = '''
81 <div style="position: absolute; top: 10px; width: 200px;" align=center>
82 <span style="font-weight:bold;">Classes</span><br/>
83 <textarea id="classes" style="width: 200px; height: 310px;">.foobar\n.xyzz y\n.test\n.dummy\n#myId\n#myStory</textarea>
84 </div>
85 <div style="left: 225px; position: absolute; top: 10px;">
86 <span style="font-weight:bold;">Selector Expression</span><br/>
87 <textarea id="expression" style="width: 400px; height: 100px;"></textarea>
88 <br/>
89 </div>
90 <button onclick="runCss(true, true)" style="position: absolute; left: 430px; top: 135px;">Parse</button>
91 <button onclick="runCss()" style="position: absolute; left: 500px; top: 135p x;">Check</button>
92 <button onclick="runCss(true)" style="position: absolute; left: 570px; top: 135px;">Debug</button>
93 <div style="top: 160px; left: 225px; position: absolute;">
94 <span style="font-weight:bold;">Result</span><br/>
95 <div id="result" style="width: 400px; height: 158px; border: black solid 1 px;"></textarea>
96 </div>
97 ''';
98
99 document.body.appendChild(element);
100
101 // TODO(terry): Needed so runCss isn't shakened out.
102 if (false) {
103 runCss();
104 }
105
106 initCssWorld();
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698