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

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

Issue 8805008: Various scanner fixes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased and update language.status Created 9 years 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/characters.dart ('k') | dart/frog/leg/scanner/scanner.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 /** 5 /**
6 * A keyword in the Dart programming language. 6 * A keyword in the Dart programming language.
7 */ 7 */
8 class Keyword implements SourceString { 8 class Keyword implements SourceString {
9 static final Keyword BREAK = const Keyword("break"); 9 static final Keyword BREAK = const Keyword("break");
10 static final Keyword CASE = const Keyword("case"); 10 static final Keyword CASE = const Keyword("case");
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 154 }
155 return _KEYWORD_STATE; 155 return _KEYWORD_STATE;
156 } 156 }
157 157
158 static KeywordState computeKeywordStateTable(int start, List<String> strings, 158 static KeywordState computeKeywordStateTable(int start, List<String> strings,
159 int offset, int length) { 159 int offset, int length) {
160 List<KeywordState> result = new List<KeywordState>(26); 160 List<KeywordState> result = new List<KeywordState>(26);
161 assert(length != 0); 161 assert(length != 0);
162 int chunk = 0; 162 int chunk = 0;
163 int chunkStart = -1; 163 int chunkStart = -1;
164 bool isLeaf = false;
164 for (int i = offset; i < offset + length; i++) { 165 for (int i = offset; i < offset + length; i++) {
166 if (strings[i].length == start) {
167 isLeaf = true;
168 }
165 if (strings[i].length > start) { 169 if (strings[i].length > start) {
166 int c = strings[i].charCodeAt(start); 170 int c = strings[i].charCodeAt(start);
167 if (chunk != c) { 171 if (chunk != c) {
168 if (chunkStart != -1) { 172 if (chunkStart != -1) {
173 assert(result[chunk - $a] === null);
169 result[chunk - $a] = computeKeywordStateTable(start + 1, strings, 174 result[chunk - $a] = computeKeywordStateTable(start + 1, strings,
170 chunkStart, 175 chunkStart,
171 i - chunkStart); 176 i - chunkStart);
172 } 177 }
173 chunkStart = i; 178 chunkStart = i;
174 chunk = c; 179 chunk = c;
175 } 180 }
176 } 181 }
177 } 182 }
178 if (chunkStart != -1) { 183 if (chunkStart != -1) {
184 assert(result[chunk - $a] === null);
179 result[chunk - $a] = 185 result[chunk - $a] =
180 computeKeywordStateTable(start + 1, strings, chunkStart, 186 computeKeywordStateTable(start + 1, strings, chunkStart,
181 offset + length - chunkStart); 187 offset + length - chunkStart);
182 } else { 188 } else {
183 assert(length == 1); 189 assert(length == 1);
184 return new LeafKeywordState(strings[offset]); 190 return new LeafKeywordState(strings[offset]);
185 } 191 }
186 return new ArrayKeywordState(result); 192 if (isLeaf) {
193 return new ArrayKeywordState(result, strings[offset]);
194 } else {
195 return new ArrayKeywordState(result, null);
196 }
187 } 197 }
188 } 198 }
189 199
190 /** 200 /**
191 * A state with multiple outgoing transitions. 201 * A state with multiple outgoing transitions.
192 */ 202 */
193 class ArrayKeywordState extends KeywordState { 203 class ArrayKeywordState extends KeywordState {
194 final List<KeywordState> table; 204 final List<KeywordState> table;
205 final Keyword keyword;
195 206
196 ArrayKeywordState(List<KeywordState> this.table); 207 ArrayKeywordState(List<KeywordState> this.table, String syntax)
208 : keyword = (syntax === null) ? null : Keyword.keywords[syntax];
197 209
198 bool isLeaf() => false; 210 bool isLeaf() => false;
199 211
200 KeywordState next(int c) => table[c - $a]; 212 KeywordState next(int c) => table[c - $a];
201 213
202 Keyword get keyword() {
203 throw "should not be called";
204 }
205
206 String toString() { 214 String toString() {
207 StringBuffer sb = new StringBuffer(); 215 StringBuffer sb = new StringBuffer();
208 sb.add("["); 216 sb.add("[");
217 if (keyword !== null) {
218 sb.add("*");
219 sb.add(keyword);
220 sb.add(" ");
221 }
209 List<KeywordState> foo = table; 222 List<KeywordState> foo = table;
210 for (int i = 0; i < foo.length; i++) { 223 for (int i = 0; i < foo.length; i++) {
211 if (foo[i] != null) { 224 if (foo[i] != null) {
212 sb.add("${i + $a}: ${foo[i]}; "); 225 sb.add("${new String.fromCharCodes([i + $a])}: ${foo[i]}; ");
213 } 226 }
214 } 227 }
215 sb.add("]"); 228 sb.add("]");
216 return sb.toString(); 229 return sb.toString();
217 } 230 }
218 } 231 }
219 232
220 /** 233 /**
221 * A state that has no outgoing transitions. 234 * A state that has no outgoing transitions.
222 */ 235 */
223 class LeafKeywordState extends KeywordState { 236 class LeafKeywordState extends KeywordState {
224 Keyword keyword; 237 final Keyword keyword;
225 238
226 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; 239 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax];
227 240
228 bool isLeaf() => true; 241 bool isLeaf() => true;
229 242
230 KeywordState next(int c) => null; 243 KeywordState next(int c) => null;
231 244
232 String toString() => keyword.syntax; 245 String toString() => keyword.syntax;
233 } 246 }
OLDNEW
« no previous file with comments | « dart/frog/leg/scanner/characters.dart ('k') | dart/frog/leg/scanner/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698