Mercurial > cpython-lru_cache-weakref
annotate Lib/tokenize.py @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 0bec699783d0 |
| children | 64eb119b816d 93daa4fde087 |
| rev | line source |
|---|---|
|
5173
ff4f8fa8a273
Fixed doc string, added __version__, fixed 1 bug.
Guido van Rossum <guido@python.org>
parents:
5172
diff
changeset
|
1 """Tokenization help for Python programs. |
| 558 | 2 |
|
18351
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
3 generate_tokens(readline) is a generator that breaks a stream of |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
4 text into Python tokens. It accepts a readline-like method which is called |
|
18351
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
5 repeatedly to get the next line of input (or "" for EOF). It generates |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
6 5-tuples with these members: |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
7 |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
8 the token type (see token.py) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
9 the token (a string) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
10 the starting (row, column) indices of the token (a 2-tuple of ints) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
11 the ending (row, column) indices of the token (a 2-tuple of ints) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
12 the original line (string) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
13 |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
14 It is designed to match the working of the Python tokenizer exactly, except |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
15 that it produces COMMENT tokens for comments and gives type OP for all |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
16 operators |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
17 |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
18 Older entry points |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
19 tokenize_loop(readline, tokeneater) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
20 tokenize(readline, tokeneater=printtoken) |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
21 are the same, except instead of generating tokens, tokeneater is a callback |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
22 function to which the 5 fields described above are passed as 5 arguments, |
|
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
23 each time a new token is found.""" |
|
5173
ff4f8fa8a273
Fixed doc string, added __version__, fixed 1 bug.
Guido van Rossum <guido@python.org>
parents:
5172
diff
changeset
|
24 |
|
18609
59446d0f8341
Preliminary support for "from __future__ import generators" to enable
Guido van Rossum <guido@python.org>
parents:
18351
diff
changeset
|
25 from __future__ import generators |
|
59446d0f8341
Preliminary support for "from __future__ import generators" to enable
Guido van Rossum <guido@python.org>
parents:
18351
diff
changeset
|
26 |
|
16899
320fa50a1a7d
Add __author__ and __credits__ variables.
Ka-Ping Yee <ping@zesty.ca>
parents:
16889
diff
changeset
|
27 __author__ = 'Ka-Ping Yee <ping@lfw.org>' |
| 16901 | 28 __credits__ = \ |
| 29 'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro' | |
|
5173
ff4f8fa8a273
Fixed doc string, added __version__, fixed 1 bug.
Guido van Rossum <guido@python.org>
parents:
5172
diff
changeset
|
30 |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
31 import string, re |
| 5172 | 32 from token import * |
| 558 | 33 |
|
16889
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16514
diff
changeset
|
34 import token |
|
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16514
diff
changeset
|
35 __all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize", "NL"] |
|
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16514
diff
changeset
|
36 del token |
|
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16514
diff
changeset
|
37 |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
38 COMMENT = N_TOKENS |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
39 tok_name[COMMENT] = 'COMMENT' |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
40 NL = N_TOKENS + 1 |
|
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
41 tok_name[NL] = 'NL' |
|
16889
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16514
diff
changeset
|
42 N_TOKENS += 2 |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
43 |
|
16514
90c600a819e9
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
15898
diff
changeset
|
44 def group(*choices): return '(' + '|'.join(choices) + ')' |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
45 def any(*choices): return apply(group, choices) + '*' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
46 def maybe(*choices): return apply(group, choices) + '?' |
| 558 | 47 |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
48 Whitespace = r'[ \f\t]*' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
49 Comment = r'#[^\r\n]*' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
50 Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment) |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
51 Name = r'[a-zA-Z_]\w*' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
52 |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
53 Hexnumber = r'0[xX][\da-fA-F]*[lL]?' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
54 Octnumber = r'0[0-7]*[lL]?' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
55 Decnumber = r'[1-9]\d*[lL]?' |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
56 Intnumber = group(Hexnumber, Octnumber, Decnumber) |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
57 Exponent = r'[eE][-+]?\d+' |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
58 Pointfloat = group(r'\d+\.\d*', r'\.\d+') + maybe(Exponent) |
|
19621
0bec699783d0
SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents:
19052
diff
changeset
|
59 Expfloat = r'\d+' + Exponent |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
60 Floatnumber = group(Pointfloat, Expfloat) |
|
19621
0bec699783d0
SF patch #455966: Allow leading 0 in float/imag literals.
Tim Peters <tim.peters@gmail.com>
parents:
19052
diff
changeset
|
61 Imagnumber = group(r'\d+[jJ]', Floatnumber + r'[jJ]') |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
62 Number = group(Imagnumber, Floatnumber, Intnumber) |
| 558 | 63 |
|
15080
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
64 # Tail end of ' string. |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
65 Single = r"[^'\\]*(?:\\.[^'\\]*)*'" |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
66 # Tail end of " string. |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
67 Double = r'[^"\\]*(?:\\.[^"\\]*)*"' |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
68 # Tail end of ''' string. |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
69 Single3 = r"[^'\\]*(?:(?:\\.|'(?!''))[^'\\]*)*'''" |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
70 # Tail end of """ string. |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
71 Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""' |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
72 Triple = group("[uU]?[rR]?'''", '[uU]?[rR]?"""') |
|
15080
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
73 # Single-line ' or " string. |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
74 String = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'", |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
75 r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"') |
| 558 | 76 |
|
15080
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
77 # Because of leftmost-then-longest match semantics, be sure to put the |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
78 # longest operators first (e.g., if = came before ==, == would get |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
79 # recognized as two instances of =). |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
80 Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=", |
|
19052
3969fcbf9500
Add new tokens // and //=, in support of PEP 238.
Guido van Rossum <guido@python.org>
parents:
18781
diff
changeset
|
81 r"//=?", |
|
15080
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
82 r"[+\-*/%&|^=<>]=?", |
|
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
83 r"~") |
|
14166
e9c2f830f9ba
Update for augmented assignment, tested & approved by Guido.
Thomas Wouters <thomas@python.org>
parents:
14021
diff
changeset
|
84 |
| 558 | 85 Bracket = '[][(){}]' |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
86 Special = group(r'\r?\n', r'[:;.,`]') |
| 5172 | 87 Funny = group(Operator, Bracket, Special) |
| 558 | 88 |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
89 PlainToken = group(Number, Funny, String, Name) |
| 5172 | 90 Token = Ignore + PlainToken |
| 558 | 91 |
|
15080
0e0ea56e4be8
Possible fix for Skip's bug 116136 (sre recursion limit hit in tokenize.py).
Tim Peters <tim.peters@gmail.com>
parents:
14166
diff
changeset
|
92 # First (or only) line of ' or " string. |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
93 ContStr = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" + |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
94 group("'", r'\\\r?\n'), |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
95 r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' + |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
96 group('"', r'\\\r?\n')) |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
97 PseudoExtras = group(r'\\\r?\n', Comment, Triple) |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
98 PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name) |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
99 |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
100 tokenprog, pseudoprog, single3prog, double3prog = map( |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
101 re.compile, (Token, PseudoToken, Single3, Double3)) |
|
6532
d369629e8c27
New, fixed version with proper r"..." and R"..." support from Ka-Ping.
Guido van Rossum <guido@python.org>
parents:
6531
diff
changeset
|
102 endprogs = {"'": re.compile(Single), '"': re.compile(Double), |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
103 "'''": single3prog, '"""': double3prog, |
|
6532
d369629e8c27
New, fixed version with proper r"..." and R"..." support from Ka-Ping.
Guido van Rossum <guido@python.org>
parents:
6531
diff
changeset
|
104 "r'''": single3prog, 'r"""': double3prog, |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
105 "u'''": single3prog, 'u"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
106 "ur'''": single3prog, 'ur"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
107 "R'''": single3prog, 'R"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
108 "U'''": single3prog, 'U"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
109 "uR'''": single3prog, 'uR"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
110 "Ur'''": single3prog, 'Ur"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
111 "UR'''": single3prog, 'UR"""': double3prog, |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
112 'r': None, 'R': None, 'u': None, 'U': None} |
| 5172 | 113 |
| 114 tabsize = 8 | |
|
14021
5b34b70ecf22
Convert some old-style string exceptions to class exceptions.
Fred Drake <fdrake@acm.org>
parents:
7839
diff
changeset
|
115 |
|
17178
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
116 class TokenError(Exception): pass |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
117 |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
118 class StopTokenizing(Exception): pass |
|
14021
5b34b70ecf22
Convert some old-style string exceptions to class exceptions.
Fred Drake <fdrake@acm.org>
parents:
7839
diff
changeset
|
119 |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
120 def printtoken(type, token, (srow, scol), (erow, ecol), line): # for testing |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
121 print "%d,%d-%d,%d:\t%s\t%s" % \ |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
122 (srow, scol, erow, ecol, tok_name[type], repr(token)) |
| 5172 | 123 |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
124 def tokenize(readline, tokeneater=printtoken): |
|
17178
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
125 try: |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
126 tokenize_loop(readline, tokeneater) |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
127 except StopTokenizing: |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
128 pass |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
129 |
|
18351
44a87c300f2b
Turns out Neil didn't intend for *all* of his gen-branch work to get
Tim Peters <tim.peters@gmail.com>
parents:
18148
diff
changeset
|
130 # backwards compatible interface |
|
17178
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
131 def tokenize_loop(readline, tokeneater): |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
132 for token_info in generate_tokens(readline): |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
133 apply(tokeneater, token_info) |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
134 |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
135 def generate_tokens(readline): |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
136 lnum = parenlev = continued = 0 |
|
18781
01ae962df885
Use string.ascii_letters instead of string.letters (SF bug #226706).
Fred Drake <fdrake@acm.org>
parents:
18609
diff
changeset
|
137 namechars, numchars = string.ascii_letters + '_', '0123456789' |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
138 contstr, needcont = '', 0 |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
139 contline = None |
| 5172 | 140 indents = [0] |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
141 |
| 5172 | 142 while 1: # loop over lines in stream |
| 143 line = readline() | |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
144 lnum = lnum + 1 |
| 5172 | 145 pos, max = 0, len(line) |
| 558 | 146 |
| 5172 | 147 if contstr: # continued string |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
148 if not line: |
|
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
149 raise TokenError, ("EOF in multi-line string", strstart) |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
150 endmatch = endprog.match(line) |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
151 if endmatch: |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
152 pos = end = endmatch.end(0) |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
153 yield (STRING, contstr + line[:end], |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
154 strstart, (lnum, end), contline + line) |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
155 contstr, needcont = '', 0 |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
156 contline = None |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
157 elif needcont and line[-2:] != '\\\n' and line[-3:] != '\\\r\n': |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
158 yield (ERRORTOKEN, contstr + line, |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
159 strstart, (lnum, len(line)), contline) |
| 5172 | 160 contstr = '' |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
161 contline = None |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
162 continue |
| 5172 | 163 else: |
| 164 contstr = contstr + line | |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
165 contline = contline + line |
| 5172 | 166 continue |
| 167 | |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
168 elif parenlev == 0 and not continued: # new statement |
| 5172 | 169 if not line: break |
| 170 column = 0 | |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
171 while pos < max: # measure leading whitespace |
| 5172 | 172 if line[pos] == ' ': column = column + 1 |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
173 elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize |
| 5172 | 174 elif line[pos] == '\f': column = 0 |
| 175 else: break | |
| 176 pos = pos + 1 | |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
177 if pos == max: break |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
178 |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
179 if line[pos] in '#\r\n': # skip comments or blank lines |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
180 yield ((NL, COMMENT)[line[pos] == '#'], line[pos:], |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
181 (lnum, pos), (lnum, len(line)), line) |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
182 continue |
| 558 | 183 |
| 5172 | 184 if column > indents[-1]: # count indents or dedents |
| 185 indents.append(column) | |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
186 yield (INDENT, line[:pos], (lnum, 0), (lnum, pos), line) |
| 5172 | 187 while column < indents[-1]: |
| 188 indents = indents[:-1] | |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
189 yield (DEDENT, '', (lnum, pos), (lnum, pos), line) |
| 5172 | 190 |
| 191 else: # continued statement | |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
192 if not line: |
|
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
193 raise TokenError, ("EOF in multi-line statement", (lnum, 0)) |
| 5172 | 194 continued = 0 |
| 195 | |
| 196 while pos < max: | |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
197 pseudomatch = pseudoprog.match(line, pos) |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
198 if pseudomatch: # scan for tokens |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
199 start, end = pseudomatch.span(1) |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
200 spos, epos, pos = (lnum, start), (lnum, end), end |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
201 token, initial = line[start:end], line[start] |
| 5172 | 202 |
|
17178
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
203 if initial in numchars or \ |
|
707f95d05e69
Provide a StopTokenizing exception for conveniently exiting the loop.
Ka-Ping Yee <ping@zesty.ca>
parents:
16901
diff
changeset
|
204 (initial == '.' and token != '.'): # ordinary number |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
205 yield (NUMBER, token, spos, epos, line) |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
206 elif initial in '\r\n': |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
207 yield (parenlev > 0 and NL or NEWLINE, |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
208 token, spos, epos, line) |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
209 elif initial == '#': |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
210 yield (COMMENT, token, spos, epos, line) |
|
6532
d369629e8c27
New, fixed version with proper r"..." and R"..." support from Ka-Ping.
Guido van Rossum <guido@python.org>
parents:
6531
diff
changeset
|
211 elif token in ("'''", '"""', # triple-quoted |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
212 "r'''", 'r"""', "R'''", 'R"""', |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
213 "u'''", 'u"""', "U'''", 'U"""', |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
214 "ur'''", 'ur"""', "Ur'''", 'Ur"""', |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
215 "uR'''", 'uR"""', "UR'''", 'UR"""'): |
| 5172 | 216 endprog = endprogs[token] |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
217 endmatch = endprog.match(line, pos) |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
218 if endmatch: # all on one line |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
219 pos = endmatch.end(0) |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
220 token = line[start:pos] |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
221 yield (STRING, token, spos, (lnum, pos), line) |
| 5172 | 222 else: |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
223 strstart = (lnum, start) # multiple lines |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
224 contstr = line[start:] |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
225 contline = line |
| 5172 | 226 break |
|
6532
d369629e8c27
New, fixed version with proper r"..." and R"..." support from Ka-Ping.
Guido van Rossum <guido@python.org>
parents:
6531
diff
changeset
|
227 elif initial in ("'", '"') or \ |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
228 token[:2] in ("r'", 'r"', "R'", 'R"', |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
229 "u'", 'u"', "U'", 'U"') or \ |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
230 token[:3] in ("ur'", 'ur"', "Ur'", 'Ur"', |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
231 "uR'", 'uR"', "UR'", 'UR"' ): |
| 5172 | 232 if token[-1] == '\n': # continued string |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
233 strstart = (lnum, start) |
|
15898
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
234 endprog = (endprogs[initial] or endprogs[token[1]] or |
|
8366fcfb6090
Add tokenizer support and tests for u'', U"", uR'', Ur"", etc.
Ka-Ping Yee <ping@zesty.ca>
parents:
15873
diff
changeset
|
235 endprogs[token[2]]) |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
236 contstr, needcont = line[start:], 1 |
|
7839
d4f5321b9d9e
Differentiate between NEWLINE token (an official newline) and NL token
Guido van Rossum <guido@python.org>
parents:
6532
diff
changeset
|
237 contline = line |
| 5172 | 238 break |
| 239 else: # ordinary string | |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
240 yield (STRING, token, spos, epos, line) |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
241 elif initial in namechars: # ordinary name |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
242 yield (NAME, token, spos, epos, line) |
|
6531
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
243 elif initial == '\\': # continued stmt |
|
e497a7fc0aa8
Redone (by Ka-Ping) using the new re module, and adding recognition
Guido van Rossum <guido@python.org>
parents:
5721
diff
changeset
|
244 continued = 1 |
| 5172 | 245 else: |
|
5266
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
246 if initial in '([{': parenlev = parenlev + 1 |
|
1efc4273fdb7
Ka-Ping's muich improved version of March 26, 1997:
Guido van Rossum <guido@python.org>
parents:
5178
diff
changeset
|
247 elif initial in ')]}': parenlev = parenlev - 1 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
248 yield (OP, token, spos, epos, line) |
| 5172 | 249 else: |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
250 yield (ERRORTOKEN, line[pos], |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
251 (lnum, pos), (lnum, pos+1), line) |
| 5172 | 252 pos = pos + 1 |
| 253 | |
| 254 for indent in indents[1:]: # pop remaining indent levels | |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
255 yield (DEDENT, '', (lnum, 0), (lnum, 0), '') |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17178
diff
changeset
|
256 yield (ENDMARKER, '', (lnum, 0), (lnum, 0), '') |
| 5172 | 257 |
| 258 if __name__ == '__main__': # testing | |
| 259 import sys | |
|
5277
7df5a0d1f523
Ping's latest. Fixes triple quoted strings ending in odd
Guido van Rossum <guido@python.org>
parents:
5266
diff
changeset
|
260 if len(sys.argv) > 1: tokenize(open(sys.argv[1]).readline) |
|
5721
138b176ec40f
Correct typo in last line (test program invocation).
Guido van Rossum <guido@python.org>
parents:
5277
diff
changeset
|
261 else: tokenize(sys.stdin.readline) |
