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

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

Issue 10917170: Improve handling of built-in identifiers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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 /** 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 const Keyword BREAK = const Keyword("break"); 9 static const List<Keyword> values = const <Keyword> [
10 static const Keyword CASE = const Keyword("case"); 10 const Keyword("break"),
11 static const Keyword CATCH = const Keyword("catch"); 11 const Keyword("case"),
12 static const Keyword CLASS = const Keyword("class"); 12 const Keyword("catch"),
13 static const Keyword CONST = const Keyword("const"); 13 const Keyword("class"),
14 static const Keyword CONTINUE = const Keyword("continue"); 14 const Keyword("const"),
15 static const Keyword DEFAULT = const Keyword("default"); 15 const Keyword("continue"),
16 static const Keyword DO = const Keyword("do"); 16 const Keyword("default"),
17 static const Keyword ELSE = const Keyword("else"); 17 const Keyword("do"),
18 static const Keyword EXTENDS = const Keyword("extends"); 18 const Keyword("else"),
19 static const Keyword FALSE = const Keyword("false"); 19 const Keyword("extends"),
20 static const Keyword FINAL = const Keyword("final"); 20 const Keyword("false"),
21 static const Keyword FINALLY = const Keyword("finally"); 21 const Keyword("final"),
22 static const Keyword FOR = const Keyword("for"); 22 const Keyword("finally"),
23 static const Keyword IF = const Keyword("if"); 23 const Keyword("for"),
24 static const Keyword IN = const Keyword("in"); 24 const Keyword("if"),
25 static const Keyword IS = const Keyword("is", info: IS_INFO); 25 const Keyword("in"),
26 static const Keyword NEW = const Keyword("new"); 26 const Keyword("is", info: IS_INFO),
27 static const Keyword NULL = const Keyword("null"); 27 const Keyword("new"),
28 static const Keyword RETURN = const Keyword("return"); 28 const Keyword("null"),
29 static const Keyword SUPER = const Keyword("super"); 29 const Keyword("return"),
30 static const Keyword SWITCH = const Keyword("switch"); 30 const Keyword("super"),
31 static const Keyword THIS = const Keyword("this"); 31 const Keyword("switch"),
32 static const Keyword THROW = const Keyword("throw"); 32 const Keyword("this"),
33 static const Keyword TRUE = const Keyword("true"); 33 const Keyword("throw"),
34 static const Keyword TRY = const Keyword("try"); 34 const Keyword("true"),
35 static const Keyword VAR = const Keyword("var"); 35 const Keyword("try"),
36 static const Keyword VOID = const Keyword("void"); 36 const Keyword("var"),
37 static const Keyword WHILE = const Keyword("while"); 37 const Keyword("void"),
38 const Keyword("while"),
38 39
39 // Pseudo keywords: 40 const Keyword("abstract", isBuiltIn: true),
40 static const Keyword ABSTRACT = const Keyword("abstract", isPseudo: true); 41 const Keyword("as", info: AS_INFO, isBuiltIn: true),
41 static const Keyword AS = const Keyword("as", info: AS_INFO, isPseudo: true); 42 const Keyword("assert", isBuiltIn: true),
42 static const Keyword ASSERT = const Keyword("assert", isPseudo: true); 43 const Keyword("external", isBuiltIn: true),
43 static const Keyword EXTERNAL = const Keyword("external", isPseudo: true); 44 const Keyword("factory", isBuiltIn: true),
44 static const Keyword FACTORY = const Keyword("factory", isPseudo: true); 45 const Keyword("get", isBuiltIn: true),
45 static const Keyword GET = const Keyword("get", isPseudo: true); 46 const Keyword("implements", isBuiltIn: true),
46 static const Keyword IMPLEMENTS = const Keyword("implements", isPseudo: true); 47 const Keyword("interface", isBuiltIn: true),
47 static const Keyword IMPORT = const Keyword("import", isPseudo: true); 48 const Keyword("operator", isBuiltIn: true),
48 static const Keyword INTERFACE = const Keyword("interface", isPseudo: true); 49 const Keyword("set", isBuiltIn: true),
49 static const Keyword LIBRARY = const Keyword("library", isPseudo: true); 50 const Keyword("static", isBuiltIn: true),
50 static const Keyword NATIVE = const Keyword("native", isPseudo: true); 51 const Keyword("typedef", isBuiltIn: true),
51 static const Keyword OPERATOR = const Keyword("operator", isPseudo: true);
52 static const Keyword ON = const Keyword("on", isPseudo: true);
53 static const Keyword SET = const Keyword("set", isPseudo: true);
54 static const Keyword SOURCE = const Keyword("source", isPseudo: true);
55 static const Keyword STATIC = const Keyword("static", isPseudo: true);
56 static const Keyword TYPEDEF = const Keyword("typedef", isPseudo: true);
57 52
58 static const List<Keyword> values = const <Keyword> [ 53 const Keyword("hide", isPseudo: true),
59 AS, 54 const Keyword("import", isPseudo: true),
60 BREAK, 55 const Keyword("library", isPseudo: true),
61 CASE, 56 const Keyword("native", isPseudo: true),
62 CATCH, 57 const Keyword("on", isPseudo: true),
63 CONST, 58 const Keyword("part", isPseudo: true),
64 CONTINUE, 59 const Keyword("show", isPseudo: true),
65 DEFAULT, 60 const Keyword("source", isPseudo: true) ];
66 DO, 61
67 ELSE, 62 static const DYNAMIC = const Keyword("Dynamic", isBuiltIn: true);
68 FALSE,
69 FINAL,
70 FINALLY,
71 FOR,
72 IF,
73 IN,
74 IS,
75 NEW,
76 NULL,
77 RETURN,
78 SUPER,
79 SWITCH,
80 THIS,
81 THROW,
82 TRUE,
83 TRY,
84 VAR,
85 VOID,
86 WHILE,
87 ABSTRACT,
88 ASSERT,
89 CLASS,
90 EXTENDS,
91 EXTERNAL,
92 FACTORY,
93 GET,
94 IMPLEMENTS,
95 IMPORT,
96 INTERFACE,
97 LIBRARY,
98 NATIVE,
99 OPERATOR,
100 ON,
101 SET,
102 SOURCE,
103 STATIC,
104 TYPEDEF ];
105 63
106 final String syntax; 64 final String syntax;
107 final bool isPseudo; 65 final bool isPseudo;
66 final bool isBuiltIn;
108 final PrecedenceInfo info; 67 final PrecedenceInfo info;
109 68
110 static Map<String, Keyword> _keywords; 69 static Map<String, Keyword> _keywords;
111 static Map<String, Keyword> get keywords { 70 static Map<String, Keyword> get keywords {
112 if (_keywords === null) { 71 if (_keywords === null) {
113 _keywords = computeKeywordMap(); 72 _keywords = computeKeywordMap();
114 } 73 }
115 return _keywords; 74 return _keywords;
116 } 75 }
117 76
118 const Keyword(String this.syntax, 77 const Keyword(String this.syntax,
119 [bool this.isPseudo = false, 78 [bool this.isPseudo = false,
79 bool this.isBuiltIn = false,
120 PrecedenceInfo this.info = KEYWORD_INFO]); 80 PrecedenceInfo this.info = KEYWORD_INFO]);
121 81
122 static Map<String, Keyword> computeKeywordMap() { 82 static Map<String, Keyword> computeKeywordMap() {
123 Map<String, Keyword> result = new LinkedHashMap<String, Keyword>(); 83 Map<String, Keyword> result = new LinkedHashMap<String, Keyword>();
124 for (Keyword keyword in values) { 84 for (Keyword keyword in values) {
125 result[keyword.syntax] = keyword; 85 result[keyword.syntax] = keyword;
126 } 86 }
127 return result; 87 return result;
128 } 88 }
129 89
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 final Keyword keyword; 215 final Keyword keyword;
256 216
257 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax]; 217 LeafKeywordState(String syntax) : keyword = Keyword.keywords[syntax];
258 218
259 bool isLeaf() => true; 219 bool isLeaf() => true;
260 220
261 KeywordState next(int c) => null; 221 KeywordState next(int c) => null;
262 222
263 String toString() => keyword.syntax; 223 String toString() => keyword.syntax;
264 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698