| 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 /** | 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 SET, | 103 SET, |
| 104 SOURCE, | 104 SOURCE, |
| 105 STATIC, | 105 STATIC, |
| 106 TYPEDEF ]; | 106 TYPEDEF ]; |
| 107 | 107 |
| 108 final String syntax; | 108 final String syntax; |
| 109 final bool isPseudo; | 109 final bool isPseudo; |
| 110 final PrecedenceInfo info; | 110 final PrecedenceInfo info; |
| 111 | 111 |
| 112 static Map<String, Keyword> _keywords; | 112 static Map<String, Keyword> _keywords; |
| 113 static Map<String, Keyword> get keywords() { | 113 static Map<String, Keyword> get keywords { |
| 114 if (_keywords === null) { | 114 if (_keywords === null) { |
| 115 _keywords = computeKeywordMap(); | 115 _keywords = computeKeywordMap(); |
| 116 } | 116 } |
| 117 return _keywords; | 117 return _keywords; |
| 118 } | 118 } |
| 119 | 119 |
| 120 const Keyword(String this.syntax, | 120 const Keyword(String this.syntax, |
| 121 [bool this.isPseudo = false, | 121 [bool this.isPseudo = false, |
| 122 PrecedenceInfo this.info = KEYWORD_INFO]); | 122 PrecedenceInfo this.info = KEYWORD_INFO]); |
| 123 | 123 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 Iterator<int> iterator() => new StringCodeIterator(syntax); | 138 Iterator<int> iterator() => new StringCodeIterator(syntax); |
| 139 | 139 |
| 140 void printOn(StringBuffer sb) { | 140 void printOn(StringBuffer sb) { |
| 141 sb.add(syntax); | 141 sb.add(syntax); |
| 142 } | 142 } |
| 143 | 143 |
| 144 String toString() => syntax; | 144 String toString() => syntax; |
| 145 String slowToString() => syntax; | 145 String slowToString() => syntax; |
| 146 String get stringValue() => syntax; | 146 String get stringValue => syntax; |
| 147 | 147 |
| 148 SourceString copyWithoutQuotes(int initial, int terminal) { | 148 SourceString copyWithoutQuotes(int initial, int terminal) { |
| 149 // TODO(lrn): consider remodelling to avoid having this method in keywords. | 149 // TODO(lrn): consider remodelling to avoid having this method in keywords. |
| 150 return this; | 150 return this; |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool isEmpty() => false; | 153 bool isEmpty() => false; |
| 154 bool isPrivate() => false; | 154 bool isPrivate() => false; |
| 155 } | 155 } |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * Abstract state in a state machine for scanning keywords. | 158 * Abstract state in a state machine for scanning keywords. |
| 159 */ | 159 */ |
| 160 class KeywordState { | 160 class KeywordState { |
| 161 abstract bool isLeaf(); | 161 abstract bool isLeaf(); |
| 162 abstract KeywordState next(int c); | 162 abstract KeywordState next(int c); |
| 163 abstract Keyword get keyword(); | 163 abstract Keyword get keyword(); |
| 164 | 164 |
| 165 static KeywordState _KEYWORD_STATE; | 165 static KeywordState _KEYWORD_STATE; |
| 166 static KeywordState get KEYWORD_STATE() { | 166 static KeywordState get KEYWORD_STATE { |
| 167 if (_KEYWORD_STATE === null) { | 167 if (_KEYWORD_STATE === null) { |
| 168 List<String> strings = new List<String>(Keyword.values.length); | 168 List<String> strings = new List<String>(Keyword.values.length); |
| 169 for (int i = 0; i < Keyword.values.length; i++) { | 169 for (int i = 0; i < Keyword.values.length; i++) { |
| 170 strings[i] = Keyword.values[i].syntax; | 170 strings[i] = Keyword.values[i].syntax; |
| 171 } | 171 } |
| 172 strings.sort((a,b) => a.compareTo(b)); | 172 strings.sort((a,b) => a.compareTo(b)); |
| 173 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length); | 173 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length); |
| 174 } | 174 } |
| 175 return _KEYWORD_STATE; | 175 return _KEYWORD_STATE; |
| 176 } | 176 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 final Keyword keyword; | 257 final Keyword keyword; |
| 258 | 258 |
| 259 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; | 259 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; |
| 260 | 260 |
| 261 bool isLeaf() => true; | 261 bool isLeaf() => true; |
| 262 | 262 |
| 263 KeywordState next(int c) => null; | 263 KeywordState next(int c) => null; |
| 264 | 264 |
| 265 String toString() => keyword.syntax; | 265 String toString() => keyword.syntax; |
| 266 } | 266 } |
| OLD | NEW |