Changeset 391 for python/trunk/Lib/tokenize.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/tokenize.py
r2 r391 24 24 25 25 __author__ = 'Ka-Ping Yee <ping@lfw.org>' 26 __credits__ = \27 'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger'26 __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' 27 'Skip Montanaro, Raymond Hettinger') 28 28 29 29 import string, re … … 31 31 32 32 import token 33 __all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize",34 33 __all__ = [x for x in dir(token) if not x.startswith("_")] 34 __all__ += ["COMMENT", "tokenize", "generate_tokens", "NL", "untokenize"] 35 35 del x 36 36 del token … … 71 71 # Tail end of """ string. 72 72 Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""' 73 Triple = group("[uU ]?[rR]?'''", '[uU]?[rR]?"""')73 Triple = group("[uUbB]?[rR]?'''", '[uUbB]?[rR]?"""') 74 74 # Single-line ' or " string. 75 String = group(r"[uU ]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",76 r'[uU ]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"')75 String = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'", 76 r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"') 77 77 78 78 # Because of leftmost-then-longest match semantics, be sure to put the … … 92 92 93 93 # First (or only) line of ' or " string. 94 ContStr = group(r"[uU ]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +94 ContStr = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" + 95 95 group("'", r'\\\r?\n'), 96 r'[uU ]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +96 r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' + 97 97 group('"', r'\\\r?\n')) 98 PseudoExtras = group(r'\\\r?\n ', Comment, Triple)98 PseudoExtras = group(r'\\\r?\n|\Z', Comment, Triple) 99 99 PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name) 100 100 … … 289 289 except StopIteration: 290 290 line = '' 291 lnum = lnum +1291 lnum += 1 292 292 pos, max = 0, len(line) 293 293 … … 317 317 column = 0 318 318 while pos < max: # measure leading whitespace 319 if line[pos] == ' ': column = column + 1 320 elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize 321 elif line[pos] == '\f': column = 0 322 else: break 323 pos = pos + 1 324 if pos == max: break 319 if line[pos] == ' ': 320 column += 1 321 elif line[pos] == '\t': 322 column = (column//tabsize + 1)*tabsize 323 elif line[pos] == '\f': 324 column = 0 325 else: 326 break 327 pos += 1 328 if pos == max: 329 break 325 330 326 331 if line[pos] in '#\r\n': # skip comments or blank lines … … 358 363 start, end = pseudomatch.span(1) 359 364 spos, epos, pos = (lnum, start), (lnum, end), end 365 if start == end: 366 continue 360 367 token, initial = line[start:end], line[start] 361 368 … … 398 405 continued = 1 399 406 else: 400 if initial in '([{': parenlev = parenlev + 1 401 elif initial in ')]}': parenlev = parenlev - 1 407 if initial in '([{': 408 parenlev += 1 409 elif initial in ')]}': 410 parenlev -= 1 402 411 yield (OP, token, spos, epos, line) 403 412 else: 404 413 yield (ERRORTOKEN, line[pos], 405 414 (lnum, pos), (lnum, pos+1), line) 406 pos = pos +1415 pos += 1 407 416 408 417 for indent in indents[1:]: # pop remaining indent levels … … 412 421 if __name__ == '__main__': # testing 413 422 import sys 414 if len(sys.argv) > 1: tokenize(open(sys.argv[1]).readline) 415 else: tokenize(sys.stdin.readline) 423 if len(sys.argv) > 1: 424 tokenize(open(sys.argv[1]).readline) 425 else: 426 tokenize(sys.stdin.readline)
Note:
See TracChangeset
for help on using the changeset viewer.