bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)

Also point to start of tokens in parsing errors.

Fixes bpo-34683
This commit is contained in:
Ammar Askar 2018-09-24 17:12:49 -04:00 committed by Guido van Rossum
parent 223e501fb9
commit 025eb98dc0
11 changed files with 65 additions and 21 deletions

View file

@ -390,7 +390,7 @@ error_at_directive(PySTEntryObject *ste, PyObject *name)
if (PyUnicode_Compare(PyTuple_GET_ITEM(data, 0), name) == 0) {
PyErr_SyntaxLocationObject(ste->ste_table->st_filename,
PyLong_AsLong(PyTuple_GET_ITEM(data, 1)),
PyLong_AsLong(PyTuple_GET_ITEM(data, 2)));
PyLong_AsLong(PyTuple_GET_ITEM(data, 2)) + 1);
return 0;
}
@ -990,7 +990,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
PyErr_Format(PyExc_SyntaxError, DUPLICATE_ARGUMENT, name);
PyErr_SyntaxLocationObject(st->st_filename,
st->st_cur->ste_lineno,
st->st_cur->ste_col_offset);
st->st_cur->ste_col_offset + 1);
goto error;
}
val |= flag;
@ -1179,7 +1179,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
e_name->v.Name.id);
PyErr_SyntaxLocationObject(st->st_filename,
s->lineno,
s->col_offset);
s->col_offset + 1);
VISIT_QUIT(st, 0);
}
if (s->v.AnnAssign.simple &&
@ -1274,7 +1274,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
msg, name);
PyErr_SyntaxLocationObject(st->st_filename,
s->lineno,
s->col_offset);
s->col_offset + 1);
VISIT_QUIT(st, 0);
}
if (!symtable_add_def(st, name, DEF_GLOBAL))
@ -1306,7 +1306,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
PyErr_Format(PyExc_SyntaxError, msg, name);
PyErr_SyntaxLocationObject(st->st_filename,
s->lineno,
s->col_offset);
s->col_offset + 1);
VISIT_QUIT(st, 0);
}
if (!symtable_add_def(st, name, DEF_NONLOCAL))
@ -1645,7 +1645,7 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
int lineno = st->st_cur->ste_lineno;
int col_offset = st->st_cur->ste_col_offset;
PyErr_SetString(PyExc_SyntaxError, IMPORT_STAR_WARNING);
PyErr_SyntaxLocationObject(st->st_filename, lineno, col_offset);
PyErr_SyntaxLocationObject(st->st_filename, lineno, col_offset + 1);
Py_DECREF(store_name);
return 0;
}
@ -1736,7 +1736,7 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
"'yield' inside generator expression");
PyErr_SyntaxLocationObject(st->st_filename,
st->st_cur->ste_lineno,
st->st_cur->ste_col_offset);
st->st_cur->ste_col_offset + 1);
symtable_exit_block(st, (void *)e);
return 0;
}