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

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

Issue 9695048: Template parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Siggi's comments Created 8 years, 9 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 | « utils/template/codegen.dart ('k') | utils/template/parser.dart » ('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) 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 class Identifier extends ASTNode {
11 String name;
12
13 Identifier(this.name, SourceSpan span): super(span);
14
15 visit(TreeVisitor visitor) => visitor.visitIdentifier(this);
16
17 String toString() => name;
18 }
19
20 class StringValue extends ASTNode {
21 String value;
22
23 StringValue(this.value, SourceSpan span): super(span);
24
25 visit(TreeVisitor visitor) => visitor.visitStringValue(this);
26
27 String toString() => value;
28 }
29
30 // CDO/CDC (Comment Definition Open <!-- and Comment Definition Close -->).
31 class CommentDefinition extends ASTNode {
32 String comment;
33
34 CommentDefinition(this.comment, SourceSpan span): super(span);
35
36 visit(TreeVisitor visitor) => visitor.visitCommentDefinition(this);
37
38 String toString() => '<!-- ${comment} -->';
39 }
40
41 class Template extends ASTNode {
42 TemplateSignature signature;
43 TemplateContent content;
44
45 Template(this.signature, this.content, SourceSpan span):
46 super(span);
47
48 visit(TreeVisitor visitor) => visitor.visitTemplate(this);
49
50 String toString() => "${signature.toString()} \r{\r${content.toString()}\r}\r" ;
51 }
52
53 class TemplateSignature extends ASTNode {
54 String name;
55 List<Map<Identifier, Identifier>> params; // Map of {type:, name:}
56
57 TemplateSignature(this.name, this.params, SourceSpan span): super(span);
58
59 visit(TreeVisitor visitor) => visitor.visitTemplateSignature(this);
60
61 String paramsAsString() {
62 StringBuffer buff = new StringBuffer();
63 bool first = true;
64 for (final param in params) {
65 if (!first) {
66 buff.add(", ");
67 }
68 if (param['type'] != null) {
69 buff.add(param['type']);
70 buff.add(' ');
71 }
72 buff.add(param['name']);
73 first = false;
74 }
75
76 return buff.toString();
77 }
78
79 String toString() => "template ${name}(${paramsAsString()})";
80 }
81
82 class TemplateChildren extends ASTNode {
83 List<ASTNode> children;
84
85 TemplateChildren(this.children, SourceSpan span): super(span);
86 TemplateChildren.empty(SourceSpan span): super(span);
87
88 add(var child) {
89 if (children == null) {
90 children = new List<ASTNode>();
91 }
92 children.add(child);
93 }
94
95 ASTNode last() => children.last();
96 ASTNode removeLast() => children.removeLast();
97 bool get anyChildren() => children != null && children.length > 0;
98
99 visit(TreeVisitor visitor) => visitor.visitTemplateChildren(this);
100
101 String toString() {
102 StringBuffer buff = new StringBuffer();
103 if (children != null) {
104 for (final child in children) {
105 buff.add(child.toString());
106 }
107 }
108
109 return buff.toString();
110 }
111 }
112
113 class TemplateContent extends ASTNode {
114 css.Stylesheet css;
115 TemplateDocument html;
116
117 TemplateContent(this.css, this.html, SourceSpan span) : super(span);
118
119 visit(TreeVisitor visitor) => visitor.visitTemplateContent(this);
120 }
121
122 class TemplateDocument extends TemplateChildren {
123 TemplateDocument(List<ASTNode> children, SourceSpan span):
124 super(children, span);
125
126 visit(TreeVisitor visitor) => visitor.visitTemplateDocument(this);
127 }
128
129 class TemplateElement extends TemplateChildren {
130 int tagTokenId;
131 List<TemplateAttribute> attributes;
132 StringValue _varName;
133
134 TemplateElement(this.tagTokenId, SourceSpan span): super.empty(span);
135 TemplateElement.fragment(SourceSpan span) : super.empty(span), tagTokenId = -1 ;
136 TemplateElement.attributes(this.tagTokenId, this.attributes, this._varName,
137 SourceSpan span): super.empty(span);
138
139 bool get isFragment() => tagTokenId == -1;
140 bool get anyAttributes() => attributes != null;
141
142 visit(TreeVisitor visitor) => visitor.visitTemplateElement(this);
143
144 bool get hasVar() => _varName != null;
145 String get varName() => hasVar ? _varName.value : null;
146
147 String attributesToString() {
148 StringBuffer buff = new StringBuffer();
149
150 for (final attr in attributes) {
151 buff.add(' ${attr.toString()}');
152 }
153
154 return buff.toString();
155 }
156
157 String get tagName() => isFragment ?
158 'root' : TokenKind.tagNameFromTokenId(tagTokenId);
159
160 String tagStartToString() => "<${tagName} ${attributesToString()}>";
161
162 String tagEndToString() => "</${tagName}>";
163
164 String toString() {
165 StringBuffer buff = new StringBuffer(tagStartToString());
166
167 if (children != null) {
168 for (final child in children) {
169 buff.add(child.toString());
170 }
171
172 buff.add(tagEndToString());
173 }
174
175 return buff.toString();
176 }
177 }
178
179 class TemplateAttribute extends ASTNode {
180 String name;
181 String value;
182
183 TemplateAttribute(this.name, this.value, SourceSpan span): super(span);
184
185 visit(TreeVisitor visitor) => visitor.visitTemplateAttribute(this);
186
187 String toString() => "${name}=\"${value}\"";
188 }
189
190 class TemplateText extends ASTNode {
191 String value;
192
193 TemplateText(this.value, SourceSpan span): super(span);
194
195 visit(TreeVisitor visitor) => visitor.visitTemplateText(this);
196
197 String toString() => value;
198 }
199
200 class TemplateExpression extends ASTNode {
201 String expression;
202
203 TemplateExpression(this.expression, SourceSpan span): super(span);
204
205 visit(TreeVisitor visitor) => visitor.visitTemplateExpression(this);
206
207 String toString() => "\$\{value}";
208 }
209
210 class TemplateEachCommand extends ASTNode {
211 String listName;
212 TemplateDocument documentFragment;
213
214 TemplateEachCommand(this.listName, this.documentFragment, SourceSpan span):
215 super(span);
216
217 visit(TreeVisitor visitor) => visitor.visitTemplateEachCommand(this);
218
219 String toString() => "\$\{#each ${listName}}";
220 }
221
222 class TemplateWithCommand extends ASTNode {
223 String objectName;
224 TemplateDocument documentFragment;
225
226 TemplateWithCommand(this.objectName, this.documentFragment, SourceSpan span):
227 super(span);
228
229 visit(TreeVisitor visitor) => visitor.visitTemplateWithCommand(this);
230
231 String toString() => "\$\{#with ${objectName}}";
232 }
233
234 interface TreeVisitor {
235 void visitIdentifier(Identifier node);
236 void visitStringValue(StringValue node);
237 void visitCommentDefinition(CommentDefinition node);
238 void visitTemplate(Template node);
239 void visitTemplateSignature(TemplateSignature node);
240 void visitTemplateChildren(TemplateChildren node);
241 void visitTemplateDocument(TemplateDocument node);
242 void visitTemplateContent(TemplateContent node);
243 void visitTemplateElement(TemplateElement node);
244 void visitTemplateAttribute(TemplateAttribute node);
245 void visitTemplateText(TemplateText node);
246 void visitTemplateExpression(TemplateExpression node);
247 void visitTemplateEachCommand(TemplateEachCommand node);
248 void visitTemplateWithCommand(TemplateWithCommand node);
249 }
250
251 class TreePrinter implements TreeVisitor {
252 var output;
253 TreePrinter(this.output) { output.printer = this; }
254
255 void visitIdentifier(Identifier node) {
256 output.heading('Identifier(${output.toValue(node.name)})', node.span);
257 }
258
259 void visitStringValue(StringValue node) {
260 output.heading('"${output.toValue(node.value)}"', node.span);
261 }
262
263 void visitCommentDefinition(CommentDefinition node) {
264 output.heading('CommentDefinition (CDO/CDC)', node.span);
265 output.depth++;
266 output.writeValue('comment value', node.comment);
267 output.depth--;
268 }
269
270 void visitTemplate(Template node) {
271 output.heading('Template', node.span);
272 output.depth++;
273 visitTemplateSignature(node.signature);
274 visitTemplateContent(node.content);
275 output.depth--;
276 }
277
278 void visitTemplateSignature(TemplateSignature node) {
279 output.heading('TemplateSignature', node.span);
280 output.depth++;
281 output.writeValue('Template', node);
282 output.depth--;
283 }
284
285 void visitTemplateChildren(TemplateChildren node) {
286 output.writeNodeList('children', node.children);
287 }
288
289 void visitTemplateContent(TemplateContent node) {
290 visitTemplateDocument(node.html);
291 if (node.css != null) {
292 output.depth++;
293 output.writeValue('---CSS---', node.css.toString());
294 output.depth--;
295 }
296 }
297
298 void visitTemplateDocument(TemplateDocument node) {
299 output.heading('Content', node.span);
300 output.depth++;
301 var child = node.children[0];
302 assert(node.children.length == 1 && child.tagTokenId == -1);
303 output.writeNodeList("document", node.children);
304 output.depth--;
305 }
306
307 void visitTemplateElement(TemplateElement node) {
308 output.heading('Element', node.span);
309 output.depth++;
310 output.writeValue('tag', node.tagName);
311 if (node.attributes != null && (node.attributes.length > 0)) {
312 output.writeNodeList("attributes", node.attributes);
313 }
314 visitTemplateChildren(node);
315 output.depth--;
316 }
317
318 void visitTemplateAttribute(TemplateAttribute node) {
319 output.heading('Attribute', node.span);
320 output.depth++;
321 output.writeValue('name', node.name);
322 output.writeValue('value', node.value);
323 output.depth--;
324 }
325
326 void visitTemplateText(TemplateText node) {
327 output.heading('Text', node.span);
328 output.writeValue('value', node.value);
329 }
330
331 void visitTemplateExpression(TemplateExpression node) {
332 output.heading('Interpolate', node.span);
333 output.writeValue('expression', "\$\{${node.expression}\}");
334 }
335
336 void visitTemplateEachCommand(TemplateEachCommand node) {
337 output.heading('#each', node.span);
338 output.writeValue('list', node.listName);
339 visitTemplateDocument(node.documentFragment);
340 }
341
342 void visitTemplateWithCommand(TemplateWithCommand node) {
343 output.heading('#with', node.span);
344 output.writeValue('object', node.objectName);
345 visitTemplateDocument(node.documentFragment);
346 }
347 }
348
OLDNEW
« no previous file with comments | « utils/template/codegen.dart ('k') | utils/template/parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698