Chromium Code Reviews| 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 lang.Node { | |
| 12 String name; | |
| 13 | |
| 14 Identifier(this.name, lang.SourceSpan span): super(span) {} | |
| 15 | |
| 16 visit(TreeVisitor visitor) => visitor.visitIdentifier(this); | |
| 17 | |
| 18 String toString() => name; | |
| 19 } | |
| 20 | |
| 21 class Wildcard extends lang.Node { | |
| 22 Wildcard(lang.SourceSpan span): super(span); | |
| 23 | |
| 24 visit(TreeVisitor visitor) => visitor.visitWildcard(this); | |
| 25 | |
| 26 String toString() => '*'; | |
| 27 } | |
| 28 | |
| 29 class SelectorGroup extends lang.Node { | |
|
nweiz
2011/11/23 00:59:44
As per discussion of selector hierarchy elsewhere
| |
| 30 // List of SimpleSelector(s) list contain any mix SimpleSelector or | |
| 31 // SimpleSlectorName (or class derived from SimpleSelectorName e.g., | |
| 32 // IdSelector, ClassSelector, ElementSelector, PseudoClassSelector, | |
| 33 // PseudoElementSelector, NotSelector, or Attribute | |
| 34 List<SimpleSelector> selectors; | |
| 35 | |
| 36 SelectorGroup(this.selectors, lang.SourceSpan span): super(span); | |
| 37 | |
| 38 visit(TreeVisitor visitor) => visitor.visitSelectorGroup(this); | |
| 39 | |
| 40 String toString() { | |
| 41 StringBuffer buff = new StringBuffer(); | |
| 42 for (selector in selectors) { | |
| 43 if (selector.isCombinatorDescendant()) { | |
| 44 buff.add(' '); | |
| 45 } else if (selector.isCombinatorPlus()) { | |
| 46 buff.add(' + '); | |
| 47 } else if (selector.isCombinatorGreater()) { | |
| 48 buff.add(' > '); | |
| 49 } else if (selector.isCombinatorTilde()) { | |
| 50 buff.add(' ~ '); | |
| 51 } | |
| 52 buff.add(selector.toString()); | |
| 53 } | |
| 54 return buff.toString(); | |
| 55 } | |
| 56 | |
| 57 /** A multiline string showing the node and its children. */ | |
| 58 String toDebugString() { | |
| 59 var to = new lang.TreeOutput(); | |
| 60 var tp = new TreePrinter(to); | |
| 61 this.visit(tp); | |
| 62 return to.buf.toString(); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 /* All other selectors (element, #id, .class, attribute, pseudo, negation, | |
| 67 * namespace, *) are derived from this selector. | |
| 68 */ | |
| 69 class SimpleSelector extends lang.Node { | |
| 70 int _combinator; // +, >, ~ or descendant (space), and NONE | |
| 71 var _name; | |
| 72 | |
| 73 SimpleSelector(this._name, lang.SourceSpan span, | |
| 74 [this._combinator = TokenKind.COMBINATOR_NONE]) : super(span); | |
| 75 | |
| 76 // Name can be an Identifier or WildCard we'll return either the name or '*'. | |
| 77 String get name() => isWildcard() ? '*' : _name.name; | |
|
nweiz
2011/11/23 00:59:44
I don't understand the need to have a "name" prope
| |
| 78 | |
| 79 bool isWildcard() => _name is Wildcard; | |
|
nweiz
2011/11/23 00:59:44
If you're going to have a separate Wildcard class
| |
| 80 | |
| 81 // TODO(terry): Kind of hacky to reset combinator to NONE | |
| 82 void resetCombinatorNone() { | |
| 83 assert(isCombinatorDescendant()); | |
| 84 _combinator = TokenKind.COMBINATOR_NONE; | |
| 85 } | |
| 86 | |
| 87 bool isCombinatorNone() => _combinator == TokenKind.COMBINATOR_NONE; | |
| 88 bool isCombinatorDescendant() => | |
| 89 _combinator == TokenKind.COMBINATOR_DESCENDANT; | |
| 90 bool isCombinatorPlus() => _combinator == TokenKind.COMBINATOR_PLUS; | |
| 91 bool isCombinatorGreater() => _combinator == TokenKind.COMBINATOR_GREATER; | |
| 92 bool isCombinatorTilde() => _combinator == TokenKind.COMBINATOR_TILDE; | |
| 93 | |
| 94 visit(TreeVisitor visitor) => visitor.visitSimpleSelector(this); | |
| 95 | |
| 96 String toString() => name; | |
| 97 } | |
| 98 | |
| 99 // element name | |
| 100 class ElementSelector extends SimpleSelector { | |
| 101 ElementSelector(var name, lang.SourceSpan span, | |
| 102 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 103 super(name, span, combinator); | |
| 104 | |
| 105 visit(TreeVisitor visitor) => visitor.visitElementSelector(this); | |
| 106 | |
| 107 String toString() => "$name"; | |
| 108 | |
| 109 /** A multiline string showing the node and its children. */ | |
| 110 String toDebugString() { | |
| 111 var to = new lang.TreeOutput(); | |
| 112 var tp = new TreePrinter(to); | |
| 113 this.visit(tp); | |
| 114 return to.buf.toString(); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 // namespace|element | |
| 119 class NamespaceSelector extends SimpleSelector { | |
|
nweiz
2011/11/23 00:59:44
Namespaces aren't separate simple selectors. A nam
| |
| 120 var _namespace; // null, Wildcard or Identifier | |
| 121 | |
| 122 NamespaceSelector(this._namespace, var name, lang.SourceSpan span, | |
| 123 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 124 super(name, span, combinator); | |
| 125 | |
| 126 String get namespace() => _namespace is Wildcard ? '*' : _namespace.name; | |
| 127 | |
| 128 bool isNamespaceWildcard() => _namespace is Wildcard; | |
| 129 | |
| 130 SimpleSelector get nameAsSimpleSelector() => _name; | |
| 131 | |
| 132 visit(TreeVisitor visitor) => visitor.visitNamespaceSelector(this); | |
| 133 | |
| 134 String toString() => "$namespace|$nameAsSimpleSelector"; | |
| 135 } | |
| 136 | |
| 137 // #id | |
| 138 class IdSelector extends SimpleSelector { | |
| 139 IdSelector(Identifier name, lang.SourceSpan span, | |
| 140 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 141 super(name, span, combinator); | |
| 142 | |
| 143 visit(TreeVisitor visitor) => visitor.visitIdSelector(this); | |
| 144 | |
| 145 String toString() => "#$name"; | |
| 146 } | |
| 147 | |
| 148 // .class | |
| 149 class ClassSelector extends SimpleSelector { | |
| 150 ClassSelector(Identifier name, lang.SourceSpan span, | |
| 151 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 152 super(name, span, combinator); | |
| 153 | |
| 154 visit(TreeVisitor visitor) => visitor.visitClassSelector(this); | |
| 155 | |
| 156 String toString() => ".$name"; | |
| 157 } | |
| 158 | |
| 159 // :pseudoClass | |
| 160 class PseudoClassSelector extends SimpleSelector { | |
| 161 PseudoClassSelector(Identifier name, lang.SourceSpan span, | |
| 162 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 163 super(name, span, combinator); | |
| 164 | |
| 165 visit(TreeVisitor visitor) => visitor.visitPseudoClassSelector(this); | |
| 166 | |
| 167 String toString() => ":$name"; | |
| 168 } | |
| 169 | |
| 170 // ::pseudoElement | |
| 171 class PseudoElementSelector extends SimpleSelector { | |
| 172 PseudoElementSelector(Identifier name, lang.SourceSpan span, | |
| 173 [int combinator = TokenKind.COMBINATOR_NONE]) : | |
| 174 super(name, span, combinator); | |
| 175 | |
| 176 visit(TreeVisitor visitor) => visitor.visitPseudoElementSelector(this); | |
| 177 | |
| 178 String toString() => "::$name"; | |
| 179 } | |
| 180 | |
| 181 // TODO(terry): Implement | |
| 182 // NOT | |
| 183 class NotSelector extends SimpleSelector { | |
| 184 NotSelector(String name, lang.SourceSpan span, | |
| 185 [lang.Token combinator = TokenKind.COMBINATOR_NONE]) : | |
| 186 super(name, span, combinator); | |
| 187 | |
| 188 visit(TreeVisitor visitor) => visitor.visitNotSelector(this); | |
| 189 } | |
| 190 | |
| 191 // TODO(terry): Implement | |
| 192 // [attribute] | |
| 193 class Attribute extends lang.Node { | |
| 194 var name; // NamespaceSelector or SimpleSelector | |
| 195 int matchType; // ~=, |=, ^=, $=, *=, = | |
| 196 String value; | |
| 197 } | |
| 198 | |
| 199 interface TreeVisitor { | |
| 200 void visitSelectorGroup(SelectorGroup node); | |
| 201 void visitSimpleSelector(SimpleSelector node); | |
| 202 void visitElementSelector(ElementSelector node); | |
| 203 void visitNamespaceSelector(NamespaceSelector node); | |
| 204 void visitIdSelector(IdSelector node); | |
| 205 void visitClassSelector(ClassSelector node); | |
| 206 void visitPseudoClassSelector(PseudoClassSelector node); | |
| 207 void visitPseudoElementSelector(PseudoElementSelector node); | |
| 208 void visitNotSelector(NotSelector node); | |
| 209 | |
| 210 void visitIdentifier(Identifier node); | |
| 211 void visitWildcard(Wildcard node); | |
| 212 | |
| 213 // TODO(terry): Defined for ../tree.dart. | |
| 214 void visitTypeReference(lang.TypeReference node); | |
| 215 } | |
| 216 | |
| 217 class TreePrinter implements TreeVisitor { | |
| 218 var output; | |
| 219 TreePrinter(this.output) { output.printer = this; } | |
| 220 | |
| 221 void visitSelectorGroup(SelectorGroup node) { | |
| 222 output.heading('Selector Group', node.span); | |
| 223 output.writeNodeList('selectors', node.selectors); | |
| 224 output.writeln(''); | |
| 225 } | |
| 226 | |
| 227 void visitSimpleSelector(SimpleSelector node) { | |
| 228 if (node.isCombinatorNone()) { | |
| 229 output.writeValue('combinator', "NONE"); | |
| 230 } else if (node.isCombinatorDescendant()) { | |
| 231 output.writeValue('combinator', "descendant"); | |
| 232 } else if (node.isCombinatorPlus()) { | |
| 233 output.writeValue('combinator', "+"); | |
| 234 } else if (node.isCombinatorGreater()) { | |
| 235 output.writeValue('combinator', ">"); | |
| 236 } else if (node.isCombinatorTilde()) { | |
| 237 output.writeValue('combinator', "~"); | |
| 238 } else { | |
| 239 output.writeValue('combinator', "ERROR UNKNOWN"); | |
| 240 } | |
| 241 } | |
| 242 | |
| 243 void visitNamespaceSelector(NamespaceSelector node) { | |
| 244 output.heading('Namespace Selector', node.span); | |
| 245 visitSimpleSelector(node); | |
| 246 output.writeNode('namespace', node._namespace); | |
| 247 output.writeNode('name', node._name); | |
| 248 } | |
| 249 | |
| 250 void visitElementSelector(ElementSelector node) { | |
| 251 output.heading('Element Selector', node.span); | |
| 252 visitSimpleSelector(node); | |
| 253 output.writeNode('name', node._name); | |
| 254 } | |
| 255 | |
| 256 void visitIdSelector(IdSelector node) { | |
| 257 output.heading('Id Selector', node.span); | |
| 258 visitSimpleSelector(node); | |
| 259 output.writeNode('name', node._name); | |
| 260 } | |
| 261 | |
| 262 void visitClassSelector(ClassSelector node) { | |
| 263 output.heading('Class Selector', node.span); | |
| 264 visitSimpleSelector(node); | |
| 265 output.writeNode('name', node._name); | |
| 266 } | |
| 267 | |
| 268 void visitPseudoClassSelector(PseudoClassSelector node) { | |
| 269 output.heading('Pseudo Class Selector', node.span); | |
| 270 visitSimpleSelector(node); | |
| 271 output.writeNode('name', node._name); | |
| 272 } | |
| 273 | |
| 274 void visitPseudoElementSelector(PseudoElementSelector node) { | |
| 275 output.heading('Pseudo Element Selector', node.span); | |
| 276 visitSimpleSelector(node); | |
| 277 output.writeNode('name', node._name); | |
| 278 } | |
| 279 | |
| 280 void visitNotSelector(NotSelector node) { | |
| 281 visitSimpleSelector(node); | |
| 282 output.heading('Not Selector', node.span); | |
| 283 } | |
| 284 | |
| 285 void visitIdentifier(Identifier node) { | |
| 286 output.heading('Identifier(' + output.toValue(node.name) + ")", node.span); | |
| 287 } | |
| 288 | |
| 289 void visitWildcard(Wildcard node) { | |
| 290 output.heading('Wildcard(*)', node.span); | |
| 291 } | |
| 292 | |
| 293 // TODO(terry): Defined for frog/tree.dart. | |
| 294 void visitTypeReference(lang.TypeReference node) { | |
| 295 output.heading('Unimplemented'); | |
| 296 } | |
| 297 } | |
| OLD | NEW |