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

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

Issue 8585044: Fixes issues in string interpolation tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove debugging code Created 9 years, 1 month 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 '''Generates the Tokenizer class into tokenenizer.g.dart.''' 6 '''Generates the Tokenizer class into tokenenizer.g.dart.'''
7 7
8 import re 8 import re
9 from token_info import tokens, keywords 9 from token_info import tokens, keywords
10 from codegen import CodeWriter, HEADER 10 from codegen import CodeWriter, HEADER
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if self.includeWhitespace: 63 if self.includeWhitespace:
64 self.writeWhitespace(cw) 64 self.writeWhitespace(cw)
65 for key, case in sorted(self.cases.items()): 65 for key, case in sorted(self.cases.items()):
66 cw.enterBlock('case %s:' % makeSafe(key)) 66 cw.enterBlock('case %s:' % makeSafe(key))
67 67
68 case.writeCases(cw) 68 case.writeCases(cw)
69 cw.exitBlock() 69 cw.exitBlock()
70 if self.includeWhitespace: 70 if self.includeWhitespace:
71 cw.enterBlock('default:') 71 cw.enterBlock('default:')
72 cw.enterBlock('if (isIdentifierStart(ch)) {') 72 cw.enterBlock('if (isIdentifierStart(ch)) {')
73 cw.writeln('return this.finishIdentifier();') 73 cw.writeln('return this.finishIdentifier(ch);')
74 cw.exitBlock('} else if (isDigit(ch)) {') 74 cw.exitBlock('} else if (isDigit(ch)) {')
75 cw.enterBlock() 75 cw.enterBlock()
76 cw.writeln('return this.finishNumber();') 76 cw.writeln('return this.finishNumber();')
77 cw.exitBlock('} else {') 77 cw.exitBlock('} else {')
78 cw.enterBlock() 78 cw.enterBlock()
79 cw.writeln(self.defaultReturn()) 79 cw.writeln(self.defaultReturn())
80 cw.exitBlock('}') 80 cw.exitBlock('}')
81 else: 81 else:
82 cw.writeln('default: ' + self.defaultReturn()) 82 cw.writeln('default: ' + self.defaultReturn())
83 cw.exitBlock('}') 83 cw.exitBlock('}')
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 cw.enterBlock() 237 cw.enterBlock()
238 cw.writeln() 238 cw.writeln()
239 writeClass(cw, 'IdentifierStart', OrTest( 239 writeClass(cw, 'IdentifierStart', OrTest(
240 CharTest('a', 'z'), CharTest('A', 'Z'), CharTest('_'))) #TODO: CharTest('$') 240 CharTest('a', 'z'), CharTest('A', 'Z'), CharTest('_'))) #TODO: CharTest('$')
241 writeClass(cw, 'Digit', CharTest('0', '9')) 241 writeClass(cw, 'Digit', CharTest('0', '9'))
242 writeClass(cw, 'HexDigit', OrTest( 242 writeClass(cw, 'HexDigit', OrTest(
243 ExplicitTest('isDigit(c)'), CharTest('a', 'f'), CharTest('A', 'F'))) 243 ExplicitTest('isDigit(c)'), CharTest('a', 'f'), CharTest('A', 'F')))
244 writeClass(cw, 'Whitespace', OrTest( 244 writeClass(cw, 'Whitespace', OrTest(
245 CharTest(' '), CharTest('\t'), CharTest('\n'), CharTest('\r'))) 245 CharTest(' '), CharTest('\t'), CharTest('\n'), CharTest('\r')))
246 writeClass(cw, 'IdentifierPart', OrTest( 246 writeClass(cw, 'IdentifierPart', OrTest(
247 ExplicitTest('isIdentifierStart(c)'), ExplicitTest('isDigit(c)'))) 247 ExplicitTest('isIdentifierStart(c)'),
248 ExplicitTest('isDigit(c)'),
249 CharTest('$')))
250 # This is like IdentifierPart, but without $
251 writeClass(cw, 'InterpIdentifierPart', OrTest(
252 ExplicitTest('isIdentifierStart(c)'),
253 ExplicitTest('isDigit(c)')))
248 254
249 def writeExtraMethods(cw): 255 def writeExtraMethods(cw):
250 lengths = {} 256 lengths = {}
251 for kw in keywords: 257 for kw in keywords:
252 l = len(kw.text) 258 l = len(kw.text)
253 if not lengths.has_key(l): 259 if not lengths.has_key(l):
254 lengths[l] = LengthGroup(l) 260 lengths[l] = LengthGroup(l)
255 lengths[l].add(kw) 261 lengths[l].add(kw)
256 262
257 # TODO(jimhug): Consider merging this with the finishIdentifier code. 263 # TODO(jimhug): Consider merging this with the finishIdentifier code.
(...skipping 29 matching lines...) Expand all
287 pat = re.compile('@(.)', re.DOTALL) 293 pat = re.compile('@(.)', re.DOTALL)
288 text = pat.sub(makeSafe1, TOKENIZER) 294 text = pat.sub(makeSafe1, TOKENIZER)
289 out.write(text % { 295 out.write(text % {
290 'cases': casesCode, 296 'cases': casesCode,
291 'extraMethods': extraMethods, 297 'extraMethods': extraMethods,
292 'helperMethods': helperMethods }) 298 'helperMethods': helperMethods })
293 out.close() 299 out.close()
294 300
295 301
296 if __name__ == '__main__': main() 302 if __name__ == '__main__': main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698