tokenize
index
/usr/lib/python2.2/tokenize.py

Tokenization help for Python programs.
 
generate_tokens(readline) is a generator that breaks a stream of
text into Python tokens.  It accepts a readline-like method which is called
repeatedly to get the next line of input (or "" for EOF).  It generates
5-tuples with these members:
 
    the token type (see token.py)
    the token (a string)
    the starting (row, column) indices of the token (a 2-tuple of ints)
    the ending (row, column) indices of the token (a 2-tuple of ints)
    the original line (string)
 
It is designed to match the working of the Python tokenizer exactly, except
that it produces COMMENT tokens for comments and gives type OP for all
operators
 
Older entry points
    tokenize_loop(readline, tokeneater)
    tokenize(readline, tokeneater=printtoken)
are the same, except instead of generating tokens, tokeneater is a callback
function to which the 5 fields described above are passed as 5 arguments,
each time a new token is found.

 
Modules
            
re
string
 
Classes
            
exceptions.Exception
StopTokenizing
TokenError
 
class StopTokenizing(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'tokenize'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
class TokenError(exceptions.Exception)
       
   Data and non-method functions defined here:
__doc__ = None
__module__ = 'tokenize'

Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)
 
Functions
            
any(*choices)
generate_tokens(readline)
group(*choices)
maybe(*choices)
printtoken(type, token, (srow, scol), (erow, ecol), line)
tokenize(readline, tokeneater=<function printtoken>)
tokenize_loop(readline, tokeneater)
# backwards compatible interface
 
Data
             AMPER = 19
AMPEREQUAL = 42
BACKQUOTE = 25
Bracket = '[][(){}]'
CIRCUMFLEX = 33
CIRCUMFLEXEQUAL = 44
COLON = 11
COMMA = 12
COMMENT = 52
Comment = '#[^\\r\\n]*'
ContStr = '([uU]?[rR]?\'[^\\n\'\\\\]*(?:\\\\.[^\\n\'\\\\]*...\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*("|\\\\\\r?\\n))'
DEDENT = 6
DOT = 23
DOUBLESLASH = 48
DOUBLESLASHEQUAL = 49
DOUBLESTAR = 36
DOUBLESTAREQUAL = 47
Decnumber = '[1-9]\\d*[lL]?'
Double = '[^"\\\\]*(?:\\\\.[^"\\\\]*)*"'
Double3 = '[^"\\\\]*(?:(?:\\\\.|"(?!""))[^"\\\\]*)*"""'
ENDMARKER = 0
EQEQUAL = 28
EQUAL = 22
ERRORTOKEN = 51
Expfloat = '\\d+[eE][-+]?\\d+'
Exponent = '[eE][-+]?\\d+'
Floatnumber = '((\\d+\\.\\d*|\\.\\d+)([eE][-+]?\\d+)?|\\d+[eE][-+]?\\d+)'
Funny = '((\\*\\*=?|>>=?|<<=?|<>|!=|//=?|[+\\-*/%&|^=<>]=?|~)|[][(){}]|(\\r?\\n|[:;.,`]))'
GREATER = 21
GREATEREQUAL = 31
Hexnumber = '0[xX][\\da-fA-F]*[lL]?'
INDENT = 5
Ignore = '[ \\f\\t]*(\\\\\\r?\\n[ \\f\\t]*)*(#[^\\r\\n]*)?'
Imagnumber = '(\\d+[jJ]|((\\d+\\.\\d*|\\.\\d+)([eE][-+]?\\d+)?|\\d+[eE][-+]?\\d+)[jJ])'
Intnumber = '(0[xX][\\da-fA-F]*[lL]?|0[0-7]*[lL]?|[1-9]\\d*[lL]?)'
LBRACE = 26
LEFTSHIFT = 34
LEFTSHIFTEQUAL = 45
LESS = 20
LESSEQUAL = 30
LPAR = 7
LSQB = 9
MINEQUAL = 38
MINUS = 15
NAME = 1
NEWLINE = 4
NL = 53
NOTEQUAL = 29
NT_OFFSET = 256
NUMBER = 2
N_TOKENS = 54
Name = '[a-zA-Z_]\\w*'
Number = '((\\d+[jJ]|((\\d+\\.\\d*|\\.\\d+)([eE][-+]?\\d+...][\\da-fA-F]*[lL]?|0[0-7]*[lL]?|[1-9]\\d*[lL]?))'
OP = 50
Octnumber = '0[0-7]*[lL]?'
Operator = '(\\*\\*=?|>>=?|<<=?|<>|!=|//=?|[+\\-*/%&|^=<>]=?|~)'
PERCENT = 24
PERCENTEQUAL = 41
PLUS = 14
PLUSEQUAL = 37
PlainToken = '(((\\d+[jJ]|((\\d+\\.\\d*|\\.\\d+)([eE][-+]?\\d...\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*")|[a-zA-Z_]\\w*)'
Pointfloat = '(\\d+\\.\\d*|\\.\\d+)([eE][-+]?\\d+)?'
PseudoExtras = '(\\\\\\r?\\n|#[^\\r\\n]*|([uU]?[rR]?\'\'\'|[uU]?[rR]?"""))'
PseudoToken = '[ \\f\\t]*((\\\\\\r?\\n|#[^\\r\\n]*|([uU]?[rR]?...\\.[^\\n"\\\\]*)*("|\\\\\\r?\\n))|[a-zA-Z_]\\w*)'
RBRACE = 27
RIGHTSHIFT = 35
RIGHTSHIFTEQUAL = 46
RPAR = 8
RSQB = 10
SEMI = 13
SLASH = 17
SLASHEQUAL = 40
STAR = 16
STAREQUAL = 39
STRING = 3
Single = "[^'\\\\]*(?:\\\\.[^'\\\\]*)*'"
Single3 = "[^'\\\\]*(?:(?:\\\\.|'(?!''))[^'\\\\]*)*'''"
Special = '(\\r?\\n|[:;.,`])'
String = '([uU]?[rR]?\'[^\\n\'\\\\]*(?:\\\\.[^\\n\'\\\\]*...|[uU]?[rR]?"[^\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*")'
TILDE = 32
Token = '[ \\f\\t]*(\\\\\\r?\\n[ \\f\\t]*)*(#[^\\r\\n]*)...\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*")|[a-zA-Z_]\\w*)'
Triple = '([uU]?[rR]?\'\'\'|[uU]?[rR]?""")'
VBAR = 18
VBAREQUAL = 43
Whitespace = '[ \\f\\t]*'
__all__ = ['AMPER', 'AMPEREQUAL', 'BACKQUOTE', 'CIRCUMFLEX', 'CIRCUMFLEXEQUAL', 'COLON', 'COMMA', 'DEDENT', 'DOT', 'DOUBLESLASH', 'DOUBLESLASHEQUAL', 'DOUBLESTAR', 'DOUBLESTAREQUAL', 'ENDMARKER', 'EQEQUAL', 'EQUAL', 'ERRORTOKEN', 'GREATER', 'GREATEREQUAL', 'INDENT', ...]
__author__ = 'Ka-Ping Yee '
__credits__ = 'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro'
__file__ = '/usr/lib/python2.2/tokenize.pyc'
__name__ = 'tokenize'
double3prog = <_sre.SRE_Pattern object>
endprogs = {'"': <_sre.SRE_Pattern object>, '"""': <_sre.SRE_Pattern object>, "'": <_sre.SRE_Pattern object>, "'''": <_sre.SRE_Pattern object>, 'R': None, 'R"""': <_sre.SRE_Pattern object>, "R'''": <_sre.SRE_Pattern object>, 'U': None, 'U"""': <_sre.SRE_Pattern object>, "U'''": <_sre.SRE_Pattern object>, ...}
generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 4096)
pseudoprog = <_sre.SRE_Pattern object>
single3prog = <_sre.SRE_Pattern object>
tabsize = 8
tok_name = {0: 'ENDMARKER', 1: 'NAME', 2: 'NUMBER', 3: 'STRING', 4: 'NEWLINE', 5: 'INDENT', 6: 'DEDENT', 7: 'LPAR', 8: 'RPAR', 9: 'LSQB', ...}
tokenprog = <_sre.SRE_Pattern object>
x = 'tok_name'
 
Author
             Ka-Ping Yee <ping@lfw.org>
 
Credits
             GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro