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

Side by Side Diff: utils/css/treebase.dart

Issue 9695048: Template parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix GIT mixup - ugh 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
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 /**
5 * The base type for all nodes in a dart abstract syntax tree.
6 */
7 class ASTNode {
Siggi Cherem (dart-lang) 2012/03/15 01:21:25 there is a lot of code copied from the parser in f
terry 2012/03/15 19:02:49 Since frog will be going away I didn't want to rel
8 /** The source code this [ASTNode] represents. */
9 SourceSpan span;
10
11 ASTNode(this.span) {}
12
13 /** Classic double-dispatch visitor for implementing passes. */
14 abstract visit(TreeVisitor visitor);
15
16 /** A multiline string showing the node and its children. */
17 String toDebugString() {
18 var to = new TreeOutput();
19 var tp = new TreePrinter(to);
20 this.visit(tp);
21 return to.buf.toString();
22 }
23 }
24
25 /** The base type for expressions. */
26 // TODO(terry): Should be abstract class but frog doesn't support abstract class keyword yet.
Siggi Cherem (dart-lang) 2012/03/15 01:21:25 80 col (here and below)
terry 2012/03/15 19:02:49 Done.
27 class Expression extends ASTNode {
28 Expression(SourceSpan span): super(span) {}
29 }
30
31 /** The base type for a reference to a [Type]. */
32 // TODO(terry): Should be abstract class but frog doesn't support abstract class keyword yet.
33 class TypeReference extends ASTNode {
34 TypeReference(SourceSpan span): super(span) {}
35 }
36
37 // TODO(jimhug): Clean-up and factor out of core.
38 /** Simple class to provide a textual dump of trees for debugging. */
39 class TreeOutput {
40 int depth;
41 StringBuffer buf;
42
43 var printer;
44
45 static void dump(ASTNode node) {
46 var o = new TreeOutput();
47 node.visit(new TreePrinter(o));
48 print(o.buf);
49 }
50
51 TreeOutput(): this.depth = 0, this.buf = new StringBuffer() {
52 }
53
54 void write(String s) {
55 for (int i=0; i < depth; i++) {
56 buf.add(' ');
57 }
58 buf.add(s);
59 }
60
61 void writeln(String s) {
62 write(s);
63 buf.add('\n');
64 }
65
66 void heading(String name, span) {
67 write(name);
68 buf.add(' (${span.locationText})');
69 buf.add('\n');
70 }
71
72 String toValue(value) {
73 if (value == null) return 'null';
74 else if (value is Identifier) return value.name;
75 else return value.toString();
76 }
77
78 void writeNode(String label, ASTNode node) {
79 write(label + ': ');
80 depth += 1;
81 if (node != null) node.visit(printer);
82 else writeln('null');
83 depth -= 1;
84 }
85
86 void writeValue(String label, value) {
87 var v = toValue(value);
88 writeln('${label}: ${v}');
89 }
90
91 void writeList(String label, List list) {
92 write(label + ': ');
93 if (list == null) {
94 buf.add('null');
95 buf.add('\n');
96 } else {
97 for (var item in list) {
98 buf.add(item.toString());
99 buf.add(', ');
100 }
101 buf.add('\n');
102 }
103 }
104
105 void writeNodeList(String label, List list) {
106 writeln('${label} [');
107 if (list != null) {
108 depth += 1;
109 for (var node in list) {
110 if (node != null) {
111 node.visit(printer);
112 } else {
113 writeln('null');
114 }
115 }
116 depth -= 1;
117 writeln(']');
118 }
119 }
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698