diff options
author | dgp <dgp@users.sourceforge.net> | 2007-07-16 19:50:41 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2007-07-16 19:50:41 (GMT) |
commit | 6122754a220a2b6625224214b2560b4c3f594e4b (patch) | |
tree | 4b0cbdf1fa486e3764329308f95b98433b6fd35b /generic | |
parent | 63bfe35d1acdbed6099149dc3b8cbf5ea1c8413d (diff) | |
download | tcl-6122754a220a2b6625224214b2560b4c3f594e4b.zip tcl-6122754a220a2b6625224214b2560b4c3f594e4b.tar.gz tcl-6122754a220a2b6625224214b2560b4c3f594e4b.tar.bz2 |
* generic/tclCompExpr.c: More commentary.
* tests/parseExpr.test: Several tests of syntax error messages
to check that when expression substrings are truncated they leave
visible the context relevant to the reported error.
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCompExpr.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index da9007f..bab56f5 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclCompExpr.c,v 1.68 2007/07/12 22:13:12 dgp Exp $ + * RCS: @(#) $Id: tclCompExpr.c,v 1.69 2007/07/16 19:50:46 dgp Exp $ */ #include "tclInt.h" @@ -514,6 +514,7 @@ ParseExpr( nodes->precedence = prec[lexeme]; nodes->left = OT_NONE; nodes->right = OT_NONE; + /* TODO: explain. */ nodes->parent = -1; nodesUsed++; } @@ -849,19 +850,32 @@ ParseExpr( } /* case LEAF */ case UNARY: + /* + * A unary operator appearing just after something that's not an + * operator is a syntax error -- something trying to be the left + * operand of an operator that doesn't take one. + */ if (NotOperator(lastParsed)) { msg = Tcl_ObjPrintf("missing operator at %s", mark); scanned = 0; insertMark = 1; code = TCL_ERROR; + /* Escape the parse loop to report the syntax error. */ continue; } - lastParsed = nodesUsed; - nodePtr->lexeme = lexeme; - nodePtr->precedence = prec[lexeme]; - nodePtr->left = OT_NONE; - nodePtr->right = OT_NONE; + /* Create an OpNode for the unary operator */ + nodePtr->lexeme = lexeme; /* Remember the operator... */ + nodePtr->precedence = prec[lexeme]; /* ... and its precedence. */ + nodePtr->left = OT_NONE; /* No left operand */ + nodePtr->right = OT_NONE; /* Right operand not + * yet known. */ + /* TODO: explain */ nodePtr->parent = nodePtr - nodes - 1; + /* + * Remember this unary operator as the last thing parsed for + * the next pass through the loop. + */ + lastParsed = nodesUsed; nodesUsed++; break; @@ -869,6 +883,11 @@ ParseExpr( OpNode *otherPtr = NULL; unsigned char precedence = prec[lexeme]; + /* + * A binary operand appearing just after another operator is a + * syntax error -- one of the two operators is missing an operand. + */ + if (IsOperator(lastParsed)) { if ((lexeme == CLOSE_PAREN) && (nodePtr[-1].lexeme == OPEN_PAREN)) { @@ -879,6 +898,7 @@ ParseExpr( */ scanned = 0; + /* TODO: explain */ lastParsed = OT_EMPTY; nodePtr[-1].left--; break; @@ -923,6 +943,7 @@ ParseExpr( continue; } + /* TODO: explain */ if (lastParsed == OT_NONE) { otherPtr = nodes + lastOpen - 1; lastParsed = lastOpen; |