OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 | 4 |
5 part of csslib.visitor; | 5 part of csslib.visitor; |
6 | 6 |
7 // TODO(terry): Enable class for debug only; when conditional imports enabled. | 7 // TODO(terry): Enable class for debug only; when conditional imports enabled. |
8 | 8 |
9 /** Helper function to dump the CSS AST. */ | 9 /** Helper function to dump the CSS AST. */ |
10 String treeToDebugString(StyleSheet styleSheet, [bool useSpan = false]) { | 10 String treeToDebugString(StyleSheet styleSheet, [bool useSpan = false]) { |
11 var to = new TreeOutput(); | 11 var to = new TreeOutput(); |
12 new _TreePrinter(to, useSpan)..visitTree(styleSheet); | 12 new _TreePrinter(to, useSpan)..visitTree(styleSheet); |
13 return to.toString(); | 13 return to.toString(); |
14 } | 14 } |
15 | 15 |
16 /** Tree dump for debug output of the CSS AST. */ | 16 /** Tree dump for debug output of the CSS AST. */ |
17 class _TreePrinter extends Visitor { | 17 class _TreePrinter extends Visitor { |
18 final TreeOutput output; | 18 final TreeOutput output; |
19 final bool useSpan; | 19 final bool useSpan; |
20 _TreePrinter(this.output, this.useSpan) { output.printer = this; } | 20 _TreePrinter(this.output, this.useSpan) { |
| 21 output.printer = this; |
| 22 } |
21 | 23 |
22 void visitTree(StyleSheet tree) => visitStylesheet(tree); | 24 void visitTree(StyleSheet tree) => visitStylesheet(tree); |
23 | 25 |
24 void heading(String heading, node) { | 26 void heading(String heading, node) { |
25 if (useSpan) { | 27 if (useSpan) { |
26 output.heading(heading, node.span); | 28 output.heading(heading, node.span); |
27 } else { | 29 } else { |
28 output.heading(heading); | 30 output.heading(heading); |
29 } | 31 } |
30 } | 32 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 void visitSelectorGroup(SelectorGroup node) { | 239 void visitSelectorGroup(SelectorGroup node) { |
238 heading('Selector Group', node); | 240 heading('Selector Group', node); |
239 output.depth++; | 241 output.depth++; |
240 output.writeNodeList('selectors', node.selectors); | 242 output.writeNodeList('selectors', node.selectors); |
241 output.depth--; | 243 output.depth--; |
242 } | 244 } |
243 | 245 |
244 void visitSelector(Selector node) { | 246 void visitSelector(Selector node) { |
245 heading('Selector', node); | 247 heading('Selector', node); |
246 output.depth++; | 248 output.depth++; |
247 output.writeNodeList('simpleSelectorsSequences', | 249 output.writeNodeList( |
248 node.simpleSelectorSequences); | 250 'simpleSelectorsSequences', node.simpleSelectorSequences); |
249 output.depth--; | 251 output.depth--; |
250 } | 252 } |
251 | 253 |
252 void visitSimpleSelectorSequence(SimpleSelectorSequence node) { | 254 void visitSimpleSelectorSequence(SimpleSelectorSequence node) { |
253 heading('SimpleSelectorSequence', node); | 255 heading('SimpleSelectorSequence', node); |
254 output.depth++; | 256 output.depth++; |
255 if (node.isCombinatorNone) { | 257 if (node.isCombinatorNone) { |
256 output.writeValue('combinator', "NONE"); | 258 output.writeValue('combinator', "NONE"); |
257 } else if (node.isCombinatorDescendant) { | 259 } else if (node.isCombinatorDescendant) { |
258 output.writeValue('combinator', "descendant"); | 260 output.writeValue('combinator', "descendant"); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 output.writeValue('1st value', node.first); | 365 output.writeValue('1st value', node.first); |
364 output.writeValue('2nd value', node.second); | 366 output.writeValue('2nd value', node.second); |
365 output.depth--; | 367 output.depth--; |
366 } | 368 } |
367 | 369 |
368 void visitLiteralTerm(LiteralTerm node) { | 370 void visitLiteralTerm(LiteralTerm node) { |
369 heading('LiteralTerm', node); | 371 heading('LiteralTerm', node); |
370 output.depth++; | 372 output.depth++; |
371 output.writeValue('value', node.text); | 373 output.writeValue('value', node.text); |
372 output.depth--; | 374 output.depth--; |
373 } | 375 } |
374 | 376 |
375 void visitHexColorTerm(HexColorTerm node) { | 377 void visitHexColorTerm(HexColorTerm node) { |
376 heading('HexColorTerm', node); | 378 heading('HexColorTerm', node); |
377 output.depth++; | 379 output.depth++; |
378 output.writeValue('hex value', node.text); | 380 output.writeValue('hex value', node.text); |
379 output.writeValue('decimal value', node.value); | 381 output.writeValue('decimal value', node.value); |
380 output.depth--; | 382 output.depth--; |
381 } | 383 } |
382 | 384 |
383 void visitNumberTerm(NumberTerm node) { | 385 void visitNumberTerm(NumberTerm node) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 } | 551 } |
550 | 552 |
551 void visitPaddingExpression(PaddingExpression node) { | 553 void visitPaddingExpression(PaddingExpression node) { |
552 heading('Dart Style PaddingExpression', node); | 554 heading('Dart Style PaddingExpression', node); |
553 } | 555 } |
554 | 556 |
555 void visitWidthExpression(WidthExpression node) { | 557 void visitWidthExpression(WidthExpression node) { |
556 heading('Dart Style WidthExpression', node); | 558 heading('Dart Style WidthExpression', node); |
557 } | 559 } |
558 } | 560 } |
OLD | NEW |