diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | generic/tclParseExpr.c | 50 | ||||
-rw-r--r-- | tests/expr.test | 16 |
3 files changed, 70 insertions, 4 deletions
@@ -1,3 +1,11 @@ +2001-04-09 Donal K. Fellows <fellowsd@cs.man.ac.uk> + + * tests/expr.test (expr-21.*): Tests to check below fix. + * generic/tclParseExpr.c (GetLexeme): Now recognises the + non-numeric boolean literals for what they are. It no longer makes + sense for anyone to create functions with the same name as one of + them, but this was true in 7.* as well [Bug #217777; finally!] + 2001-04-07 Miguel Sofer <msofer@users.sourceforge.net> * generic/tclExecute.c: Avoid panic when there are extra items in diff --git a/generic/tclParseExpr.c b/generic/tclParseExpr.c index fbdd9ea..ccd58a9 100644 --- a/generic/tclParseExpr.c +++ b/generic/tclParseExpr.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: tclParseExpr.c,v 1.7 2000/05/09 00:00:35 hobbs Exp $ + * RCS: @(#) $Id: tclParseExpr.c,v 1.8 2001/04/09 09:48:41 dkf Exp $ */ #include "tclInt.h" @@ -1199,7 +1199,7 @@ ParsePrimaryExpr(infoPtr) exprTokenPtr->size = infoPtr->size; exprTokenPtr->numComponents = 1; break; - + case DOLLAR: /* * $var variable reference. @@ -1406,7 +1406,7 @@ ParsePrimaryExpr(infoPtr) exprTokenPtr->size = (infoPtr->next - exprTokenPtr->start); exprTokenPtr->numComponents = parsePtr->numTokens - firstIndex; break; - + default: goto syntaxError; } @@ -1778,6 +1778,50 @@ GetLexeme(infoPtr) infoPtr->size = (src - infoPtr->start); infoPtr->next = src; parsePtr->term = infoPtr->next; + /* + * Check for boolean literals (true, false, yes, no, on, off) + */ + switch (infoPtr->start[0]) { + case 'f': + if (infoPtr->size == 5 && + strncmp("false", infoPtr->start, 5) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } + break; + case 'n': + if (infoPtr->size == 2 && + strncmp("no", infoPtr->start, 2) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } + break; + case 'o': + if (infoPtr->size == 3 && + strncmp("off", infoPtr->start, 3) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } else if (infoPtr->size == 2 && + strncmp("on", infoPtr->start, 2) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } + break; + case 't': + if (infoPtr->size == 4 && + strncmp("true", infoPtr->start, 4) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } + break; + case 'y': + if (infoPtr->size == 3 && + strncmp("yes", infoPtr->start, 3) == 0) { + infoPtr->lexeme = LITERAL; + return TCL_OK; + } + break; + } return TCL_OK; } infoPtr->lexeme = UNKNOWN; diff --git a/tests/expr.test b/tests/expr.test index 05b8f9d..b4487e3 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -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: expr.test,v 1.11 2000/11/24 15:14:01 dkf Exp $ +# RCS: @(#) $Id: expr.test,v 1.12 2001/04/09 09:48:41 dkf Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -753,6 +753,20 @@ test expr-20.7 {handling of compile error in runtime case} { list [catch {expr + {[error foo]}} msg] $msg } {1 foo} +# Test for non-numeric boolean literal handling +test expr-21.1 {non-numeric boolean literals} {expr false } false +test expr-21.2 {non-numeric boolean literals} {expr true } true +test expr-21.3 {non-numeric boolean literals} {expr off } off +test expr-21.4 {non-numeric boolean literals} {expr on } on +test expr-21.5 {non-numeric boolean literals} {expr no } no +test expr-21.6 {non-numeric boolean literals} {expr yes } yes +test expr-21.7 {non-numeric boolean literals} {expr !false} 1 +test expr-21.8 {non-numeric boolean literals} {expr !true } 0 +test expr-21.9 {non-numeric boolean literals} {expr !off } 1 +test expr-21.10 {non-numeric boolean literals} {expr !on } 0 +test expr-21.11 {non-numeric boolean literals} {expr !no } 1 +test expr-21.12 {non-numeric boolean literals} {expr !yes } 0 + # cleanup if {[info exists a]} { unset a |