[Python-checkins] CVS: python/dist/src/Python exceptions.c,1.6,1.7 pythonrun.c,2.101,2.102

Fred L. Drake python-dev@python.org
2000年7月11日 10:53:03 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv7915/Python
Modified Files:
	exceptions.c pythonrun.c 
Log Message:
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.
Index: exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** exceptions.c	2000年07月09日 22:27:10	1.6
--- exceptions.c	2000年07月11日 17:52:59	1.7
***************
*** 69,72 ****
--- 69,77 ----
 +-- AttributeError\n\
 +-- SyntaxError\n\
+ | |\n\
+ | +-- IndentationError\n\
+ | |\n\
+ | +-- TabError\n\
+ |\n\
 +-- TypeError\n\
 +-- AssertionError\n\
***************
*** 784,787 ****
--- 789,798 ----
 MemoryError__doc__[] = "Out of memory.";
 
+ static char
+ IndentationError__doc__[] = "Improper indentation.";
+ 
+ static char
+ TabError__doc__[] = "Improper mixture of spaces and tabs.";
+ 
 
 
***************
*** 818,821 ****
--- 829,834 ----
 PyObject *PyExc_NotImplementedError;
 PyObject *PyExc_SyntaxError;
+ PyObject *PyExc_IndentationError;
+ PyObject *PyExc_TabError;
 PyObject *PyExc_SystemError;
 PyObject *PyExc_SystemExit;
***************
*** 879,882 ****
--- 892,899 ----
 {"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__},
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.101
retrieving revision 2.102
diff -C2 -r2.101 -r2.102
*** pythonrun.c	2000年07月09日 03:09:56	2.101
--- pythonrun.c	2000年07月11日 17:53:00	2.102
***************
*** 15,18 ****
--- 15,19 ----
 #include "grammar.h"
 #include "node.h"
+ #include "token.h"
 #include "parsetok.h"
 #include "errcode.h"
***************
*** 984,989 ****
 	perrdetail *err;
 {
! 	PyObject *v, *w;
 	char *msg = NULL;
 	v = Py_BuildValue("(ziiz)", err->filename,
 			 err->lineno, err->offset, err->text);
--- 985,991 ----
 	perrdetail *err;
 {
! 	PyObject *v, *w, *errtype;
 	char *msg = NULL;
+ 	errtype = PyExc_SyntaxError;
 	v = Py_BuildValue("(ziiz)", err->filename,
 			 err->lineno, err->offset, err->text);
***************
*** 994,998 ****
 	switch (err->error) {
 	case E_SYNTAX:
! 		msg = "invalid syntax";
 		break;
 	case E_TOKEN:
--- 996,1010 ----
 	switch (err->error) {
 	case E_SYNTAX:
! 		errtype = PyExc_IndentationError;
! 		if (err->expected == INDENT)
! 			msg = "expected an indented block";
! 		else if (err->token == INDENT)
! 			msg = "unexpected indent";
! 		else if (err->token == DEDENT)
! 			msg = "unexpected unindent";
! 		else {
! 			errtype = PyExc_SyntaxError;
! 			msg = "invalid syntax";
! 		}
 		break;
 	case E_TOKEN:
***************
*** 1010,1014 ****
 		msg = "unexpected EOF while parsing";
 		break;
! 	case E_INDENT:
 		msg = "inconsistent use of tabs and spaces in indentation";
 		break;
--- 1022,1027 ----
 		msg = "unexpected EOF while parsing";
 		break;
! 	case E_TABSPACE:
! 		errtype = PyExc_TabError;
 		msg = "inconsistent use of tabs and spaces in indentation";
 		break;
***************
*** 1016,1019 ****
--- 1029,1040 ----
 		msg = "expression too long";
 		break;
+ 	case E_DEDENT:
+ 		errtype = PyExc_IndentationError;
+ 		msg = "unindent does not match any outer indentation level";
+ 		break;
+ 	case E_TOODEEP:
+ 		errtype = PyExc_IndentationError;
+ 		msg = "too many levels of indentation";
+ 		break;
 	default:
 		fprintf(stderr, "error=%d\n", err->error);
***************
*** 1023,1027 ****
 	w = Py_BuildValue("(sO)", msg, v);
 	Py_XDECREF(v);
! 	PyErr_SetObject(PyExc_SyntaxError, w);
 	Py_XDECREF(w);
 }
--- 1044,1048 ----
 	w = Py_BuildValue("(sO)", msg, v);
 	Py_XDECREF(v);
! 	PyErr_SetObject(errtype, w);
 	Py_XDECREF(w);
 }

AltStyle によって変換されたページ (->オリジナル) /