Mercurial > cpython-lru_cache-weakref
annotate Parser/tokenizer.c @ 15842:f6cd36498a50 legacy-trunk
Document extensions to .pth files.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Sat, 13 Jan 2001 09:54:41 +0000 |
| parents | 6f6f965c5e2d |
| children | 1fe8e50e6e1b |
| rev | line source |
|---|---|
| 145 | 1 |
| 6 | 2 /* Tokenizer implementation */ |
| 3 | |
| 86 | 4 #include "pgenheaders.h" |
| 5 | |
| 6 | 6 #include <ctype.h> |
| 7 | |
| 8 #include "tokenizer.h" | |
| 9 #include "errcode.h" | |
| 10 | |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
11 extern char *PyOS_Readline(char *); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
12 /* Return malloc'ed string including trailing \n; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
13 empty malloc'ed string for EOF; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
14 NULL if interrupted */ |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
15 |
|
678
205b947b1d3c
Make tabs always 8 spaces wide -- it's more portable.
Guido van Rossum <guido@python.org>
parents:
477
diff
changeset
|
16 /* Don't ever change this -- it would break the portability of Python code */ |
| 6 | 17 #define TABSIZE 8 |
| 18 | |
|
7118
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
19 /* Convert a possibly signed character to a nonnegative int */ |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
20 /* XXX This assumes characters are 8 bits wide */ |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
21 #ifdef __CHAR_UNSIGNED__ |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
22 #define Py_CHARMASK(c) (c) |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
23 #else |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
24 #define Py_CHARMASK(c) ((c) & 0xff) |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
25 #endif |
|
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
26 |
| 86 | 27 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
28 static struct tok_state *tok_new(void); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
29 static int tok_nextc(struct tok_state *tok); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
30 static void tok_backup(struct tok_state *tok, int c); |
| 86 | 31 |
| 6 | 32 /* Token names */ |
| 33 | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
34 char *_PyParser_TokenNames[] = { |
| 6 | 35 "ENDMARKER", |
| 36 "NAME", | |
| 37 "NUMBER", | |
| 38 "STRING", | |
| 39 "NEWLINE", | |
| 40 "INDENT", | |
| 41 "DEDENT", | |
| 42 "LPAR", | |
| 43 "RPAR", | |
| 44 "LSQB", | |
| 45 "RSQB", | |
| 46 "COLON", | |
| 47 "COMMA", | |
| 48 "SEMI", | |
| 49 "PLUS", | |
| 50 "MINUS", | |
| 51 "STAR", | |
| 52 "SLASH", | |
| 53 "VBAR", | |
| 54 "AMPER", | |
| 55 "LESS", | |
| 56 "GREATER", | |
| 57 "EQUAL", | |
| 58 "DOT", | |
| 59 "PERCENT", | |
| 60 "BACKQUOTE", | |
| 61 "LBRACE", | |
| 62 "RBRACE", | |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
63 "EQEQUAL", |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
64 "NOTEQUAL", |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
65 "LESSEQUAL", |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
66 "GREATEREQUAL", |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
67 "TILDE", |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
68 "CIRCUMFLEX", |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
69 "LEFTSHIFT", |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
70 "RIGHTSHIFT", |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
71 "DOUBLESTAR", |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
72 "PLUSEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
73 "MINEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
74 "STAREQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
75 "SLASHEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
76 "PERCENTEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
77 "AMPEREQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
78 "VBAREQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
79 "CIRCUMFLEXEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
80 "LEFTSHIFTEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
81 "RIGHTSHIFTEQUAL", |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
82 "DOUBLESTAREQUAL", |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
83 /* This table must match the #defines in token.h! */ |
| 6 | 84 "OP", |
| 85 "<ERRORTOKEN>", | |
| 86 "<N_TOKENS>" | |
| 87 }; | |
| 88 | |
| 89 | |
| 90 /* Create and initialize a new tok_state structure */ | |
| 91 | |
| 92 static struct tok_state * | |
| 13659 | 93 tok_new(void) |
| 6 | 94 { |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
95 struct tok_state *tok = PyMem_NEW(struct tok_state, 1); |
| 6 | 96 if (tok == NULL) |
| 97 return NULL; | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
98 tok->buf = tok->cur = tok->end = tok->inp = tok->start = NULL; |
| 6 | 99 tok->done = E_OK; |
| 100 tok->fp = NULL; | |
| 101 tok->tabsize = TABSIZE; | |
| 102 tok->indent = 0; | |
| 103 tok->indstack[0] = 0; | |
| 104 tok->atbol = 1; | |
| 105 tok->pendin = 0; | |
| 106 tok->prompt = tok->nextprompt = NULL; | |
| 107 tok->lineno = 0; | |
|
1284
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
108 tok->level = 0; |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
109 tok->filename = NULL; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
110 tok->altwarning = 0; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
111 tok->alterror = 0; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
112 tok->alttabsize = 1; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
113 tok->altindstack[0] = 0; |
| 6 | 114 return tok; |
| 115 } | |
| 116 | |
| 117 | |
| 118 /* Set up tokenizer for string */ | |
| 119 | |
| 120 struct tok_state * | |
| 13659 | 121 PyTokenizer_FromString(char *str) |
| 6 | 122 { |
| 123 struct tok_state *tok = tok_new(); | |
| 124 if (tok == NULL) | |
| 125 return NULL; | |
|
1897
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
126 tok->buf = tok->cur = tok->end = tok->inp = str; |
| 6 | 127 return tok; |
| 128 } | |
| 129 | |
| 130 | |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
131 /* Set up tokenizer for file */ |
| 6 | 132 |
| 133 struct tok_state * | |
| 13659 | 134 PyTokenizer_FromFile(FILE *fp, char *ps1, char *ps2) |
| 6 | 135 { |
| 136 struct tok_state *tok = tok_new(); | |
| 137 if (tok == NULL) | |
| 138 return NULL; | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
139 if ((tok->buf = PyMem_NEW(char, BUFSIZ)) == NULL) { |
|
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
140 PyMem_DEL(tok); |
| 6 | 141 return NULL; |
| 142 } | |
| 143 tok->cur = tok->inp = tok->buf; | |
| 144 tok->end = tok->buf + BUFSIZ; | |
| 145 tok->fp = fp; | |
| 146 tok->prompt = ps1; | |
| 147 tok->nextprompt = ps2; | |
| 148 return tok; | |
| 149 } | |
| 150 | |
| 151 | |
| 152 /* Free a tok_state structure */ | |
| 153 | |
| 154 void | |
| 13659 | 155 PyTokenizer_Free(struct tok_state *tok) |
| 6 | 156 { |
| 157 if (tok->fp != NULL && tok->buf != NULL) | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
158 PyMem_DEL(tok->buf); |
|
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
159 PyMem_DEL(tok); |
| 6 | 160 } |
| 161 | |
| 162 | |
| 163 /* Get next char, updating state; error code goes into tok->done */ | |
| 164 | |
| 165 static int | |
| 13659 | 166 tok_nextc(register struct tok_state *tok) |
| 6 | 167 { |
| 168 for (;;) { | |
|
1897
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
169 if (tok->cur != tok->inp) { |
|
7118
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
170 return Py_CHARMASK(*tok->cur++); /* Fast path */ |
|
1897
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
171 } |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
172 if (tok->done != E_OK) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
173 return EOF; |
| 6 | 174 if (tok->fp == NULL) { |
|
1897
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
175 char *end = strchr(tok->inp, '\n'); |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
176 if (end != NULL) |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
177 end++; |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
178 else { |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
179 end = strchr(tok->inp, '\0'); |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
180 if (end == tok->inp) { |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
181 tok->done = E_EOF; |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
182 return EOF; |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
183 } |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
184 } |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
185 if (tok->start == NULL) |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
186 tok->buf = tok->cur; |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
187 tok->lineno++; |
|
3fbda8768855
* Parser/tokenizer.c (tok_nextc): count line numbers when parsing
Guido van Rossum <guido@python.org>
parents:
1835
diff
changeset
|
188 tok->inp = end; |
|
7118
e9108e97a5a0
tok_nextc() should return unsigned characters, to avoid mistaking
Guido van Rossum <guido@python.org>
parents:
5379
diff
changeset
|
189 return Py_CHARMASK(*tok->cur++); |
| 6 | 190 } |
| 191 if (tok->prompt != NULL) { | |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
192 char *new = PyOS_Readline(tok->prompt); |
| 6 | 193 if (tok->nextprompt != NULL) |
| 194 tok->prompt = tok->nextprompt; | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
195 if (new == NULL) |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
196 tok->done = E_INTR; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
197 else if (*new == '\0') { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
198 PyMem_FREE(new); |
| 6 | 199 tok->done = E_EOF; |
| 200 } | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
201 else if (tok->start != NULL) { |
|
13093
cbe02b8aee07
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
202 size_t start = tok->start - tok->buf; |
|
cbe02b8aee07
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
203 size_t oldlen = tok->cur - tok->buf; |
|
cbe02b8aee07
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12576
diff
changeset
|
204 size_t newlen = oldlen + strlen(new); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
205 char *buf = tok->buf; |
|
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
206 PyMem_RESIZE(buf, char, newlen+1); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
207 tok->lineno++; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
208 if (buf == NULL) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
209 PyMem_DEL(tok->buf); |
|
2044
281e40652e23
Parser/tokenizer.c (tok_nextc): zap tok->buf after freeing;
Guido van Rossum <guido@python.org>
parents:
1897
diff
changeset
|
210 tok->buf = NULL; |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
211 PyMem_FREE(new); |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
212 tok->done = E_NOMEM; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
213 return EOF; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
214 } |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
215 tok->buf = buf; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
216 tok->cur = tok->buf + oldlen; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
217 strcpy(tok->buf + oldlen, new); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
218 PyMem_FREE(new); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
219 tok->inp = tok->buf + newlen; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
220 tok->end = tok->inp + 1; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
221 tok->start = tok->buf + start; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
222 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
223 else { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
224 tok->lineno++; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
225 if (tok->buf != NULL) |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12224
diff
changeset
|
226 PyMem_DEL(tok->buf); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
227 tok->buf = new; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
228 tok->cur = tok->buf; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
229 tok->inp = strchr(tok->buf, '\0'); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
230 tok->end = tok->inp + 1; |
| 6 | 231 } |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
232 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
233 else { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
234 int done = 0; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
235 int cur = 0; |
|
2732
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
236 char *pt; |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
237 if (tok->start == NULL) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
238 if (tok->buf == NULL) { |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
239 tok->buf = PyMem_NEW(char, BUFSIZ); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
240 if (tok->buf == NULL) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
241 tok->done = E_NOMEM; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
242 return EOF; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
243 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
244 tok->end = tok->buf + BUFSIZ; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
245 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
246 if (fgets(tok->buf, (int)(tok->end - tok->buf), |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
247 tok->fp) == NULL) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
248 tok->done = E_EOF; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
249 done = 1; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
250 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
251 else { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
252 tok->done = E_OK; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
253 tok->inp = strchr(tok->buf, '\0'); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
254 done = tok->inp[-1] == '\n'; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
255 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
256 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
257 else { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
258 cur = tok->cur - tok->buf; |
|
2149
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
259 if (feof(tok->fp)) { |
|
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
260 tok->done = E_EOF; |
|
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
261 done = 1; |
|
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
262 } |
|
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
263 else |
|
6060d7fb07e3
fix loop on unterminated triple quotes
Guido van Rossum <guido@python.org>
parents:
2060
diff
changeset
|
264 tok->done = E_OK; |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
265 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
266 tok->lineno++; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
267 /* Read until '\n' or EOF */ |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
268 while (!done) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
269 int curstart = tok->start == NULL ? -1 : |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
270 tok->start - tok->buf; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
271 int curvalid = tok->inp - tok->buf; |
|
3116
db139a4112f3
fix bogus resize length in nextc
Guido van Rossum <guido@python.org>
parents:
2801
diff
changeset
|
272 int newsize = curvalid + BUFSIZ; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
273 char *newbuf = tok->buf; |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
274 PyMem_RESIZE(newbuf, char, newsize); |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
275 if (newbuf == NULL) { |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
276 tok->done = E_NOMEM; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
277 tok->cur = tok->inp; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
278 return EOF; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
279 } |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
280 tok->buf = newbuf; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
281 tok->inp = tok->buf + curvalid; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
282 tok->end = tok->buf + newsize; |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
283 tok->start = curstart < 0 ? NULL : |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
284 tok->buf + curstart; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
285 if (fgets(tok->inp, |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
286 (int)(tok->end - tok->inp), |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
287 tok->fp) == NULL) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
288 /* Last line does not end in \n, |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
289 fake one */ |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
290 strcpy(tok->inp, "\n"); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
291 } |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
292 tok->inp = strchr(tok->inp, '\0'); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
293 done = tok->inp[-1] == '\n'; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
294 } |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
295 tok->cur = tok->buf + cur; |
|
5311
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
296 #ifndef macintosh |
|
2732
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
297 /* replace "\r\n" with "\n" */ |
|
5311
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
298 /* For Mac we leave the \r, giving a syntax error */ |
|
2732
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
299 pt = tok->inp - 2; |
|
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
300 if (pt >= tok->buf && *pt == '\r') { |
|
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
301 *pt++ = '\n'; |
|
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
302 *pt = '\0'; |
|
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
303 tok->inp = pt; |
|
daa150b3a6e4
replace "\r\n" with "\n" at line end (Jim Ahlstrom)
Guido van Rossum <guido@python.org>
parents:
2149
diff
changeset
|
304 } |
|
5311
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
305 #endif |
| 6 | 306 } |
| 307 if (tok->done != E_OK) { | |
| 308 if (tok->prompt != NULL) | |
|
9047
6d2eb58f0418
Replace all calls to fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
7945
diff
changeset
|
309 PySys_WriteStderr("\n"); |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
310 tok->cur = tok->inp; |
| 6 | 311 return EOF; |
| 312 } | |
| 313 } | |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
314 /*NOTREACHED*/ |
| 6 | 315 } |
| 316 | |
| 317 | |
| 318 /* Back-up one character */ | |
| 319 | |
| 320 static void | |
| 13659 | 321 tok_backup(register struct tok_state *tok, register int c) |
| 6 | 322 { |
| 323 if (c != EOF) { | |
|
2044
281e40652e23
Parser/tokenizer.c (tok_nextc): zap tok->buf after freeing;
Guido van Rossum <guido@python.org>
parents:
1897
diff
changeset
|
324 if (--tok->cur < tok->buf) |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
325 Py_FatalError("tok_backup: begin of buffer"); |
| 6 | 326 if (*tok->cur != c) |
| 327 *tok->cur = c; | |
| 328 } | |
| 329 } | |
| 330 | |
| 331 | |
| 332 /* Return the token corresponding to a single character */ | |
| 333 | |
| 334 int | |
| 13659 | 335 PyToken_OneChar(int c) |
| 6 | 336 { |
| 337 switch (c) { | |
| 338 case '(': return LPAR; | |
| 339 case ')': return RPAR; | |
| 340 case '[': return LSQB; | |
| 341 case ']': return RSQB; | |
| 342 case ':': return COLON; | |
| 343 case ',': return COMMA; | |
| 344 case ';': return SEMI; | |
| 345 case '+': return PLUS; | |
| 346 case '-': return MINUS; | |
| 347 case '*': return STAR; | |
| 348 case '/': return SLASH; | |
| 349 case '|': return VBAR; | |
| 350 case '&': return AMPER; | |
| 351 case '<': return LESS; | |
| 352 case '>': return GREATER; | |
| 353 case '=': return EQUAL; | |
| 354 case '.': return DOT; | |
| 355 case '%': return PERCENT; | |
| 356 case '`': return BACKQUOTE; | |
| 357 case '{': return LBRACE; | |
| 358 case '}': return RBRACE; | |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
359 case '^': return CIRCUMFLEX; |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
360 case '~': return TILDE; |
| 6 | 361 default: return OP; |
| 362 } | |
| 363 } | |
| 364 | |
| 365 | |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
366 int |
| 13659 | 367 PyToken_TwoChars(int c1, int c2) |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
368 { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
369 switch (c1) { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
370 case '=': |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
371 switch (c2) { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
372 case '=': return EQEQUAL; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
373 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
374 break; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
375 case '!': |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
376 switch (c2) { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
377 case '=': return NOTEQUAL; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
378 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
379 break; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
380 case '<': |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
381 switch (c2) { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
382 case '>': return NOTEQUAL; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
383 case '=': return LESSEQUAL; |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
384 case '<': return LEFTSHIFT; |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
385 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
386 break; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
387 case '>': |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
388 switch (c2) { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
389 case '=': return GREATEREQUAL; |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
390 case '>': return RIGHTSHIFT; |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
391 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
392 break; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
393 case '+': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
394 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
395 case '=': return PLUSEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
396 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
397 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
398 case '-': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
399 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
400 case '=': return MINEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
401 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
402 break; |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
403 case '*': |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
404 switch (c2) { |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
405 case '*': return DOUBLESTAR; |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
406 case '=': return STAREQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
407 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
408 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
409 case '/': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
410 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
411 case '=': return SLASHEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
412 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
413 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
414 case '|': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
415 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
416 case '=': return VBAREQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
417 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
418 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
419 case '%': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
420 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
421 case '=': return PERCENTEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
422 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
423 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
424 case '&': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
425 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
426 case '=': return AMPEREQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
427 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
428 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
429 case '^': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
430 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
431 case '=': return CIRCUMFLEXEQUAL; |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
432 } |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
433 break; |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
434 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
435 return OP; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
436 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
437 |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
438 int |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
439 PyToken_ThreeChars(int c1, int c2, int c3) |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
440 { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
441 switch (c1) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
442 case '<': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
443 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
444 case '<': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
445 switch (c3) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
446 case '=': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
447 return LEFTSHIFTEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
448 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
449 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
450 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
451 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
452 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
453 case '>': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
454 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
455 case '>': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
456 switch (c3) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
457 case '=': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
458 return RIGHTSHIFTEQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
459 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
460 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
461 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
462 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
463 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
464 case '*': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
465 switch (c2) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
466 case '*': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
467 switch (c3) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
468 case '=': |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
469 return DOUBLESTAREQUAL; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
470 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
471 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
472 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
473 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
474 break; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
475 } |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
476 return OP; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
477 } |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
478 |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
479 static int |
| 13659 | 480 indenterror(struct tok_state *tok) |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
481 { |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
482 if (tok->alterror) { |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
483 tok->done = E_TABSPACE; |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
484 tok->cur = tok->inp; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
485 return 1; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
486 } |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
487 if (tok->altwarning) { |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
488 PySys_WriteStderr("%s: inconsistent use of tabs and spaces " |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
489 "in indentation\n", tok->filename); |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
490 tok->altwarning = 0; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
491 } |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
492 return 0; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
493 } |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
494 |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
495 |
| 6 | 496 /* Get next token, after space stripping etc. */ |
| 497 | |
| 498 int | |
| 13659 | 499 PyTokenizer_Get(register struct tok_state *tok, char **p_start, |
| 500 char **p_end) | |
| 6 | 501 { |
| 502 register int c; | |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
503 int blankline; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
504 |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
505 *p_start = *p_end = NULL; |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
506 nextline: |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
507 tok->start = NULL; |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
508 blankline = 0; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
509 |
| 6 | 510 /* Get indentation level */ |
| 511 if (tok->atbol) { | |
| 512 register int col = 0; | |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
513 register int altcol = 0; |
| 6 | 514 tok->atbol = 0; |
| 515 for (;;) { | |
| 516 c = tok_nextc(tok); | |
| 517 if (c == ' ') | |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
518 col++, altcol++; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
519 else if (c == '\t') { |
| 6 | 520 col = (col/tok->tabsize + 1) * tok->tabsize; |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
521 altcol = (altcol/tok->alttabsize + 1) |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
522 * tok->alttabsize; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
523 } |
|
2801
e911f2fb179c
ignore control-l in whitespace
Guido van Rossum <guido@python.org>
parents:
2732
diff
changeset
|
524 else if (c == '\014') /* Control-L (formfeed) */ |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
525 col = altcol = 0; /* For Emacs users */ |
| 6 | 526 else |
| 527 break; | |
| 528 } | |
| 529 tok_backup(tok, c); | |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
530 if (c == '#' || c == '\n') { |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
531 /* Lines with only whitespace and/or comments |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
532 shouldn't affect the indentation and are |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
533 not passed to the parser as NEWLINE tokens, |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
534 except *totally* empty lines in interactive |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
535 mode, which signal the end of a command group. */ |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
536 if (col == 0 && c == '\n' && tok->prompt != NULL) |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
537 blankline = 0; /* Let it through */ |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
538 else |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
539 blankline = 1; /* Ignore completely */ |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
540 /* We can't jump back right here since we still |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
541 may need to skip to the end of a comment */ |
| 6 | 542 } |
|
1284
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
543 if (!blankline && tok->level == 0) { |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
544 if (col == tok->indstack[tok->indent]) { |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
545 /* No change */ |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
546 if (altcol != tok->altindstack[tok->indent]) { |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
547 if (indenterror(tok)) |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
548 return ERRORTOKEN; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
549 } |
| 6 | 550 } |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
551 else if (col > tok->indstack[tok->indent]) { |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
552 /* Indent -- always one */ |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
553 if (tok->indent+1 >= MAXINDENT) { |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
554 tok->done = E_TOODEEP; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
555 tok->cur = tok->inp; |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
556 return ERRORTOKEN; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
557 } |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
558 if (altcol <= tok->altindstack[tok->indent]) { |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
559 if (indenterror(tok)) |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
560 return ERRORTOKEN; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
561 } |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
562 tok->pendin++; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
563 tok->indstack[++tok->indent] = col; |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
564 tok->altindstack[tok->indent] = altcol; |
| 6 | 565 } |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
566 else /* col < tok->indstack[tok->indent] */ { |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
567 /* Dedent -- any number, must be consistent */ |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
568 while (tok->indent > 0 && |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
569 col < tok->indstack[tok->indent]) { |
|
7324
55125b1144fa
Swap two statements in the dedent check loop. This makes absolutely
Guido van Rossum <guido@python.org>
parents:
7315
diff
changeset
|
570 tok->pendin--; |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
571 tok->indent--; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
572 } |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
573 if (col != tok->indstack[tok->indent]) { |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
574 tok->done = E_DEDENT; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
575 tok->cur = tok->inp; |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
576 return ERRORTOKEN; |
|
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
577 } |
|
7945
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
578 if (altcol != tok->altindstack[tok->indent]) { |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
579 if (indenterror(tok)) |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
580 return ERRORTOKEN; |
|
dc132cc39573
Add checking for inconsistent tab usage
Guido van Rossum <guido@python.org>
parents:
7324
diff
changeset
|
581 } |
| 6 | 582 } |
| 583 } | |
| 584 } | |
| 585 | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
586 tok->start = tok->cur; |
| 6 | 587 |
| 588 /* Return pending indents/dedents */ | |
| 589 if (tok->pendin != 0) { | |
| 590 if (tok->pendin < 0) { | |
| 591 tok->pendin++; | |
| 592 return DEDENT; | |
| 593 } | |
| 594 else { | |
| 595 tok->pendin--; | |
| 596 return INDENT; | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 again: | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
601 tok->start = NULL; |
| 6 | 602 /* Skip spaces */ |
| 603 do { | |
| 604 c = tok_nextc(tok); | |
|
2801
e911f2fb179c
ignore control-l in whitespace
Guido van Rossum <guido@python.org>
parents:
2732
diff
changeset
|
605 } while (c == ' ' || c == '\t' || c == '\014'); |
| 6 | 606 |
| 607 /* Set start of current token */ | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
608 tok->start = tok->cur - 1; |
| 6 | 609 |
|
12142
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
610 /* Skip comment, while looking for tab-setting magic */ |
| 6 | 611 if (c == '#') { |
|
12142
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
612 static char *tabforms[] = { |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
613 "tab-width:", /* Emacs */ |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
614 ":tabstop=", /* vim, full form */ |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
615 ":ts=", /* vim, abbreviated form */ |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
616 "set tabsize=", /* will vi never die? */ |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
617 /* more templates can be added here to support other editors */ |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
618 }; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
619 char cbuf[80]; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
620 char *tp, **cp; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
621 tp = cbuf; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
622 do { |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
623 *tp++ = c = tok_nextc(tok); |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
624 } while (c != EOF && c != '\n' && |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
625 tp - cbuf + 1 < sizeof(cbuf)); |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
626 *tp = '\0'; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
627 for (cp = tabforms; |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
628 cp < tabforms + sizeof(tabforms)/sizeof(tabforms[0]); |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
629 cp++) { |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
630 if ((tp = strstr(cbuf, *cp))) { |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
631 int newsize = atoi(tp + strlen(*cp)); |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
632 |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
633 if (newsize >= 1 && newsize <= 40) { |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
634 tok->tabsize = newsize; |
|
12224
2dc1bdb4088e
Only write message about changed Tab size with -v.
Guido van Rossum <guido@python.org>
parents:
12142
diff
changeset
|
635 if (Py_VerboseFlag) |
|
2dc1bdb4088e
Only write message about changed Tab size with -v.
Guido van Rossum <guido@python.org>
parents:
12142
diff
changeset
|
636 PySys_WriteStderr( |
|
12142
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
637 "Tab size set to %d\n", |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
638 newsize); |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
639 } |
|
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
640 } |
| 6 | 641 } |
|
12142
43c36f63f867
Fix by Eric Raymond: make the code that looks for various bits of
Guido van Rossum <guido@python.org>
parents:
11971
diff
changeset
|
642 while (c != EOF && c != '\n') |
| 6 | 643 c = tok_nextc(tok); |
| 644 } | |
| 645 | |
| 646 /* Check for EOF and errors now */ | |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
647 if (c == EOF) { |
| 6 | 648 return tok->done == E_EOF ? ENDMARKER : ERRORTOKEN; |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
649 } |
| 6 | 650 |
| 651 /* Identifier (most frequent token!) */ | |
| 652 if (isalpha(c) || c == '_') { | |
|
11971
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
653 /* Process r"", u"" and ur"" */ |
|
5341
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
654 switch (c) { |
|
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
655 case 'r': |
|
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
656 case 'R': |
|
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
657 c = tok_nextc(tok); |
|
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
658 if (c == '"' || c == '\'') |
|
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
659 goto letter_quote; |
|
11971
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
660 break; |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
661 case 'u': |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
662 case 'U': |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
663 c = tok_nextc(tok); |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
664 if (c == 'r' || c == 'R') |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
665 c = tok_nextc(tok); |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
666 if (c == '"' || c == '\'') |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
667 goto letter_quote; |
|
574283db2b3d
Marc-Andre Lemburg: add new string token types u"..." and ur"..."
Guido van Rossum <guido@python.org>
parents:
9590
diff
changeset
|
668 break; |
|
5341
67e5237ce141
Now that the string-sig has settled on r"obin" strings, restrict the
Guido van Rossum <guido@python.org>
parents:
5311
diff
changeset
|
669 } |
|
5265
3c1788ab9761
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
670 while (isalnum(c) || c == '_') { |
| 6 | 671 c = tok_nextc(tok); |
|
5265
3c1788ab9761
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
672 } |
| 6 | 673 tok_backup(tok, c); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
674 *p_start = tok->start; |
| 6 | 675 *p_end = tok->cur; |
| 676 return NAME; | |
| 677 } | |
| 678 | |
| 679 /* Newline */ | |
| 680 if (c == '\n') { | |
| 681 tok->atbol = 1; | |
|
1284
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
682 if (blankline || tok->level > 0) |
|
326
ff0862e3d63a
Completely ignore lines with only a newline token on them, except
Guido van Rossum <guido@python.org>
parents:
293
diff
changeset
|
683 goto nextline; |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
684 *p_start = tok->start; |
| 6 | 685 *p_end = tok->cur - 1; /* Leave '\n' out of the string */ |
| 686 return NEWLINE; | |
| 687 } | |
| 688 | |
|
5311
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
689 #ifdef macintosh |
|
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
690 if (c == '\r') { |
|
9047
6d2eb58f0418
Replace all calls to fprintf(stderr, ...) with PySys_WriteStderr(...).
Guido van Rossum <guido@python.org>
parents:
7945
diff
changeset
|
691 PySys_WriteStderr( |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
692 "File contains \\r characters (incorrect line endings?)\n"); |
|
5311
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
693 tok->done = E_TOKEN; |
|
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
694 tok->cur = tok->inp; |
|
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
695 return ERRORTOKEN; |
|
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
696 } |
|
782597cf6151
(Jack:) On the Mac, give syntax error on \r.
Guido van Rossum <guido@python.org>
parents:
5265
diff
changeset
|
697 #endif |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
698 /* Period or number starting with period? */ |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
699 if (c == '.') { |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
700 c = tok_nextc(tok); |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
701 if (isdigit(c)) { |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
702 goto fraction; |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
703 } |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
704 else { |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
705 tok_backup(tok, c); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
706 *p_start = tok->start; |
|
410
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
707 *p_end = tok->cur; |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
708 return DOT; |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
709 } |
|
fd061dae9e57
Added shift and mask ops.
Guido van Rossum <guido@python.org>
parents:
400
diff
changeset
|
710 } |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
711 |
| 6 | 712 /* Number */ |
| 713 if (isdigit(c)) { | |
| 714 if (c == '0') { | |
| 715 /* Hex or octal */ | |
| 716 c = tok_nextc(tok); | |
| 717 if (c == '.') | |
| 718 goto fraction; | |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
719 #ifndef WITHOUT_COMPLEX |
|
3364
bc17e8313ea0
use only j for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3333
diff
changeset
|
720 if (c == 'j' || c == 'J') |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
721 goto imaginary; |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
722 #endif |
| 6 | 723 if (c == 'x' || c == 'X') { |
| 724 /* Hex */ | |
| 725 do { | |
| 726 c = tok_nextc(tok); | |
| 727 } while (isxdigit(c)); | |
| 728 } | |
| 729 else { | |
|
477
436c81030853
Add warning XXX that 09.9 isn't accepted.
Guido van Rossum <guido@python.org>
parents:
410
diff
changeset
|
730 /* XXX This is broken! E.g., |
|
436c81030853
Add warning XXX that 09.9 isn't accepted.
Guido van Rossum <guido@python.org>
parents:
410
diff
changeset
|
731 09.9 should be accepted as float! */ |
| 6 | 732 /* Octal; c is first char of it */ |
| 733 /* There's no 'isoctdigit' macro, sigh */ | |
| 734 while ('0' <= c && c < '8') { | |
| 735 c = tok_nextc(tok); | |
| 736 } | |
| 737 } | |
|
236
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
738 if (c == 'l' || c == 'L') |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
739 c = tok_nextc(tok); |
| 6 | 740 } |
| 741 else { | |
| 742 /* Decimal */ | |
| 743 do { | |
| 744 c = tok_nextc(tok); | |
| 745 } while (isdigit(c)); | |
|
236
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
746 if (c == 'l' || c == 'L') |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
747 c = tok_nextc(tok); |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
748 else { |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
749 /* Accept floating point numbers. |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
750 XXX This accepts incomplete things like |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
751 XXX 12e or 1e+; worry run-time */ |
|
236
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
752 if (c == '.') { |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
753 fraction: |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
754 /* Fraction */ |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
755 do { |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
756 c = tok_nextc(tok); |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
757 } while (isdigit(c)); |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
758 } |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
759 if (c == 'e' || c == 'E') { |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
760 /* Exponent part */ |
| 6 | 761 c = tok_nextc(tok); |
|
236
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
762 if (c == '+' || c == '-') |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
763 c = tok_nextc(tok); |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
764 while (isdigit(c)) { |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
765 c = tok_nextc(tok); |
|
0a92b6a1b9c0
Added recognition of 'l' or 'L' as long integer suffix
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
766 } |
| 6 | 767 } |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
768 #ifndef WITHOUT_COMPLEX |
|
3364
bc17e8313ea0
use only j for imaginary constants
Guido van Rossum <guido@python.org>
parents:
3333
diff
changeset
|
769 if (c == 'j' || c == 'J') |
|
3333
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
770 /* Imaginary part */ |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
771 imaginary: |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
772 c = tok_nextc(tok); |
|
4b5bff95804e
changes for pow(**) and complex
Guido van Rossum <guido@python.org>
parents:
3116
diff
changeset
|
773 #endif |
| 6 | 774 } |
| 775 } | |
| 776 tok_backup(tok, c); | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
777 *p_start = tok->start; |
| 6 | 778 *p_end = tok->cur; |
| 779 return NUMBER; | |
| 780 } | |
|
5265
3c1788ab9761
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
781 |
|
3c1788ab9761
Support for alternative string quotes (a"xx", b"xx", c"xx", ...).
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
782 letter_quote: |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
783 /* String */ |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
784 if (c == '\'' || c == '"') { |
|
7315
3a55fbb99f20
Fixed the bug in searching for triple quotes -- change the 'quote2'
Guido van Rossum <guido@python.org>
parents:
7118
diff
changeset
|
785 int quote2 = tok->cur - tok->start + 1; |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
786 int quote = c; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
787 int triple = 0; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
788 int tripcount = 0; |
| 6 | 789 for (;;) { |
| 790 c = tok_nextc(tok); | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
791 if (c == '\n') { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
792 if (!triple) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
793 tok->done = E_TOKEN; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
794 tok_backup(tok, c); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
795 return ERRORTOKEN; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
796 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
797 tripcount = 0; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
798 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
799 else if (c == EOF) { |
| 6 | 800 tok->done = E_TOKEN; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
801 tok->cur = tok->inp; |
| 6 | 802 return ERRORTOKEN; |
| 803 } | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
804 else if (c == quote) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
805 tripcount++; |
|
7315
3a55fbb99f20
Fixed the bug in searching for triple quotes -- change the 'quote2'
Guido van Rossum <guido@python.org>
parents:
7118
diff
changeset
|
806 if (tok->cur - tok->start == quote2) { |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
807 c = tok_nextc(tok); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
808 if (c == quote) { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
809 triple = 1; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
810 tripcount = 0; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
811 continue; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
812 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
813 tok_backup(tok, c); |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
814 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
815 if (!triple || tripcount == 3) |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
816 break; |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
817 } |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
818 else if (c == '\\') { |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
819 tripcount = 0; |
| 6 | 820 c = tok_nextc(tok); |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
821 if (c == EOF) { |
| 6 | 822 tok->done = E_TOKEN; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
823 tok->cur = tok->inp; |
| 6 | 824 return ERRORTOKEN; |
| 825 } | |
| 826 } | |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
827 else |
|
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
828 tripcount = 0; |
| 6 | 829 } |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
830 *p_start = tok->start; |
|
1364
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1284
diff
changeset
|
831 *p_end = tok->cur; |
|
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1284
diff
changeset
|
832 return STRING; |
|
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1284
diff
changeset
|
833 } |
|
132602d854d8
Changes to accept double-quoted strings on input.
Guido van Rossum <guido@python.org>
parents:
1284
diff
changeset
|
834 |
| 6 | 835 /* Line continuation */ |
| 836 if (c == '\\') { | |
| 837 c = tok_nextc(tok); | |
| 838 if (c != '\n') { | |
| 839 tok->done = E_TOKEN; | |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
840 tok->cur = tok->inp; |
| 6 | 841 return ERRORTOKEN; |
| 842 } | |
| 843 goto again; /* Read next line */ | |
| 844 } | |
| 845 | |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
846 /* Check for two-character token */ |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
847 { |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
848 int c2 = tok_nextc(tok); |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
849 int token = PyToken_TwoChars(c, c2); |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
850 if (token != OP) { |
|
14163
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
851 int c3 = tok_nextc(tok); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
852 int token3 = PyToken_ThreeChars(c, c2, c3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
853 if (token3 != OP) { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
854 token = token3; |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
855 } else { |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
856 tok_backup(tok, c3); |
|
1b9fd0cbd914
Support for three-token characters (**=, >>=, <<=) which was written by
Thomas Wouters <thomas@python.org>
parents:
13659
diff
changeset
|
857 } |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
858 *p_start = tok->start; |
|
400
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
859 *p_end = tok->cur; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
860 return token; |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
861 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
862 tok_backup(tok, c2); |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
863 } |
|
d189a2f681a6
Added 2-char tokens and new versions of comparisons
Guido van Rossum <guido@python.org>
parents:
326
diff
changeset
|
864 |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
865 /* Keep track of parentheses nesting level */ |
|
1284
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
866 switch (c) { |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
867 case '(': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
868 case '[': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
869 case '{': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
870 tok->level++; |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
871 break; |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
872 case ')': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
873 case ']': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
874 case '}': |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
875 tok->level--; |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
876 break; |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
877 } |
|
dbce72afe261
* selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
878 |
| 6 | 879 /* Punctuation character */ |
|
1835
d799889c01e3
* Parser/tokenizer.c: backup over illegal newline in string
Guido van Rossum <guido@python.org>
parents:
1364
diff
changeset
|
880 *p_start = tok->start; |
| 6 | 881 *p_end = tok->cur; |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
882 return PyToken_OneChar(c); |
| 6 | 883 } |
| 884 | |
| 885 | |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4577
diff
changeset
|
886 #ifdef Py_DEBUG |
| 6 | 887 |
| 888 void | |
| 13659 | 889 tok_dump(int type, char *start, char *end) |
| 6 | 890 { |
|
5379
1c9a84e0981d
Another directory quickly renamed.
Guido van Rossum <guido@python.org>
parents:
5341
diff
changeset
|
891 printf("%s", _PyParser_TokenNames[type]); |
| 6 | 892 if (type == NAME || type == NUMBER || type == STRING || type == OP) |
| 893 printf("(%.*s)", (int)(end - start), start); | |
| 894 } | |
| 895 | |
| 896 #endif |
