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

Side by Side Diff: utils/css/tree.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
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 // Generated by scripts/tree_gen.py. 4 // Generated by scripts/tree_gen.py.
5 5
6 ///////////////////////////////////////////////////////////////////////// 6 /////////////////////////////////////////////////////////////////////////
7 // CSS specific types: 7 // CSS specific types:
8 ///////////////////////////////////////////////////////////////////////// 8 /////////////////////////////////////////////////////////////////////////
9 9
10 10
11 class Identifier extends lang.Node { 11 class Identifier extends lang.Node {
12 String name; 12 String name;
13 13
14 Identifier(this.name, lang.SourceSpan span): super(span) {} 14 Identifier(this.name, lang.SourceSpan span): super(span);
15 15
16 visit(TreeVisitor visitor) => visitor.visitIdentifier(this); 16 visit(TreeVisitor visitor) => visitor.visitIdentifier(this);
17 17
18 String toString() => name; 18 String toString() => name;
19 } 19 }
20 20
21 class Wildcard extends lang.Node { 21 class Wildcard extends lang.Node {
22 Wildcard(lang.SourceSpan span): super(span); 22 Wildcard(lang.SourceSpan span): super(span);
23 23
24 visit(TreeVisitor visitor) => visitor.visitWildcard(this); 24 visit(TreeVisitor visitor) => visitor.visitWildcard(this);
25 25
26 String toString() => '*'; 26 String toString() => '*';
27 } 27 }
28 28
29 // /* .... */
30 class Comment extends lang.Node {
31 String comment;
32
33 Comment(this.comment, lang.SourceSpan span): super(span);
34
35 visit(TreeVisitor visitor) => visitor.visitComment(this);
36
37 String toString() => '/* ${comment} */';
38 }
39
40 // CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->).
41 class CommentDefinition extends Comment {
42 CommentDefinition(String comment, lang.SourceSpan span): super(comment, span);
43
44 visit(TreeVisitor visitor) => visitor.visitCommentDefinition(this);
45
46 String toString() => '<!-- ${comment} -->';
47 }
48
29 class SelectorGroup extends lang.Node { 49 class SelectorGroup extends lang.Node {
30 // List of SimpleSelector(s) list contain any mix SimpleSelector or 50 List<Selector> _selectors;
31 // SimpleSlectorName (or class derived from SimpleSelectorName e.g.,
32 // IdSelector, ClassSelector, ElementSelector, PseudoClassSelector,
33 // PseudoElementSelector, NotSelector, or Attribute
34 List<SimpleSelector> selectors;
35 51
36 SelectorGroup(this.selectors, lang.SourceSpan span): super(span); 52 SelectorGroup(this._selectors, lang.SourceSpan span): super(span);
53
54 List<Selector> get selectors() => _selectors;
37 55
38 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this); 56 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this);
39 57
40 String toString() { 58 String toString() {
41 StringBuffer buff = new StringBuffer(); 59 StringBuffer buff = new StringBuffer();
42 for (selector in selectors) { 60 int idx = 0;
43 if (selector.isCombinatorDescendant()) { 61 for (var selector in _selectors) {
44 buff.add(' '); 62 if (idx++ > 0) {
45 } else if (selector.isCombinatorPlus()) { 63 buff.add(', ');
46 buff.add(' + ');
47 } else if (selector.isCombinatorGreater()) {
48 buff.add(' > ');
49 } else if (selector.isCombinatorTilde()) {
50 buff.add(' ~ ');
51 } 64 }
52 buff.add(selector.toString()); 65 buff.add(selector.toString());
53 } 66 }
54 return buff.toString(); 67 return buff.toString();
55 } 68 }
56 69
57 /** A multiline string showing the node and its children. */ 70 /** A multiline string showing the node and its children. */
58 String toDebugString() { 71 String toDebugString() {
59 var to = new lang.TreeOutput(); 72 var to = new lang.TreeOutput();
60 var tp = new TreePrinter(to); 73 var tp = new TreePrinter(to);
61 this.visit(tp); 74 this.visit(tp);
62 return to.buf.toString(); 75 return to.buf.toString();
63 } 76 }
64 } 77 }
65 78
79 class Selector extends lang.Node {
80 List<SimpleSelectorSequence> _simpleSelectorSequences;
81
82 Selector(this._simpleSelectorSequences, lang.SourceSpan span) : super(span);
83
84 List<SimpleSelectorSequence> get simpleSelectorSequences() =>
85 _simpleSelectorSequences;
86
87 add(SimpleSelectorSequence seq) => _simpleSelectorSequences.add(seq);
88
89 List<SimpleSelectorSequence> get simpleSelectorSquences() =>
90 _simpleSelectorSequences;
91
92 int get length() => _simpleSelectorSequences.length;
93
94 String toString() {
95 StringBuffer buff = new StringBuffer();
96 for (_simpleSelectorSequence in _simpleSelectorSequences) {
97 buff.add(_simpleSelectorSequence.toString());
98 }
99 return buff.toString();
100 }
101
102 visit(TreeVisitor visitor) => visitor.visitSelector(this);
103 }
104
105 class SimpleSelectorSequence extends lang.Node {
106 int _combinator; // +, >, ~, NONE
107 SimpleSelector _selector;
108
109 SimpleSelectorSequence(this._selector, lang.SourceSpan span,
110 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span);
111
112 get simpleSelector() => _selector;
113
114 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE;
115 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS;
116 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER;
117 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE;
118 bool isCombinatorDescendant() =>
119 _combinator == TokenKind.COMBINATOR_DESCENDANT;
120
121 String _combinatorToString() =>
122 isCombinatorDescendant() ? ' ' :
123 isCombinatorPlus() ? '+' :
124 isCombinatorGreater() ? '>' :
125 isCombinatorTilde() ? '~' : '';
126
127 visit(TreeVisitor visitor) => visitor.visitSimpleSelectorSequence(this);
128
129 String toString() => _combinatorToString() + _selector.toString();
130 }
131
66 /* All other selectors (element, #id, .class, attribute, pseudo, negation, 132 /* All other selectors (element, #id, .class, attribute, pseudo, negation,
67 * namespace, *) are derived from this selector. 133 * namespace, *) are derived from this selector.
68 */ 134 */
69 class SimpleSelector extends lang.Node { 135 class SimpleSelector extends lang.Node {
70 int _combinator; // +, >, ~ or descendant (space), and NONE
71 var _name; 136 var _name;
72 137
73 SimpleSelector(this._name, lang.SourceSpan span, 138 SimpleSelector(this._name, lang.SourceSpan span) : super(span);
74 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span);
75 139
76 // Name can be an Identifier or WildCard we'll return either the name or '*'. 140 // Name can be an Identifier or WildCard we'll return either the name or '*'.
77 String get name() => isWildcard() ? '*' : _name.name; 141 String get name() => isWildcard() ? '*' : _name.name;
78 142
79 bool isWildcard() => _name is Wildcard; 143 bool isWildcard() => _name is Wildcard;
80 144
81 // TODO(terry): Kind of hacky to reset combinator to NONE
82 void resetCombinatorNone() {
83 assert(isCombinatorDescendant());
84 _combinator = TokenKind.COMBINATOR_NONE;
85 }
86
87 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE;
88 bool isCombinatorDescendant() =>
89 _combinator == TokenKind.COMBINATOR_DESCENDANT;
90 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS;
91 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER;
92 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE;
93
94 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this); 145 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this);
95 146
96 String toString() => name; 147 String toString() => name;
97 } 148 }
98 149
99 // element name 150 // element name
100 class ElementSelector extends SimpleSelector { 151 class ElementSelector extends SimpleSelector {
101 ElementSelector(var name, lang.SourceSpan span, 152 ElementSelector(var name, lang.SourceSpan span) : super(name, span);
102 [int combinator = TokenKind.COMBINATOR_NONE]) :
103 super(name, span, combinator);
104 153
105 visit(TreeVisitor visitor) => visitor.visitElementSelector(this); 154 visit(TreeVisitor visitor) => visitor.visitElementSelector(this);
106 155
107 String toString() => "$name"; 156 String toString() => "$name";
108 157
109 /** A multiline string showing the node and its children. */ 158 /** A multiline string showing the node and its children. */
110 String toDebugString() { 159 String toDebugString() {
111 var to = new lang.TreeOutput(); 160 var to = new lang.TreeOutput();
112 var tp = new TreePrinter(to); 161 var tp = new TreePrinter(to);
113 this.visit(tp); 162 this.visit(tp);
114 return to.buf.toString(); 163 return to.buf.toString();
115 } 164 }
116 } 165 }
117 166
118 // namespace|element 167 // namespace|element
119 class NamespaceSelector extends SimpleSelector { 168 class NamespaceSelector extends SimpleSelector {
120 var _namespace; // null, Wildcard or Identifier 169 var _namespace; // null, Wildcard or Identifier
121 170
122 NamespaceSelector(this._namespace, var name, lang.SourceSpan span, 171 NamespaceSelector(this._namespace, var name, lang.SourceSpan span) :
123 [int combinator = TokenKind.COMBINATOR_NONE]) : 172 super(name, span);
124 super(name, span, combinator);
125 173
126 String get namespace() => _namespace is Wildcard ? '*' : _namespace.name; 174 String get namespace() => _namespace is Wildcard ? '*' : _namespace.name;
127 175
128 bool isNamespaceWildcard() => _namespace is Wildcard; 176 bool isNamespaceWildcard() => _namespace is Wildcard;
129 177
130 SimpleSelector get nameAsSimpleSelector() => _name; 178 SimpleSelector get nameAsSimpleSelector() => _name;
131 179
132 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this); 180 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this);
133 181
134 String toString() => "$namespace|$nameAsSimpleSelector"; 182 String toString() => "$namespace|$nameAsSimpleSelector";
135 } 183 }
136 184
185 // [attr op value]
186 class AttributeSelector extends SimpleSelector {
187 int _op;
188 var _value;
189
190 AttributeSelector(Identifier name, this._op, this._value,
191 lang.SourceSpan span) : super(name, span);
192
193 String matchOperator() {
194 switch (_op) {
195 case TokenKind.EQUALS:
196 return '=';
197 case TokenKind.INCLUDES:
198 return '~=';
199 case TokenKind.DASH_MATCH:
200 return '|=';
201 case TokenKind.PREFIX_MATCH:
202 return '^=';
203 case TokenKind.SUFFIX_MATCH:
204 return '\$=';
205 case TokenKind.SUBSTRING_MATCH:
206 return '*=';
207 }
208 }
209
210 // Return the TokenKind for operator used by visitAttributeSelector.
211 String matchOperatorAsTokenString() {
212 switch (_op) {
213 case TokenKind.EQUALS:
214 return 'EQUALS';
215 case TokenKind.INCLUDES:
216 return 'INCLUDES';
217 case TokenKind.DASH_MATCH:
218 return 'DASH_MATCH';
219 case TokenKind.PREFIX_MATCH:
220 return 'PREFIX_MATCH';
221 case TokenKind.SUFFIX_MATCH:
222 return 'SUFFIX_MATCH';
223 case TokenKind.SUBSTRING_MATCH:
224 return 'SUBSTRING_MATCH';
225 }
226 }
227
228 String valueToString() {
229 if (_value is Identifier) {
230 return _value.name;
231 } else {
232 return '"${_value}"';
233 }
234 }
235
236 visit(TreeVisitor visitor) => visitor.visitAttributeSelector(this);
237
238 String toString() => "[${name} ${matchOperator()} ${valueToString()}]";
239 }
240
137 // #id 241 // #id
138 class IdSelector extends SimpleSelector { 242 class IdSelector extends SimpleSelector {
139 IdSelector(Identifier name, lang.SourceSpan span, 243 IdSelector(Identifier name, lang.SourceSpan span) : super(name, span);
140 [int combinator = TokenKind.COMBINATOR_NONE]) :
141 super(name, span, combinator);
142 244
143 visit(TreeVisitor visitor) => visitor.visitIdSelector(this); 245 visit(TreeVisitor visitor) => visitor.visitIdSelector(this);
144 246
145 String toString() => "#$name"; 247 String toString() => "#$name";
146 } 248 }
147 249
148 // .class 250 // .class
149 class ClassSelector extends SimpleSelector { 251 class ClassSelector extends SimpleSelector {
150 ClassSelector(Identifier name, lang.SourceSpan span, 252 ClassSelector(Identifier name, lang.SourceSpan span) : super(name, span);
151 [int combinator = TokenKind.COMBINATOR_NONE]) :
152 super(name, span, combinator);
153 253
154 visit(TreeVisitor visitor) => visitor.visitClassSelector(this); 254 visit(TreeVisitor visitor) => visitor.visitClassSelector(this);
155 255
156 String toString() => ".$name"; 256 String toString() => ".$name";
157 } 257 }
158 258
159 // :pseudoClass 259 // :pseudoClass
160 class PseudoClassSelector extends SimpleSelector { 260 class PseudoClassSelector extends SimpleSelector {
161 PseudoClassSelector(Identifier name, lang.SourceSpan span, 261 PseudoClassSelector(Identifier name, lang.SourceSpan span) :
162 [int combinator = TokenKind.COMBINATOR_NONE]) : 262 super(name, span);
163 super(name, span, combinator);
164 263
165 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this); 264 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this);
166 265
167 String toString() => ":$name"; 266 String toString() => ":$name";
168 } 267 }
169 268
170 // ::pseudoElement 269 // ::pseudoElement
171 class PseudoElementSelector extends SimpleSelector { 270 class PseudoElementSelector extends SimpleSelector {
172 PseudoElementSelector(Identifier name, lang.SourceSpan span, 271 PseudoElementSelector(Identifier name, lang.SourceSpan span) :
173 [int combinator = TokenKind.COMBINATOR_NONE]) : 272 super(name, span);
174 super(name, span, combinator);
175 273
176 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this); 274 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this);
177 275
178 String toString() => "::$name"; 276 String toString() => "::$name";
179 } 277 }
180 278
181 // TODO(terry): Implement 279 // TODO(terry): Implement
182 // NOT 280 // NOT
183 class NotSelector extends SimpleSelector { 281 class NotSelector extends SimpleSelector {
184 NotSelector(String name, lang.SourceSpan span, 282 NotSelector(String name, lang.SourceSpan span) : super(name, span);
185 [lang.Token combinator = TokenKind.COMBINATOR_NONE]) :
186 super(name, span, combinator);
187 283
188 visit(TreeVisitor visitor) => visitor.visitNotSelector(this); 284 visit(TreeVisitor visitor) => visitor.visitNotSelector(this);
189 } 285 }
190 286
191 // TODO(terry): Implement 287 class Stylesheet extends lang.Node {
192 // [attribute] 288 // Contains charset, ruleset, directives (media, page, etc.)
193 class Attribute extends lang.Node { 289 List<lang.Node> _topLevels;
194 var name; // NamespaceSelector or SimpleSelector 290
195 int matchType; // ~=, |=, ^=, $=, *=, = 291 Stylesheet(this._topLevels, lang.SourceSpan span) : super(span) {
196 String value; 292 for (var node in _topLevels) {
293 assert(node is TopLevelProduction || node is Directive);
294 }
295 }
296
297 visit(TreeVisitor visitor) => visitor.visitStylesheet(this);
298
299 List<lang.Node> get topLevels() => _topLevels;
300
301 String toString() {
302 StringBuffer buff = new StringBuffer();
303 for (var topLevel in _topLevels) {
304 buff.add(topLevel.toString());
305 }
306 return buff.toString();
307 }
308
309 /** A multiline string showing the node and its children. */
310 String toDebugString() {
311 var to = new lang.TreeOutput();
312 var tp = new TreePrinter(to);
313 this.visit(tp);
314 return to.buf.toString();
315 }
316 }
317
318 class TopLevelProduction extends lang.Node {
319 TopLevelProduction(lang.SourceSpan span) : super(span);
320
321 visit(TreeVisitor visitor) => visitor.visitTopLevelProduction(this);
322
323 String toString() => "TopLevelProduction";
324 }
325
326 class RuleSet extends TopLevelProduction {
327 SelectorGroup _selectorGroup;
328 DeclarationGroup _declarationGroup;
329
330 RuleSet(this._selectorGroup, this._declarationGroup, lang.SourceSpan span) :
331 super(span);
332
333 SelectorGroup get selectorGroup() => _selectorGroup;
334 DeclarationGroup get declarationGroup() => _declarationGroup;
335
336 visit(TreeVisitor visitor) => visitor.visitRuleSet(this);
337
338 String toString() =>
339 "\n${_selectorGroup.toString()} {\n" +
340 "${_declarationGroup.toString()}}\n";
341 }
342
343 class Directive extends lang.Node {
344 Directive(lang.SourceSpan span) : super(span);
345
346 String toString() => "Directive";
347
348 bool get isBuiltIn() => true; // Known CSS directive?
349 bool get isExtension() => false; // SCSS extension?
350
351 visit(TreeVisitor visitor) => visitor.visitDirective(this);
352 }
353
354 class ImportDirective extends Directive {
355 String _import;
356 List<String> _media;
357
358 ImportDirective(this._import, this._media, lang.SourceSpan span) :
359 super(span);
360
361 visit(TreeVisitor visitor) => visitor.visitImportDirective(this);
362
363 String toString() {
364 StringBuffer buff = new StringBuffer();
365
366 buff.add('@import url(${_import})');
367
368 int idx = 0;
369 for (var medium in _media) {
370 buff.add(idx++ == 0 ? ' $medium' : ',$medium');
371 }
372 buff.add('\n');
373
374 return buff.toString();
375 }
376 }
377
378 class MediaDirective extends Directive {
379 List<String> _media;
380 RuleSet _ruleset;
nweiz 2012/01/04 19:05:41 Shouldn't this be a list of RuleSets?
381
382 MediaDirective(this._media, this._ruleset, lang.SourceSpan span) :
383 super(span);
384
385 visit(TreeVisitor visitor) => visitor.visitMediaDirective(this);
386
387 String toString() {
388 StringBuffer buff = new StringBuffer();
389
390 buff.add('@media');
391 int idx = 0;
392 for (var medium in _media) {
393 buff.add(idx++ == 0 ? ' $medium' : ',$medium');
394 }
395 buff.add(' {\n');
396 buff.add(_ruleset.toString());
397 buff.add('\n\}\n');
398
399 return buff.toString();
400 }
401 }
402
403 class PageDirective extends Directive {
404 String _pseudoPage;
405 DeclarationGroup _decls;
406
407 PageDirective(this._pseudoPage, this._decls, lang.SourceSpan span) :
408 super(span);
409
410 visit(TreeVisitor visitor) => visitor.visitPageDirective(this);
411
412 // @page : pseudoPage {
413 // decls
414 // }
415 String toString() {
416 StringBuffer buff = new StringBuffer();
417
418 buff.add('@page ');
419 if (_pseudoPage != null) {
420 buff.add(': ${_pseudoPage} ');
421 }
422 buff.add('{\n${_decls.toString()}\n}\n');
423
424 return buff.toString();
425 }
426 }
427
428 class KeyFrameDirective extends Directive {
429 var _name;
430 List<KeyFrameBlock> _blocks;
431
432 KeyFrameDirective(this._name, lang.SourceSpan span) :
433 _blocks = [], super(span);
434
435 add(KeyFrameBlock block) {
436 _blocks.add(block);
437 }
438
439 String get name() => _name;
440
441 visit(TreeVisitor visitor) => visitor.visitKeyFrameDirective(this);
442
443 String toString() {
444 StringBuffer buff = new StringBuffer();
445 buff.add('@-webkit-keyframes ${_name} {\n');
446 for (var block in _blocks) {
447 buff.add(block.toString());
448 }
449 buff.add('}\n');
450 return buff.toString();
451 }
452 }
453
454 class KeyFrameBlock extends lang.Expression {
455 Expressions _blockSelectors;
456 DeclarationGroup _declarations;
457
458 KeyFrameBlock(this._blockSelectors, this._declarations, lang.SourceSpan span):
459 super(span);
460
461 visit(TreeVisitor visitor) => visitor.visitKeyFrameBlock(this);
462
463 String toString() {
464 StringBuffer buff = new StringBuffer();
465 buff.add(' ${_blockSelectors.toString()} {\n');
466 buff.add(_declarations.toString());
467 buff.add(' }\n');
468 return buff.toString();
469 }
470 }
471
472 // TODO(terry): TBD
473 class FontFaceDirective extends Directive {
474 List<Declaration> _declarations;
nweiz 2012/01/04 19:05:41 Shouldn't this be a DeclarationGroup?
475
476 FontFaceDirective(this._declarations, lang.SourceSpan span) : super(span);
477
478 visit(TreeVisitor visitor) => visitor.visitFontFaceDirective(this);
479
480 String toString() {
481 return "TO BE DONE";
482 }
483 }
484
485 class IncludeDirective extends Directive {
486 String _include;
487 Stylesheet _stylesheet;
488
489 IncludeDirective(this._include, this._stylesheet, lang.SourceSpan span) :
490 super(span);
491
492 visit(TreeVisitor visitor) => visitor.visitIncludeDirective(this);
493
494 bool get isBuiltIn() => false;
495 bool get isExtension() => true;
496
497 Stylesheet get styleSheet() => _stylesheet;
498
499 String toString() {
500 StringBuffer buff = new StringBuffer();
501 buff.add('/****** @include ${_include} ******/\n');
502 buff.add(_stylesheet != null ? _stylesheet.toString() : '// <EMPTY>');
503 buff.add('/****** End of ${_include} ******/\n\n');
504 return buff.toString();
505 }
506 }
507
508 class StyletDirective extends Directive {
509 String _dartClassName;
510 List<RuleSet> _rulesets;
511
512 StyletDirective(this._dartClassName, this._rulesets, lang.SourceSpan span) :
513 super(span);
514
515 bool get isBuiltIn() => false;
516 bool get isExtension() => true;
517
518 String get dartClassName() => _dartClassName;
519 List<RuleSet> get rulesets() => _rulesets;
520
521 visit(TreeVisitor visitor) => visitor.visitStyletDirective(this);
522
523 // TODO(terry): Output Dart class
524 String toString() => '/* @stylet export as ${_dartClassName} */\n';
525 }
526
527 class Declaration extends lang.Node {
528 Identifier _property;
529 lang.Expression _expression;
530 bool _important;
531
532 Declaration(this._property, this._expression, lang.SourceSpan span) :
533 _important = false, super(span);
534
535 String get property() => _property.name;
536 lang.Expression get expression() => _expression;
537
538 bool get important() => _important;
539 set important(bool value) => _important = value;
540 String importantAsString() => _important ? ' !important' : '';
541
542 visit(TreeVisitor visitor) => visitor.visitDeclaration(this);
543
544 String toString() =>
545 "${_property.name}: ${_expression.toString()}${importantAsString()}";
546 }
547
548 class DeclarationGroup extends lang.Node {
549 List<Declaration> _declarations;
550
551 DeclarationGroup(this._declarations, lang.SourceSpan span) : super(span);
552
553 List<Declaration> get declarations() => _declarations;
554
555 visit(TreeVisitor visitor) => visitor.visitDeclarationGroup(this);
556
557 String toString() {
558 StringBuffer buff = new StringBuffer();
559 int idx = 0;
560 for (var declaration in _declarations) {
561 buff.add(" ${declaration.toString()};\n");
562 }
563 return buff.toString();
564 }
565 }
566
567 class OperatorSlash extends lang.Expression {
568 OperatorSlash(lang.SourceSpan span) : super(span);
569
570 visit(TreeVisitor visitor) => visitor.visitOperatorSlash(this);
571
572 String toString() => ' /';
573 }
574
575 class OperatorComma extends lang.Expression {
576 OperatorComma(lang.SourceSpan span) : super(span);
577
578 visit(TreeVisitor visitor) => visitor.visitOperatorComma(this);
579
580 String toString() => ',';
581 }
582
583 class LiteralTerm extends lang.Expression {
584 var _value;
585 String _text;
586
587 LiteralTerm(this._value, this._text, lang.SourceSpan span) : super(span);
588
589 get value() => _value;
590 String get text() => _text;
591
592 visit(TreeVisitor visitor) => visitor.visitLiteralTerm(this);
593
594 String toString() => _text;
595 }
596
597 class NumberTerm extends LiteralTerm {
598 NumberTerm(var value, String t, lang.SourceSpan span) : super(value, t, span);
599
600 visit(TreeVisitor visitor) => visitor.visitNumberTerm(this);
601 }
602
603 class UnitTerm extends LiteralTerm {
604 int _unit;
605
606 UnitTerm(var value, String t, lang.SourceSpan span, this._unit) :
607 super(value, t, span);
608
609 int get unit() => _unit;
610
611 visit(TreeVisitor visitor) => visitor.visitUnitTerm(this);
612
613 String toString() => '${text}${unitToString()}';
614 String unitToString() => TokenKind.unitToString(_unit);
615 }
616
617 class LengthTerm extends UnitTerm {
618 LengthTerm(var value, String t, lang.SourceSpan span,
619 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
620 assert(this._unit == TokenKind.UNIT_LENGTH_PX ||
621 this._unit == TokenKind.UNIT_LENGTH_CM ||
622 this._unit == TokenKind.UNIT_LENGTH_MM ||
623 this._unit == TokenKind.UNIT_LENGTH_IN ||
624 this._unit == TokenKind.UNIT_LENGTH_PT ||
625 this._unit == TokenKind.UNIT_LENGTH_PC);
626 }
627
628 visit(TreeVisitor visitor) => visitor.visitLengthTerm(this);
629 }
630
631 class PercentageTerm extends LiteralTerm {
632 PercentageTerm(var value, String t, lang.SourceSpan span) :
633 super(value, t, span);
634
635 visit(TreeVisitor visitor) => visitor.visitPercentageTerm(this);
636
637 String toString() => '${text}%';
638
639 }
640
641 class EmTerm extends LiteralTerm {
642 EmTerm(var value, String t, lang.SourceSpan span) :
643 super(value, t, span);
644
645 visit(TreeVisitor visitor) => visitor.visitEmTerm(this);
646
647 String toString() => '${text}em';
648 }
649
650 class ExTerm extends LiteralTerm {
651 ExTerm(var value, String t, lang.SourceSpan span) :
652 super(value, t, span);
653
654 visit(TreeVisitor visitor) => visitor.visitExTerm(this);
655
656 String toString() => '${text}ex';
657 }
658
659 class AngleTerm extends UnitTerm {
660 AngleTerm(var value, String t, lang.SourceSpan span,
661 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
662 assert(this._unit == TokenKind.UNIT_ANGLE_DEG ||
663 this._unit == TokenKind.UNIT_ANGLE_RAD ||
664 this._unit == TokenKind.UNIT_ANGLE_GRAD);
665 }
666
667 visit(TreeVisitor visitor) => visitor.visitAngleTerm(this);
668 }
669
670 class TimeTerm extends UnitTerm {
671 TimeTerm(var value, String t, lang.SourceSpan span,
672 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
673 assert(this._unit == TokenKind.UNIT_ANGLE_DEG ||
674 this._unit == TokenKind.UNIT_TIME_MS ||
675 this._unit == TokenKind.UNIT_TIME_S);
676 }
677
678 visit(TreeVisitor visitor) => visitor.visitTimeTerm(this);
679 }
680
681 class FreqTerm extends UnitTerm {
682 FreqTerm(var value, String t, lang.SourceSpan span,
683 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) {
684 assert(_unit == TokenKind.UNIT_FREQ_HZ || _unit == TokenKind.UNIT_FREQ_KHZ);
685 }
686
687 visit(TreeVisitor visitor) => visitor.visitFreqTerm(this);
688 }
689
690 class FractionTerm extends LiteralTerm {
691 FractionTerm(var value, String t, lang.SourceSpan span) :
692 super(value, t, span);
693
694 visit(TreeVisitor visitor) => visitor.visitFractionTerm(this);
695
696 String toString() => '${text}fr';
697 }
698
699 class UriTerm extends LiteralTerm {
700 UriTerm(String value, lang.SourceSpan span) : super(value, value, span);
701
702 visit(TreeVisitor visitor) => visitor.visitUriTerm(this);
703
704 String toString() => 'url(${text})';
705 }
706
707 class HexColorTerm extends LiteralTerm {
708 HexColorTerm(var value, String t, lang.SourceSpan span) :
709 super(value, t, span);
710
711 visit(TreeVisitor visitor) => visitor.visitHexColorTerm(this);
712
713 String toString() => '#${text}';
714 }
715
716 class FunctionTerm extends LiteralTerm {
717 Expressions _params;
718
719 FunctionTerm(var value, String t, this._params, lang.SourceSpan span)
720 : super(value, t, span);
721
722 visit(TreeVisitor visitor) => visitor.visitFunctionTerm(this);
723
724 String toString() {
725 // TODO(terry): Optimize rgb to a hexcolor.
726 StringBuffer buff = new StringBuffer();
727
728 buff.add('${text}(');
729 buff.add(_params.toString());
730 buff.add(')');
731
732 return buff.toString();
733 }
734 }
735
736 class GroupTerm extends lang.Expression {
737 List<LiteralTerm> _terms;
738
739 GroupTerm(lang.SourceSpan span) : _terms = [], super(span);
740
741 add(LiteralTerm term) {
742 _terms.add(term);
743 }
744
745 visit(TreeVisitor visitor) => visitor.visitGroupTerm(this);
746
747 String toString() {
748 StringBuffer buff = new StringBuffer();
749 buff.add('(');
750 int idx = 0;
751 for (var term in _terms) {
752 if (idx++ > 0) {
753 buff.add(' ');
754 }
755 buff.add(term.toString());
756 }
757 buff.add(')');
758 return buff.toString();
759 }
760 }
761
762 class ItemTerm extends NumberTerm {
763 ItemTerm(var value, String t, lang.SourceSpan span) : super(value, t, span);
764
765 visit(TreeVisitor visitor) => visitor.visitItemTerm(this);
766
767 String toString() => '[${text}]';
768 }
769
770 class Expressions extends lang.Expression {
771 List<lang.Expression> _expressions;
772
773 Expressions(lang.SourceSpan span): super(span), _expressions = [];
774
775 add(lang.Expression expression) {
776 _expressions.add(expression);
777 }
778
779 List<lang.Expression> get expressions() => _expressions;
780
781 visit(TreeVisitor visitor) => visitor.visitExpressions(this);
782
783 String toString() {
784 StringBuffer buff = new StringBuffer();
785 int idx = 0;
786 for (var expression in _expressions) {
787 // Add space seperator between terms without an operator.
788 // TODO(terry): Should have a BinaryExpression to solve this problem.
789 if (idx > 0 &&
790 !(expression is OperatorComma || expression is OperatorSlash)) {
791 buff.add(' ');
792 }
793 buff.add(expression.toString());
794 idx++;
795 }
796 return buff.toString();
797 }
798 }
799
800 class BinaryExpression extends lang.Expression {
801 lang.Token op;
802 lang.Expression x;
803 lang.Expression y;
804
805 BinaryExpression(this.op, this.x, this.y, lang.SourceSpan span): super(span);
806
807 visit(TreeVisitor visitor) => visitor.visitBinaryExpression(this);
808 }
809
810 class UnaryExpression extends lang.Expression {
811 lang.Token op;
812 lang.Expression self;
813
814 UnaryExpression(this.op, this.self, lang.SourceSpan span): super(span);
815
816 visit(TreeVisitor visitor) => visitor.visitUnaryExpression(this);
197 } 817 }
198 818
199 interface TreeVisitor { 819 interface TreeVisitor {
820 void visitComment(Comment node);
821 void visitCommentDefinition(CommentDefinition node);
822 void visitStylesheet(Stylesheet node);
823 void visitTopLevelProduction(TopLevelProduction node);
824 void visitDirective(Directive node);
825 void visitMediaDirective(MediaDirective node);
826 void visitPageDirective(PageDirective node);
827 void visitImportDirective(ImportDirective node);
828 void visitKeyFrameDirective(KeyFrameDirective node);
829 void visitKeyFrameBlock(KeyFrameBlock node);
830 void visitFontFaceDirective(FontFaceDirective node);
831 void visitIncludeDirective(IncludeDirective node);
832 void visitStyletDirective(StyletDirective node);
833
834 void visitRuleSet(RuleSet node);
835 void visitDeclarationGroup(DeclarationGroup node);
836 void visitDeclaration(Declaration node);
200 void visitSelectorGroup(SelectorGroup node); 837 void visitSelectorGroup(SelectorGroup node);
838 void visitSelector(Selector node);
839 void visitSimpleSelectorSequence(SimpleSelectorSequence node);
201 void visitSimpleSelector(SimpleSelector node); 840 void visitSimpleSelector(SimpleSelector node);
202 void visitElementSelector(ElementSelector node); 841 void visitElementSelector(ElementSelector node);
203 void visitNamespaceSelector(NamespaceSelector node); 842 void visitNamespaceSelector(NamespaceSelector node);
843 void visitAttributeSelector(AttributeSelector node);
204 void visitIdSelector(IdSelector node); 844 void visitIdSelector(IdSelector node);
205 void visitClassSelector(ClassSelector node); 845 void visitClassSelector(ClassSelector node);
206 void visitPseudoClassSelector(PseudoClassSelector node); 846 void visitPseudoClassSelector(PseudoClassSelector node);
207 void visitPseudoElementSelector(PseudoElementSelector node); 847 void visitPseudoElementSelector(PseudoElementSelector node);
208 void visitNotSelector(NotSelector node); 848 void visitNotSelector(NotSelector node);
209 849
850 void visitLiteralTerm(LiteralTerm node);
851 void visitHexColorTerm(HexColorTerm node);
852 void visitNumberTerm(NumberTerm node);
853 void visitUnitTerm(UnitTerm node);
854 void visitLengthTerm(LengthTerm node);
855 void visitPercentageTerm(PercentageTerm node);
856 void visitEmTerm(EmTerm node);
857 void visitExTerm(ExTerm node);
858 void visitAngleTerm(AngleTerm node);
859 void visitTimeTerm(TimeTerm node);
860 void visitFreqTerm(FreqTerm node);
861 void visitFractionTerm(FractionTerm node);
862 void visitUriTerm(UriTerm node);
863 void visitFunctionTerm(FunctionTerm node);
864 void visitGroupTerm(GroupTerm node);
865 void visitItemTerm(ItemTerm node);
866 void visitOperatorSlash(OperatorSlash node);
867 void visitOperatorComma(OperatorComma node);
868
869 void visitExpressions(Expressions node);
870 void visitBinaryExpression(BinaryExpression node);
871 void visitUnaryExpression(UnaryExpression node);
872
210 void visitIdentifier(Identifier node); 873 void visitIdentifier(Identifier node);
211 void visitWildcard(Wildcard node); 874 void visitWildcard(Wildcard node);
212 875
213 // TODO(terry): Defined for ../tree.dart. 876 // TODO(terry): Defined for ../tree.dart.
214 void visitTypeReference(lang.TypeReference node); 877 void visitTypeReference(lang.TypeReference node);
215 } 878 }
216 879
217 class TreePrinter implements TreeVisitor { 880 class TreePrinter implements TreeVisitor {
218 var output; 881 var output;
219 TreePrinter(this.output) { output.printer = this; } 882 TreePrinter(this.output) { output.printer = this; }
220 883
884 void visitStylesheet(Stylesheet node) {
885 output.heading('Stylesheet', node.span);
886 output.depth++;
887 output.writeNodeList('productions', node._topLevels);
888 output.depth--;
889 }
890
891 void visitTopLevelProduction(TopLevelProduction node) {
892 output.heading('TopLevelProduction', node.span);
893 }
894
895 void visitDirective(Directive node) {
896 output.heading('Directive', node.span);
897 }
898
899 void visitComment(Comment node) {
900 output.heading('Comment', node.span);
901 output.depth++;
902 output.writeValue('comment value', node.comment);
903 output.depth--;
904 }
905
906 void visitCommentDefinition(CommentDefinition node) {
907 output.heading('CommentDefinition (CDO/CDC)', node.span);
908 output.depth++;
909 output.writeValue('comment value', node.comment);
910 output.depth--;
911 }
912
913 void visitMediaDirective(MediaDirective node) {
914 output.heading('MediaDirective', node.span);
915 output.depth++;
916 output.writeNodeList('media', node._media);
917 visitRuleSet(node._ruleset);
918 output.depth--;
919 }
920
921 void visitPageDirective(PageDirective node) {
922 output.heading('PageDirective', node.span);
923 output.depth++;
924 output.writeValue('pseudo page', node._pseudoPage);
925 visitDeclarationGroup(node._decls);
926 output.depth;
927 }
928
929 void visitImportDirective(ImportDirective node) {
930 output.heading('ImportDirective', node.span);
931 output.depth++;
932 output.writeValue('import', node._import);
933 output.writeNodeList('media', node._media);
934 output.depth--;
935 }
936
937 void visitKeyFrameDirective(KeyFrameDirective node) {
938 output.heading('KeyFrameDirective', node.span);
939 output.depth++;
940 output.writeValue('name', node._name);
941 output.writeNodeList('blocks', node._blocks);
942 output.depth--;
943 }
944
945 void visitKeyFrameBlock(KeyFrameBlock node) {
946 output.heading('KeyFrameBlock', node.span);
947 output.depth++;
948 visitExpressions(node._blockSelectors);
949 visitDeclarationGroup(node._declarations);
950 output.depth--;
951 }
952
953 void visitFontFaceDirective(FontFaceDirective node) {
954 // TODO(terry): To Be Implemented
955 }
956
957 void visitIncludeDirective(IncludeDirective node) {
958 output.heading('IncludeDirective', node.span);
959 output.writeValue('include', node._include);
960 output.depth++;
961 if (node._stylesheet != null) {
962 visitStylesheet(node._stylesheet);
963 } else {
964 output.writeValue('StyleSheet', '<EMPTY>');
965 }
966 output.depth--;
967 }
968
969 void visitStyletDirective(StyletDirective node) {
970 output.heading('StyletDirective', node.span);
971 output.writeValue('dartClassName', node._dartClassName);
972 output.depth++;
973 output.writeNodeList('rulesets', node._rulesets);
974 output.depth--;
975 }
976
977 void visitRuleSet(RuleSet node) {
978 output.heading('Ruleset', node.span);
979 output.depth++;
980 visitSelectorGroup(node._selectorGroup);
981 visitDeclarationGroup(node._declarationGroup);
982 output.depth--;
983 }
984
985 void visitDeclarationGroup(DeclarationGroup node) {
986 output.heading('DeclarationGroup', node.span);
987 output.depth++;
988 output.writeNodeList('declarations', node._declarations);
989 output.depth--;
990 }
991
992 void visitDeclaration(Declaration node) {
993 output.heading('Declaration', node.span);
994 output.depth++;
995 output.write('property');
996 visitIdentifier(node._property);
997 output.writeNode('expression', node._expression);
998 if (node.important) {
999 output.writeValue('!important', 'true');
1000 }
1001 output.depth--;
1002 }
1003
221 void visitSelectorGroup(SelectorGroup node) { 1004 void visitSelectorGroup(SelectorGroup node) {
222 output.heading('Selector Group', node.span); 1005 output.heading('Selector Group', node.span);
1006 output.depth++;
223 output.writeNodeList('selectors', node.selectors); 1007 output.writeNodeList('selectors', node.selectors);
224 output.writeln(''); 1008 output.depth--;
225 } 1009 }
226 1010
227 void visitSimpleSelector(SimpleSelector node) { 1011 void visitSelector(Selector node) {
1012 output.heading('Selector', node.span);
1013 output.depth++;
1014 output.writeNodeList('simpleSelectorsSequences',
1015 node._simpleSelectorSequences);
1016 output.depth--;
1017 }
1018
1019 void visitSimpleSelectorSequence(SimpleSelectorSequence node) {
1020 output.heading('SimpleSelectorSequence', node.span);
1021 output.depth++;
228 if (node.isCombinatorNone()) { 1022 if (node.isCombinatorNone()) {
229 output.writeValue('combinator', "NONE"); 1023 output.writeValue('combinator', "NONE");
230 } else if (node.isCombinatorDescendant()) { 1024 } else if (node.isCombinatorDescendant()) {
231 output.writeValue('combinator', "descendant"); 1025 output.writeValue('combinator', "descendant");
232 } else if (node.isCombinatorPlus()) { 1026 } else if (node.isCombinatorPlus()) {
233 output.writeValue('combinator', "+"); 1027 output.writeValue('combinator', "+");
234 } else if (node.isCombinatorGreater()) { 1028 } else if (node.isCombinatorGreater()) {
235 output.writeValue('combinator', ">"); 1029 output.writeValue('combinator', ">");
236 } else if (node.isCombinatorTilde()) { 1030 } else if (node.isCombinatorTilde()) {
237 output.writeValue('combinator', "~"); 1031 output.writeValue('combinator', "~");
238 } else { 1032 } else {
239 output.writeValue('combinator', "ERROR UNKNOWN"); 1033 output.writeValue('combinator', "ERROR UNKNOWN");
240 } 1034 }
1035
1036 var selector = node._selector;
1037 if (selector is NamespaceSelector) {
1038 visitNamespaceSelector(selector);
1039 } else if (selector is ElementSelector) {
1040 visitElementSelector(selector);
1041 } else if (selector is IdSelector) {
1042 visitIdSelector(selector);
1043 } else if (selector is ClassSelector) {
1044 visitClassSelector(selector);
1045 } else if (selector is PseudoClassSelector) {
1046 visitPseudoClassSelector(selector);
1047 } else if (selector is PseudoElementSelector) {
1048 visitPseudoElementSelector(selector);
1049 } else if (selector is NotSelector) {
1050 visitNotSelector(selector);
1051 } else if (selector is AttributeSelector) {
1052 visitAttributeSelector(selector);
1053 } else {
1054 output.heading('SimpleSelector', selector.span);
1055 output.depth++;
1056 visitSimpleSelector(selector);
1057 output.depth--;
1058 }
1059
1060 output.depth--;
1061 }
1062
1063 void visitSimpleSelector(SimpleSelector node) {
1064 visitIdentifier(node._name);
241 } 1065 }
242 1066
243 void visitNamespaceSelector(NamespaceSelector node) { 1067 void visitNamespaceSelector(NamespaceSelector node) {
244 output.heading('Namespace Selector', node.span); 1068 output.heading('Namespace Selector', node.span);
245 visitSimpleSelector(node); 1069 output.depth++;
246 output.writeNode('namespace', node._namespace); 1070
247 output.writeNode('name', node._name); 1071 var namespace = node._namespace;
1072 if (namespace is Identifier) {
1073 visitIdentifier(namespace);
1074 } else if (namespace is Wildcard) {
1075 visitWildcard(namespace);
1076 } else {
1077 output.writeln("NULL");
1078 }
1079
1080 visitSimpleSelector(node);
1081 output.depth--;
248 } 1082 }
249 1083
250 void visitElementSelector(ElementSelector node) { 1084 void visitElementSelector(ElementSelector node) {
251 output.heading('Element Selector', node.span); 1085 output.heading('Element Selector', node.span);
252 visitSimpleSelector(node); 1086 output.depth++;
253 output.writeNode('name', node._name); 1087 visitSimpleSelector(node);
1088 output.depth--;
1089 }
1090
1091 void visitAttributeSelector(AttributeSelector node) {
1092 output.heading('AttributeSelector', node.span);
1093 output.depth++;
1094 visitSimpleSelector(node);
1095 String tokenStr = node.matchOperatorAsTokenString();
1096 output.writeValue('operator', '${node.matchOperator()} (${tokenStr})');
1097 output.writeValue('value', node.valueToString());
1098 output.depth--;
254 } 1099 }
255 1100
256 void visitIdSelector(IdSelector node) { 1101 void visitIdSelector(IdSelector node) {
257 output.heading('Id Selector', node.span); 1102 output.heading('Id Selector', node.span);
258 visitSimpleSelector(node); 1103 output.depth++;
259 output.writeNode('name', node._name); 1104 visitSimpleSelector(node);
1105 output.depth--;
260 } 1106 }
261 1107
262 void visitClassSelector(ClassSelector node) { 1108 void visitClassSelector(ClassSelector node) {
263 output.heading('Class Selector', node.span); 1109 output.heading('Class Selector', node.span);
264 visitSimpleSelector(node); 1110 output.depth++;
265 output.writeNode('name', node._name); 1111 visitSimpleSelector(node);
1112 output.depth--;
266 } 1113 }
267 1114
268 void visitPseudoClassSelector(PseudoClassSelector node) { 1115 void visitPseudoClassSelector(PseudoClassSelector node) {
269 output.heading('Pseudo Class Selector', node.span); 1116 output.heading('Pseudo Class Selector', node.span);
270 visitSimpleSelector(node); 1117 output.depth++;
271 output.writeNode('name', node._name); 1118 visitSimpleSelector(node);
1119 output.depth--;
272 } 1120 }
273 1121
274 void visitPseudoElementSelector(PseudoElementSelector node) { 1122 void visitPseudoElementSelector(PseudoElementSelector node) {
275 output.heading('Pseudo Element Selector', node.span); 1123 output.heading('Pseudo Element Selector', node.span);
276 visitSimpleSelector(node); 1124 output.depth++;
277 output.writeNode('name', node._name); 1125 visitSimpleSelector(node);
1126 output.depth--;
278 } 1127 }
279 1128
280 void visitNotSelector(NotSelector node) { 1129 void visitNotSelector(NotSelector node) {
281 visitSimpleSelector(node); 1130 visitSimpleSelector(node);
1131 output.depth++;
282 output.heading('Not Selector', node.span); 1132 output.heading('Not Selector', node.span);
1133 output.depth--;
1134 }
1135
1136 void visitLiteralTerm(LiteralTerm node) {
1137 output.heading('LiteralTerm', node.span);
1138 output.depth++;
1139 output.writeValue('value', node.text);
1140 output.depth--;
1141 }
1142
1143 void visitHexColorTerm(HexColorTerm node) {
1144 output.heading('HexColorTerm', node.span);
1145 output.depth++;
1146 output.writeValue('hex value', node.text);
1147 output.writeValue('decimal value', node.value);
1148 output.depth--;
1149 }
1150
1151 void visitNumberTerm(NumberTerm node) {
1152 output.heading('NumberTerm', node.span);
1153 output.depth++;
1154 output.writeValue('value', node.text);
1155 output.depth--;
1156 }
1157
1158 void visitUnitTerm(UnitTerm node) {
1159 String unitValue;
1160
1161 output.depth++;
1162 output.writeValue('value', node.text);
1163 output.writeValue('unit', node.unitToString());
1164 output.depth--;
1165 }
1166
1167 void visitLengthTerm(LengthTerm node) {
1168 output.heading('LengthTerm', node.span);
1169 visitUnitTerm(node);
1170 }
1171
1172 void visitPercentageTerm(PercentageTerm node) {
1173 output.heading('PercentageTerm', node.span);
1174 output.depth++;
1175 visitLiteralTerm(node);
1176 output.depth--;
1177 }
1178
1179 void visitEmTerm(EmTerm node) {
1180 output.heading('EmTerm', node.span);
1181 output.depth++;
1182 visitLiteralTerm(node);
1183 output.depth--;
1184 }
1185
1186 void visitExTerm(ExTerm node) {
1187 output.heading('ExTerm', node.span);
1188 output.depth++;
1189 visitLiteralTerm(node);
1190 output.depth--;
1191 }
1192
1193 void visitAngleTerm(AngleTerm node) {
1194 output.heading('AngleTerm', node.span);
1195 visitUnitTerm(node);
1196 }
1197
1198 void visitTimeTerm(TimeTerm node) {
1199 output.heading('TimeTerm', node.span);
1200 visitUnitTerm(node);
1201 }
1202
1203 void visitFreqTerm(FreqTerm node) {
1204 output.heading('FreqTerm', node.span);
1205 visitUnitTerm(node);
1206 }
1207
1208 void visitFractionTerm(FractionTerm node) {
1209 output.heading('FractionTerm', node.span);
1210 output.depth++;
1211 visitLiteralTerm(node);
1212 output.depth--;
1213 }
1214
1215 void visitUriTerm(UriTerm node) {
1216 output.heading('UriTerm', node.span);
1217 output.depth++;
1218 visitLiteralTerm(node);
1219 output.depth--;
1220 }
1221
1222 void visitFunctionTerm(FunctionTerm node) {
1223 output.heading('FunctionTerm', node.span);
1224 output.depth++;
1225 visitLiteralTerm(node);
1226 visitExpressions(node._params);
1227 output.depth--;
1228 }
1229
1230 void visitGroupTerm(GroupTerm node) {
1231 output.heading('GroupTerm', node.span);
1232 output.depth++;
1233 output.writeNodeList('grouped terms', node._terms);
1234 output.depth--;
1235 }
1236
1237 void visitItemTerm(ItemTerm node) {
1238 output.heading('ItemTerm', node.span);
1239 visitNumberTerm(node);
1240 }
1241
1242 void visitOperatorSlash(OperatorSlash node) {
1243 output.heading('OperatorSlash', node.span);
1244 }
1245
1246 void visitOperatorComma(OperatorComma node) {
1247 output.heading('OperatorComma', node.span);
1248 }
1249
1250 void visitExpressions(Expressions node) {
1251 output.heading('Expressions', node.span);
1252 output.depth++;
1253 output.writeNodeList('expressions', node._expressions);
1254 output.depth--;
1255 }
1256
1257 void visitBinaryExpression(BinaryExpression node) {
1258 output.heading('BinaryExpression', node.span);
1259 // TODO(terry): TBD
1260 }
1261
1262 void visitUnaryExpression(UnaryExpression node) {
1263 output.heading('UnaryExpression', node.span);
1264 // TODO(terry): TBD
283 } 1265 }
284 1266
285 void visitIdentifier(Identifier node) { 1267 void visitIdentifier(Identifier node) {
286 output.heading('Identifier(' + output.toValue(node.name) + ")", node.span); 1268 output.heading('Identifier(' + output.toValue(node.name) + ")", node.span);
287 } 1269 }
288 1270
289 void visitWildcard(Wildcard node) { 1271 void visitWildcard(Wildcard node) {
290 output.heading('Wildcard(*)', node.span); 1272 output.heading('Wildcard(*)', node.span);
291 } 1273 }
292 1274
293 // TODO(terry): Defined for frog/tree.dart. 1275 // TODO(terry): Defined for frog/tree.dart.
294 void visitTypeReference(lang.TypeReference node) { 1276 void visitTypeReference(lang.TypeReference node) {
295 output.heading('Unimplemented'); 1277 output.heading('Unimplemented');
296 } 1278 }
297 } 1279 }
OLDNEW
« utils/css/parser.dart ('K') | « utils/css/tool.dart ('k') | utils/css/uitest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698