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

Side by Side Diff: frog/scripts/token_info.py

Issue 10548047: Remove frog from the repository. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move test and update apidoc.gyp. Created 8 years, 6 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
« no previous file with comments | « frog/scripts/from_inputs_to_outputs.py ('k') | frog/scripts/token_kind_gen.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # BSD-style license that can be found in the LICENSE file.
4
5 class Token:
6 def __init__(self, name, text, precedence, customFinishCode=None,
7 stringRepr=None):
8 self.name = name
9 self.text = text
10 self.precedence = precedence
11 self.customFinishCode = customFinishCode
12
13 if stringRepr is None:
14 if self.text:
15 stringRepr = self.text
16 elif self.name is not None:
17 stringRepr = self.name.lower().replace('_', ' ')
18
19 self.stringRepr = stringRepr
20
21 # roughly the user-definable operators
22 EXCLUDES = ['!=', '===', '!==', '&&', '||']
23 INCLUDES = ['[]', '[]=', '~']
24 if text in INCLUDES or (self.precedence >= 6 and text not in EXCLUDES):
25 self.methodName = ':' + name.lower()
26 else:
27 self.methodName = None
28
29 def getFinishCode(self):
30 if self.customFinishCode:
31 return self.customFinishCode
32 else:
33 return '_finishToken(TokenKind.%s)' % self.name
34
35
36 class Keyword:
37 def __init__(self, name, text, isPseudo, precedence=0):
38 self.name = name
39 self.text = text
40 self.isPseudo = isPseudo
41 self.precedence = precedence
42
43 if isPseudo:
44 prefix = 'pseudo-'
45 else:
46 prefix = ''
47
48 self.stringRepr = '%skeyword %r' % (prefix, self.text)
49
50 def __repr__(self):
51 return 'Keyword(%r)' % self.text
52
53
54 tokens = [
55 Token('END_OF_FILE', "", 0),
56
57 Token('LPAREN', "(", 0),
58 Token('RPAREN', ")", 0),
59 Token('LBRACK', "[", 0),
60 Token('RBRACK', "]", 0),
61 Token('LBRACE', "{", 0, '_finishOpenBrace()'),
62 Token('RBRACE', "}", 0, '_finishCloseBrace()'),
63 Token('COLON', ":", 0),
64 Token('ARROW', "=>", 0),
65 Token('SEMICOLON', ";", 0),
66 Token('COMMA', ",", 0),
67 Token('HASH', "#", 0),
68 Token('HASHBANG', "#!", 0, 'finishHashBang()'),
69
70 Token('DOT', ".", 0, 'finishDot()'),
71 Token('ELLIPSIS', "...", 0),
72 Token('INCR', "++", 0),
73 Token('DECR', "--", 0),
74
75 Token('BIT_NOT', "~", 0),
76 Token('NOT', "!", 0),
77
78 # Assignment operators
79 Token('ASSIGN', "=", 2),
80 Token('ASSIGN_OR', "|=", 2),
81 Token('ASSIGN_XOR', "^=", 2),
82 Token('ASSIGN_AND', "&=", 2),
83 Token('ASSIGN_SHL', "<<=", 2),
84 Token('ASSIGN_SAR', ">>=", 2),
85 Token('ASSIGN_SHR', ">>>=", 2),
86 Token('ASSIGN_ADD', "+=", 2),
87 Token('ASSIGN_SUB', "-=", 2),
88 Token('ASSIGN_MUL', "*=", 2),
89 Token('ASSIGN_DIV', "/=", 2),
90 Token('ASSIGN_TRUNCDIV', "~/=", 2),
91 Token('ASSIGN_MOD', "%=", 2),
92
93 Token('CONDITIONAL', "?", 3),
94
95 Token('OR', "||", 4),
96 Token('AND', "&&", 5),
97 Token('BIT_OR', "|", 6),
98 Token('BIT_XOR', "^", 7),
99 Token('BIT_AND', "&", 8),
100
101 # Shift operators
102 Token('SHL', "<<", 11),
103 Token('SAR', ">>", 11),
104 Token('SHR', ">>>", 11),
105
106 # Additive operators
107 Token('ADD', "+", 12),
108 Token('SUB', "-", 12),
109
110 # Multiplicative operators
111 Token('MUL', "*", 13),
112 Token('DIV', "/", 13),
113 Token('TRUNCDIV', "~/", 13),
114 Token('MOD', "%", 13),
115
116 # Equality operators
117 Token('EQ', "==", 9),
118 Token('NE', "!=", 9),
119 Token('EQ_STRICT', "===", 9),
120 Token('NE_STRICT', "!==", 9),
121
122 # Relational operators
123 Token('LT', "<", 10),
124 Token('GT', ">", 10),
125 Token('LTE', "<=", 10),
126 Token('GTE', ">=", 10),
127
128 # Special tokens for index operator methods
129 Token('INDEX', "[]", 0),
130 Token('SETINDEX', "[]=", 0),
131
132
133 Token('STRING', "", 0),
134 Token('STRING_PART', "", 0),
135 Token('INTEGER', "", 0),
136 Token('HEX_INTEGER', "", 0),
137 Token('DOUBLE', "", 0),
138
139 Token('WHITESPACE', "", 0),
140 Token('COMMENT', "", 0),
141 Token('ERROR', "", 0),
142
143 Token('INCOMPLETE_STRING', "", 0),
144 Token('INCOMPLETE_COMMENT', "", 0),
145 Token('INCOMPLETE_MULTILINE_STRING_DQ', "", 0),
146 Token('INCOMPLETE_MULTILINE_STRING_SQ', "", 0),
147
148
149 Token(None, '//', 0, 'finishSingleLineComment()'),
150 Token(None, '/*', 0, 'finishMultiLineComment()'),
151 Token(None, '$"', 0, 'finishString(34/*"*/)'),
152 Token(None, '$\'', 0, 'finishString(39/*\'*/)'),
153 Token(None, '$', 0, 'finishIdentifier(36/*$*/)'),
154 Token(None, '@"', 0, 'finishRawString(34/*"*/)'),
155 Token(None, '@\'', 0, 'finishRawString(39/*\'*/)'),
156 Token(None, '"', 0, 'finishString(34/*"*/)'),
157 Token(None, '\'', 0, 'finishString(39/*\'*/)'),
158 Token(None, '0', 0, 'finishNumber()'),
159 Token(None, '0x', 0, 'finishHex()'),
160 Token(None, '0X', 0, 'finishHex()'),
161
162 Token('IDENTIFIER', "", 0), # must be last
163
164 ]
165
166 # TODO(jimhug): Validate this list with Dart.g and with the lang spec.
167 keywords = [
168 Keyword('ABSTRACT', "abstract", True),
169 Keyword('ASSERT', "assert", True),
170 Keyword('AWAIT', "await", False), # experimental feature
171 Keyword('BREAK', "break", False),
172 Keyword('CALL', "call", True),
173 Keyword('CASE', "case", False),
174 Keyword('CATCH', "catch", False),
175 Keyword('CLASS', "class", False),
176 Keyword('CONST', "const", False),
177 Keyword('CONTINUE', "continue", False),
178 Keyword('DEFAULT', "default", False),
179 Keyword('DO', "do", False),
180 Keyword('ELSE', "else", False),
181 Keyword('EXTENDS', "extends", False),
182 Keyword('FACTORY', "factory", True),
183 Keyword('FALSE', "false", False),
184 Keyword('FINAL', "final", False),
185 Keyword('FINALLY', "finally", False),
186 Keyword('FOR', "for", False),
187 Keyword('GET', "get", True),
188 Keyword('IF', "if", False),
189 Keyword('IMPLEMENTS', "implements", True),
190 Keyword('IMPORT', "import", True),
191 Keyword('IN', "in", False),
192 Keyword('INTERFACE', "interface", True),
193 Keyword('IS', "is", False, 10),
194 Keyword('LIBRARY', "library", True),
195 Keyword('NATIVE', "native", True),
196 Keyword('NEGATE', "negate", True),
197 Keyword('NEW', "new", False),
198 Keyword('NULL', "null", False),
199 Keyword('OPERATOR', "operator", True),
200 Keyword('RETURN', "return", False),
201 Keyword('SET', "set", True),
202 Keyword('SOURCE', "source", True),
203 Keyword('STATIC', "static", True),
204 Keyword('SUPER', "super", False),
205 Keyword('SWITCH', "switch", False),
206 Keyword('THIS', "this", False),
207 Keyword('THROW', "throw", False),
208 Keyword('TRUE', "true", False),
209 Keyword('TYPEDEF', "typedef", True),
210 Keyword('TRY', "try", False),
211 Keyword('VAR', "var", False),
212 Keyword('VOID', "void", False),
213 Keyword('WHILE', "while", False)]
OLDNEW
« no previous file with comments | « frog/scripts/from_inputs_to_outputs.py ('k') | frog/scripts/token_kind_gen.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698