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