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

Side by Side Diff: dart/frog/leg/scanner/token.dart

Issue 9447100: Return null from stringValue and call slowToString() instead of toString(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: changes Created 8 years, 10 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 | « dart/frog/leg/scanner/string_scanner.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 final int EOF_TOKEN = 0; 5 final int EOF_TOKEN = 0;
6 6
7 final int KEYWORD_TOKEN = $k; 7 final int KEYWORD_TOKEN = $k;
8 final int IDENTIFIER_TOKEN = $a; 8 final int IDENTIFIER_TOKEN = $a;
9 final int DOUBLE_TOKEN = $d; 9 final int DOUBLE_TOKEN = $d;
10 final int INT_TOKEN = $i; 10 final int INT_TOKEN = $i;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 Token next; 84 Token next;
85 85
86 Token(PrecedenceInfo this.info, int this.charOffset); 86 Token(PrecedenceInfo this.info, int this.charOffset);
87 87
88 get value() => info.value; 88 get value() => info.value;
89 String get stringValue() => info.value.stringValue; 89 String get stringValue() => info.value.stringValue;
90 int get kind() => info.kind; 90 int get kind() => info.kind;
91 int get precedence() => info.precedence; 91 int get precedence() => info.precedence;
92 92
93 String toString() => info.value.toString(); 93 String toString() => info.value.toString();
94
95 String slowToString() => toString();
94 } 96 }
95 97
96 /** 98 /**
97 * A keyword token. 99 * A keyword token.
98 */ 100 */
99 class KeywordToken extends Token { 101 class KeywordToken extends Token {
100 final Keyword value; 102 final Keyword value;
101 String get stringValue() => value.syntax; 103 String get stringValue() => value.syntax;
102 104
103 KeywordToken(Keyword value, int charOffset) 105 KeywordToken(Keyword value, int charOffset)
104 : this.value = value, super(value.info, charOffset); 106 : this.value = value, super(value.info, charOffset);
105 107
106 String toString() => value.syntax; 108 String toString() => value.syntax;
107 } 109 }
108 110
109 /** 111 /**
110 * A String-valued token. 112 * A String-valued token.
111 */ 113 */
112 class StringToken extends Token { 114 class StringToken extends Token {
113 final SourceString value; 115 final SourceString value;
114 String get stringValue() => value.stringValue; 116 String get stringValue() => value.stringValue;
115 117
116 StringToken(PrecedenceInfo info, String value, int charOffset) 118 StringToken(PrecedenceInfo info, String value, int charOffset)
117 : this.fromSource(info, new SourceString(value), charOffset); 119 : this.fromSource(info, new SourceString(value), charOffset);
118 120
119 StringToken.fromSource(PrecedenceInfo info, this.value, int charOffset) 121 StringToken.fromSource(PrecedenceInfo info, this.value, int charOffset)
120 : super(info, charOffset); 122 : super(info, charOffset);
121 123
122 String toString() => value.toString(); 124 String toString() => "StringToken(${value.slowToString()})";
125
126 String slowToString() => value.slowToString();
123 } 127 }
124 128
125 interface SourceString extends Hashable, Iterable<int> default StringWrapper { 129 interface SourceString extends Hashable, Iterable<int> default StringWrapper {
126 const SourceString(String string); 130 const SourceString(String string);
127 131
128 void printOn(StringBuffer sb); 132 void printOn(StringBuffer sb);
129 133
130 /** Gives a [SourceString] that is not including the [initial] first and 134 /** Gives a [SourceString] that is not including the [initial] first and
131 * [terminal] last characters. This is only intended to be used to remove 135 * [terminal] last characters. This is only intended to be used to remove
132 * quotes from string literals (including an initial '@' for raw strings). 136 * quotes from string literals (including an initial '@' for raw strings).
133 */ 137 */
134 SourceString copyWithoutQuotes(int initial, int terminal); 138 SourceString copyWithoutQuotes(int initial, int terminal);
135 139
136 String get stringValue(); 140 String get stringValue();
137 141
138 bool isEmpty(); 142 bool isEmpty();
139 } 143 }
140 144
141 class StringWrapper implements SourceString { 145 class StringWrapper implements SourceString {
142 final String stringValue; 146 final String stringValue;
143 147
144 const StringWrapper(String this.stringValue); 148 const StringWrapper(String this.stringValue);
145 149
146 int hashCode() => stringValue.hashCode(); 150 int hashCode() => stringValue.hashCode();
147 151
148 bool operator ==(other) { 152 bool operator ==(other) {
149 return other is SourceString && toString() == other.toString(); 153 return other is SourceString && toString() == other.slowToString();
150 } 154 }
151 155
152 Iterator<int> iterator() => new StringCodeIterator(stringValue); 156 Iterator<int> iterator() => new StringCodeIterator(stringValue);
153 157
154 void printOn(StringBuffer sb) { 158 void printOn(StringBuffer sb) {
155 sb.add(stringValue); 159 sb.add(stringValue);
156 } 160 }
157 161
158 String toString() => stringValue; 162 String toString() => stringValue;
159 163
164 String slowToString() => stringValue;
165
160 SourceString copyWithoutQuotes(int initial, int terminal) { 166 SourceString copyWithoutQuotes(int initial, int terminal) {
161 assert(0 <= initial); 167 assert(0 <= initial);
162 assert(0 <= terminal); 168 assert(0 <= terminal);
163 assert(initial + terminal <= stringValue.length); 169 assert(initial + terminal <= stringValue.length);
164 return new StringWrapper( 170 return new StringWrapper(
165 stringValue.substring(initial, stringValue.length - terminal)); 171 stringValue.substring(initial, stringValue.length - terminal));
166 } 172 }
167 173
168 bool isEmpty() => stringValue.isEmpty(); 174 bool isEmpty() => stringValue.isEmpty();
169 } 175 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 final PrecedenceInfo STRING_INTERPOLATION_INFO = 399 final PrecedenceInfo STRING_INTERPOLATION_INFO =
394 const PrecedenceInfo(const SourceString('\${'), 0, 400 const PrecedenceInfo(const SourceString('\${'), 0,
395 STRING_INTERPOLATION_TOKEN); 401 STRING_INTERPOLATION_TOKEN);
396 402
397 final PrecedenceInfo HEXADECIMAL_INFO = 403 final PrecedenceInfo HEXADECIMAL_INFO =
398 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN); 404 const PrecedenceInfo(const SourceString('hexadecimal'), 0, HEXADECIMAL_TOKEN);
399 405
400 // For reporting lexical errors. 406 // For reporting lexical errors.
401 final PrecedenceInfo ERROR_INFO = 407 final PrecedenceInfo ERROR_INFO =
402 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN); 408 const PrecedenceInfo(const SourceString('?'), 0, UNKNOWN_TOKEN);
OLDNEW
« no previous file with comments | « dart/frog/leg/scanner/string_scanner.dart ('k') | dart/frog/leg/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698