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

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