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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/scanner/keyword.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
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 implements SourceString { 10 class Keyword extends Iterable<int> implements SourceString {
11 static const List<Keyword> values = const <Keyword> [ 11 static const List<Keyword> values = const <Keyword> [
12 const Keyword("assert"), 12 const Keyword("assert"),
13 const Keyword("break"), 13 const Keyword("break"),
14 const Keyword("case"), 14 const Keyword("case"),
15 const Keyword("catch"), 15 const Keyword("catch"),
16 const Keyword("class"), 16 const Keyword("class"),
17 const Keyword("const"), 17 const Keyword("const"),
18 const Keyword("continue"), 18 const Keyword("continue"),
19 const Keyword("default"), 19 const Keyword("default"),
20 const Keyword("do"), 20 const Keyword("do"),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 return result; 96 return result;
97 } 97 }
98 98
99 int get hashCode => syntax.hashCode; 99 int get hashCode => syntax.hashCode;
100 100
101 bool operator ==(other) { 101 bool operator ==(other) {
102 return other is SourceString && toString() == other.slowToString(); 102 return other is SourceString && toString() == other.slowToString();
103 } 103 }
104 104
105 Iterator<int> iterator() => new StringCodeIterator(syntax); 105 Iterator<int> get iterator => new StringCodeIterator(syntax);
106 106
107 void printOn(StringBuffer sb) { 107 void printOn(StringBuffer sb) {
108 sb.add(syntax); 108 sb.add(syntax);
109 } 109 }
110 110
111 String toString() => syntax; 111 String toString() => syntax;
112 String slowToString() => syntax; 112 String slowToString() => syntax;
113 String get stringValue => syntax; 113 String get stringValue => syntax;
114 114
115 SourceString copyWithoutQuotes(int initial, int terminal) { 115 SourceString copyWithoutQuotes(int initial, int terminal) {
116 // TODO(lrn): consider remodelling to avoid having this method in keywords. 116 // TODO(lrn): consider remodelling to avoid having this method in keywords.
117 return this; 117 return this;
118 } 118 }
119 119
120 bool get isEmpty => false; 120 bool get isEmpty => false;
121 bool isPrivate() => false; 121 bool isPrivate() => false;
122 } 122 }
123 123
124 /** 124 /**
125 * Abstract state in a state machine for scanning keywords. 125 * Abstract state in a state machine for scanning keywords.
126 */ 126 */
127 abstract class KeywordState { 127 abstract class KeywordState {
128 bool isLeaf(); 128 bool isLeaf();
129 KeywordState next(int c); 129 KeywordState next(int c);
130 Keyword get keyword; 130 Keyword get keyword;
131 131
132 static KeywordState _KEYWORD_STATE; 132 static KeywordState _KEYWORD_STATE;
133 static KeywordState get KEYWORD_STATE { 133 static KeywordState get KEYWORD_STATE {
134 if (_KEYWORD_STATE == null) { 134 if (_KEYWORD_STATE == null) {
135 List<String> strings = new List<String>(Keyword.values.length); 135 List<String> strings =
136 new List<String>.fixedLength(Keyword.values.length);
136 for (int i = 0; i < Keyword.values.length; i++) { 137 for (int i = 0; i < Keyword.values.length; i++) {
137 strings[i] = Keyword.values[i].syntax; 138 strings[i] = Keyword.values[i].syntax;
138 } 139 }
139 strings.sort((a,b) => a.compareTo(b)); 140 strings.sort((a,b) => a.compareTo(b));
140 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length); 141 _KEYWORD_STATE = computeKeywordStateTable(0, strings, 0, strings.length);
141 } 142 }
142 return _KEYWORD_STATE; 143 return _KEYWORD_STATE;
143 } 144 }
144 145
145 static KeywordState computeKeywordStateTable(int start, List<String> strings, 146 static KeywordState computeKeywordStateTable(int start, List<String> strings,
146 int offset, int length) { 147 int offset, int length) {
147 List<KeywordState> result = new List<KeywordState>(26); 148 List<KeywordState> result = new List<KeywordState>.fixedLength(26);
148 assert(length != 0); 149 assert(length != 0);
149 int chunk = 0; 150 int chunk = 0;
150 int chunkStart = -1; 151 int chunkStart = -1;
151 bool isLeaf = false; 152 bool isLeaf = false;
152 for (int i = offset; i < offset + length; i++) { 153 for (int i = offset; i < offset + length; i++) {
153 if (strings[i].length == start) { 154 if (strings[i].length == start) {
154 isLeaf = true; 155 isLeaf = true;
155 } 156 }
156 if (strings[i].length > start) { 157 if (strings[i].length > start) {
157 int c = strings[i].charCodeAt(start); 158 int c = strings[i].charCodeAt(start);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 final Keyword keyword; 225 final Keyword keyword;
225 226
226 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; 227 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax];
227 228
228 bool isLeaf() => true; 229 bool isLeaf() => true;
229 230
230 KeywordState next(int c) => null; 231 KeywordState next(int c) => null;
231 232
232 String toString() => keyword.syntax; 233 String toString() => keyword.syntax;
233 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698