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

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

Issue 8498020: Beginning of CSS parser using frog parsering infrastructure. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added Jim's CR comments and updated tests. Created 9 years, 1 month 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/parser.dart ('k') | utils/css/tokenizer.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 //#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 classes = document.getElementById('classes');
14 final expression = document.getElementById('expression');
15 final 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 {
41 if (parseOnly) {
42 try {
43 Parser parser = new Parser(new lang.SourceFile(
44 lang.SourceFile.IN_MEMORY_FILE, cssExpr));
45 List<SelectorGroup> groups = parser.expression();
46 StringBuffer groupTree = new StringBuffer();
47 for (group in groups) {
48 String prettySelector = group.toString();
49 groupTree.add("${prettySelector}\n");
50 groupTree.add("-----\n");
51 groupTree.add(group.toDebugString());
52 }
53 dumpTree = groupTree.toString();
54 } catch (var cssParseException) {
55 templateValid = false;
56 dumpTree = cssParseException.toString();
57 }
58 } else {
59 try {
60 dumpTree = cssParseAndValidateDebug(cssExpr, cssWorld);
61 } catch (var cssException) {
62 templateValid = false;
63 dumpTree = cssException.toString();
64 }
65 }
66 }
67
68 final String bgcolor = templateValid ? "white" : "red";
jimhug 2011/11/17 16:49:27 Nit: The String type is not needed for a final dec
69 final String color = templateValid ? "black" : "white";
70 final String valid = templateValid ? "VALID" : "NOT VALID";
71 String resultStyle = 'margin: 0; height: 138px; width: 100%; border: 0; border -top: 1px solid black;';
72 result.innerHTML = '''
73 <div style="font-weight: bold; background-color: $bgcolor; color: $color;">
74 Expression: $cssExpr is $valid
75 </div>
76 <textarea style="$resultStyle">$dumpTree</textarea>
77 ''';
78 }
79
80 void main() {
81 var element = document.createElement('div');
82 element.innerHTML = '''
83 <div style="position: absolute; top: 10px; width: 200px;" align=center>
84 <span style="font-weight:bold;">Classes</span><br/>
85 <textarea id="classes" style="width: 200px; height: 310px;">.foobar\n.xyzz y\n.test\n.dummy\n#myId\n#myStory</textarea>
86 </div>
87 <div style="left: 225px; position: absolute; top: 10px;">
88 <span style="font-weight:bold;">Selector Expression</span><br/>
89 <textarea id="expression" style="width: 400px; height: 100px;"></textarea>
90 <br/>
91 </div>
92 <button onclick="runCss(true, true)" style="position: absolute; left: 430px; top: 135px;">Parse</button>
93 <button onclick="runCss()" style="position: absolute; left: 500px; top: 135p x;">Check</button>
94 <button onclick="runCss(true)" style="position: absolute; left: 570px; top: 135px;">Debug</button>
95 <div style="top: 160px; left: 225px; position: absolute;">
96 <span style="font-weight:bold;">Result</span><br/>
97 <div id="result" style="width: 400px; height: 158px; border: black solid 1 px;"></textarea>
98 </div>
99 ''';
100
101 document.body.appendChild(element);
102
103 // TODO(terry): Needed so runCss isn't shakened out.
104 if (false) {
105 runCss();
106 }
107
108 initCssWorld();
109 }
OLDNEW
« no previous file with comments | « utils/css/parser.dart ('k') | utils/css/tokenizer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698