| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // Generated by scripts/tree_gen.py. | |
| 5 | |
| 6 ///////////////////////////////////////////////////////////////////////// | |
| 7 // CSS specific types: | |
| 8 ///////////////////////////////////////////////////////////////////////// | |
| 9 | |
| 10 | |
| 11 class Identifier extends ASTNode { | |
| 12 String name; | |
| 13 | |
| 14 Identifier(this.name, SourceSpan span): super(span); | |
| 15 | |
| 16 visit(TreeVisitor visitor) => visitor.visitIdentifier(this); | |
| 17 | |
| 18 String toString() => name; | |
| 19 } | |
| 20 | |
| 21 class Wildcard extends ASTNode { | |
| 22 Wildcard(SourceSpan span): super(span); | |
| 23 | |
| 24 visit(TreeVisitor visitor) => visitor.visitWildcard(this); | |
| 25 | |
| 26 String toString() => '*'; | |
| 27 } | |
| 28 | |
| 29 // /* .... */ | |
| 30 class CssComment extends ASTNode { | |
| 31 String comment; | |
| 32 | |
| 33 CssComment(this.comment, SourceSpan span): super(span); | |
| 34 | |
| 35 visit(TreeVisitor visitor) => visitor.visitCssComment(this); | |
| 36 | |
| 37 String toString() => '/* ${comment} */'; | |
| 38 } | |
| 39 | |
| 40 // CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->). | |
| 41 class CommentDefinition extends CssComment { | |
| 42 CommentDefinition(String comment, SourceSpan span): super(comment, span); | |
| 43 | |
| 44 visit(TreeVisitor visitor) => visitor.visitCommentDefinition(this); | |
| 45 | |
| 46 String toString() => '<!-- ${comment} -->'; | |
| 47 } | |
| 48 | |
| 49 class SelectorGroup extends ASTNode { | |
| 50 List<Selector> _selectors; | |
| 51 | |
| 52 SelectorGroup(this._selectors, SourceSpan span): super(span); | |
| 53 | |
| 54 List<Selector> get selectors => _selectors; | |
| 55 | |
| 56 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this); | |
| 57 | |
| 58 String toString() { | |
| 59 StringBuffer buff = new StringBuffer(); | |
| 60 int idx = 0; | |
| 61 for (final selector in _selectors) { | |
| 62 if (idx++ > 0) { | |
| 63 buff.write(', '); | |
| 64 } | |
| 65 buff.write(selector.toString()); | |
| 66 } | |
| 67 return buff.toString(); | |
| 68 } | |
| 69 | |
| 70 /** A multiline string showing the node and its children. */ | |
| 71 String toDebugString() { | |
| 72 var to = new TreeOutput(); | |
| 73 var tp = new TreePrinter(to); | |
| 74 this.visit(tp); | |
| 75 return to.buf.toString(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 class Selector extends ASTNode { | |
| 80 List<SimpleSelectorSequence> _simpleSelectorSequences; | |
| 81 | |
| 82 Selector(this._simpleSelectorSequences, SourceSpan span) : super(span); | |
| 83 | |
| 84 List<SimpleSelectorSequence> get simpleSelectorSequences => | |
| 85 _simpleSelectorSequences; | |
| 86 | |
| 87 add(SimpleSelectorSequence seq) => _simpleSelectorSequences.add(seq); | |
| 88 | |
| 89 List<SimpleSelectorSequence> get simpleSelectorSquences => | |
| 90 _simpleSelectorSequences; | |
| 91 | |
| 92 int get length => _simpleSelectorSequences.length; | |
| 93 | |
| 94 String toString() { | |
| 95 StringBuffer buff = new StringBuffer(); | |
| 96 for (final simpleSelectorSequence in _simpleSelectorSequences) { | |
| 97 buff.write(simpleSelectorSequence.toString()); | |
| 98 } | |
| 99 return buff.toString(); | |
| 100 } | |
| 101 | |
| 102 visit(TreeVisitor visitor) => visitor.visitSelector(this); | |
| 103 } | |
| 104 | |
| 105 class SimpleSelectorSequence extends ASTNode { | |
| 106 int _combinator; // +, >, ~, NONE | |
| 107 SimpleSelector _selector; | |
| 108 | |
| 109 SimpleSelectorSequence(this._selector, SourceSpan span, | |
| 110 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span); | |
| 111 | |
| 112 get simpleSelector => _selector; | |
| 113 | |
| 114 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE; | |
| 115 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS; | |
| 116 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER; | |
| 117 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE; | |
| 118 bool isCombinatorDescendant() => | |
| 119 _combinator == TokenKind.COMBINATOR_DESCENDANT; | |
| 120 | |
| 121 String _combinatorToString() => | |
| 122 isCombinatorDescendant() ? ' ' : | |
| 123 isCombinatorPlus() ? '+' : | |
| 124 isCombinatorGreater() ? '>' : | |
| 125 isCombinatorTilde() ? '~' : ''; | |
| 126 | |
| 127 visit(TreeVisitor visitor) => visitor.visitSimpleSelectorSequence(this); | |
| 128 | |
| 129 String toString() => "${_combinatorToString()}${_selector.toString()}"; | |
| 130 } | |
| 131 | |
| 132 /* All other selectors (element, #id, .class, attribute, pseudo, negation, | |
| 133 * namespace, *) are derived from this selector. | |
| 134 */ | |
| 135 class SimpleSelector extends ASTNode { | |
| 136 var _name; | |
| 137 | |
| 138 SimpleSelector(this._name, SourceSpan span) : super(span); | |
| 139 | |
| 140 // Name can be an Identifier or WildCard we'll return either the name or '*'. | |
| 141 String get name => isWildcard() ? '*' : _name.name; | |
| 142 | |
| 143 bool isWildcard() => _name is Wildcard; | |
| 144 | |
| 145 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this); | |
| 146 | |
| 147 String toString() => name; | |
| 148 } | |
| 149 | |
| 150 // element name | |
| 151 class ElementSelector extends SimpleSelector { | |
| 152 ElementSelector(var name, SourceSpan span) : super(name, span); | |
| 153 | |
| 154 visit(TreeVisitor visitor) => visitor.visitElementSelector(this); | |
| 155 | |
| 156 String toString() => "$name"; | |
| 157 | |
| 158 /** A multiline string showing the node and its children. */ | |
| 159 String toDebugString() { | |
| 160 var to = new TreeOutput(); | |
| 161 var tp = new TreePrinter(to); | |
| 162 this.visit(tp); | |
| 163 return to.buf.toString(); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 // namespace|element | |
| 168 class NamespaceSelector extends SimpleSelector { | |
| 169 var _namespace; // null, Wildcard or Identifier | |
| 170 | |
| 171 NamespaceSelector(this._namespace, var name, SourceSpan span) : | |
| 172 super(name, span); | |
| 173 | |
| 174 String get namespace => _namespace is Wildcard ? '*' : _namespace.name; | |
| 175 | |
| 176 bool isNamespaceWildcard() => _namespace is Wildcard; | |
| 177 | |
| 178 SimpleSelector get nameAsSimpleSelector => _name; | |
| 179 | |
| 180 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this); | |
| 181 | |
| 182 String toString() => "$namespace|${nameAsSimpleSelector.name}"; | |
| 183 } | |
| 184 | |
| 185 // [attr op value] | |
| 186 class AttributeSelector extends SimpleSelector { | |
| 187 int _op; | |
| 188 var _value; | |
| 189 | |
| 190 AttributeSelector(Identifier name, this._op, this._value, | |
| 191 SourceSpan span) : super(name, span); | |
| 192 | |
| 193 String matchOperator() { | |
| 194 switch (_op) { | |
| 195 case TokenKind.EQUALS: | |
| 196 return '='; | |
| 197 case TokenKind.INCLUDES: | |
| 198 return '~='; | |
| 199 case TokenKind.DASH_MATCH: | |
| 200 return '|='; | |
| 201 case TokenKind.PREFIX_MATCH: | |
| 202 return '^='; | |
| 203 case TokenKind.SUFFIX_MATCH: | |
| 204 return '\$='; | |
| 205 case TokenKind.SUBSTRING_MATCH: | |
| 206 return '*='; | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 // Return the TokenKind for operator used by visitAttributeSelector. | |
| 211 String matchOperatorAsTokenString() { | |
| 212 switch (_op) { | |
| 213 case TokenKind.EQUALS: | |
| 214 return 'EQUALS'; | |
| 215 case TokenKind.INCLUDES: | |
| 216 return 'INCLUDES'; | |
| 217 case TokenKind.DASH_MATCH: | |
| 218 return 'DASH_MATCH'; | |
| 219 case TokenKind.PREFIX_MATCH: | |
| 220 return 'PREFIX_MATCH'; | |
| 221 case TokenKind.SUFFIX_MATCH: | |
| 222 return 'SUFFIX_MATCH'; | |
| 223 case TokenKind.SUBSTRING_MATCH: | |
| 224 return 'SUBSTRING_MATCH'; | |
| 225 } | |
| 226 } | |
| 227 | |
| 228 String valueToString() { | |
| 229 if (_value is Identifier) { | |
| 230 return _value.name; | |
| 231 } else { | |
| 232 return '"${_value}"'; | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 visit(TreeVisitor visitor) => visitor.visitAttributeSelector(this); | |
| 237 | |
| 238 String toString() => "[${name} ${matchOperator()} ${valueToString()}]"; | |
| 239 } | |
| 240 | |
| 241 // #id | |
| 242 class IdSelector extends SimpleSelector { | |
| 243 IdSelector(Identifier name, SourceSpan span) : super(name, span); | |
| 244 | |
| 245 visit(TreeVisitor visitor) => visitor.visitIdSelector(this); | |
| 246 | |
| 247 String toString() => "#$name"; | |
| 248 } | |
| 249 | |
| 250 // .class | |
| 251 class ClassSelector extends SimpleSelector { | |
| 252 ClassSelector(Identifier name, SourceSpan span) : super(name, span); | |
| 253 | |
| 254 visit(TreeVisitor visitor) => visitor.visitClassSelector(this); | |
| 255 | |
| 256 String toString() => ".$name"; | |
| 257 } | |
| 258 | |
| 259 // :pseudoClass | |
| 260 class PseudoClassSelector extends SimpleSelector { | |
| 261 PseudoClassSelector(Identifier name, SourceSpan span) : | |
| 262 super(name, span); | |
| 263 | |
| 264 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this); | |
| 265 | |
| 266 String toString() => ":$name"; | |
| 267 } | |
| 268 | |
| 269 // ::pseudoElement | |
| 270 class PseudoElementSelector extends SimpleSelector { | |
| 271 PseudoElementSelector(Identifier name, SourceSpan span) : | |
| 272 super(name, span); | |
| 273 | |
| 274 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this); | |
| 275 | |
| 276 String toString() => "::$name"; | |
| 277 } | |
| 278 | |
| 279 // TODO(terry): Implement | |
| 280 // NOT | |
| 281 class NotSelector extends SimpleSelector { | |
| 282 NotSelector(String name, SourceSpan span) : super(name, span); | |
| 283 | |
| 284 visit(TreeVisitor visitor) => visitor.visitNotSelector(this); | |
| 285 } | |
| 286 | |
| 287 class Stylesheet extends ASTNode { | |
| 288 // Contains charset, ruleset, directives (media, page, etc.) | |
| 289 List<ASTNode> _topLevels; | |
| 290 | |
| 291 Stylesheet(this._topLevels, SourceSpan span) : super(span) { | |
| 292 for (final node in _topLevels) { | |
| 293 assert(node is TopLevelProduction || node is Directive); | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 visit(TreeVisitor visitor) => visitor.visitStylesheet(this); | |
| 298 | |
| 299 List<ASTNode> get topLevels => _topLevels; | |
| 300 | |
| 301 String toString() { | |
| 302 StringBuffer buff = new StringBuffer(); | |
| 303 for (final topLevel in _topLevels) { | |
| 304 buff.write(topLevel.toString()); | |
| 305 } | |
| 306 return buff.toString(); | |
| 307 } | |
| 308 | |
| 309 /** A multiline string showing the node and its children. */ | |
| 310 String toDebugString() { | |
| 311 var to = new TreeOutput(); | |
| 312 var tp = new TreePrinter(to); | |
| 313 this.visit(tp); | |
| 314 return to.buf.toString(); | |
| 315 } | |
| 316 } | |
| 317 | |
| 318 class TopLevelProduction extends ASTNode { | |
| 319 TopLevelProduction(SourceSpan span) : super(span); | |
| 320 | |
| 321 visit(TreeVisitor visitor) => visitor.visitTopLevelProduction(this); | |
| 322 | |
| 323 String toString() => "TopLevelProduction"; | |
| 324 } | |
| 325 | |
| 326 class RuleSet extends TopLevelProduction { | |
| 327 SelectorGroup _selectorGroup; | |
| 328 DeclarationGroup _declarationGroup; | |
| 329 | |
| 330 RuleSet(this._selectorGroup, this._declarationGroup, SourceSpan span) : | |
| 331 super(span); | |
| 332 | |
| 333 SelectorGroup get selectorGroup => _selectorGroup; | |
| 334 DeclarationGroup get declarationGroup => _declarationGroup; | |
| 335 | |
| 336 visit(TreeVisitor visitor) => visitor.visitRuleSet(this); | |
| 337 | |
| 338 String toString() => | |
| 339 "\n${_selectorGroup.toString()} {\n" | |
| 340 "${_declarationGroup.toString()}}\n"; | |
| 341 } | |
| 342 | |
| 343 class Directive extends ASTNode { | |
| 344 Directive(SourceSpan span) : super(span); | |
| 345 | |
| 346 String toString() => "Directive"; | |
| 347 | |
| 348 bool get isBuiltIn => true; // Known CSS directive? | |
| 349 bool get isExtension => false; // SCSS extension? | |
| 350 | |
| 351 visit(TreeVisitor visitor) => visitor.visitDirective(this); | |
| 352 } | |
| 353 | |
| 354 class ImportDirective extends Directive { | |
| 355 String _import; | |
| 356 List<String> _media; | |
| 357 | |
| 358 ImportDirective(this._import, this._media, SourceSpan span) : | |
| 359 super(span); | |
| 360 | |
| 361 visit(TreeVisitor visitor) => visitor.visitImportDirective(this); | |
| 362 | |
| 363 String toString() { | |
| 364 StringBuffer buff = new StringBuffer(); | |
| 365 | |
| 366 buff.write('@import url(${_import})'); | |
| 367 | |
| 368 int idx = 0; | |
| 369 for (final medium in _media) { | |
| 370 buff.write(idx++ == 0 ? ' $medium' : ',$medium'); | |
| 371 } | |
| 372 buff.write('\n'); | |
| 373 | |
| 374 return buff.toString(); | |
| 375 } | |
| 376 } | |
| 377 | |
| 378 class MediaDirective extends Directive { | |
| 379 List<String> _media; | |
| 380 RuleSet _ruleset; | |
| 381 | |
| 382 MediaDirective(this._media, this._ruleset, SourceSpan span) : | |
| 383 super(span); | |
| 384 | |
| 385 visit(TreeVisitor visitor) => visitor.visitMediaDirective(this); | |
| 386 | |
| 387 String toString() { | |
| 388 StringBuffer buff = new StringBuffer(); | |
| 389 | |
| 390 buff.write('@media'); | |
| 391 int idx = 0; | |
| 392 for (var medium in _media) { | |
| 393 buff.write(idx++ == 0 ? ' $medium' : ',$medium'); | |
| 394 } | |
| 395 buff.write(' {\n'); | |
| 396 buff.write(_ruleset.toString()); | |
| 397 buff.write('\n\}\n'); | |
| 398 | |
| 399 return buff.toString(); | |
| 400 } | |
| 401 } | |
| 402 | |
| 403 class PageDirective extends Directive { | |
| 404 String _pseudoPage; | |
| 405 DeclarationGroup _decls; | |
| 406 | |
| 407 PageDirective(this._pseudoPage, this._decls, SourceSpan span) : | |
| 408 super(span); | |
| 409 | |
| 410 visit(TreeVisitor visitor) => visitor.visitPageDirective(this); | |
| 411 | |
| 412 // @page : pseudoPage { | |
| 413 // decls | |
| 414 // } | |
| 415 String toString() { | |
| 416 StringBuffer buff = new StringBuffer(); | |
| 417 | |
| 418 buff.write('@page '); | |
| 419 if (_pseudoPage != null) { | |
| 420 buff.write(': ${_pseudoPage} '); | |
| 421 } | |
| 422 buff.write('{\n${_decls.toString()}\n}\n'); | |
| 423 | |
| 424 return buff.toString(); | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 class KeyFrameDirective extends Directive { | |
| 429 var _name; | |
| 430 List<KeyFrameBlock> _blocks; | |
| 431 | |
| 432 KeyFrameDirective(this._name, SourceSpan span) : | |
| 433 _blocks = [], super(span); | |
| 434 | |
| 435 add(KeyFrameBlock block) { | |
| 436 _blocks.add(block); | |
| 437 } | |
| 438 | |
| 439 String get name => _name; | |
| 440 | |
| 441 visit(TreeVisitor visitor) => visitor.visitKeyFrameDirective(this); | |
| 442 | |
| 443 String toString() { | |
| 444 StringBuffer buff = new StringBuffer(); | |
| 445 buff.write('@-webkit-keyframes ${_name} {\n'); | |
| 446 for (final block in _blocks) { | |
| 447 buff.write(block.toString()); | |
| 448 } | |
| 449 buff.write('}\n'); | |
| 450 return buff.toString(); | |
| 451 } | |
| 452 } | |
| 453 | |
| 454 class KeyFrameBlock extends Expression { | |
| 455 Expressions _blockSelectors; | |
| 456 DeclarationGroup _declarations; | |
| 457 | |
| 458 KeyFrameBlock(this._blockSelectors, this._declarations, SourceSpan span): | |
| 459 super(span); | |
| 460 | |
| 461 visit(TreeVisitor visitor) => visitor.visitKeyFrameBlock(this); | |
| 462 | |
| 463 String toString() { | |
| 464 StringBuffer buff = new StringBuffer(); | |
| 465 buff.write(' ${_blockSelectors.toString()} {\n'); | |
| 466 buff.write(_declarations.toString()); | |
| 467 buff.write(' }\n'); | |
| 468 return buff.toString(); | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 // TODO(terry): TBD | |
| 473 class FontFaceDirective extends Directive { | |
| 474 List<Declaration> _declarations; | |
| 475 | |
| 476 FontFaceDirective(this._declarations, SourceSpan span) : super(span); | |
| 477 | |
| 478 visit(TreeVisitor visitor) => visitor.visitFontFaceDirective(this); | |
| 479 | |
| 480 String toString() { | |
| 481 return "TO BE DONE"; | |
| 482 } | |
| 483 } | |
| 484 | |
| 485 class IncludeDirective extends Directive { | |
| 486 String _include; | |
| 487 Stylesheet _stylesheet; | |
| 488 | |
| 489 IncludeDirective(this._include, this._stylesheet, SourceSpan span) : | |
| 490 super(span); | |
| 491 | |
| 492 visit(TreeVisitor visitor) => visitor.visitIncludeDirective(this); | |
| 493 | |
| 494 bool get isBuiltIn => false; | |
| 495 bool get isExtension => true; | |
| 496 | |
| 497 Stylesheet get styleSheet => _stylesheet; | |
| 498 | |
| 499 String toString() { | |
| 500 StringBuffer buff = new StringBuffer(); | |
| 501 buff.write('/****** @include ${_include} ******/\n'); | |
| 502 buff.write(_stylesheet != null ? _stylesheet.toString() : '// <EMPTY>'); | |
| 503 buff.write('/****** End of ${_include} ******/\n\n'); | |
| 504 return buff.toString(); | |
| 505 } | |
| 506 } | |
| 507 | |
| 508 class StyletDirective extends Directive { | |
| 509 String _dartClassName; | |
| 510 List<RuleSet> _rulesets; | |
| 511 | |
| 512 StyletDirective(this._dartClassName, this._rulesets, SourceSpan span) : | |
| 513 super(span); | |
| 514 | |
| 515 bool get isBuiltIn => false; | |
| 516 bool get isExtension => true; | |
| 517 | |
| 518 String get dartClassName => _dartClassName; | |
| 519 List<RuleSet> get rulesets => _rulesets; | |
| 520 | |
| 521 visit(TreeVisitor visitor) => visitor.visitStyletDirective(this); | |
| 522 | |
| 523 // TODO(terry): Output Dart class | |
| 524 String toString() => '/* @stylet export as ${_dartClassName} */\n'; | |
| 525 } | |
| 526 | |
| 527 class Declaration extends ASTNode { | |
| 528 Identifier _property; | |
| 529 Expression _expression; | |
| 530 bool _important; | |
| 531 | |
| 532 Declaration(this._property, this._expression, SourceSpan span) : | |
| 533 _important = false, super(span); | |
| 534 | |
| 535 String get property => _property.name; | |
| 536 Expression get expression => _expression; | |
| 537 | |
| 538 bool get important => _important; | |
| 539 set important(bool value) => _important = value; | |
| 540 String importantAsString() => _important ? ' !important' : ''; | |
| 541 | |
| 542 visit(TreeVisitor visitor) => visitor.visitDeclaration(this); | |
| 543 | |
| 544 String toString() => | |
| 545 "${_property.name}: ${_expression.toString()}${importantAsString()}"; | |
| 546 } | |
| 547 | |
| 548 class DeclarationGroup extends ASTNode { | |
| 549 List<Declaration> _declarations; | |
| 550 | |
| 551 DeclarationGroup(this._declarations, SourceSpan span) : super(span); | |
| 552 | |
| 553 List<Declaration> get declarations => _declarations; | |
| 554 | |
| 555 visit(TreeVisitor visitor) => visitor.visitDeclarationGroup(this); | |
| 556 | |
| 557 String toString() { | |
| 558 StringBuffer buff = new StringBuffer(); | |
| 559 int idx = 0; | |
| 560 for (final declaration in _declarations) { | |
| 561 buff.write(" ${declaration.toString()};\n"); | |
| 562 } | |
| 563 return buff.toString(); | |
| 564 } | |
| 565 } | |
| 566 | |
| 567 class OperatorSlash extends Expression { | |
| 568 OperatorSlash(SourceSpan span) : super(span); | |
| 569 | |
| 570 visit(TreeVisitor visitor) => visitor.visitOperatorSlash(this); | |
| 571 | |
| 572 String toString() => ' /'; | |
| 573 } | |
| 574 | |
| 575 class OperatorComma extends Expression { | |
| 576 OperatorComma(SourceSpan span) : super(span); | |
| 577 | |
| 578 visit(TreeVisitor visitor) => visitor.visitOperatorComma(this); | |
| 579 | |
| 580 String toString() => ','; | |
| 581 } | |
| 582 | |
| 583 class LiteralTerm extends Expression { | |
| 584 var _value; | |
| 585 String _text; | |
| 586 | |
| 587 LiteralTerm(this._value, this._text, SourceSpan span) : super(span); | |
| 588 | |
| 589 get value => _value; | |
| 590 String get text => _text; | |
| 591 | |
| 592 visit(TreeVisitor visitor) => visitor.visitLiteralTerm(this); | |
| 593 | |
| 594 String toString() => _text; | |
| 595 } | |
| 596 | |
| 597 class NumberTerm extends LiteralTerm { | |
| 598 NumberTerm(var value, String t, SourceSpan span) : super(value, t, span); | |
| 599 | |
| 600 visit(TreeVisitor visitor) => visitor.visitNumberTerm(this); | |
| 601 } | |
| 602 | |
| 603 class UnitTerm extends LiteralTerm { | |
| 604 int _unit; | |
| 605 | |
| 606 UnitTerm(var value, String t, SourceSpan span, this._unit) : | |
| 607 super(value, t, span); | |
| 608 | |
| 609 int get unit => _unit; | |
| 610 | |
| 611 visit(TreeVisitor visitor) => visitor.visitUnitTerm(this); | |
| 612 | |
| 613 String toString() => '${text}${unitToString()}'; | |
| 614 String unitToString() => TokenKind.unitToString(_unit); | |
| 615 } | |
| 616 | |
| 617 class LengthTerm extends UnitTerm { | |
| 618 LengthTerm(var value, String t, SourceSpan span, | |
| 619 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | |
| 620 assert(this._unit == TokenKind.UNIT_LENGTH_PX || | |
| 621 this._unit == TokenKind.UNIT_LENGTH_CM || | |
| 622 this._unit == TokenKind.UNIT_LENGTH_MM || | |
| 623 this._unit == TokenKind.UNIT_LENGTH_IN || | |
| 624 this._unit == TokenKind.UNIT_LENGTH_PT || | |
| 625 this._unit == TokenKind.UNIT_LENGTH_PC); | |
| 626 } | |
| 627 | |
| 628 visit(TreeVisitor visitor) => visitor.visitLengthTerm(this); | |
| 629 } | |
| 630 | |
| 631 class PercentageTerm extends LiteralTerm { | |
| 632 PercentageTerm(var value, String t, SourceSpan span) : | |
| 633 super(value, t, span); | |
| 634 | |
| 635 visit(TreeVisitor visitor) => visitor.visitPercentageTerm(this); | |
| 636 | |
| 637 String toString() => '${text}%'; | |
| 638 | |
| 639 } | |
| 640 | |
| 641 class EmTerm extends LiteralTerm { | |
| 642 EmTerm(var value, String t, SourceSpan span) : | |
| 643 super(value, t, span); | |
| 644 | |
| 645 visit(TreeVisitor visitor) => visitor.visitEmTerm(this); | |
| 646 | |
| 647 String toString() => '${text}em'; | |
| 648 } | |
| 649 | |
| 650 class ExTerm extends LiteralTerm { | |
| 651 ExTerm(var value, String t, SourceSpan span) : | |
| 652 super(value, t, span); | |
| 653 | |
| 654 visit(TreeVisitor visitor) => visitor.visitExTerm(this); | |
| 655 | |
| 656 String toString() => '${text}ex'; | |
| 657 } | |
| 658 | |
| 659 class AngleTerm extends UnitTerm { | |
| 660 AngleTerm(var value, String t, SourceSpan span, | |
| 661 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | |
| 662 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || | |
| 663 this._unit == TokenKind.UNIT_ANGLE_RAD || | |
| 664 this._unit == TokenKind.UNIT_ANGLE_GRAD); | |
| 665 } | |
| 666 | |
| 667 visit(TreeVisitor visitor) => visitor.visitAngleTerm(this); | |
| 668 } | |
| 669 | |
| 670 class TimeTerm extends UnitTerm { | |
| 671 TimeTerm(var value, String t, SourceSpan span, | |
| 672 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | |
| 673 assert(this._unit == TokenKind.UNIT_ANGLE_DEG || | |
| 674 this._unit == TokenKind.UNIT_TIME_MS || | |
| 675 this._unit == TokenKind.UNIT_TIME_S); | |
| 676 } | |
| 677 | |
| 678 visit(TreeVisitor visitor) => visitor.visitTimeTerm(this); | |
| 679 } | |
| 680 | |
| 681 class FreqTerm extends UnitTerm { | |
| 682 FreqTerm(var value, String t, SourceSpan span, | |
| 683 [int unit = TokenKind.UNIT_LENGTH_PX]) : super(value, t, span, unit) { | |
| 684 assert(_unit == TokenKind.UNIT_FREQ_HZ || _unit == TokenKind.UNIT_FREQ_KHZ); | |
| 685 } | |
| 686 | |
| 687 visit(TreeVisitor visitor) => visitor.visitFreqTerm(this); | |
| 688 } | |
| 689 | |
| 690 class FractionTerm extends LiteralTerm { | |
| 691 FractionTerm(var value, String t, SourceSpan span) : | |
| 692 super(value, t, span); | |
| 693 | |
| 694 visit(TreeVisitor visitor) => visitor.visitFractionTerm(this); | |
| 695 | |
| 696 String toString() => '${text}fr'; | |
| 697 } | |
| 698 | |
| 699 class UriTerm extends LiteralTerm { | |
| 700 UriTerm(String value, SourceSpan span) : super(value, value, span); | |
| 701 | |
| 702 visit(TreeVisitor visitor) => visitor.visitUriTerm(this); | |
| 703 | |
| 704 String toString() => 'url(${text})'; | |
| 705 } | |
| 706 | |
| 707 class HexColorTerm extends LiteralTerm { | |
| 708 HexColorTerm(var value, String t, SourceSpan span) : | |
| 709 super(value, t, span); | |
| 710 | |
| 711 visit(TreeVisitor visitor) => visitor.visitHexColorTerm(this); | |
| 712 | |
| 713 String toString() => '#${text}'; | |
| 714 } | |
| 715 | |
| 716 class FunctionTerm extends LiteralTerm { | |
| 717 Expressions _params; | |
| 718 | |
| 719 FunctionTerm(var value, String t, this._params, SourceSpan span) | |
| 720 : super(value, t, span); | |
| 721 | |
| 722 visit(TreeVisitor visitor) => visitor.visitFunctionTerm(this); | |
| 723 | |
| 724 String toString() { | |
| 725 // TODO(terry): Optimize rgb to a hexcolor. | |
| 726 StringBuffer buff = new StringBuffer(); | |
| 727 | |
| 728 buff.write('${text}('); | |
| 729 buff.write(_params.toString()); | |
| 730 buff.write(')'); | |
| 731 | |
| 732 return buff.toString(); | |
| 733 } | |
| 734 } | |
| 735 | |
| 736 class GroupTerm extends Expression { | |
| 737 List<LiteralTerm> _terms; | |
| 738 | |
| 739 GroupTerm(SourceSpan span) : _terms = [], super(span); | |
| 740 | |
| 741 add(LiteralTerm term) { | |
| 742 _terms.add(term); | |
| 743 } | |
| 744 | |
| 745 visit(TreeVisitor visitor) => visitor.visitGroupTerm(this); | |
| 746 | |
| 747 String toString() { | |
| 748 StringBuffer buff = new StringBuffer(); | |
| 749 buff.write('('); | |
| 750 int idx = 0; | |
| 751 for (final term in _terms) { | |
| 752 if (idx++ > 0) { | |
| 753 buff.write(' '); | |
| 754 } | |
| 755 buff.write(term.toString()); | |
| 756 } | |
| 757 buff.write(')'); | |
| 758 return buff.toString(); | |
| 759 } | |
| 760 } | |
| 761 | |
| 762 class ItemTerm extends NumberTerm { | |
| 763 ItemTerm(var value, String t, SourceSpan span) : super(value, t, span); | |
| 764 | |
| 765 visit(TreeVisitor visitor) => visitor.visitItemTerm(this); | |
| 766 | |
| 767 String toString() => '[${text}]'; | |
| 768 } | |
| 769 | |
| 770 class Expressions extends Expression { | |
| 771 List<Expression> _expressions; | |
| 772 | |
| 773 Expressions(SourceSpan span): super(span), _expressions = []; | |
| 774 | |
| 775 add(Expression expression) { | |
| 776 _expressions.add(expression); | |
| 777 } | |
| 778 | |
| 779 List<Expression> get expressions => _expressions; | |
| 780 | |
| 781 visit(TreeVisitor visitor) => visitor.visitExpressions(this); | |
| 782 | |
| 783 String toString() { | |
| 784 StringBuffer buff = new StringBuffer(); | |
| 785 int idx = 0; | |
| 786 for (final expression in _expressions) { | |
| 787 // Add space seperator between terms without an operator. | |
| 788 // TODO(terry): Should have a BinaryExpression to solve this problem. | |
| 789 if (idx > 0 && | |
| 790 !(expression is OperatorComma || expression is OperatorSlash)) { | |
| 791 buff.write(' '); | |
| 792 } | |
| 793 buff.write(expression.toString()); | |
| 794 idx++; | |
| 795 } | |
| 796 return buff.toString(); | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 class BinaryExpression extends Expression { | |
| 801 Token op; | |
| 802 Expression x; | |
| 803 Expression y; | |
| 804 | |
| 805 BinaryExpression(this.op, this.x, this.y, SourceSpan span): super(span); | |
| 806 | |
| 807 visit(TreeVisitor visitor) => visitor.visitBinaryExpression(this); | |
| 808 } | |
| 809 | |
| 810 class UnaryExpression extends Expression { | |
| 811 Token op; | |
| 812 Expression self; | |
| 813 | |
| 814 UnaryExpression(this.op, this.self, SourceSpan span): super(span); | |
| 815 | |
| 816 visit(TreeVisitor visitor) => visitor.visitUnaryExpression(this); | |
| 817 } | |
| 818 | |
| 819 abstract class TreeVisitor { | |
| 820 void visitCssComment(CssComment node); | |
| 821 void visitCommentDefinition(CommentDefinition node); | |
| 822 void visitStylesheet(Stylesheet node); | |
| 823 void visitTopLevelProduction(TopLevelProduction node); | |
| 824 void visitDirective(Directive node); | |
| 825 void visitMediaDirective(MediaDirective node); | |
| 826 void visitPageDirective(PageDirective node); | |
| 827 void visitImportDirective(ImportDirective node); | |
| 828 void visitKeyFrameDirective(KeyFrameDirective node); | |
| 829 void visitKeyFrameBlock(KeyFrameBlock node); | |
| 830 void visitFontFaceDirective(FontFaceDirective node); | |
| 831 void visitIncludeDirective(IncludeDirective node); | |
| 832 void visitStyletDirective(StyletDirective node); | |
| 833 | |
| 834 void visitRuleSet(RuleSet node); | |
| 835 void visitDeclarationGroup(DeclarationGroup node); | |
| 836 void visitDeclaration(Declaration node); | |
| 837 void visitSelectorGroup(SelectorGroup node); | |
| 838 void visitSelector(Selector node); | |
| 839 void visitSimpleSelectorSequence(SimpleSelectorSequence node); | |
| 840 void visitSimpleSelector(SimpleSelector node); | |
| 841 void visitElementSelector(ElementSelector node); | |
| 842 void visitNamespaceSelector(NamespaceSelector node); | |
| 843 void visitAttributeSelector(AttributeSelector node); | |
| 844 void visitIdSelector(IdSelector node); | |
| 845 void visitClassSelector(ClassSelector node); | |
| 846 void visitPseudoClassSelector(PseudoClassSelector node); | |
| 847 void visitPseudoElementSelector(PseudoElementSelector node); | |
| 848 void visitNotSelector(NotSelector node); | |
| 849 | |
| 850 void visitLiteralTerm(LiteralTerm node); | |
| 851 void visitHexColorTerm(HexColorTerm node); | |
| 852 void visitNumberTerm(NumberTerm node); | |
| 853 void visitUnitTerm(UnitTerm node); | |
| 854 void visitLengthTerm(LengthTerm node); | |
| 855 void visitPercentageTerm(PercentageTerm node); | |
| 856 void visitEmTerm(EmTerm node); | |
| 857 void visitExTerm(ExTerm node); | |
| 858 void visitAngleTerm(AngleTerm node); | |
| 859 void visitTimeTerm(TimeTerm node); | |
| 860 void visitFreqTerm(FreqTerm node); | |
| 861 void visitFractionTerm(FractionTerm node); | |
| 862 void visitUriTerm(UriTerm node); | |
| 863 void visitFunctionTerm(FunctionTerm node); | |
| 864 void visitGroupTerm(GroupTerm node); | |
| 865 void visitItemTerm(ItemTerm node); | |
| 866 void visitOperatorSlash(OperatorSlash node); | |
| 867 void visitOperatorComma(OperatorComma node); | |
| 868 | |
| 869 void visitExpressions(Expressions node); | |
| 870 void visitBinaryExpression(BinaryExpression node); | |
| 871 void visitUnaryExpression(UnaryExpression node); | |
| 872 | |
| 873 void visitIdentifier(Identifier node); | |
| 874 void visitWildcard(Wildcard node); | |
| 875 | |
| 876 // TODO(terry): Defined for ../tree.dart. | |
| 877 void visitTypeReference(TypeReference node); | |
| 878 } | |
| 879 | |
| 880 class TreePrinter implements TreeVisitor { | |
| 881 var output; | |
| 882 TreePrinter(this.output) { output.printer = this; } | |
| 883 | |
| 884 void visitStylesheet(Stylesheet node) { | |
| 885 output.heading('Stylesheet', node.span); | |
| 886 output.depth++; | |
| 887 output.writeNodeList('productions', node._topLevels); | |
| 888 output.depth--; | |
| 889 } | |
| 890 | |
| 891 void visitTopLevelProduction(TopLevelProduction node) { | |
| 892 output.heading('TopLevelProduction', node.span); | |
| 893 } | |
| 894 | |
| 895 void visitDirective(Directive node) { | |
| 896 output.heading('Directive', node.span); | |
| 897 } | |
| 898 | |
| 899 void visitCssComment(CssComment node) { | |
| 900 output.heading('Comment', node.span); | |
| 901 output.depth++; | |
| 902 output.writeValue('comment value', node.comment); | |
| 903 output.depth--; | |
| 904 } | |
| 905 | |
| 906 void visitCommentDefinition(CommentDefinition node) { | |
| 907 output.heading('CommentDefinition (CDO/CDC)', node.span); | |
| 908 output.depth++; | |
| 909 output.writeValue('comment value', node.comment); | |
| 910 output.depth--; | |
| 911 } | |
| 912 | |
| 913 void visitMediaDirective(MediaDirective node) { | |
| 914 output.heading('MediaDirective', node.span); | |
| 915 output.depth++; | |
| 916 output.writeNodeList('media', node._media); | |
| 917 visitRuleSet(node._ruleset); | |
| 918 output.depth--; | |
| 919 } | |
| 920 | |
| 921 void visitPageDirective(PageDirective node) { | |
| 922 output.heading('PageDirective', node.span); | |
| 923 output.depth++; | |
| 924 output.writeValue('pseudo page', node._pseudoPage); | |
| 925 visitDeclarationGroup(node._decls); | |
| 926 output.depth; | |
| 927 } | |
| 928 | |
| 929 void visitImportDirective(ImportDirective node) { | |
| 930 output.heading('ImportDirective', node.span); | |
| 931 output.depth++; | |
| 932 output.writeValue('import', node._import); | |
| 933 output.writeNodeList('media', node._media); | |
| 934 output.depth--; | |
| 935 } | |
| 936 | |
| 937 void visitKeyFrameDirective(KeyFrameDirective node) { | |
| 938 output.heading('KeyFrameDirective', node.span); | |
| 939 output.depth++; | |
| 940 output.writeValue('name', node._name); | |
| 941 output.writeNodeList('blocks', node._blocks); | |
| 942 output.depth--; | |
| 943 } | |
| 944 | |
| 945 void visitKeyFrameBlock(KeyFrameBlock node) { | |
| 946 output.heading('KeyFrameBlock', node.span); | |
| 947 output.depth++; | |
| 948 visitExpressions(node._blockSelectors); | |
| 949 visitDeclarationGroup(node._declarations); | |
| 950 output.depth--; | |
| 951 } | |
| 952 | |
| 953 void visitFontFaceDirective(FontFaceDirective node) { | |
| 954 // TODO(terry): To Be Implemented | |
| 955 } | |
| 956 | |
| 957 void visitIncludeDirective(IncludeDirective node) { | |
| 958 output.heading('IncludeDirective', node.span); | |
| 959 output.writeValue('include', node._include); | |
| 960 output.depth++; | |
| 961 if (node._stylesheet != null) { | |
| 962 visitStylesheet(node._stylesheet); | |
| 963 } else { | |
| 964 output.writeValue('StyleSheet', '<EMPTY>'); | |
| 965 } | |
| 966 output.depth--; | |
| 967 } | |
| 968 | |
| 969 void visitStyletDirective(StyletDirective node) { | |
| 970 output.heading('StyletDirective', node.span); | |
| 971 output.writeValue('dartClassName', node._dartClassName); | |
| 972 output.depth++; | |
| 973 output.writeNodeList('rulesets', node._rulesets); | |
| 974 output.depth--; | |
| 975 } | |
| 976 | |
| 977 void visitRuleSet(RuleSet node) { | |
| 978 output.heading('Ruleset', node.span); | |
| 979 output.depth++; | |
| 980 visitSelectorGroup(node._selectorGroup); | |
| 981 visitDeclarationGroup(node._declarationGroup); | |
| 982 output.depth--; | |
| 983 } | |
| 984 | |
| 985 void visitDeclarationGroup(DeclarationGroup node) { | |
| 986 output.heading('DeclarationGroup', node.span); | |
| 987 output.depth++; | |
| 988 output.writeNodeList('declarations', node._declarations); | |
| 989 output.depth--; | |
| 990 } | |
| 991 | |
| 992 void visitDeclaration(Declaration node) { | |
| 993 output.heading('Declaration', node.span); | |
| 994 output.depth++; | |
| 995 output.write('property'); | |
| 996 visitIdentifier(node._property); | |
| 997 output.writeNode('expression', node._expression); | |
| 998 if (node.important) { | |
| 999 output.writeValue('!important', 'true'); | |
| 1000 } | |
| 1001 output.depth--; | |
| 1002 } | |
| 1003 | |
| 1004 void visitSelectorGroup(SelectorGroup node) { | |
| 1005 output.heading('Selector Group', node.span); | |
| 1006 output.depth++; | |
| 1007 output.writeNodeList('selectors', node.selectors); | |
| 1008 output.depth--; | |
| 1009 } | |
| 1010 | |
| 1011 void visitSelector(Selector node) { | |
| 1012 output.heading('Selector', node.span); | |
| 1013 output.depth++; | |
| 1014 output.writeNodeList('simpleSelectorsSequences', | |
| 1015 node._simpleSelectorSequences); | |
| 1016 output.depth--; | |
| 1017 } | |
| 1018 | |
| 1019 void visitSimpleSelectorSequence(SimpleSelectorSequence node) { | |
| 1020 output.heading('SimpleSelectorSequence', node.span); | |
| 1021 output.depth++; | |
| 1022 if (node.isCombinatorNone()) { | |
| 1023 output.writeValue('combinator', "NONE"); | |
| 1024 } else if (node.isCombinatorDescendant()) { | |
| 1025 output.writeValue('combinator', "descendant"); | |
| 1026 } else if (node.isCombinatorPlus()) { | |
| 1027 output.writeValue('combinator', "+"); | |
| 1028 } else if (node.isCombinatorGreater()) { | |
| 1029 output.writeValue('combinator', ">"); | |
| 1030 } else if (node.isCombinatorTilde()) { | |
| 1031 output.writeValue('combinator', "~"); | |
| 1032 } else { | |
| 1033 output.writeValue('combinator', "ERROR UNKNOWN"); | |
| 1034 } | |
| 1035 | |
| 1036 var selector = node._selector; | |
| 1037 if (selector is NamespaceSelector) { | |
| 1038 visitNamespaceSelector(selector); | |
| 1039 } else if (selector is ElementSelector) { | |
| 1040 visitElementSelector(selector); | |
| 1041 } else if (selector is IdSelector) { | |
| 1042 visitIdSelector(selector); | |
| 1043 } else if (selector is ClassSelector) { | |
| 1044 visitClassSelector(selector); | |
| 1045 } else if (selector is PseudoClassSelector) { | |
| 1046 visitPseudoClassSelector(selector); | |
| 1047 } else if (selector is PseudoElementSelector) { | |
| 1048 visitPseudoElementSelector(selector); | |
| 1049 } else if (selector is NotSelector) { | |
| 1050 visitNotSelector(selector); | |
| 1051 } else if (selector is AttributeSelector) { | |
| 1052 visitAttributeSelector(selector); | |
| 1053 } else { | |
| 1054 output.heading('SimpleSelector', selector.span); | |
| 1055 output.depth++; | |
| 1056 visitSimpleSelector(selector); | |
| 1057 output.depth--; | |
| 1058 } | |
| 1059 | |
| 1060 output.depth--; | |
| 1061 } | |
| 1062 | |
| 1063 void visitSimpleSelector(SimpleSelector node) { | |
| 1064 visitIdentifier(node._name); | |
| 1065 } | |
| 1066 | |
| 1067 void visitNamespaceSelector(NamespaceSelector node) { | |
| 1068 output.heading('Namespace Selector', node.span); | |
| 1069 output.depth++; | |
| 1070 | |
| 1071 var namespace = node._namespace; | |
| 1072 if (namespace is Identifier) { | |
| 1073 visitIdentifier(namespace); | |
| 1074 } else if (namespace is Wildcard) { | |
| 1075 visitWildcard(namespace); | |
| 1076 } else { | |
| 1077 output.writeln("NULL"); | |
| 1078 } | |
| 1079 | |
| 1080 visitSimpleSelector(node.nameAsSimpleSelector); | |
| 1081 output.depth--; | |
| 1082 } | |
| 1083 | |
| 1084 void visitElementSelector(ElementSelector node) { | |
| 1085 output.heading('Element Selector', node.span); | |
| 1086 output.depth++; | |
| 1087 visitSimpleSelector(node); | |
| 1088 output.depth--; | |
| 1089 } | |
| 1090 | |
| 1091 void visitAttributeSelector(AttributeSelector node) { | |
| 1092 output.heading('AttributeSelector', node.span); | |
| 1093 output.depth++; | |
| 1094 visitSimpleSelector(node); | |
| 1095 String tokenStr = node.matchOperatorAsTokenString(); | |
| 1096 output.writeValue('operator', '${node.matchOperator()} (${tokenStr})'); | |
| 1097 output.writeValue('value', node.valueToString()); | |
| 1098 output.depth--; | |
| 1099 } | |
| 1100 | |
| 1101 void visitIdSelector(IdSelector node) { | |
| 1102 output.heading('Id Selector', node.span); | |
| 1103 output.depth++; | |
| 1104 visitSimpleSelector(node); | |
| 1105 output.depth--; | |
| 1106 } | |
| 1107 | |
| 1108 void visitClassSelector(ClassSelector node) { | |
| 1109 output.heading('Class Selector', node.span); | |
| 1110 output.depth++; | |
| 1111 visitSimpleSelector(node); | |
| 1112 output.depth--; | |
| 1113 } | |
| 1114 | |
| 1115 void visitPseudoClassSelector(PseudoClassSelector node) { | |
| 1116 output.heading('Pseudo Class Selector', node.span); | |
| 1117 output.depth++; | |
| 1118 visitSimpleSelector(node); | |
| 1119 output.depth--; | |
| 1120 } | |
| 1121 | |
| 1122 void visitPseudoElementSelector(PseudoElementSelector node) { | |
| 1123 output.heading('Pseudo Element Selector', node.span); | |
| 1124 output.depth++; | |
| 1125 visitSimpleSelector(node); | |
| 1126 output.depth--; | |
| 1127 } | |
| 1128 | |
| 1129 void visitNotSelector(NotSelector node) { | |
| 1130 visitSimpleSelector(node); | |
| 1131 output.depth++; | |
| 1132 output.heading('Not Selector', node.span); | |
| 1133 output.depth--; | |
| 1134 } | |
| 1135 | |
| 1136 void visitLiteralTerm(LiteralTerm node) { | |
| 1137 output.heading('LiteralTerm', node.span); | |
| 1138 output.depth++; | |
| 1139 output.writeValue('value', node.text); | |
| 1140 output.depth--; | |
| 1141 } | |
| 1142 | |
| 1143 void visitHexColorTerm(HexColorTerm node) { | |
| 1144 output.heading('HexColorTerm', node.span); | |
| 1145 output.depth++; | |
| 1146 output.writeValue('hex value', node.text); | |
| 1147 output.writeValue('decimal value', node.value); | |
| 1148 output.depth--; | |
| 1149 } | |
| 1150 | |
| 1151 void visitNumberTerm(NumberTerm node) { | |
| 1152 output.heading('NumberTerm', node.span); | |
| 1153 output.depth++; | |
| 1154 output.writeValue('value', node.text); | |
| 1155 output.depth--; | |
| 1156 } | |
| 1157 | |
| 1158 void visitUnitTerm(UnitTerm node) { | |
| 1159 String unitValue; | |
| 1160 | |
| 1161 output.depth++; | |
| 1162 output.writeValue('value', node.text); | |
| 1163 output.writeValue('unit', node.unitToString()); | |
| 1164 output.depth--; | |
| 1165 } | |
| 1166 | |
| 1167 void visitLengthTerm(LengthTerm node) { | |
| 1168 output.heading('LengthTerm', node.span); | |
| 1169 visitUnitTerm(node); | |
| 1170 } | |
| 1171 | |
| 1172 void visitPercentageTerm(PercentageTerm node) { | |
| 1173 output.heading('PercentageTerm', node.span); | |
| 1174 output.depth++; | |
| 1175 visitLiteralTerm(node); | |
| 1176 output.depth--; | |
| 1177 } | |
| 1178 | |
| 1179 void visitEmTerm(EmTerm node) { | |
| 1180 output.heading('EmTerm', node.span); | |
| 1181 output.depth++; | |
| 1182 visitLiteralTerm(node); | |
| 1183 output.depth--; | |
| 1184 } | |
| 1185 | |
| 1186 void visitExTerm(ExTerm node) { | |
| 1187 output.heading('ExTerm', node.span); | |
| 1188 output.depth++; | |
| 1189 visitLiteralTerm(node); | |
| 1190 output.depth--; | |
| 1191 } | |
| 1192 | |
| 1193 void visitAngleTerm(AngleTerm node) { | |
| 1194 output.heading('AngleTerm', node.span); | |
| 1195 visitUnitTerm(node); | |
| 1196 } | |
| 1197 | |
| 1198 void visitTimeTerm(TimeTerm node) { | |
| 1199 output.heading('TimeTerm', node.span); | |
| 1200 visitUnitTerm(node); | |
| 1201 } | |
| 1202 | |
| 1203 void visitFreqTerm(FreqTerm node) { | |
| 1204 output.heading('FreqTerm', node.span); | |
| 1205 visitUnitTerm(node); | |
| 1206 } | |
| 1207 | |
| 1208 void visitFractionTerm(FractionTerm node) { | |
| 1209 output.heading('FractionTerm', node.span); | |
| 1210 output.depth++; | |
| 1211 visitLiteralTerm(node); | |
| 1212 output.depth--; | |
| 1213 } | |
| 1214 | |
| 1215 void visitUriTerm(UriTerm node) { | |
| 1216 output.heading('UriTerm', node.span); | |
| 1217 output.depth++; | |
| 1218 visitLiteralTerm(node); | |
| 1219 output.depth--; | |
| 1220 } | |
| 1221 | |
| 1222 void visitFunctionTerm(FunctionTerm node) { | |
| 1223 output.heading('FunctionTerm', node.span); | |
| 1224 output.depth++; | |
| 1225 visitLiteralTerm(node); | |
| 1226 visitExpressions(node._params); | |
| 1227 output.depth--; | |
| 1228 } | |
| 1229 | |
| 1230 void visitGroupTerm(GroupTerm node) { | |
| 1231 output.heading('GroupTerm', node.span); | |
| 1232 output.depth++; | |
| 1233 output.writeNodeList('grouped terms', node._terms); | |
| 1234 output.depth--; | |
| 1235 } | |
| 1236 | |
| 1237 void visitItemTerm(ItemTerm node) { | |
| 1238 output.heading('ItemTerm', node.span); | |
| 1239 visitNumberTerm(node); | |
| 1240 } | |
| 1241 | |
| 1242 void visitOperatorSlash(OperatorSlash node) { | |
| 1243 output.heading('OperatorSlash', node.span); | |
| 1244 } | |
| 1245 | |
| 1246 void visitOperatorComma(OperatorComma node) { | |
| 1247 output.heading('OperatorComma', node.span); | |
| 1248 } | |
| 1249 | |
| 1250 void visitExpressions(Expressions node) { | |
| 1251 output.heading('Expressions', node.span); | |
| 1252 output.depth++; | |
| 1253 output.writeNodeList('expressions', node._expressions); | |
| 1254 output.depth--; | |
| 1255 } | |
| 1256 | |
| 1257 void visitBinaryExpression(BinaryExpression node) { | |
| 1258 output.heading('BinaryExpression', node.span); | |
| 1259 // TODO(terry): TBD | |
| 1260 } | |
| 1261 | |
| 1262 void visitUnaryExpression(UnaryExpression node) { | |
| 1263 output.heading('UnaryExpression', node.span); | |
| 1264 // TODO(terry): TBD | |
| 1265 } | |
| 1266 | |
| 1267 void visitIdentifier(Identifier node) { | |
| 1268 output.heading('Identifier(${output.toValue(node.name)})', node.span); | |
| 1269 } | |
| 1270 | |
| 1271 void visitWildcard(Wildcard node) { | |
| 1272 output.heading('Wildcard(*)', node.span); | |
| 1273 } | |
| 1274 | |
| 1275 // TODO(terry): Defined for frog/tree.dart. | |
| 1276 void visitTypeReference(TypeReference node) { | |
| 1277 output.heading('Unimplemented'); | |
| 1278 } | |
| 1279 } | |
| OLD | NEW |