diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2020-08-24 13:31:00 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2020-08-24 13:31:00 (GMT) |
commit | fe94c1d6c4fa1c0d810d2eb6b845e7d0faf8812c (patch) | |
tree | 8142f58dec8cbaef0dbba7953de362400c6c4cb4 | |
parent | 1192757fb71a5f28fa60aa3e5c23ac851adabc3e (diff) | |
download | tcl-fe94c1d6c4fa1c0d810d2eb6b845e7d0faf8812c.zip tcl-fe94c1d6c4fa1c0d810d2eb6b845e7d0faf8812c.tar.gz tcl-fe94c1d6c4fa1c0d810d2eb6b845e7d0faf8812c.tar.bz2 |
Tricky case in function calls.
-rw-r--r-- | generic/tclCompExpr.c | 33 | ||||
-rw-r--r-- | tests/expr.test | 16 |
2 files changed, 46 insertions, 3 deletions
diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index 5c5a491..30ca876 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -676,9 +676,10 @@ ParseExpr( OpNode *newPtr = NULL; do { - if (size <= UINT_MAX/sizeof(OpNode)) { - newPtr = (OpNode *)attemptckrealloc(nodes, size * sizeof(OpNode)); - } + if (size <= UINT_MAX/sizeof(OpNode)) { + newPtr = (OpNode *) attemptckrealloc(nodes, + size * sizeof(OpNode)); + } } while ((newPtr == NULL) && ((size -= (size - nodesUsed) / 2) > nodesUsed)); if (newPtr == NULL) { @@ -748,6 +749,32 @@ ParseExpr( } else if (Tcl_GetBooleanFromObj(NULL,literal,&b) == TCL_OK) { lexeme = BOOLEAN; } else { + /* + * Tricky case: see test expr-62.10 + */ + + int scanned2 = scanned; + do { + scanned2 += TclParseAllWhiteSpace( + start + scanned2, numBytes - scanned2); + scanned2 += ParseLexeme( + start + scanned2, numBytes - scanned2, &lexeme, + NULL); + } while (lexeme == COMMENT); + if (lexeme == OPEN_PAREN) { + /* + * Actually a function call, but with obscuring + * comments. Skip to the start of the parentheses. + * Note that we assume that open parentheses are one + * byte long. + */ + + lexeme = FUNCTION; + Tcl_ListObjAppendElement(NULL, funcList, literal); + scanned = scanned2 - 1; + break; + } + Tcl_DecrRefCount(literal); msg = Tcl_ObjPrintf("invalid bareword \"%.*s%s\"", (scanned < limit) ? scanned : limit - 3, start, diff --git a/tests/expr.test b/tests/expr.test index 41d028b..4e8706f 100644 --- a/tests/expr.test +++ b/tests/expr.test @@ -7429,6 +7429,22 @@ test expr-62.6 {TIP 582: comments don't splice tokens} { ne#don't splice 2} } 1 +test expr-62.7 {TIP 582: comments can go inside function calls} { + expr {max(1,# comment + 2)} +} 2 +test expr-62.8 {TIP 582: comments can go inside function calls} { + expr {max(1# comment + ,2)} +} 2 +test expr-62.9 {TIP 582: comments can go inside function calls} { + expr {max(# comment + 1,2)} +} 2 +test expr-62.10 {TIP 582: comments can go inside function calls} { + expr {max# comment + (1,2)} +} 2 # cleanup unset -nocomplain a |