summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--generic/tclCompExpr.c36
2 files changed, 38 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 01b575a..5d04b8d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2007-07-09 Don Porter <dgp@users.sourceforge.net>
+ * generic/tclCompExpr.c: Revision so that the END lexeme never
+ gets inserted into the parse tree. Later tree traversal never reaches
+ it since its location in the tree is not variable. Starting and
+ stopping with the START lexeme (node 0) is sufficient. Also finished
+ lexeme code commentary.
+
* generic/tclCompExpr.c: Added missing creation and return
of the Tcl_Parse fields that indicate error conditions. [Bug 1749987]
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c
index 3474562..7741634 100644
--- a/generic/tclCompExpr.c
+++ b/generic/tclCompExpr.c
@@ -10,7 +10,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.60 2007/07/09 14:51:44 dgp Exp $
+ * RCS: @(#) $Id: tclCompExpr.c,v 1.61 2007/07/09 17:34:14 dgp Exp $
*/
#include "tclInt.h"
@@ -70,7 +70,7 @@
/* Leaf lexemes */
#define NUMBER ( LEAF | 1) /* For literal numbers */
-#define SCRIPT ( LEAF | 2) /* Command substitution; [foo] */
+#define SCRIPT ( LEAF | 2) /* Script substitution; [foo] */
#define BOOLEAN ( LEAF | BAREWORD) /* For literal booleans */
#define BRACED ( LEAF | 4) /* Braced string; {foo bar} */
#define VARIABLE ( LEAF | 5) /* Variable substitution; $x */
@@ -163,8 +163,33 @@
* ParseExpr(). */
#define IN_LIST ( BINARY | 25)
#define NOT_IN_LIST ( BINARY | 26)
-#define CLOSE_PAREN ( BINARY | 27) /**/
-#define END ( BINARY | 28) /**/
+#define CLOSE_PAREN ( BINARY | 27) /* By categorizing the CLOSE_PAREN
+ * lexeme as a BINARY operator, the
+ * normal parsing rules for binary
+ * operators assure that a close paren
+ * will not directly follow another
+ * operator, and the machinery already
+ * in place to connect operands to
+ * operators according to precedence
+ * performs most of the work of
+ * matching open and close parens for
+ * us. In the end though, a close
+ * paren is not really a binary
+ * operator, and some special coding
+ * in ParseExpr() make sure we never
+ * put an actual CLOSE_PAREN node
+ * in the parse tree. The
+ * sub-expression between parens
+ * becomes the single argument of
+ * the matching OPEN_PAREN unary
+ * operator. */
+#define END ( BINARY | 28) /* This lexeme represents the end of
+ * the string being parsed. Treating
+ * it as a binary operator follows the
+ * same logic as the CLOSE_PAREN lexeme
+ * and END pairs with START, in the
+ * same way that CLOSE_PAREN pairs with
+ * OPEN_PAREN. */
/*
* Integer codes indicating the form of an operand of an operator.
@@ -793,6 +818,9 @@ ParseExpr(
code = TCL_ERROR;
continue;
}
+ if (lexeme == END) {
+ continue;
+ }
/*
* Link orphan as left operand of new node.