diff options
author | Fred Drake <fdrake@acm.org> | 2000-07-11 17:53:00 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2000-07-11 17:53:00 (GMT) |
commit | 85f363990cbd6df21015eebdc171c533176e3407 (patch) | |
tree | 4aa69857ffe21991384e379799f42ba308a58086 /Parser | |
parent | 88e1932930245b2f7ed300ff8b31034db7ecda5b (diff) | |
download | cpython-85f363990cbd6df21015eebdc171c533176e3407.zip cpython-85f363990cbd6df21015eebdc171c533176e3407.tar.gz cpython-85f363990cbd6df21015eebdc171c533176e3407.tar.bz2 |
Create two new exceptions: IndentationError and TabError. These are
used for indentation related errors. This patch includes Ping's
improvements for indentation-related error messages.
Closes SourceForge patches #100734 and #100856.
Diffstat (limited to 'Parser')
-rw-r--r-- | Parser/parser.c | 12 | ||||
-rw-r--r-- | Parser/parser.h | 3 | ||||
-rw-r--r-- | Parser/parsetok.c | 4 | ||||
-rw-r--r-- | Parser/tokenizer.c | 14 |
4 files changed, 20 insertions, 13 deletions
diff --git a/Parser/parser.c b/Parser/parser.c index ee40f21..b74de7f 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -205,11 +205,12 @@ classify(g, type, str) } int -PyParser_AddToken(ps, type, str, lineno) +PyParser_AddToken(ps, type, str, lineno, expected_ret) register parser_state *ps; register int type; char *str; int lineno; + int *expected_ret; { register int ilabel; int err; @@ -285,6 +286,15 @@ PyParser_AddToken(ps, type, str, lineno) /* Stuck, report syntax error */ D(printf(" Error.\n")); + if (expected_ret) { + if (s->s_lower == s->s_upper - 1) { + /* Only one possible expected token */ + *expected_ret = ps->p_grammar-> + g_ll.ll_label[s->s_lower].lb_type; + } + else + *expected_ret = -1; + } return E_SYNTAX; } } diff --git a/Parser/parser.h b/Parser/parser.h index 6087373..d0df8cf 100644 --- a/Parser/parser.h +++ b/Parser/parser.h @@ -38,7 +38,8 @@ typedef struct { parser_state *PyParser_New(grammar *g, int start); void PyParser_Delete(parser_state *ps); -int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno); +int PyParser_AddToken(parser_state *ps, int type, char *str, int lineno, + int *expected_ret); void PyGrammar_AddAccelerators(grammar *g); #ifdef __cplusplus diff --git a/Parser/parsetok.c b/Parser/parsetok.c index 9ac1606..9d090f1 100644 --- a/Parser/parsetok.c +++ b/Parser/parsetok.c @@ -139,8 +139,8 @@ parsetok(tok, g, start, err_ret) strncpy(str, a, len); str[len] = '\0'; if ((err_ret->error = - PyParser_AddToken(ps, (int)type, str, - tok->lineno)) != E_OK) { + PyParser_AddToken(ps, (int)type, str, tok->lineno, + &(err_ret->expected))) != E_OK) { if (err_ret->error != E_DONE) PyMem_DEL(str); break; diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 0ef3fc0..d4ec345 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -412,13 +412,13 @@ indenterror(tok) struct tok_state *tok; { if (tok->alterror) { - tok->done = E_INDENT; + tok->done = E_TABSPACE; tok->cur = tok->inp; return 1; } if (tok->altwarning) { - PySys_WriteStderr("%s: inconsistent tab/space usage\n", - tok->filename); + PySys_WriteStderr("%s: inconsistent use of tabs and spaces " + "in indentation\n", tok->filename); tok->altwarning = 0; } return 0; @@ -484,9 +484,7 @@ PyTokenizer_Get(tok, p_start, p_end) else if (col > tok->indstack[tok->indent]) { /* Indent -- always one */ if (tok->indent+1 >= MAXINDENT) { - PySys_WriteStderr( - "excessive indent\n"); - tok->done = E_TOKEN; + tok->done = E_TOODEEP; tok->cur = tok->inp; return ERRORTOKEN; } @@ -506,9 +504,7 @@ PyTokenizer_Get(tok, p_start, p_end) tok->indent--; } if (col != tok->indstack[tok->indent]) { - PySys_WriteStderr( - "inconsistent dedent\n"); - tok->done = E_TOKEN; + tok->done = E_DEDENT; tok->cur = tok->inp; return ERRORTOKEN; } |