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

Side by Side Diff: utils/template/htmltree.dart

Issue 10010009: Calculator App for ChromeOS with fixes for templates/CSS to support this application. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mininimal templates and more text node tests. Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 // Generated by scripts/tree_gen.py. 4 // Generated by scripts/tree_gen.py.
5 5
6 ///////////////////////////////////////////////////////////////////////// 6 /////////////////////////////////////////////////////////////////////////
7 // CSS specific types: 7 // CSS specific types:
8 ///////////////////////////////////////////////////////////////////////// 8 /////////////////////////////////////////////////////////////////////////
9 9
10 class Identifier extends ASTNode { 10 class Identifier extends ASTNode {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return buff.toString(); 76 return buff.toString();
77 } 77 }
78 78
79 String toString() => "template ${name}(${paramsAsString()})"; 79 String toString() => "template ${name}(${paramsAsString()})";
80 } 80 }
81 81
82 class TemplateChildren extends ASTNode { 82 class TemplateChildren extends ASTNode {
83 List<ASTNode> children; 83 List<ASTNode> children;
84 84
85 TemplateChildren(this.children, SourceSpan span): super(span); 85 TemplateChildren(this.children, SourceSpan span): super(span);
86 TemplateChildren.empty(SourceSpan span): super(span); 86 TemplateChildren.empty(SourceSpan span): children = [], super(span);
87 87
88 add(var child) { 88 add(var child) {
89 if (children == null) { 89 if (children == null) {
90 children = new List<ASTNode>(); 90 children = new List<ASTNode>();
91 } 91 }
92 children.add(child); 92 children.add(child);
93 } 93 }
94 94
95 ASTNode last() => children.last(); 95 ASTNode last() => children.last();
96 ASTNode removeLast() => children.removeLast(); 96 ASTNode removeLast() => children.removeLast();
97 bool get anyChildren() => children != null && children.length > 0; 97 bool get anyChildren() => children != null && children.length > 0;
98 98
99 visit(TreeVisitor visitor) => visitor.visitTemplateChildren(this); 99 visit(TreeVisitor visitor) => visitor.visitTemplateChildren(this);
100 100
101 String toString() { 101 String toString() {
102 StringBuffer buff = new StringBuffer(); 102 StringBuffer buff = new StringBuffer();
103 if (children != null) { 103 if (children != null) {
104 for (final child in children) { 104 for (final child in children) {
105 buff.add(child.toString()); 105 buff.add(child.toString());
106 } 106 }
107 } 107 }
108 108
109 return buff.toString(); 109 return buff.toString();
110 } 110 }
111 } 111 }
112 112
113 class TemplateGetter extends ASTNode {
114 String name;
115 List<Map<Identifier, Identifier>> params;
116 TemplateDocument docFrag;
117
118 TemplateGetter(this.name, this.params, this.docFrag, SourceSpan span) :
119 super(span);
120
121 visit(TreeVisitor visitor) => visitor.visitTemplateGetter(this);
122
123 String paramsAsString() {
124 StringBuffer buff = new StringBuffer();
125 bool first = true;
126 for (final param in params) {
127 if (!first) {
128 buff.add(", ");
129 }
130 if (param['type'] != null && param['type'].length > 0) {
131 buff.add(param['type']);
132 buff.add(' ');
133 }
134 buff.add(param['name']);
135 first = false;
136 }
137
138 return buff.toString();
139 }
140
141 String getterSignatureAsString() => "${name}(${paramsAsString()})";
142 }
143
113 class TemplateContent extends ASTNode { 144 class TemplateContent extends ASTNode {
114 css.Stylesheet css; 145 css.Stylesheet css;
115 TemplateDocument html; 146 TemplateDocument html;
147 List<TemplateGetter> getters;
116 148
117 TemplateContent(this.css, this.html, SourceSpan span) : super(span); 149 TemplateContent(this.css, this.html, this.getters, SourceSpan span) :
150 super(span);
118 151
119 visit(TreeVisitor visitor) => visitor.visitTemplateContent(this); 152 visit(TreeVisitor visitor) => visitor.visitTemplateContent(this);
120 } 153 }
121 154
122 class TemplateDocument extends TemplateChildren { 155 class TemplateDocument extends TemplateChildren {
123 TemplateDocument(List<ASTNode> children, SourceSpan span): 156 TemplateDocument(List<ASTNode> children, SourceSpan span):
124 super(children, span); 157 super(children, span);
125 158
126 visit(TreeVisitor visitor) => visitor.visitTemplateDocument(this); 159 visit(TreeVisitor visitor) => visitor.visitTemplateDocument(this);
127 } 160 }
(...skipping 12 matching lines...) Expand all
140 bool get anyAttributes() => attributes != null; 173 bool get anyAttributes() => attributes != null;
141 174
142 visit(TreeVisitor visitor) => visitor.visitTemplateElement(this); 175 visit(TreeVisitor visitor) => visitor.visitTemplateElement(this);
143 176
144 bool get hasVar() => _varName != null; 177 bool get hasVar() => _varName != null;
145 String get varName() => hasVar ? _varName.value : null; 178 String get varName() => hasVar ? _varName.value : null;
146 179
147 String attributesToString() { 180 String attributesToString() {
148 StringBuffer buff = new StringBuffer(); 181 StringBuffer buff = new StringBuffer();
149 182
150 for (final attr in attributes) { 183 if (attributes != null) {
151 buff.add(' ${attr.toString()}'); 184 for (final attr in attributes) {
185 buff.add(' ${attr.toString()}');
Jacob 2012/04/05 18:06:01 i don't think the toString() is needed
186 }
152 } 187 }
153 188
154 return buff.toString(); 189 return buff.toString();
155 } 190 }
156 191
157 String get tagName() => isFragment ? 192 String get tagName() => isFragment ?
158 'root' : TokenKind.tagNameFromTokenId(tagTokenId); 193 'root' : TokenKind.tagNameFromTokenId(tagTokenId);
159 194
160 String tagStartToString() => "<${tagName} ${attributesToString()}>"; 195 bool get scoped() => !TokenKind.unscopedTag(tagTokenId);
196
197 String tagStartToString() => "<${tagName}${attributesToString()}>";
161 198
162 String tagEndToString() => "</${tagName}>"; 199 String tagEndToString() => "</${tagName}>";
163 200
164 String toString() { 201 String toString() {
165 StringBuffer buff = new StringBuffer(tagStartToString()); 202 StringBuffer buff = new StringBuffer(tagStartToString());
166 203
167 if (children != null) { 204 if (children != null) {
168 for (final child in children) { 205 for (final child in children) {
169 buff.add(child.toString()); 206 buff.add(child.toString());
170 } 207 }
(...skipping 26 matching lines...) Expand all
197 String toString() => value; 234 String toString() => value;
198 } 235 }
199 236
200 class TemplateExpression extends ASTNode { 237 class TemplateExpression extends ASTNode {
201 String expression; 238 String expression;
202 239
203 TemplateExpression(this.expression, SourceSpan span): super(span); 240 TemplateExpression(this.expression, SourceSpan span): super(span);
204 241
205 visit(TreeVisitor visitor) => visitor.visitTemplateExpression(this); 242 visit(TreeVisitor visitor) => visitor.visitTemplateExpression(this);
206 243
207 String toString() => "\$\{value}"; 244 String toString() => "\$\{${expression}}";
208 } 245 }
209 246
210 class TemplateEachCommand extends ASTNode { 247 class TemplateEachCommand extends ASTNode {
211 String listName; 248 String listName;
212 String loopItem; 249 String loopItem;
213 TemplateDocument documentFragment; 250 TemplateDocument documentFragment;
214 251
215 TemplateEachCommand(this.listName, this.loopItem, this.documentFragment, 252 TemplateEachCommand(this.listName, this.loopItem, this.documentFragment,
216 SourceSpan span): super(span); 253 SourceSpan span): super(span);
217 254
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 void visitTemplateChildren(TemplateChildren node); 296 void visitTemplateChildren(TemplateChildren node);
260 void visitTemplateDocument(TemplateDocument node); 297 void visitTemplateDocument(TemplateDocument node);
261 void visitTemplateContent(TemplateContent node); 298 void visitTemplateContent(TemplateContent node);
262 void visitTemplateElement(TemplateElement node); 299 void visitTemplateElement(TemplateElement node);
263 void visitTemplateAttribute(TemplateAttribute node); 300 void visitTemplateAttribute(TemplateAttribute node);
264 void visitTemplateText(TemplateText node); 301 void visitTemplateText(TemplateText node);
265 void visitTemplateExpression(TemplateExpression node); 302 void visitTemplateExpression(TemplateExpression node);
266 void visitTemplateEachCommand(TemplateEachCommand node); 303 void visitTemplateEachCommand(TemplateEachCommand node);
267 void visitTemplateWithCommand(TemplateWithCommand node); 304 void visitTemplateWithCommand(TemplateWithCommand node);
268 void visitTemplateCall(TemplateCall node); 305 void visitTemplateCall(TemplateCall node);
306 void visitTemplateGetter(TemplateGetter node);
269 } 307 }
270 308
271 class TreePrinter implements TreeVisitor { 309 class TreePrinter implements TreeVisitor {
272 var output; 310 var output;
273 TreePrinter(this.output) { output.printer = this; } 311 TreePrinter(this.output) { output.printer = this; }
274 312
275 void visitIdentifier(Identifier node) { 313 void visitIdentifier(Identifier node) {
276 output.heading('Identifier(${output.toValue(node.name)})', node.span); 314 output.heading('Identifier(${output.toValue(node.name)})', node.span);
277 } 315 }
278 316
(...skipping 27 matching lines...) Expand all
306 output.writeNodeList('children', node.children); 344 output.writeNodeList('children', node.children);
307 } 345 }
308 346
309 void visitTemplateContent(TemplateContent node) { 347 void visitTemplateContent(TemplateContent node) {
310 visitTemplateDocument(node.html); 348 visitTemplateDocument(node.html);
311 if (node.css != null) { 349 if (node.css != null) {
312 output.depth++; 350 output.depth++;
313 output.writeValue('---CSS---', node.css.toString()); 351 output.writeValue('---CSS---', node.css.toString());
314 output.depth--; 352 output.depth--;
315 } 353 }
354 if (node.getters != null) {
355 output.depth++;
356 output.writeNodeList('---GETTERS---', node.getters);
357 output.depth--;
358 }
316 } 359 }
317 360
318 void visitTemplateDocument(TemplateDocument node) { 361 void visitTemplateDocument(TemplateDocument node) {
319 output.heading('Content', node.span); 362 output.heading('Content', node.span);
320 output.depth++; 363 output.depth++;
321 var child = node.children[0]; 364 // TODO(terry): Ugly use dynamic[0] instead children[0] to surpress warning.
322 assert(node.children.length == 1 && child.tagTokenId == -1); 365 assert(node.children.length == 1 &&
366 node.children.dynamic[0].tagTokenId == -1);
323 output.writeNodeList("document", node.children); 367 output.writeNodeList("document", node.children);
324 output.depth--; 368 output.depth--;
325 } 369 }
326 370
327 void visitTemplateElement(TemplateElement node) { 371 void visitTemplateElement(TemplateElement node) {
328 output.heading('Element', node.span); 372 output.heading('Element', node.span);
329 output.depth++; 373 output.depth++;
330 output.writeValue('tag', node.tagName); 374 output.writeValue('tag', node.tagName);
331 if (node.attributes != null && (node.attributes.length > 0)) { 375 if (node.attributes != null && (node.attributes.length > 0)) {
332 output.writeNodeList("attributes", node.attributes); 376 output.writeNodeList("attributes", node.attributes);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 output.writeValue('object', node.objectName); 408 output.writeValue('object', node.objectName);
365 visitTemplateDocument(node.documentFragment); 409 visitTemplateDocument(node.documentFragment);
366 } 410 }
367 411
368 void visitTemplateCall(TemplateCall node) { 412 void visitTemplateCall(TemplateCall node) {
369 output.heading('#call template', node.span); 413 output.heading('#call template', node.span);
370 output.writeValue('templateToCall', node.toCall); 414 output.writeValue('templateToCall', node.toCall);
371 output.writeValue('params', node.params); 415 output.writeValue('params', node.params);
372 } 416 }
373 417
418 void visitTemplateGetter(TemplateGetter node) {
419 output.heading('template getter', node.span);
420 output.writeValue('getter Signature', node.getterSignatureAsString());
421 visitTemplateDocument(node.docFrag);
422 }
374 } 423 }
375 424
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698