summaryrefslogtreecommitdiffstats
path: root/Parser/tokenizer.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-04-09 21:38:06 (GMT)
committerGuido van Rossum <guido@python.org>1998-04-09 21:38:06 (GMT)
commit926f13a0819eb3d40a0d0fd38ff25ef0c7d489b3 (patch)
treea8328e6f26b187da5385cec3a0955ad8b4fc9539 /Parser/tokenizer.c
parente77a992a0d77fa09f0f541d8730d439abda81187 (diff)
downloadcpython-926f13a0819eb3d40a0d0fd38ff25ef0c7d489b3.zip
cpython-926f13a0819eb3d40a0d0fd38ff25ef0c7d489b3.tar.gz
cpython-926f13a0819eb3d40a0d0fd38ff25ef0c7d489b3.tar.bz2
Add checking for inconsistent tab usage
Diffstat (limited to 'Parser/tokenizer.c')
-rw-r--r--Parser/tokenizer.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index 21583ac..c2cb151 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -125,6 +125,11 @@ tok_new()
tok->prompt = tok->nextprompt = NULL;
tok->lineno = 0;
tok->level = 0;
+ tok->filename = NULL;
+ tok->altwarning = 0;
+ tok->alterror = 0;
+ tok->alttabsize = 1;
+ tok->altindstack[0] = 0;
return tok;
}
@@ -422,6 +427,24 @@ PyToken_TwoChars(c1, c2)
}
+static int
+indenterror(tok)
+ struct tok_state *tok;
+{
+ if (tok->alterror) {
+ tok->done = E_INDENT;
+ tok->cur = tok->inp;
+ return 1;
+ }
+ if (tok->altwarning) {
+ fprintf(stderr, "%s: inconsistent tab/space usage\n",
+ tok->filename);
+ tok->altwarning = 0;
+ }
+ return 0;
+}
+
+
/* Get next token, after space stripping etc. */
int
@@ -440,15 +463,19 @@ PyTokenizer_Get(tok, p_start, p_end)
/* Get indentation level */
if (tok->atbol) {
register int col = 0;
+ register int altcol = 0;
tok->atbol = 0;
for (;;) {
c = tok_nextc(tok);
if (c == ' ')
- col++;
- else if (c == '\t')
+ col++, altcol++;
+ else if (c == '\t') {
col = (col/tok->tabsize + 1) * tok->tabsize;
+ altcol = (altcol/tok->alttabsize + 1)
+ * tok->alttabsize;
+ }
else if (c == '\014') /* Control-L (formfeed) */
- col = 0; /* For Emacs users */
+ col = altcol = 0; /* For Emacs users */
else
break;
}
@@ -469,6 +496,10 @@ PyTokenizer_Get(tok, p_start, p_end)
if (!blankline && tok->level == 0) {
if (col == tok->indstack[tok->indent]) {
/* No change */
+ if (altcol != tok->altindstack[tok->indent]) {
+ if (indenterror(tok))
+ return ERRORTOKEN;
+ }
}
else if (col > tok->indstack[tok->indent]) {
/* Indent -- always one */
@@ -478,8 +509,13 @@ PyTokenizer_Get(tok, p_start, p_end)
tok->cur = tok->inp;
return ERRORTOKEN;
}
+ if (altcol <= tok->altindstack[tok->indent]) {
+ if (indenterror(tok))
+ return ERRORTOKEN;
+ }
tok->pendin++;
tok->indstack[++tok->indent] = col;
+ tok->altindstack[tok->indent] = altcol;
}
else /* col < tok->indstack[tok->indent] */ {
/* Dedent -- any number, must be consistent */
@@ -495,6 +531,10 @@ PyTokenizer_Get(tok, p_start, p_end)
tok->cur = tok->inp;
return ERRORTOKEN;
}
+ if (altcol != tok->altindstack[tok->indent]) {
+ if (indenterror(tok))
+ return ERRORTOKEN;
+ }
}
}
}