--nSaKzIhbgS Content-Type: text/plain; charset=us-ascii Content-Description: message body and .signature Content-Transfer-Encoding: 7bit Greg Stein writes: > Speaking out of my butt here, without looking at code, I would suspect that > the parser can return specializations "syntax error" to indicate that a > problem with indentation occurred. And I'm sure you'll find the way to do it. ;) Here's a patch that sets up the IndentationError and TabError exceptions, and gets TabError raised when -tt is in effect. If you can figure out how to get IndentationError raised for other indentation-related errors, I'll be interested in seeing it. Essentially, the parser-generator will need to be able to distinguish between INDENT/DEDENT errors and other errors, and I've not dug deep enough to figure that one out. The tab/space errors are easy since they're in the hand-coded lexer. -Fred -- Fred L. Drake, Jr. <fdrake at beopen.com> BeOpen PythonLabs Team Member --nSaKzIhbgS Content-Type: text/plain Content-Description: SyntaxError specialization Content-Disposition: inline; filename="indentation-error.patch" Content-Transfer-Encoding: 7bit *** cvs-python/Include/pyerrors.h Fri Jun 30 19:58:04 2000 --- python/Include/pyerrors.h Mon Jul 3 19:35:06 2000 *************** *** 54,59 **** --- 54,61 ---- extern DL_IMPORT(PyObject *) PyExc_RuntimeError; extern DL_IMPORT(PyObject *) PyExc_NotImplementedError; extern DL_IMPORT(PyObject *) PyExc_SyntaxError; + extern DL_IMPORT(PyObject *) PyExc_IndentationError; + extern DL_IMPORT(PyObject *) PyExc_TabError; extern DL_IMPORT(PyObject *) PyExc_SystemError; extern DL_IMPORT(PyObject *) PyExc_SystemExit; extern DL_IMPORT(PyObject *) PyExc_TypeError; *** cvs-python/Lib/test/test_exceptions.py Tue Jun 20 14:52:57 2000 --- python/Lib/test/test_exceptions.py Tue Jul 4 00:36:58 2000 *************** *** 86,91 **** --- 86,99 ---- try: exec '/\n' except SyntaxError: pass + r(IndentationError) + + r(TabError) + # can only be tested under -tt, and is the only test for -tt + #try: compile("try:\n\t1/0\n \t1/0\nfinally:\n pass\n", '<string>', 'exec') + #except TabError: pass + #else: raise TestFailed + r(SystemError) print '(hard to reproduce)' *** cvs-python/Lib/test/output/test_exceptions Sun Jun 25 06:44:57 2000 --- python/Lib/test/output/test_exceptions Tue Jul 4 00:43:31 2000 *************** *** 28,33 **** --- 28,37 ---- spam SyntaxError spam + IndentationError + spam + TabError + spam SystemError (hard to reproduce) spam *** cvs-python/Python/exceptions.c Sat Jul 1 00:45:52 2000 --- python/Python/exceptions.c Mon Jul 3 19:34:25 2000 *************** *** 68,73 **** --- 68,78 ---- |\n\ +-- AttributeError\n\ +-- SyntaxError\n\ + | |\n\ + | +-- IndentationError\n\ + | |\n\ + | +-- TabError\n\ + |\n\ +-- TypeError\n\ +-- AssertionError\n\ +-- LookupError\n\ *************** *** 773,778 **** --- 778,789 ---- static char MemoryError__doc__[] = "Out of memory."; + static char + IndentationError__doc__[] = "Improper indentation."; + + static char + TabError__doc__[] = "Improper mixture of spaces and tabs."; + /* module global functions */ *************** *** 807,812 **** --- 818,825 ---- PyObject *PyExc_RuntimeError; PyObject *PyExc_NotImplementedError; PyObject *PyExc_SyntaxError; + PyObject *PyExc_IndentationError; + PyObject *PyExc_TabError; PyObject *PyExc_SystemError; PyObject *PyExc_SystemExit; PyObject *PyExc_UnboundLocalError; *************** *** 868,873 **** --- 881,890 ---- {"AttributeError", &PyExc_AttributeError, 0, AttributeError__doc__}, {"SyntaxError", &PyExc_SyntaxError, 0, SyntaxError__doc__, SyntaxError_methods, SyntaxError__classinit__}, + {"IndentationError", &PyExc_IndentationError, &PyExc_SyntaxError, + IndentationError__doc__}, + {"TabError", &PyExc_TabError, &PyExc_IndentationError, + TabError__doc__}, {"AssertionError", &PyExc_AssertionError, 0, AssertionError__doc__}, {"LookupError", &PyExc_LookupError, 0, LookupError__doc__}, {"IndexError", &PyExc_IndexError, &PyExc_LookupError, *** cvs-python/Python/pythonrun.c Fri Jun 30 19:58:06 2000 --- python/Python/pythonrun.c Mon Jul 3 20:01:33 2000 *************** *** 983,990 **** err_input(err) perrdetail *err; { ! PyObject *v, *w; char *msg = NULL; v = Py_BuildValue("(ziiz)", err->filename, err->lineno, err->offset, err->text); if (err->text != NULL) { --- 983,991 ---- err_input(err) perrdetail *err; { ! PyObject *v, *w, *errtype; char *msg = NULL; + errtype = PyExc_SyntaxError; v = Py_BuildValue("(ziiz)", err->filename, err->lineno, err->offset, err->text); if (err->text != NULL) { *************** *** 1010,1015 **** --- 1011,1017 ---- msg = "unexpected EOF while parsing"; break; case E_INDENT: + errtype = PyExc_TabError; msg = "inconsistent use of tabs and spaces in indentation"; break; case E_OVERFLOW: *************** *** 1022,1028 **** } w = Py_BuildValue("(sO)", msg, v); Py_XDECREF(v); ! PyErr_SetObject(PyExc_SyntaxError, w); Py_XDECREF(w); } --- 1024,1030 ---- } w = Py_BuildValue("(sO)", msg, v); Py_XDECREF(v); ! PyErr_SetObject(errtype, w); Py_XDECREF(w); } --nSaKzIhbgS--
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4