OLD | NEW |
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 ASTNode { |
12 String name; | 12 String name; |
13 | 13 |
14 Identifier(this.name, lang.SourceSpan span): super(span); | 14 Identifier(this.name, 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 ASTNode { |
22 Wildcard(lang.SourceSpan span): super(span); | 22 Wildcard(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 // /* .... */ | 29 // /* .... */ |
30 class CssComment extends lang.Node { | 30 class CssComment extends ASTNode { |
31 String comment; | 31 String comment; |
32 | 32 |
33 CssComment(this.comment, lang.SourceSpan span): super(span); | 33 CssComment(this.comment, SourceSpan span): super(span); |
34 | 34 |
35 visit(TreeVisitor visitor) => visitor.visitCssComment(this); | 35 visit(TreeVisitor visitor) => visitor.visitCssComment(this); |
36 | 36 |
37 String toString() => '/* ${comment} */'; | 37 String toString() => '/* ${comment} */'; |
38 } | 38 } |
39 | 39 |
40 // CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->). | 40 // CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->). |
41 class CommentDefinition extends CssComment { | 41 class CommentDefinition extends CssComment { |
42 CommentDefinition(String comment, lang.SourceSpan span): super(comment, span); | 42 CommentDefinition(String comment, SourceSpan span): super(comment, span); |
43 | 43 |
44 visit(TreeVisitor visitor) => visitor.visitCommentDefinition(this); | 44 visit(TreeVisitor visitor) => visitor.visitCommentDefinition(this); |
45 | 45 |
46 String toString() => '<!-- ${comment} -->'; | 46 String toString() => '<!-- ${comment} -->'; |
47 } | 47 } |
48 | 48 |
49 class SelectorGroup extends lang.Node { | 49 class SelectorGroup extends ASTNode { |
50 List<Selector> _selectors; | 50 List<Selector> _selectors; |
51 | 51 |
52 SelectorGroup(this._selectors, lang.SourceSpan span): super(span); | 52 SelectorGroup(this._selectors, SourceSpan span): super(span); |
53 | 53 |
54 List<Selector> get selectors() => _selectors; | 54 List<Selector> get selectors() => _selectors; |
55 | 55 |
56 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this); | 56 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this); |
57 | 57 |
58 String toString() { | 58 String toString() { |
59 StringBuffer buff = new StringBuffer(); | 59 StringBuffer buff = new StringBuffer(); |
60 int idx = 0; | 60 int idx = 0; |
61 for (final selector in _selectors) { | 61 for (final selector in _selectors) { |
62 if (idx++ > 0) { | 62 if (idx++ > 0) { |
63 buff.add(', '); | 63 buff.add(', '); |
64 } | 64 } |
65 buff.add(selector.toString()); | 65 buff.add(selector.toString()); |
66 } | 66 } |
67 return buff.toString(); | 67 return buff.toString(); |
68 } | 68 } |
69 | 69 |
70 /** A multiline string showing the node and its children. */ | 70 /** A multiline string showing the node and its children. */ |
71 String toDebugString() { | 71 String toDebugString() { |
72 var to = new lang.TreeOutput(); | 72 var to = new TreeOutput(); |
73 var tp = new TreePrinter(to); | 73 var tp = new TreePrinter(to); |
74 this.visit(tp); | 74 this.visit(tp); |
75 return to.buf.toString(); | 75 return to.buf.toString(); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 class Selector extends lang.Node { | 79 class Selector extends ASTNode { |
80 List<SimpleSelectorSequence> _simpleSelectorSequences; | 80 List<SimpleSelectorSequence> _simpleSelectorSequences; |
81 | 81 |
82 Selector(this._simpleSelectorSequences, lang.SourceSpan span) : super(span); | 82 Selector(this._simpleSelectorSequences, SourceSpan span) : super(span); |
83 | 83 |
84 List<SimpleSelectorSequence> get simpleSelectorSequences() => | 84 List<SimpleSelectorSequence> get simpleSelectorSequences() => |
85 _simpleSelectorSequences; | 85 _simpleSelectorSequences; |
86 | 86 |
87 add(SimpleSelectorSequence seq) => _simpleSelectorSequences.add(seq); | 87 add(SimpleSelectorSequence seq) => _simpleSelectorSequences.add(seq); |
88 | 88 |
89 List<SimpleSelectorSequence> get simpleSelectorSquences() => | 89 List<SimpleSelectorSequence> get simpleSelectorSquences() => |
90 _simpleSelectorSequences; | 90 _simpleSelectorSequences; |
91 | 91 |
92 int get length() => _simpleSelectorSequences.length; | 92 int get length() => _simpleSelectorSequences.length; |
93 | 93 |
94 String toString() { | 94 String toString() { |
95 StringBuffer buff = new StringBuffer(); | 95 StringBuffer buff = new StringBuffer(); |
96 for (_simpleSelectorSequence in _simpleSelectorSequences) { | 96 for (final simpleSelectorSequence in _simpleSelectorSequences) { |
97 buff.add(_simpleSelectorSequence.toString()); | 97 buff.add(simpleSelectorSequence.toString()); |
98 } | 98 } |
99 return buff.toString(); | 99 return buff.toString(); |
100 } | 100 } |
101 | 101 |
102 visit(TreeVisitor visitor) => visitor.visitSelector(this); | 102 visit(TreeVisitor visitor) => visitor.visitSelector(this); |
103 } | 103 } |
104 | 104 |
105 class SimpleSelectorSequence extends lang.Node { | 105 class SimpleSelectorSequence extends ASTNode { |
106 int _combinator; // +, >, ~, NONE | 106 int _combinator; // +, >, ~, NONE |
107 SimpleSelector _selector; | 107 SimpleSelector _selector; |
108 | 108 |
109 SimpleSelectorSequence(this._selector, lang.SourceSpan span, | 109 SimpleSelectorSequence(this._selector, SourceSpan span, |
110 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span); | 110 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span); |
111 | 111 |
112 get simpleSelector() => _selector; | 112 get simpleSelector() => _selector; |
113 | 113 |
114 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE; | 114 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE; |
115 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS; | 115 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS; |
116 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER; | 116 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER; |
117 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE; | 117 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE; |
118 bool isCombinatorDescendant() => | 118 bool isCombinatorDescendant() => |
119 _combinator == TokenKind.COMBINATOR_DESCENDANT; | 119 _combinator == TokenKind.COMBINATOR_DESCENDANT; |
120 | 120 |
121 String _combinatorToString() => | 121 String _combinatorToString() => |
122 isCombinatorDescendant() ? ' ' : | 122 isCombinatorDescendant() ? ' ' : |
123 isCombinatorPlus() ? '+' : | 123 isCombinatorPlus() ? '+' : |
124 isCombinatorGreater() ? '>' : | 124 isCombinatorGreater() ? '>' : |
125 isCombinatorTilde() ? '~' : ''; | 125 isCombinatorTilde() ? '~' : ''; |
126 | 126 |
127 visit(TreeVisitor visitor) => visitor.visitSimpleSelectorSequence(this); | 127 visit(TreeVisitor visitor) => visitor.visitSimpleSelectorSequence(this); |
128 | 128 |
129 String toString() => _combinatorToString() + _selector.toString(); | 129 String toString() => _combinatorToString() + _selector.toString(); |
130 } | 130 } |
131 | 131 |
132 /* All other selectors (element, #id, .class, attribute, pseudo, negation, | 132 /* All other selectors (element, #id, .class, attribute, pseudo, negation, |
133 * namespace, *) are derived from this selector. | 133 * namespace, *) are derived from this selector. |
134 */ | 134 */ |
135 class SimpleSelector extends lang.Node { | 135 class SimpleSelector extends ASTNode { |
136 var _name; | 136 var _name; |
137 | 137 |
138 SimpleSelector(this._name, lang.SourceSpan span) : super(span); | 138 SimpleSelector(this._name, SourceSpan span) : super(span); |
139 | 139 |
140 // 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 '*'. |
141 String get name() => isWildcard() ? '*' : _name.name; | 141 String get name() => isWildcard() ? '*' : _name.name; |
142 | 142 |
143 bool isWildcard() => _name is Wildcard; | 143 bool isWildcard() => _name is Wildcard; |
144 | 144 |
145 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this); | 145 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this); |
146 | 146 |
147 String toString() => name; | 147 String toString() => name; |
148 } | 148 } |
149 | 149 |
150 // element name | 150 // element name |
151 class ElementSelector extends SimpleSelector { | 151 class ElementSelector extends SimpleSelector { |
152 ElementSelector(var name, lang.SourceSpan span) : super(name, span); | 152 ElementSelector(var name, SourceSpan span) : super(name, span); |
153 | 153 |
154 visit(TreeVisitor visitor) => visitor.visitElementSelector(this); | 154 visit(TreeVisitor visitor) => visitor.visitElementSelector(this); |
155 | 155 |
156 String toString() => "$name"; | 156 String toString() => "$name"; |
157 | 157 |
158 /** A multiline string showing the node and its children. */ | 158 /** A multiline string showing the node and its children. */ |
159 String toDebugString() { | 159 String toDebugString() { |
160 var to = new lang.TreeOutput(); | 160 var to = new TreeOutput(); |
161 var tp = new TreePrinter(to); | 161 var tp = new TreePrinter(to); |
162 this.visit(tp); | 162 this.visit(tp); |
163 return to.buf.toString(); | 163 return to.buf.toString(); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 // namespace|element | 167 // namespace|element |
168 class NamespaceSelector extends SimpleSelector { | 168 class NamespaceSelector extends SimpleSelector { |
169 var _namespace; // null, Wildcard or Identifier | 169 var _namespace; // null, Wildcard or Identifier |
170 | 170 |
171 NamespaceSelector(this._namespace, var name, lang.SourceSpan span) : | 171 NamespaceSelector(this._namespace, var name, SourceSpan span) : |
172 super(name, span); | 172 super(name, span); |
173 | 173 |
174 String get namespace() => _namespace is Wildcard ? '*' : _namespace.name; | 174 String get namespace() => _namespace is Wildcard ? '*' : _namespace.name; |
175 | 175 |
176 bool isNamespaceWildcard() => _namespace is Wildcard; | 176 bool isNamespaceWildcard() => _namespace is Wildcard; |
177 | 177 |
178 SimpleSelector get nameAsSimpleSelector() => _name; | 178 SimpleSelector get nameAsSimpleSelector() => _name; |
179 | 179 |
180 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this); | 180 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this); |
181 | 181 |
182 String toString() => "$namespace|${nameAsSimpleSelector.name}"; | 182 String toString() => "$namespace|${nameAsSimpleSelector.name}"; |
183 } | 183 } |
184 | 184 |
185 // [attr op value] | 185 // [attr op value] |
186 class AttributeSelector extends SimpleSelector { | 186 class AttributeSelector extends SimpleSelector { |
187 int _op; | 187 int _op; |
188 var _value; | 188 var _value; |
189 | 189 |
190 AttributeSelector(Identifier name, this._op, this._value, | 190 AttributeSelector(Identifier name, this._op, this._value, |
191 lang.SourceSpan span) : super(name, span); | 191 SourceSpan span) : super(name, span); |
192 | 192 |
193 String matchOperator() { | 193 String matchOperator() { |
194 switch (_op) { | 194 switch (_op) { |
195 case TokenKind.EQUALS: | 195 case TokenKind.EQUALS: |
196 return '='; | 196 return '='; |
197 case TokenKind.INCLUDES: | 197 case TokenKind.INCLUDES: |
198 return '~='; | 198 return '~='; |
199 case TokenKind.DASH_MATCH: | 199 case TokenKind.DASH_MATCH: |
200 return '|='; | 200 return '|='; |
201 case TokenKind.PREFIX_MATCH: | 201 case TokenKind.PREFIX_MATCH: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 visit(TreeVisitor visitor) => visitor.visitAttributeSelector(this); | 236 visit(TreeVisitor visitor) => visitor.visitAttributeSelector(this); |
237 | 237 |
238 String toString() => "[${name} ${matchOperator()} ${valueToString()}]"; | 238 String toString() => "[${name} ${matchOperator()} ${valueToString()}]"; |
239 } | 239 } |
240 | 240 |
241 // #id | 241 // #id |
242 class IdSelector extends SimpleSelector { | 242 class IdSelector extends SimpleSelector { |
243 IdSelector(Identifier name, lang.SourceSpan span) : super(name, span); | 243 IdSelector(Identifier name, SourceSpan span) : super(name, span); |
244 | 244 |
245 visit(TreeVisitor visitor) => visitor.visitIdSelector(this); | 245 visit(TreeVisitor visitor) => visitor.visitIdSelector(this); |
246 | 246 |
247 String toString() => "#$name"; | 247 String toString() => "#$name"; |
248 } | 248 } |
249 | 249 |
250 // .class | 250 // .class |
251 class ClassSelector extends SimpleSelector { | 251 class ClassSelector extends SimpleSelector { |
252 ClassSelector(Identifier name, lang.SourceSpan span) : super(name, span); | 252 ClassSelector(Identifier name, SourceSpan span) : super(name, span); |
253 | 253 |
254 visit(TreeVisitor visitor) => visitor.visitClassSelector(this); | 254 visit(TreeVisitor visitor) => visitor.visitClassSelector(this); |
255 | 255 |
256 String toString() => ".$name"; | 256 String toString() => ".$name"; |
257 } | 257 } |
258 | 258 |
259 // :pseudoClass | 259 // :pseudoClass |
260 class PseudoClassSelector extends SimpleSelector { | 260 class PseudoClassSelector extends SimpleSelector { |
261 PseudoClassSelector(Identifier name, lang.SourceSpan span) : | 261 PseudoClassSelector(Identifier name, SourceSpan span) : |
262 super(name, span); | 262 super(name, span); |
263 | 263 |
264 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this); | 264 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this); |
265 | 265 |
266 String toString() => ":$name"; | 266 String toString() => ":$name"; |
267 } | 267 } |
268 | 268 |
269 // ::pseudoElement | 269 // ::pseudoElement |
270 class PseudoElementSelector extends SimpleSelector { | 270 class PseudoElementSelector extends SimpleSelector { |
271 PseudoElementSelector(Identifier name, lang.SourceSpan span) : | 271 PseudoElementSelector(Identifier name, SourceSpan span) : |
272 super(name, span); | 272 super(name, span); |
273 | 273 |
274 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this); | 274 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this); |
275 | 275 |
276 String toString() => "::$name"; | 276 String toString() => "::$name"; |
277 } | 277 } |
278 | 278 |
279 // TODO(terry): Implement | 279 // TODO(terry): Implement |
280 // NOT | 280 // NOT |
281 class NotSelector extends SimpleSelector { | 281 class NotSelector extends SimpleSelector { |
282 NotSelector(String name, lang.SourceSpan span) : super(name, span); | 282 NotSelector(String name, SourceSpan span) : super(name, span); |
283 | 283 |
284 visit(TreeVisitor visitor) => visitor.visitNotSelector(this); | 284 visit(TreeVisitor visitor) => visitor.visitNotSelector(this); |
285 } | 285 } |
286 | 286 |
287 class Stylesheet extends lang.Node { | 287 class Stylesheet extends ASTNode { |
288 // Contains charset, ruleset, directives (media, page, etc.) | 288 // Contains charset, ruleset, directives (media, page, etc.) |
289 List<lang.Node> _topLevels; | 289 List<ASTNode> _topLevels; |
290 | 290 |
291 Stylesheet(this._topLevels, lang.SourceSpan span) : super(span) { | 291 Stylesheet(this._topLevels, SourceSpan span) : super(span) { |
292 for (final node in _topLevels) { | 292 for (final node in _topLevels) { |
293 assert(node is TopLevelProduction || node is Directive); | 293 assert(node is TopLevelProduction || node is Directive); |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 visit(TreeVisitor visitor) => visitor.visitStylesheet(this); | 297 visit(TreeVisitor visitor) => visitor.visitStylesheet(this); |
298 | 298 |
299 List<lang.Node> get topLevels() => _topLevels; | 299 List<ASTNode> get topLevels() => _topLevels; |
300 | 300 |
301 String toString() { | 301 String toString() { |
302 StringBuffer buff = new StringBuffer(); | 302 StringBuffer buff = new StringBuffer(); |
303 for (final topLevel in _topLevels) { | 303 for (final topLevel in _topLevels) { |
304 buff.add(topLevel.toString()); | 304 buff.add(topLevel.toString()); |
305 } | 305 } |
306 return buff.toString(); | 306 return buff.toString(); |
307 } | 307 } |
308 | 308 |
309 /** A multiline string showing the node and its children. */ | 309 /** A multiline string showing the node and its children. */ |
310 String toDebugString() { | 310 String toDebugString() { |
311 var to = new lang.TreeOutput(); | 311 var to = new TreeOutput(); |
312 var tp = new TreePrinter(to); | 312 var tp = new TreePrinter(to); |
313 this.visit(tp); | 313 this.visit(tp); |
314 return to.buf.toString(); | 314 return to.buf.toString(); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 class TopLevelProduction extends lang.Node { | 318 class TopLevelProduction extends ASTNode { |
319 TopLevelProduction(lang.SourceSpan span) : super(span); | 319 TopLevelProduction(SourceSpan span) : super(span); |
320 | 320 |
321 visit(TreeVisitor visitor) => visitor.visitTopLevelProduction(this); | 321 visit(TreeVisitor visitor) => visitor.visitTopLevelProduction(this); |
322 | 322 |
323 String toString() => "TopLevelProduction"; | 323 String toString() => "TopLevelProduction"; |
324 } | 324 } |
325 | 325 |
326 class RuleSet extends TopLevelProduction { | 326 class RuleSet extends TopLevelProduction { |
327 SelectorGroup _selectorGroup; | 327 SelectorGroup _selectorGroup; |
328 DeclarationGroup _declarationGroup; | 328 DeclarationGroup _declarationGroup; |
329 | 329 |
330 RuleSet(this._selectorGroup, this._declarationGroup, lang.SourceSpan span) : | 330 RuleSet(this._selectorGroup, this._declarationGroup, SourceSpan span) : |
331 super(span); | 331 super(span); |
332 | 332 |
333 SelectorGroup get selectorGroup() => _selectorGroup; | 333 SelectorGroup get selectorGroup() => _selectorGroup; |
334 DeclarationGroup get declarationGroup() => _declarationGroup; | 334 DeclarationGroup get declarationGroup() => _declarationGroup; |
335 | 335 |
336 visit(TreeVisitor visitor) => visitor.visitRuleSet(this); | 336 visit(TreeVisitor visitor) => visitor.visitRuleSet(this); |
337 | 337 |
338 String toString() => | 338 String toString() => |
339 "\n${_selectorGroup.toString()} {\n" + | 339 "\n${_selectorGroup.toString()} {\n" + |
340 "${_declarationGroup.toString()}}\n"; | 340 "${_declarationGroup.toString()}}\n"; |
341 } | 341 } |
342 | 342 |
343 class Directive extends lang.Node { | 343 class Directive extends ASTNode { |
344 Directive(lang.SourceSpan span) : super(span); | 344 Directive(SourceSpan span) : super(span); |
345 | 345 |
346 String toString() => "Directive"; | 346 String toString() => "Directive"; |
347 | 347 |
348 bool get isBuiltIn() => true; // Known CSS directive? | 348 bool get isBuiltIn() => true; // Known CSS directive? |
349 bool get isExtension() => false; // SCSS extension? | 349 bool get isExtension() => false; // SCSS extension? |
350 | 350 |
351 visit(TreeVisitor visitor) => visitor.visitDirective(this); | 351 visit(TreeVisitor visitor) => visitor.visitDirective(this); |
352 } | 352 } |
353 | 353 |
354 class ImportDirective extends Directive { | 354 class ImportDirective extends Directive { |
355 String _import; | 355 String _import; |
356 List<String> _media; | 356 List<String> _media; |
357 | 357 |
358 ImportDirective(this._import, this._media, lang.SourceSpan span) : | 358 ImportDirective(this._import, this._media, SourceSpan span) : |
359 super(span); | 359 super(span); |
360 | 360 |
361 visit(TreeVisitor visitor) => visitor.visitImportDirective(this); | 361 visit(TreeVisitor visitor) => visitor.visitImportDirective(this); |
362 | 362 |
363 String toString() { | 363 String toString() { |
364 StringBuffer buff = new StringBuffer(); | 364 StringBuffer buff = new StringBuffer(); |
365 | 365 |
366 buff.add('@import url(${_import})'); | 366 buff.add('@import url(${_import})'); |
367 | 367 |
368 int idx = 0; | 368 int idx = 0; |
369 for (final medium in _media) { | 369 for (final medium in _media) { |
370 buff.add(idx++ == 0 ? ' $medium' : ',$medium'); | 370 buff.add(idx++ == 0 ? ' $medium' : ',$medium'); |
371 } | 371 } |
372 buff.add('\n'); | 372 buff.add('\n'); |
373 | 373 |
374 return buff.toString(); | 374 return buff.toString(); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 class MediaDirective extends Directive { | 378 class MediaDirective extends Directive { |
379 List<String> _media; | 379 List<String> _media; |
380 RuleSet _ruleset; | 380 RuleSet _ruleset; |
381 | 381 |
382 MediaDirective(this._media, this._ruleset, lang.SourceSpan span) : | 382 MediaDirective(this._media, this._ruleset, SourceSpan span) : |
383 super(span); | 383 super(span); |
384 | 384 |
385 visit(TreeVisitor visitor) => visitor.visitMediaDirective(this); | 385 visit(TreeVisitor visitor) => visitor.visitMediaDirective(this); |
386 | 386 |
387 String toString() { | 387 String toString() { |
388 StringBuffer buff = new StringBuffer(); | 388 StringBuffer buff = new StringBuffer(); |
389 | 389 |
390 buff.add('@media'); | 390 buff.add('@media'); |
391 int idx = 0; | 391 int idx = 0; |
392 for (var medium in _media) { | 392 for (var medium in _media) { |
393 buff.add(idx++ == 0 ? ' $medium' : ',$medium'); | 393 buff.add(idx++ == 0 ? ' $medium' : ',$medium'); |
394 } | 394 } |
395 buff.add(' {\n'); | 395 buff.add(' {\n'); |
396 buff.add(_ruleset.toString()); | 396 buff.add(_ruleset.toString()); |
397 buff.add('\n\}\n'); | 397 buff.add('\n\}\n'); |
398 | 398 |
399 return buff.toString(); | 399 return buff.toString(); |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 class PageDirective extends Directive { | 403 class PageDirective extends Directive { |
404 String _pseudoPage; | 404 String _pseudoPage; |
405 DeclarationGroup _decls; | 405 DeclarationGroup _decls; |
406 | 406 |
407 PageDirective(this._pseudoPage, this._decls, lang.SourceSpan span) : | 407 PageDirective(this._pseudoPage, this._decls, SourceSpan span) : |
408 super(span); | 408 super(span); |
409 | 409 |
410 visit(TreeVisitor visitor) => visitor.visitPageDirective(this); | 410 visit(TreeVisitor visitor) => visitor.visitPageDirective(this); |
411 | 411 |
412 // @page : pseudoPage { | 412 // @page : pseudoPage { |
413 // decls | 413 // decls |
414 // } | 414 // } |
415 String toString() { | 415 String toString() { |
416 StringBuffer buff = new StringBuffer(); | 416 StringBuffer buff = new StringBuffer(); |
417 | 417 |
418 buff.add('@page '); | 418 buff.add('@page '); |
419 if (_pseudoPage != null) { | 419 if (_pseudoPage != null) { |
420 buff.add(': ${_pseudoPage} '); | 420 buff.add(': ${_pseudoPage} '); |
421 } | 421 } |
422 buff.add('{\n${_decls.toString()}\n}\n'); | 422 buff.add('{\n${_decls.toString()}\n}\n'); |
423 | 423 |
424 return buff.toString(); | 424 return buff.toString(); |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 class KeyFrameDirective extends Directive { | 428 class KeyFrameDirective extends Directive { |
429 var _name; | 429 var _name; |
430 List<KeyFrameBlock> _blocks; | 430 List<KeyFrameBlock> _blocks; |
431 | 431 |
432 KeyFrameDirective(this._name, lang.SourceSpan span) : | 432 KeyFrameDirective(this._name, SourceSpan span) : |
433 _blocks = [], super(span); | 433 _blocks = [], super(span); |
434 | 434 |
435 add(KeyFrameBlock block) { | 435 add(KeyFrameBlock block) { |
436 _blocks.add(block); | 436 _blocks.add(block); |
437 } | 437 } |
438 | 438 |
439 String get name() => _name; | 439 String get name() => _name; |
440 | 440 |
441 visit(TreeVisitor visitor) => visitor.visitKeyFrameDirective(this); | 441 visit(TreeVisitor visitor) => visitor.visitKeyFrameDirective(this); |
442 | 442 |
443 String toString() { | 443 String toString() { |
444 StringBuffer buff = new StringBuffer(); | 444 StringBuffer buff = new StringBuffer(); |
445 buff.add('@-webkit-keyframes ${_name} {\n'); | 445 buff.add('@-webkit-keyframes ${_name} {\n'); |
446 for (final block in _blocks) { | 446 for (final block in _blocks) { |
447 buff.add(block.toString()); | 447 buff.add(block.toString()); |
448 } | 448 } |
449 buff.add('}\n'); | 449 buff.add('}\n'); |
450 return buff.toString(); | 450 return buff.toString(); |
451 } | 451 } |
452 } | 452 } |
453 | 453 |
454 class KeyFrameBlock extends lang.Expression { | 454 class KeyFrameBlock extends Expression { |
455 Expressions _blockSelectors; | 455 Expressions _blockSelectors; |
456 DeclarationGroup _declarations; | 456 DeclarationGroup _declarations; |
457 | 457 |
458 KeyFrameBlock(this._blockSelectors, this._declarations, lang.SourceSpan span): | 458 KeyFrameBlock(this._blockSelectors, this._declarations, SourceSpan span): |
459 super(span); | 459 super(span); |
460 | 460 |
461 visit(TreeVisitor visitor) => visitor.visitKeyFrameBlock(this); | 461 visit(TreeVisitor visitor) => visitor.visitKeyFrameBlock(this); |
462 | 462 |
463 String toString() { | 463 String toString() { |
464 StringBuffer buff = new StringBuffer(); | 464 StringBuffer buff = new StringBuffer(); |
465 buff.add(' ${_blockSelectors.toString()} {\n'); | 465 buff.add(' ${_blockSelectors.toString()} {\n'); |
466 buff.add(_declarations.toString()); | 466 buff.add(_declarations.toString()); |
467 buff.add(' }\n'); | 467 buff.add(' }\n'); |
468 return buff.toString(); | 468 return buff.toString(); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |
472 // TODO(terry): TBD | 472 // TODO(terry): TBD |
473 class FontFaceDirective extends Directive { | 473 class FontFaceDirective extends Directive { |
474 List<Declaration> _declarations; | 474 List<Declaration> _declarations; |
475 | 475 |
476 FontFaceDirective(this._declarations, lang.SourceSpan span) : super(span); | 476 FontFaceDirective(this._declarations, SourceSpan span) : super(span); |
477 | 477 |
478 visit(TreeVisitor visitor) => visitor.visitFontFaceDirective(this); | 478 visit(TreeVisitor visitor) => visitor.visitFontFaceDirective(this); |
479 | 479 |
480 String toString() { | 480 String toString() { |
481 return "TO BE DONE"; | 481 return "TO BE DONE"; |
482 } | 482 } |
483 } | 483 } |
484 | 484 |
485 class IncludeDirective extends Directive { | 485 class IncludeDirective extends Directive { |
486 String _include; | 486 String _include; |
487 Stylesheet _stylesheet; | 487 Stylesheet _stylesheet; |
488 | 488 |
489 IncludeDirective(this._include, this._stylesheet, lang.SourceSpan span) : | 489 IncludeDirective(this._include, this._stylesheet, SourceSpan span) : |
490 super(span); | 490 super(span); |
491 | 491 |
492 visit(TreeVisitor visitor) => visitor.visitIncludeDirective(this); | 492 visit(TreeVisitor visitor) => visitor.visitIncludeDirective(this); |
493 | 493 |
494 bool get isBuiltIn() => false; | 494 bool get isBuiltIn() => false; |
495 bool get isExtension() => true; | 495 bool get isExtension() => true; |
496 | 496 |
497 Stylesheet get styleSheet() => _stylesheet; | 497 Stylesheet get styleSheet() => _stylesheet; |
498 | 498 |
499 String toString() { | 499 String toString() { |
500 StringBuffer buff = new StringBuffer(); | 500 StringBuffer buff = new StringBuffer(); |
501 buff.add('/****** @include ${_include} ******/\n'); | 501 buff.add('/****** @include ${_include} ******/\n'); |
502 buff.add(_stylesheet != null ? _stylesheet.toString() : '// <EMPTY>'); | 502 buff.add(_stylesheet != null ? _stylesheet.toString() : '// <EMPTY>'); |
503 buff.add('/****** End of ${_include} ******/\n\n'); | 503 buff.add('/****** End of ${_include} ******/\n\n'); |
504 return buff.toString(); | 504 return buff.toString(); |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 class StyletDirective extends Directive { | 508 class StyletDirective extends Directive { |
509 String _dartClassName; | 509 String _dartClassName; |
510 List<RuleSet> _rulesets; | 510 List<RuleSet> _rulesets; |
511 | 511 |
512 StyletDirective(this._dartClassName, this._rulesets, lang.SourceSpan span) : | 512 StyletDirective(this._dartClassName, this._rulesets, SourceSpan span) : |
513 super(span); | 513 super(span); |
514 | 514 |
515 bool get isBuiltIn() => false; | 515 bool get isBuiltIn() => false; |
516 bool get isExtension() => true; | 516 bool get isExtension() => true; |
517 | 517 |
518 String get dartClassName() => _dartClassName; | 518 String get dartClassName() => _dartClassName; |
519 List<RuleSet> get rulesets() => _rulesets; | 519 List<RuleSet> get rulesets() => _rulesets; |
520 | 520 |
521 visit(TreeVisitor visitor) => visitor.visitStyletDirective(this); | 521 visit(TreeVisitor visitor) => visitor.visitStyletDirective(this); |
522 | 522 |
523 // TODO(terry): Output Dart class | 523 // TODO(terry): Output Dart class |
524 String toString() => '/* @stylet export as ${_dartClassName} */\n'; | 524 String toString() => '/* @stylet export as ${_dartClassName} */\n'; |
525 } | 525 } |
526 | 526 |
527 class Declaration extends lang.Node { | 527 class Declaration extends ASTNode { |
528 Identifier _property; | 528 Identifier _property; |
529 lang.Expression _expression; | 529 Expression _expression; |
530 bool _important; | 530 bool _important; |
531 | 531 |
532 Declaration(this._property, this._expression, lang.SourceSpan span) : | 532 Declaration(this._property, this._expression, SourceSpan span) : |
533 _important = false, super(span); | 533 _important = false, super(span); |
534 | 534 |
535 String get property() => _property.name; | 535 String get property() => _property.name; |
536 lang.Expression get expression() => _expression; | 536 Expression get expression() => _expression; |
537 | 537 |
538 bool get important() => _important; | 538 bool get important() => _important; |
539 set important(bool value) => _important = value; | 539 set important(bool value) => _important = value; |
540 String importantAsString() => _important ? ' !important' : ''; | 540 String importantAsString() => _important ? ' !important' : ''; |
541 | 541 |
542 visit(TreeVisitor visitor) => visitor.visitDeclaration(this); | 542 visit(TreeVisitor visitor) => visitor.visitDeclaration(this); |
543 | 543 |
544 String toString() => | 544 String toString() => |
545 "${_property.name}: ${_expression.toString()}${importantAsString()}"; | 545 "${_property.name}: ${_expression.toString()}${importantAsString()}"; |
546 } | 546 } |
547 | 547 |
548 class DeclarationGroup extends lang.Node { | 548 class DeclarationGroup extends ASTNode { |
549 List<Declaration> _declarations; | 549 List<Declaration> _declarations; |
550 | 550 |
551 DeclarationGroup(this._declarations, lang.SourceSpan span) : super(span); | 551 DeclarationGroup(this._declarations, SourceSpan span) : super(span); |
552 | 552 |
553 List<Declaration> get declarations() => _declarations; | 553 List<Declaration> get declarations() => _declarations; |
554 | 554 |
555 visit(TreeVisitor visitor) => visitor.visitDeclarationGroup(this); | 555 visit(TreeVisitor visitor) => visitor.visitDeclarationGroup(this); |
556 | 556 |
557 String toString() { | 557 String toString() { |
558 StringBuffer buff = new StringBuffer(); | 558 StringBuffer buff = new StringBuffer(); |
559 int idx = 0; | 559 int idx = 0; |
560 for (final declaration in _declarations) { | 560 for (final declaration in _declarations) { |
561 buff.add(" ${declaration.toString()};\n"); | 561 buff.add(" ${declaration.toString()};\n"); |
562 } | 562 } |
563 return buff.toString(); | 563 return buff.toString(); |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 class OperatorSlash extends lang.Expression { | 567 class OperatorSlash extends Expression { |
568 OperatorSlash(lang.SourceSpan span) : super(span); | 568 OperatorSlash(SourceSpan span) : super(span); |
569 | 569 |
570 visit(TreeVisitor visitor) => visitor.visitOperatorSlash(this); | 570 visit(TreeVisitor visitor) => visitor.visitOperatorSlash(this); |
571 | 571 |
572 String toString() => ' /'; | 572 String toString() => ' /'; |
573 } | 573 } |
574 | 574 |
575 class OperatorComma extends lang.Expression { | 575 class OperatorComma extends Expression { |
576 OperatorComma(lang.SourceSpan span) : super(span); | 576 OperatorComma(SourceSpan span) : super(span); |
577 | 577 |
578 visit(TreeVisitor visitor) => visitor.visitOperatorComma(this); | 578 visit(TreeVisitor visitor) => visitor.visitOperatorComma(this); |
579 | 579 |
580 String toString() => ','; | 580 String toString() => ','; |
581 } | 581 } |
582 | 582 |
583 class LiteralTerm extends lang.Expression { | 583 class LiteralTerm extends Expression { |
584 var _value; | 584 var _value; |
585 String _text; | 585 String _text; |
586 | 586 |
587 LiteralTerm(this._value, this._text, lang.SourceSpan span) : super(span); | 587 LiteralTerm(this._value, this._text, SourceSpan span) : super(span); |
588 | 588 |
589 get value() => _value; | 589 get value() => _value; |
590 String get text() => _text; | 590 String get text() => _text; |
591 | 591 |
592 visit(TreeVisitor visitor) => visitor.visitLiteralTerm(this); | 592 visit(TreeVisitor visitor) => visitor.visitLiteralTerm(this); |
593 | 593 |
594 String toString() => _text; | 594 String toString() => _text; |
595 } | 595 } |
596 | 596 |
597 class NumberTerm extends LiteralTerm { | 597 class NumberTerm extends LiteralTerm { |
598 NumberTerm(var value, String t, lang.SourceSpan span) : super(value, t, span); | 598 NumberTerm(var value, String t, SourceSpan span) : super(value, t, span); |
599 | 599 |
600 visit(TreeVisitor visitor) => visitor.visitNumberTerm(this); | 600 visit(TreeVisitor visitor) => visitor.visitNumberTerm(this); |
601 } | 601 } |
602 | 602 |
603 class UnitTerm extends LiteralTerm { | 603 class UnitTerm extends LiteralTerm { |
604 int _unit; | 604 int _unit; |
605 | 605 |
606 UnitTerm(var value, String t, lang.SourceSpan span, this._unit) : | 606 UnitTerm(var value, String t, SourceSpan span, this._unit) : |
607 super(value, t, span); | 607 super(value, t, span); |
608 | 608 |
609 int get unit() => _unit; | 609 int get unit() => _unit; |
610 | 610 |
611 visit(TreeVisitor visitor) => visitor.visitUnitTerm(this); | 611 visit(TreeVisitor visitor) => visitor.visitUnitTerm(this); |
612 | 612 |
613 String toString() => '${text}${unitToString()}'; | 613 String toString() => '${text}${unitToString()}'; |
614 String unitToString() => TokenKind.unitToString(_unit); | 614 String unitToString() => TokenKind.unitToString(_unit); |
615 } | 615 } |
616 | 616 |
617 class LengthTerm extends UnitTerm { | 617 class LengthTerm extends UnitTerm { |
618 LengthTerm(var value, String t, lang.SourceSpan span, | 618 LengthTerm(var value, String t, SourceSpan span, |
619 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | 619 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { |
620 assert(this._unit == TokenKind.UNIT_LENGTH_PX || | 620 assert(this._unit == TokenKind.UNIT_LENGTH_PX || |
621 this._unit == TokenKind.UNIT_LENGTH_CM || | 621 this._unit == TokenKind.UNIT_LENGTH_CM || |
622 this._unit == TokenKind.UNIT_LENGTH_MM || | 622 this._unit == TokenKind.UNIT_LENGTH_MM || |
623 this._unit == TokenKind.UNIT_LENGTH_IN || | 623 this._unit == TokenKind.UNIT_LENGTH_IN || |
624 this._unit == TokenKind.UNIT_LENGTH_PT || | 624 this._unit == TokenKind.UNIT_LENGTH_PT || |
625 this._unit == TokenKind.UNIT_LENGTH_PC); | 625 this._unit == TokenKind.UNIT_LENGTH_PC); |
626 } | 626 } |
627 | 627 |
628 visit(TreeVisitor visitor) => visitor.visitLengthTerm(this); | 628 visit(TreeVisitor visitor) => visitor.visitLengthTerm(this); |
629 } | 629 } |
630 | 630 |
631 class PercentageTerm extends LiteralTerm { | 631 class PercentageTerm extends LiteralTerm { |
632 PercentageTerm(var value, String t, lang.SourceSpan span) : | 632 PercentageTerm(var value, String t, SourceSpan span) : |
633 super(value, t, span); | 633 super(value, t, span); |
634 | 634 |
635 visit(TreeVisitor visitor) => visitor.visitPercentageTerm(this); | 635 visit(TreeVisitor visitor) => visitor.visitPercentageTerm(this); |
636 | 636 |
637 String toString() => '${text}%'; | 637 String toString() => '${text}%'; |
638 | 638 |
639 } | 639 } |
640 | 640 |
641 class EmTerm extends LiteralTerm { | 641 class EmTerm extends LiteralTerm { |
642 EmTerm(var value, String t, lang.SourceSpan span) : | 642 EmTerm(var value, String t, SourceSpan span) : |
643 super(value, t, span); | 643 super(value, t, span); |
644 | 644 |
645 visit(TreeVisitor visitor) => visitor.visitEmTerm(this); | 645 visit(TreeVisitor visitor) => visitor.visitEmTerm(this); |
646 | 646 |
647 String toString() => '${text}em'; | 647 String toString() => '${text}em'; |
648 } | 648 } |
649 | 649 |
650 class ExTerm extends LiteralTerm { | 650 class ExTerm extends LiteralTerm { |
651 ExTerm(var value, String t, lang.SourceSpan span) : | 651 ExTerm(var value, String t, SourceSpan span) : |
652 super(value, t, span); | 652 super(value, t, span); |
653 | 653 |
654 visit(TreeVisitor visitor) => visitor.visitExTerm(this); | 654 visit(TreeVisitor visitor) => visitor.visitExTerm(this); |
655 | 655 |
656 String toString() => '${text}ex'; | 656 String toString() => '${text}ex'; |
657 } | 657 } |
658 | 658 |
659 class AngleTerm extends UnitTerm { | 659 class AngleTerm extends UnitTerm { |
660 AngleTerm(var value, String t, lang.SourceSpan span, | 660 AngleTerm(var value, String t, SourceSpan span, |
661 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | 661 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { |
662 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || | 662 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || |
663 this._unit == TokenKind.UNIT_ANGLE_RAD || | 663 this._unit == TokenKind.UNIT_ANGLE_RAD || |
664 this._unit == TokenKind.UNIT_ANGLE_GRAD); | 664 this._unit == TokenKind.UNIT_ANGLE_GRAD); |
665 } | 665 } |
666 | 666 |
667 visit(TreeVisitor visitor) => visitor.visitAngleTerm(this); | 667 visit(TreeVisitor visitor) => visitor.visitAngleTerm(this); |
668 } | 668 } |
669 | 669 |
670 class TimeTerm extends UnitTerm { | 670 class TimeTerm extends UnitTerm { |
671 TimeTerm(var value, String t, lang.SourceSpan span, | 671 TimeTerm(var value, String t, SourceSpan span, |
672 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | 672 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { |
673 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || | 673 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || |
674 this._unit == TokenKind.UNIT_TIME_MS || | 674 this._unit == TokenKind.UNIT_TIME_MS || |
675 this._unit == TokenKind.UNIT_TIME_S); | 675 this._unit == TokenKind.UNIT_TIME_S); |
676 } | 676 } |
677 | 677 |
678 visit(TreeVisitor visitor) => visitor.visitTimeTerm(this); | 678 visit(TreeVisitor visitor) => visitor.visitTimeTerm(this); |
679 } | 679 } |
680 | 680 |
681 class FreqTerm extends UnitTerm { | 681 class FreqTerm extends UnitTerm { |
682 FreqTerm(var value, String t, lang.SourceSpan span, | 682 FreqTerm(var value, String t, SourceSpan span, |
683 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | 683 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { |
684 assert(_unit == TokenKind.UNIT_FREQ_HZ || _unit == TokenKind.UNIT_FREQ_KHZ); | 684 assert(_unit == TokenKind.UNIT_FREQ_HZ || _unit == TokenKind.UNIT_FREQ_KHZ); |
685 } | 685 } |
686 | 686 |
687 visit(TreeVisitor visitor) => visitor.visitFreqTerm(this); | 687 visit(TreeVisitor visitor) => visitor.visitFreqTerm(this); |
688 } | 688 } |
689 | 689 |
690 class FractionTerm extends LiteralTerm { | 690 class FractionTerm extends LiteralTerm { |
691 FractionTerm(var value, String t, lang.SourceSpan span) : | 691 FractionTerm(var value, String t, SourceSpan span) : |
692 super(value, t, span); | 692 super(value, t, span); |
693 | 693 |
694 visit(TreeVisitor visitor) => visitor.visitFractionTerm(this); | 694 visit(TreeVisitor visitor) => visitor.visitFractionTerm(this); |
695 | 695 |
696 String toString() => '${text}fr'; | 696 String toString() => '${text}fr'; |
697 } | 697 } |
698 | 698 |
699 class UriTerm extends LiteralTerm { | 699 class UriTerm extends LiteralTerm { |
700 UriTerm(String value, lang.SourceSpan span) : super(value, value, span); | 700 UriTerm(String value, SourceSpan span) : super(value, value, span); |
701 | 701 |
702 visit(TreeVisitor visitor) => visitor.visitUriTerm(this); | 702 visit(TreeVisitor visitor) => visitor.visitUriTerm(this); |
703 | 703 |
704 String toString() => 'url(${text})'; | 704 String toString() => 'url(${text})'; |
705 } | 705 } |
706 | 706 |
707 class HexColorTerm extends LiteralTerm { | 707 class HexColorTerm extends LiteralTerm { |
708 HexColorTerm(var value, String t, lang.SourceSpan span) : | 708 HexColorTerm(var value, String t, SourceSpan span) : |
709 super(value, t, span); | 709 super(value, t, span); |
710 | 710 |
711 visit(TreeVisitor visitor) => visitor.visitHexColorTerm(this); | 711 visit(TreeVisitor visitor) => visitor.visitHexColorTerm(this); |
712 | 712 |
713 String toString() => '#${text}'; | 713 String toString() => '#${text}'; |
714 } | 714 } |
715 | 715 |
716 class FunctionTerm extends LiteralTerm { | 716 class FunctionTerm extends LiteralTerm { |
717 Expressions _params; | 717 Expressions _params; |
718 | 718 |
719 FunctionTerm(var value, String t, this._params, lang.SourceSpan span) | 719 FunctionTerm(var value, String t, this._params, SourceSpan span) |
720 : super(value, t, span); | 720 : super(value, t, span); |
721 | 721 |
722 visit(TreeVisitor visitor) => visitor.visitFunctionTerm(this); | 722 visit(TreeVisitor visitor) => visitor.visitFunctionTerm(this); |
723 | 723 |
724 String toString() { | 724 String toString() { |
725 // TODO(terry): Optimize rgb to a hexcolor. | 725 // TODO(terry): Optimize rgb to a hexcolor. |
726 StringBuffer buff = new StringBuffer(); | 726 StringBuffer buff = new StringBuffer(); |
727 | 727 |
728 buff.add('${text}('); | 728 buff.add('${text}('); |
729 buff.add(_params.toString()); | 729 buff.add(_params.toString()); |
730 buff.add(')'); | 730 buff.add(')'); |
731 | 731 |
732 return buff.toString(); | 732 return buff.toString(); |
733 } | 733 } |
734 } | 734 } |
735 | 735 |
736 class GroupTerm extends lang.Expression { | 736 class GroupTerm extends Expression { |
737 List<LiteralTerm> _terms; | 737 List<LiteralTerm> _terms; |
738 | 738 |
739 GroupTerm(lang.SourceSpan span) : _terms = [], super(span); | 739 GroupTerm(SourceSpan span) : _terms = [], super(span); |
740 | 740 |
741 add(LiteralTerm term) { | 741 add(LiteralTerm term) { |
742 _terms.add(term); | 742 _terms.add(term); |
743 } | 743 } |
744 | 744 |
745 visit(TreeVisitor visitor) => visitor.visitGroupTerm(this); | 745 visit(TreeVisitor visitor) => visitor.visitGroupTerm(this); |
746 | 746 |
747 String toString() { | 747 String toString() { |
748 StringBuffer buff = new StringBuffer(); | 748 StringBuffer buff = new StringBuffer(); |
749 buff.add('('); | 749 buff.add('('); |
750 int idx = 0; | 750 int idx = 0; |
751 for (final term in _terms) { | 751 for (final term in _terms) { |
752 if (idx++ > 0) { | 752 if (idx++ > 0) { |
753 buff.add(' '); | 753 buff.add(' '); |
754 } | 754 } |
755 buff.add(term.toString()); | 755 buff.add(term.toString()); |
756 } | 756 } |
757 buff.add(')'); | 757 buff.add(')'); |
758 return buff.toString(); | 758 return buff.toString(); |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 class ItemTerm extends NumberTerm { | 762 class ItemTerm extends NumberTerm { |
763 ItemTerm(var value, String t, lang.SourceSpan span) : super(value, t, span); | 763 ItemTerm(var value, String t, SourceSpan span) : super(value, t, span); |
764 | 764 |
765 visit(TreeVisitor visitor) => visitor.visitItemTerm(this); | 765 visit(TreeVisitor visitor) => visitor.visitItemTerm(this); |
766 | 766 |
767 String toString() => '[${text}]'; | 767 String toString() => '[${text}]'; |
768 } | 768 } |
769 | 769 |
770 class Expressions extends lang.Expression { | 770 class Expressions extends Expression { |
771 List<lang.Expression> _expressions; | 771 List<Expression> _expressions; |
772 | 772 |
773 Expressions(lang.SourceSpan span): super(span), _expressions = []; | 773 Expressions(SourceSpan span): super(span), _expressions = []; |
774 | 774 |
775 add(lang.Expression expression) { | 775 add(Expression expression) { |
776 _expressions.add(expression); | 776 _expressions.add(expression); |
777 } | 777 } |
778 | 778 |
779 List<lang.Expression> get expressions() => _expressions; | 779 List<Expression> get expressions() => _expressions; |
780 | 780 |
781 visit(TreeVisitor visitor) => visitor.visitExpressions(this); | 781 visit(TreeVisitor visitor) => visitor.visitExpressions(this); |
782 | 782 |
783 String toString() { | 783 String toString() { |
784 StringBuffer buff = new StringBuffer(); | 784 StringBuffer buff = new StringBuffer(); |
785 int idx = 0; | 785 int idx = 0; |
786 for (final expression in _expressions) { | 786 for (final expression in _expressions) { |
787 // Add space seperator between terms without an operator. | 787 // Add space seperator between terms without an operator. |
788 // TODO(terry): Should have a BinaryExpression to solve this problem. | 788 // TODO(terry): Should have a BinaryExpression to solve this problem. |
789 if (idx > 0 && | 789 if (idx > 0 && |
790 !(expression is OperatorComma || expression is OperatorSlash)) { | 790 !(expression is OperatorComma || expression is OperatorSlash)) { |
791 buff.add(' '); | 791 buff.add(' '); |
792 } | 792 } |
793 buff.add(expression.toString()); | 793 buff.add(expression.toString()); |
794 idx++; | 794 idx++; |
795 } | 795 } |
796 return buff.toString(); | 796 return buff.toString(); |
797 } | 797 } |
798 } | 798 } |
799 | 799 |
800 class BinaryExpression extends lang.Expression { | 800 class BinaryExpression extends Expression { |
801 lang.Token op; | 801 Token op; |
802 lang.Expression x; | 802 Expression x; |
803 lang.Expression y; | 803 Expression y; |
804 | 804 |
805 BinaryExpression(this.op, this.x, this.y, lang.SourceSpan span): super(span); | 805 BinaryExpression(this.op, this.x, this.y, SourceSpan span): super(span); |
806 | 806 |
807 visit(TreeVisitor visitor) => visitor.visitBinaryExpression(this); | 807 visit(TreeVisitor visitor) => visitor.visitBinaryExpression(this); |
808 } | 808 } |
809 | 809 |
810 class UnaryExpression extends lang.Expression { | 810 class UnaryExpression extends Expression { |
811 lang.Token op; | 811 Token op; |
812 lang.Expression self; | 812 Expression self; |
813 | 813 |
814 UnaryExpression(this.op, this.self, lang.SourceSpan span): super(span); | 814 UnaryExpression(this.op, this.self, SourceSpan span): super(span); |
815 | 815 |
816 visit(TreeVisitor visitor) => visitor.visitUnaryExpression(this); | 816 visit(TreeVisitor visitor) => visitor.visitUnaryExpression(this); |
817 } | 817 } |
818 | 818 |
819 interface TreeVisitor { | 819 interface TreeVisitor { |
820 void visitCssComment(CssComment node); | 820 void visitCssComment(CssComment node); |
821 void visitCommentDefinition(CommentDefinition node); | 821 void visitCommentDefinition(CommentDefinition node); |
822 void visitStylesheet(Stylesheet node); | 822 void visitStylesheet(Stylesheet node); |
823 void visitTopLevelProduction(TopLevelProduction node); | 823 void visitTopLevelProduction(TopLevelProduction node); |
824 void visitDirective(Directive node); | 824 void visitDirective(Directive node); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 void visitOperatorComma(OperatorComma node); | 867 void visitOperatorComma(OperatorComma node); |
868 | 868 |
869 void visitExpressions(Expressions node); | 869 void visitExpressions(Expressions node); |
870 void visitBinaryExpression(BinaryExpression node); | 870 void visitBinaryExpression(BinaryExpression node); |
871 void visitUnaryExpression(UnaryExpression node); | 871 void visitUnaryExpression(UnaryExpression node); |
872 | 872 |
873 void visitIdentifier(Identifier node); | 873 void visitIdentifier(Identifier node); |
874 void visitWildcard(Wildcard node); | 874 void visitWildcard(Wildcard node); |
875 | 875 |
876 // TODO(terry): Defined for ../tree.dart. | 876 // TODO(terry): Defined for ../tree.dart. |
877 void visitTypeReference(lang.TypeReference node); | 877 void visitTypeReference(TypeReference node); |
878 } | 878 } |
879 | 879 |
880 class TreePrinter implements TreeVisitor { | 880 class TreePrinter implements TreeVisitor { |
881 var output; | 881 var output; |
882 TreePrinter(this.output) { output.printer = this; } | 882 TreePrinter(this.output) { output.printer = this; } |
883 | 883 |
884 void visitStylesheet(Stylesheet node) { | 884 void visitStylesheet(Stylesheet node) { |
885 output.heading('Stylesheet', node.span); | 885 output.heading('Stylesheet', node.span); |
886 output.depth++; | 886 output.depth++; |
887 output.writeNodeList('productions', node._topLevels); | 887 output.writeNodeList('productions', node._topLevels); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 | 1266 |
1267 void visitIdentifier(Identifier node) { | 1267 void visitIdentifier(Identifier node) { |
1268 output.heading('Identifier(' + output.toValue(node.name) + ")", node.span); | 1268 output.heading('Identifier(' + output.toValue(node.name) + ")", node.span); |
1269 } | 1269 } |
1270 | 1270 |
1271 void visitWildcard(Wildcard node) { | 1271 void visitWildcard(Wildcard node) { |
1272 output.heading('Wildcard(*)', node.span); | 1272 output.heading('Wildcard(*)', node.span); |
1273 } | 1273 } |
1274 | 1274 |
1275 // TODO(terry): Defined for frog/tree.dart. | 1275 // TODO(terry): Defined for frog/tree.dart. |
1276 void visitTypeReference(lang.TypeReference node) { | 1276 void visitTypeReference(TypeReference node) { |
1277 output.heading('Unimplemented'); | 1277 output.heading('Unimplemented'); |
1278 } | 1278 } |
1279 } | 1279 } |
OLD | NEW |