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

Side by Side Diff: pkg/csslib/lib/src/tree_printer.dart

Issue 23168002: move csslib into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/csslib/lib/src/tree_base.dart ('k') | pkg/csslib/lib/src/validate.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of csslib.visitor;
6
7 // TODO(terry): Enable class for debug only; when conditional imports enabled.
8
9 /** Helper function to dump the CSS AST. */
10 String treeToDebugString(styleSheet, [bool useSpan = false]) {
11 var to = new TreeOutput();
12 new _TreePrinter(to, useSpan)..visitTree(styleSheet);
13 return to.toString();
14 }
15
16 /** Tree dump for debug output of the CSS AST. */
17 class _TreePrinter extends Visitor {
18 var output;
19 final bool useSpan;
20 _TreePrinter(this.output, this.useSpan) { output.printer = this; }
21
22 void visitTree(tree) => visitStylesheet(tree);
23
24 void heading(String heading, node) {
25 if (useSpan) {
26 output.heading(heading, node.span);
27 } else {
28 output.heading(heading);
29 }
30 }
31
32 void visitStylesheet(StyleSheet node) {
33 heading('Stylesheet', node);
34 output.depth++;
35 super.visitStyleSheet(node);
36 output.depth--;
37 }
38
39 void visitTopLevelProduction(TopLevelProduction node) {
40 heading('TopLevelProduction', node);
41 }
42
43 void visitDirective(Directive node) {
44 heading('Directive', node);
45 }
46
47 void visitCssComment(CssComment node) {
48 heading('Comment', node);
49 output.depth++;
50 output.writeValue('comment value', node.comment);
51 output.depth--;
52 }
53
54 void visitCommentDefinition(CommentDefinition node) {
55 heading('CommentDefinition (CDO/CDC)', node);
56 output.depth++;
57 output.writeValue('comment value', node.comment);
58 output.depth--;
59 }
60
61 void visitMediaExpression(MediaExpression node) {
62 heading('MediaExpression', node);
63 output.writeValue('feature', node.mediaFeature);
64 if (node.andOperator) output.writeValue('AND operator', '');
65 visitExpressions(node.exprs);
66 }
67
68 void visitMediaQueries(MediaQuery query) {
69 output.headeing('MediaQueries');
70 output.writeValue('unary', query.unary);
71 output.writeValue('media type', query.mediaType);
72 output.writeNodeList('media expressions', query.expressions);
73 }
74
75 void visitMediaDirective(MediaDirective node) {
76 heading('MediaDirective', node);
77 output.depth++;
78 output.writeNodeList('media queries', node.mediaQueries);
79 output.writeNodeList('rule sets', node.rulesets);
80 super.visitMediaDirective(node);
81 output.depth--;
82 }
83
84 void visitPageDirective(PageDirective node) {
85 heading('PageDirective', node);
86 output.depth++;
87 output.writeValue('pseudo page', node._pseudoPage);
88 super.visitPageDirective(node);
89 output.depth;
90 }
91
92 void visitCharsetDirective(CharsetDirective node) {
93 heading('Charset Directive', node);
94 output.writeValue('charset encoding', node.charEncoding);
95 }
96
97 void visitImportDirective(ImportDirective node) {
98 heading('ImportDirective', node);
99 output.depth++;
100 output.writeValue('import', node.import);
101 super.visitImportDirective(node);
102 output.writeNodeList('media', node.mediaQueries);
103 output.depth--;
104 }
105
106 void visitKeyFrameDirective(KeyFrameDirective node) {
107 heading('KeyFrameDirective', node);
108 output.depth++;
109 output.writeValue('keyframe', node.keyFrameName);
110 output.writeValue('name', node._name);
111 output.writeNodeList('blocks', node._blocks);
112 output.depth--;
113 }
114
115 void visitKeyFrameBlock(KeyFrameBlock node) {
116 heading('KeyFrameBlock', node);
117 output.depth++;
118 super.visitKeyFrameBlock(node);
119 output.depth--;
120 }
121
122 void visitFontFaceDirective(FontFaceDirective node) {
123 // TODO(terry): To Be Implemented
124 }
125
126 void visitStyletDirective(StyletDirective node) {
127 heading('StyletDirective', node);
128 output.writeValue('dartClassName', node._dartClassName);
129 output.depth++;
130 output.writeNodeList('rulesets', node._rulesets);
131 output.depth--;
132 }
133
134 void visitNamespaceDirective(NamespaceDirective node) {
135 heading('NamespaceDirective', node);
136 output.depth++;
137 output.writeValue('prefix', node._prefix);
138 output.writeValue('uri', node._uri);
139 output.depth--;
140 }
141
142 void visitVarDefinitionDirective(VarDefinitionDirective node) {
143 heading('Less variable definition', node);
144 visitVarDefinition(node.def);
145 }
146
147 void visitRuleSet(RuleSet node) {
148 heading('Ruleset', node);
149 output.depth++;
150 super.visitRuleSet(node);
151 output.depth--;
152 }
153
154 void visitDeclarationGroup(DeclarationGroup node) {
155 heading('DeclarationGroup', node);
156 output.depth++;
157 output.writeNodeList('declarations', node._declarations);
158 output.depth--;
159 }
160
161 void visitMarginGroup(MarginGroup node) {
162 heading('MarginGroup', node);
163 output.depth++;
164 output.writeValue('@directive', node.margin_sym);
165 output.writeNodeList('declarations', node._declarations);
166 output.depth--;
167 }
168
169 void visitDeclaration(Declaration node) {
170 heading('Declaration', node);
171 output.depth++;
172 if (node.isIE7) output.write('IE7 property');
173 output.write('property');
174 super.visitDeclaration(node);
175 output.writeNode('expression', node._expression);
176 if (node.important) {
177 output.writeValue('!important', 'true');
178 }
179 output.depth--;
180 }
181
182 void visitVarDefinition(VarDefinition node) {
183 heading('Var', node);
184 output.depth++;
185 output.write('defintion');
186 super.visitVarDefinition(node);
187 output.writeNode('expression', node._expression);
188 output.depth--;
189 }
190
191 void visitSelectorGroup(SelectorGroup node) {
192 heading('Selector Group', node);
193 output.depth++;
194 output.writeNodeList('selectors', node.selectors);
195 output.depth--;
196 }
197
198 void visitSelector(Selector node) {
199 heading('Selector', node);
200 output.depth++;
201 output.writeNodeList('simpleSelectorsSequences',
202 node._simpleSelectorSequences);
203 output.depth--;
204 }
205
206 void visitSimpleSelectorSequence(SimpleSelectorSequence node) {
207 heading('SimpleSelectorSequence', node);
208 output.depth++;
209 if (node.isCombinatorNone) {
210 output.writeValue('combinator', "NONE");
211 } else if (node.isCombinatorDescendant) {
212 output.writeValue('combinator', "descendant");
213 } else if (node.isCombinatorPlus) {
214 output.writeValue('combinator', "+");
215 } else if (node.isCombinatorGreater) {
216 output.writeValue('combinator', ">");
217 } else if (node.isCombinatorTilde) {
218 output.writeValue('combinator', "~");
219 } else {
220 output.writeValue('combinator', "ERROR UNKNOWN");
221 }
222
223 super.visitSimpleSelectorSequence(node);
224
225 output.depth--;
226 }
227
228 void visitNamespaceSelector(NamespaceSelector node) {
229 heading('Namespace Selector', node);
230 output.depth++;
231
232 super.visitNamespaceSelector(node);
233
234 visitSimpleSelector(node.nameAsSimpleSelector);
235 output.depth--;
236 }
237
238 void visitElementSelector(ElementSelector node) {
239 heading('Element Selector', node);
240 output.depth++;
241 super.visitElementSelector(node);
242 output.depth--;
243 }
244
245 void visitAttributeSelector(AttributeSelector node) {
246 heading('AttributeSelector', node);
247 output.depth++;
248 super.visitAttributeSelector(node);
249 String tokenStr = node.matchOperatorAsTokenString();
250 output.writeValue('operator', '${node.matchOperator()} (${tokenStr})');
251 output.writeValue('value', node.valueToString());
252 output.depth--;
253 }
254
255 void visitIdSelector(IdSelector node) {
256 heading('Id Selector', node);
257 output.depth++;
258 super.visitIdSelector(node);
259 output.depth--;
260 }
261
262 void visitClassSelector(ClassSelector node) {
263 heading('Class Selector', node);
264 output.depth++;
265 super.visitClassSelector(node);
266 output.depth--;
267 }
268
269 void visitPseudoClassSelector(PseudoClassSelector node) {
270 heading('Pseudo Class Selector', node);
271 output.depth++;
272 super.visitPseudoClassSelector(node);
273 output.depth--;
274 }
275
276 void visitPseudoElementSelector(PseudoElementSelector node) {
277 heading('Pseudo Element Selector', node);
278 output.depth++;
279 super.visitPseudoElementSelector(node);
280 output.depth--;
281 }
282
283 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) {
284 heading('Pseudo Class Function Selector', node);
285 output.depth++;
286 visitSelectorExpression(node.expression);
287 super.visitPseudoClassFunctionSelector(node);
288 output.depth--;
289 }
290
291 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) {
292 heading('Pseudo Element Function Selector', node);
293 output.depth++;
294 visitSelectorExpression(node.expression);
295 super.visitPseudoElementFunctionSelector(node);
296 output.depth--;
297 }
298
299 void visitSelectorExpression(SelectorExpression node) {
300 heading('Selector Expression', node);
301 output.depth++;
302 output.writeNodeList('expressions', node.expressions);
303 output.depth--;
304 }
305
306 void visitNegationSelector(NegationSelector node) {
307 super.visitNegationSelector(node);
308 output.depth++;
309 heading('Negation Selector', node);
310 output.writeNode('Negation arg', node.negationArg);
311 output.depth--;
312 }
313
314 void visitUnicodeRangeTerm(UnicodeRangeTerm node) {
315 heading('UnicodeRangeTerm', node);
316 output.depth++;
317 output.writeValue('1st value', node.first);
318 output.writeValue('2nd value', node.second);
319 output.depth--;
320 }
321
322 void visitLiteralTerm(LiteralTerm node) {
323 heading('LiteralTerm', node);
324 output.depth++;
325 output.writeValue('value', node.text);
326 output.depth--;
327 }
328
329 void visitHexColorTerm(HexColorTerm node) {
330 heading('HexColorTerm', node);
331 output.depth++;
332 output.writeValue('hex value', node.text);
333 output.writeValue('decimal value', node.value);
334 output.depth--;
335 }
336
337 void visitNumberTerm(NumberTerm node) {
338 heading('NumberTerm', node);
339 output.depth++;
340 output.writeValue('value', node.text);
341 output.depth--;
342 }
343
344 void visitUnitTerm(UnitTerm node) {
345 String unitValue;
346
347 output.depth++;
348 output.writeValue('value', node.text);
349 output.writeValue('unit', node.unitToString());
350 output.depth--;
351 }
352
353 void visitLengthTerm(LengthTerm node) {
354 heading('LengthTerm', node);
355 super.visitLengthTerm(node);
356 }
357
358 void visitPercentageTerm(PercentageTerm node) {
359 heading('PercentageTerm', node);
360 output.depth++;
361 super.visitPercentageTerm(node);
362 output.depth--;
363 }
364
365 void visitEmTerm(EmTerm node) {
366 heading('EmTerm', node);
367 output.depth++;
368 super.visitEmTerm(node);
369 output.depth--;
370 }
371
372 void visitExTerm(ExTerm node) {
373 heading('ExTerm', node);
374 output.depth++;
375 super.visitExTerm(node);
376 output.depth--;
377 }
378
379 void visitAngleTerm(AngleTerm node) {
380 heading('AngleTerm', node);
381 super.visitAngleTerm(node);
382 }
383
384 void visitTimeTerm(TimeTerm node) {
385 heading('TimeTerm', node);
386 super.visitTimeTerm(node);
387 }
388
389 void visitFreqTerm(FreqTerm node) {
390 heading('FreqTerm', node);
391 super.visitFreqTerm(node);
392 }
393
394 void visitFractionTerm(FractionTerm node) {
395 heading('FractionTerm', node);
396 output.depth++;
397 super.visitFractionTerm(node);
398 output.depth--;
399 }
400
401 void visitUriTerm(UriTerm node) {
402 heading('UriTerm', node);
403 output.depth++;
404 super.visitUriTerm(node);
405 output.depth--;
406 }
407
408 void visitFunctionTerm(FunctionTerm node) {
409 heading('FunctionTerm', node);
410 output.depth++;
411 super.visitFunctionTerm(node);
412 output.depth--;
413 }
414
415 void visitGroupTerm(GroupTerm node) {
416 heading('GroupTerm', node);
417 output.depth++;
418 output.writeNodeList('grouped terms', node._terms);
419 output.depth--;
420 }
421
422 void visitItemTerm(ItemTerm node) {
423 heading('ItemTerm', node);
424 super.visitItemTerm(node);
425 }
426
427 void visitIE8Term(IE8Term node) {
428 heading('IE8Term', node);
429 visitLiteralTerm(node);
430 }
431
432 void visitOperatorSlash(OperatorSlash node) {
433 heading('OperatorSlash', node);
434 }
435
436 void visitOperatorComma(OperatorComma node) {
437 heading('OperatorComma', node);
438 }
439
440 void visitOperatorPlus(OperatorPlus node) {
441 heading('OperatorPlus', node);
442 }
443
444 void visitOperatorMinus(OperatorMinus node) {
445 heading('OperatorMinus', node);
446 }
447
448 void visitVarUsage(VarUsage node) {
449 heading('Var', node);
450 output.depth++;
451 output.write('usage ${node.name}');
452 output.writeNodeList('default values', node.defaultValues);
453 output.depth--;
454 }
455
456 void visitExpressions(Expressions node) {
457 heading('Expressions', node);
458 output.depth++;
459 output.writeNodeList('expressions', node.expressions);
460 output.depth--;
461 }
462
463 void visitBinaryExpression(BinaryExpression node) {
464 heading('BinaryExpression', node);
465 // TODO(terry): TBD
466 }
467
468 void visitUnaryExpression(UnaryExpression node) {
469 heading('UnaryExpression', node);
470 // TODO(terry): TBD
471 }
472
473 void visitIdentifier(Identifier node) {
474 heading('Identifier(${output.toValue(node.name)})', node);
475 }
476
477 void visitWildcard(Wildcard node) {
478 heading('Wildcard(*)', node);
479 }
480
481 void visitDartStyleExpression(DartStyleExpression node) {
482 heading('DartStyleExpression', node);
483 }
484
485 void visitFontExpression(FontExpression node) {
486 heading('Dart Style FontExpression', node);
487 }
488
489 void visitBoxExpression(BoxExpression node) {
490 heading('Dart Style BoxExpression', node);
491 }
492
493 void visitMarginExpression(MarginExpression node) {
494 heading('Dart Style MarginExpression', node);
495 }
496
497 void visitBorderExpression(BorderExpression node) {
498 heading('Dart Style BorderExpression', node);
499 }
500
501 void visitHeightExpression(HeightExpression node) {
502 heading('Dart Style HeightExpression', node);
503 }
504
505 void visitPaddingExpression(PaddingExpression node) {
506 heading('Dart Style PaddingExpression', node);
507 }
508
509 void visitWidthExpression(WidthExpression node) {
510 heading('Dart Style WidthExpression', node);
511 }
512 }
OLDNEW
« no previous file with comments | « pkg/csslib/lib/src/tree_base.dart ('k') | pkg/csslib/lib/src/validate.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698