| OLD | NEW |
| 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A keyword in the Dart programming language. | 8 * A keyword in the Dart programming language. |
| 9 */ | 9 */ |
| 10 class Keyword { | 10 class Keyword { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 String toString() => syntax; | 97 String toString() => syntax; |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Abstract state in a state machine for scanning keywords. | 101 * Abstract state in a state machine for scanning keywords. |
| 102 */ | 102 */ |
| 103 abstract class KeywordState { | 103 abstract class KeywordState { |
| 104 KeywordState(this.keyword); | 104 KeywordState(this.keyword); |
| 105 | 105 |
| 106 bool isLeaf(); | |
| 107 KeywordState next(int c); | 106 KeywordState next(int c); |
| 108 final Keyword keyword; | 107 final Keyword keyword; |
| 109 | 108 |
| 110 static KeywordState _KEYWORD_STATE; | 109 static KeywordState _KEYWORD_STATE; |
| 111 static KeywordState get KEYWORD_STATE { | 110 static KeywordState get KEYWORD_STATE { |
| 112 if (_KEYWORD_STATE == null) { | 111 if (_KEYWORD_STATE == null) { |
| 113 List<String> strings = | 112 List<String> strings = |
| 114 new List<String>(Keyword.values.length); | 113 new List<String>(Keyword.values.length); |
| 115 for (int i = 0; i < Keyword.values.length; i++) { | 114 for (int i = 0; i < Keyword.values.length; i++) { |
| 116 strings[i] = Keyword.values[i].syntax; | 115 strings[i] = Keyword.values[i].syntax; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 164 |
| 166 /** | 165 /** |
| 167 * A state with multiple outgoing transitions. | 166 * A state with multiple outgoing transitions. |
| 168 */ | 167 */ |
| 169 class ArrayKeywordState extends KeywordState { | 168 class ArrayKeywordState extends KeywordState { |
| 170 final List<KeywordState> table; | 169 final List<KeywordState> table; |
| 171 | 170 |
| 172 ArrayKeywordState(List<KeywordState> this.table, String syntax) | 171 ArrayKeywordState(List<KeywordState> this.table, String syntax) |
| 173 : super((syntax == null) ? null : Keyword.keywords[syntax]); | 172 : super((syntax == null) ? null : Keyword.keywords[syntax]); |
| 174 | 173 |
| 175 bool isLeaf() => false; | |
| 176 | |
| 177 KeywordState next(int c) => table[c - $a]; | 174 KeywordState next(int c) => table[c - $a]; |
| 178 | 175 |
| 179 String toString() { | 176 String toString() { |
| 180 StringBuffer sb = new StringBuffer(); | 177 StringBuffer sb = new StringBuffer(); |
| 181 sb.write("["); | 178 sb.write("["); |
| 182 if (keyword != null) { | 179 if (keyword != null) { |
| 183 sb.write("*"); | 180 sb.write("*"); |
| 184 sb.write(keyword); | 181 sb.write(keyword); |
| 185 sb.write(" "); | 182 sb.write(" "); |
| 186 } | 183 } |
| 187 List<KeywordState> foo = table; | 184 List<KeywordState> foo = table; |
| 188 for (int i = 0; i < foo.length; i++) { | 185 for (int i = 0; i < foo.length; i++) { |
| 189 if (foo[i] != null) { | 186 if (foo[i] != null) { |
| 190 sb.write("${new String.fromCharCodes([i + $a])}: ${foo[i]}; "); | 187 sb.write("${new String.fromCharCodes([i + $a])}: ${foo[i]}; "); |
| 191 } | 188 } |
| 192 } | 189 } |
| 193 sb.write("]"); | 190 sb.write("]"); |
| 194 return sb.toString(); | 191 return sb.toString(); |
| 195 } | 192 } |
| 196 } | 193 } |
| 197 | 194 |
| 198 /** | 195 /** |
| 199 * A state that has no outgoing transitions. | 196 * A state that has no outgoing transitions. |
| 200 */ | 197 */ |
| 201 class LeafKeywordState extends KeywordState { | 198 class LeafKeywordState extends KeywordState { |
| 202 LeafKeywordState(String syntax) : super(Keyword.keywords[syntax]); | 199 LeafKeywordState(String syntax) : super(Keyword.keywords[syntax]); |
| 203 | 200 |
| 204 bool isLeaf() => true; | |
| 205 | |
| 206 KeywordState next(int c) => null; | 201 KeywordState next(int c) => null; |
| 207 | 202 |
| 208 String toString() => keyword.syntax; | 203 String toString() => keyword.syntax; |
| 209 } | 204 } |
| OLD | NEW |