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

Side by Side Diff: pkg/csslib/lib/visitor.dart

Issue 814113004: Pull args, intl, logging, shelf, and source_maps out of the SDK. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also csslib. Created 6 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
« no previous file with comments | « pkg/csslib/lib/src/validate.dart ('k') | pkg/csslib/pubspec.yaml » ('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) 2012, 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 library csslib.visitor;
6
7 import 'package:source_span/source_span.dart';
8 import 'parser.dart';
9
10 part 'src/css_printer.dart';
11 part 'src/tree.dart';
12 part 'src/tree_base.dart';
13 part 'src/tree_printer.dart';
14
15 abstract class VisitorBase {
16 void visitCssComment(CssComment node);
17 void visitCommentDefinition(CommentDefinition node);
18 void visitStyleSheet(StyleSheet node);
19 void visitNoOp(NoOp node);
20 void visitTopLevelProduction(TopLevelProduction node);
21 void visitDirective(Directive node);
22 void visitMediaExpression(MediaExpression node);
23 void visitMediaQuery(MediaQuery node);
24 void visitMediaDirective(MediaDirective node);
25 void visitHostDirective(HostDirective node);
26 void visitPageDirective(PageDirective node);
27 void visitCharsetDirective(CharsetDirective node);
28 void visitImportDirective(ImportDirective node);
29 void visitKeyFrameDirective(KeyFrameDirective node);
30 void visitKeyFrameBlock(KeyFrameBlock node);
31 void visitFontFaceDirective(FontFaceDirective node);
32 void visitStyletDirective(StyletDirective node);
33 void visitNamespaceDirective(NamespaceDirective node);
34 void visitVarDefinitionDirective(VarDefinitionDirective node);
35 void visitMixinDefinition(MixinDefinition node);
36 void visitMixinRulesetDirective(MixinRulesetDirective node);
37 void visitMixinDeclarationDirective(MixinDeclarationDirective node);
38 void visitIncludeDirective(IncludeDirective node);
39 void visitContentDirective(ContentDirective node);
40
41 void visitRuleSet(RuleSet node);
42 void visitDeclarationGroup(DeclarationGroup node);
43 void visitMarginGroup(DeclarationGroup node);
44 void visitDeclaration(Declaration node);
45 void visitVarDefinition(VarDefinition node);
46 void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node);
47 void visitExtendDeclaration(ExtendDeclaration node);
48 void visitSelectorGroup(SelectorGroup node);
49 void visitSelector(Selector node);
50 void visitSimpleSelectorSequence(SimpleSelectorSequence node);
51 void visitSimpleSelector(SimpleSelector node);
52 void visitElementSelector(ElementSelector node);
53 void visitNamespaceSelector(NamespaceSelector node);
54 void visitAttributeSelector(AttributeSelector node);
55 void visitIdSelector(IdSelector node);
56 void visitClassSelector(ClassSelector node);
57 void visitPseudoClassSelector(PseudoClassSelector node);
58 void visitPseudoElementSelector(PseudoElementSelector node);
59 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node);
60 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node);
61 void visitNegationSelector(NegationSelector node);
62 void visitSelectorExpression(SelectorExpression node);
63
64 void visitUnicodeRangeTerm(UnicodeRangeTerm node);
65 void visitLiteralTerm(LiteralTerm node);
66 void visitHexColorTerm(HexColorTerm node);
67 void visitNumberTerm(NumberTerm node);
68 void visitUnitTerm(UnitTerm node);
69 void visitLengthTerm(LengthTerm node);
70 void visitPercentageTerm(PercentageTerm node);
71 void visitEmTerm(EmTerm node);
72 void visitExTerm(ExTerm node);
73 void visitAngleTerm(AngleTerm node);
74 void visitTimeTerm(TimeTerm node);
75 void visitFreqTerm(FreqTerm node);
76 void visitFractionTerm(FractionTerm node);
77 void visitUriTerm(UriTerm node);
78 void visitResolutionTerm(ResolutionTerm node);
79 void visitChTerm(ChTerm node);
80 void visitRemTerm(RemTerm node);
81 void visitViewportTerm(ViewportTerm node);
82 void visitFunctionTerm(FunctionTerm node);
83 void visitGroupTerm(GroupTerm node);
84 void visitItemTerm(ItemTerm node);
85 void visitIE8Term(IE8Term node);
86 void visitOperatorSlash(OperatorSlash node);
87 void visitOperatorComma(OperatorComma node);
88 void visitOperatorPlus(OperatorPlus node);
89 void visitOperatorMinus(OperatorMinus node);
90 void visitVarUsage(VarUsage node);
91
92 void visitExpressions(Expressions node);
93 void visitBinaryExpression(BinaryExpression node);
94 void visitUnaryExpression(UnaryExpression node);
95
96 void visitIdentifier(Identifier node);
97 void visitWildcard(Wildcard node);
98 void visitThisOperator(ThisOperator node);
99 void visitNegation(Negation node);
100
101 void visitDartStyleExpression(DartStyleExpression node);
102 void visitFontExpression(FontExpression node);
103 void visitBoxExpression(BoxExpression node);
104 void visitMarginExpression(MarginExpression node);
105 void visitBorderExpression(BorderExpression node);
106 void visitHeightExpression(HeightExpression node);
107 void visitPaddingExpression(PaddingExpression node);
108 void visitWidthExpression(WidthExpression node);
109 }
110
111 /** Base vistor class for the style sheet AST. */
112 class Visitor implements VisitorBase {
113 /** Helper function to walk a list of nodes. */
114 void _visitNodeList(List<TreeNode> list) {
115 // Don't use iterable otherwise the list can't grow while using Visitor.
116 // It certainly can't have items deleted before the index being iterated
117 // but items could be added after the index.
118 for (var index = 0; index < list.length; index++) {
119 list[index].visit(this);
120 }
121 }
122
123 void visitTree(StyleSheet tree) => visitStyleSheet(tree);
124
125 void visitStyleSheet(StyleSheet ss) {
126 _visitNodeList(ss.topLevels);
127 }
128
129 void visitNoOp(NoOp node) { }
130
131 void visitTopLevelProduction(TopLevelProduction node) { }
132
133 void visitDirective(Directive node) { }
134
135 void visitCssComment(CssComment node) { }
136
137 void visitCommentDefinition(CommentDefinition node) { }
138
139 void visitMediaExpression(MediaExpression node) {
140 visitExpressions(node.exprs);
141 }
142
143 void visitMediaQuery(MediaQuery node) {
144 for (var mediaExpr in node.expressions) {
145 visitMediaExpression(mediaExpr);
146 }
147 }
148
149 void visitMediaDirective(MediaDirective node) {
150 for (var mediaQuery in node.mediaQueries) {
151 visitMediaQuery(mediaQuery);
152 }
153 for (var ruleset in node.rulesets) {
154 visitRuleSet(ruleset);
155 }
156 }
157
158 void visitHostDirective(HostDirective node) {
159 for (var ruleset in node.rulesets) {
160 visitRuleSet(ruleset);
161 }
162 }
163
164 void visitPageDirective(PageDirective node) {
165 for (var declGroup in node._declsMargin) {
166 if (declGroup is MarginGroup) {
167 visitMarginGroup(declGroup);
168 } else {
169 visitDeclarationGroup(declGroup);
170 }
171 }
172 }
173
174 void visitCharsetDirective(CharsetDirective node) { }
175
176 void visitImportDirective(ImportDirective node) {
177 for (var mediaQuery in node.mediaQueries) {
178 visitMediaQuery(mediaQuery);
179 }
180 }
181
182 void visitKeyFrameDirective(KeyFrameDirective node) {
183 visitIdentifier(node.name);
184 _visitNodeList(node._blocks);
185 }
186
187 void visitKeyFrameBlock(KeyFrameBlock node) {
188 visitExpressions(node._blockSelectors);
189 visitDeclarationGroup(node._declarations);
190 }
191
192 void visitFontFaceDirective(FontFaceDirective node) {
193 visitDeclarationGroup(node._declarations);
194 }
195
196 void visitStyletDirective(StyletDirective node) {
197 _visitNodeList(node.rulesets);
198 }
199
200 void visitNamespaceDirective(NamespaceDirective node) { }
201
202 void visitVarDefinitionDirective(VarDefinitionDirective node) {
203 visitVarDefinition(node.def);
204 }
205
206 void visitMixinRulesetDirective(MixinRulesetDirective node) {
207 _visitNodeList(node.rulesets);
208 }
209
210 void visitMixinDefinition(MixinDefinition node) { }
211
212 void visitMixinDeclarationDirective(MixinDeclarationDirective node) {
213 visitDeclarationGroup(node.declarations);
214 }
215
216 void visitIncludeDirective(IncludeDirective node) {
217 for (var index = 0; index < node.args.length; index++) {
218 var param = node.args[index];
219 _visitNodeList(param);
220 }
221 }
222
223 void visitContentDirective(ContentDirective node) {
224 // TODO(terry): TBD
225 }
226
227 void visitRuleSet(RuleSet node) {
228 visitSelectorGroup(node._selectorGroup);
229 visitDeclarationGroup(node._declarationGroup);
230 }
231
232 void visitDeclarationGroup(DeclarationGroup node) {
233 _visitNodeList(node.declarations);
234 }
235
236 void visitMarginGroup(MarginGroup node) => visitDeclarationGroup(node);
237
238 void visitDeclaration(Declaration node) {
239 visitIdentifier(node._property);
240 if (node._expression != null) node._expression.visit(this);
241 }
242
243 void visitVarDefinition(VarDefinition node) {
244 visitIdentifier(node._property);
245 if (node._expression != null) node._expression.visit(this);
246 }
247
248 void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node) {
249 visitIncludeDirective(node.include);
250 }
251
252 void visitExtendDeclaration(ExtendDeclaration node) {
253 _visitNodeList(node.selectors);
254 }
255
256 void visitSelectorGroup(SelectorGroup node) {
257 _visitNodeList(node.selectors);
258 }
259
260 void visitSelector(Selector node) {
261 _visitNodeList(node.simpleSelectorSequences);
262 }
263
264 void visitSimpleSelectorSequence(SimpleSelectorSequence node) {
265 node.simpleSelector.visit(this);
266 }
267
268 void visitSimpleSelector(SimpleSelector node) => node._name.visit(this);
269
270 void visitNamespaceSelector(NamespaceSelector node) {
271 if (node._namespace != null) node._namespace.visit(this);
272 if (node.nameAsSimpleSelector != null) {
273 node.nameAsSimpleSelector.visit(this);
274 }
275 }
276
277 void visitElementSelector(ElementSelector node) => visitSimpleSelector(node);
278
279 void visitAttributeSelector(AttributeSelector node) {
280 visitSimpleSelector(node);
281 }
282
283 void visitIdSelector(IdSelector node) => visitSimpleSelector(node);
284
285 void visitClassSelector(ClassSelector node) => visitSimpleSelector(node);
286
287 void visitPseudoClassSelector(PseudoClassSelector node) =>
288 visitSimpleSelector(node);
289
290 void visitPseudoElementSelector(PseudoElementSelector node) =>
291 visitSimpleSelector(node);
292
293 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) =>
294 visitSimpleSelector(node);
295
296 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) =>
297 visitSimpleSelector(node);
298
299 void visitNegationSelector(NegationSelector node) =>
300 visitSimpleSelector(node);
301
302 void visitSelectorExpression(SelectorExpression node) {
303 _visitNodeList(node.expressions);
304 }
305
306 void visitUnicodeRangeTerm(UnicodeRangeTerm node) { }
307
308 void visitLiteralTerm(LiteralTerm node) { }
309
310 void visitHexColorTerm(HexColorTerm node) { }
311
312 void visitNumberTerm(NumberTerm node) { }
313
314 void visitUnitTerm(UnitTerm node) { }
315
316 void visitLengthTerm(LengthTerm node) {
317 visitUnitTerm(node);
318 }
319
320 void visitPercentageTerm(PercentageTerm node) {
321 visitLiteralTerm(node);
322 }
323
324 void visitEmTerm(EmTerm node) {
325 visitLiteralTerm(node);
326 }
327
328 void visitExTerm(ExTerm node) {
329 visitLiteralTerm(node);
330 }
331
332 void visitAngleTerm(AngleTerm node) {
333 visitUnitTerm(node);
334 }
335
336 void visitTimeTerm(TimeTerm node) {
337 visitUnitTerm(node);
338 }
339
340 void visitFreqTerm(FreqTerm node) {
341 visitUnitTerm(node);
342 }
343
344 void visitFractionTerm(FractionTerm node) {
345 visitLiteralTerm(node);
346 }
347
348 void visitUriTerm(UriTerm node) {
349 visitLiteralTerm(node);
350 }
351
352 void visitResolutionTerm(ResolutionTerm node) {
353 visitUnitTerm(node);
354 }
355
356 void visitChTerm(ChTerm node) {
357 visitUnitTerm(node);
358 }
359
360 void visitRemTerm(RemTerm node) {
361 visitUnitTerm(node);
362 }
363
364 void visitViewportTerm(ViewportTerm node) {
365 visitUnitTerm(node);
366 }
367
368 void visitFunctionTerm(FunctionTerm node) {
369 visitLiteralTerm(node);
370 visitExpressions(node._params);
371 }
372
373 void visitGroupTerm(GroupTerm node) {
374 for (var term in node._terms) {
375 term.visit(this);
376 }
377 }
378
379 void visitItemTerm(ItemTerm node) {
380 visitNumberTerm(node);
381 }
382
383 void visitIE8Term(IE8Term node) { }
384
385 void visitOperatorSlash(OperatorSlash node) { }
386
387 void visitOperatorComma(OperatorComma node) { }
388
389 void visitOperatorPlus(OperatorPlus node) { }
390
391 void visitOperatorMinus(OperatorMinus node) { }
392
393 void visitVarUsage(VarUsage node) {
394 _visitNodeList(node.defaultValues);
395 }
396
397 void visitExpressions(Expressions node) {
398 _visitNodeList(node.expressions);
399 }
400
401 void visitBinaryExpression(BinaryExpression node) {
402 // TODO(terry): TBD
403 throw UnimplementedError;
404 }
405
406 void visitUnaryExpression(UnaryExpression node) {
407 // TODO(terry): TBD
408 throw UnimplementedError;
409 }
410
411 void visitIdentifier(Identifier node) { }
412
413 void visitWildcard(Wildcard node) { }
414
415 void visitThisOperator(ThisOperator node) { }
416
417 void visitNegation(Negation node) { }
418
419 void visitDartStyleExpression(DartStyleExpression node) { }
420
421 void visitFontExpression(FontExpression node) {
422 // TODO(terry): TBD
423 throw UnimplementedError;
424 }
425
426 void visitBoxExpression(BoxExpression node) {
427 // TODO(terry): TBD
428 throw UnimplementedError;
429 }
430
431 void visitMarginExpression(MarginExpression node) {
432 // TODO(terry): TBD
433 throw UnimplementedError;
434 }
435
436 void visitBorderExpression(BorderExpression node) {
437 // TODO(terry): TBD
438 throw UnimplementedError;
439 }
440
441 void visitHeightExpression(HeightExpression node) {
442 // TODO(terry): TB
443 throw UnimplementedError;
444 }
445
446 void visitPaddingExpression(PaddingExpression node) {
447 // TODO(terry): TBD
448 throw UnimplementedError;
449 }
450
451 void visitWidthExpression(WidthExpression node) {
452 // TODO(terry): TBD
453 throw UnimplementedError;
454 }
455 }
OLDNEW
« no previous file with comments | « pkg/csslib/lib/src/validate.dart ('k') | pkg/csslib/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698