diff options
-rw-r--r-- | jim.c | 21 | ||||
-rw-r--r-- | jim_tcl.txt | 9 | ||||
-rw-r--r-- | tests/expr-new.test | 21 | ||||
-rw-r--r-- | tests/expr-old.test | 8 |
4 files changed, 49 insertions, 10 deletions
@@ -8810,13 +8810,22 @@ static const struct Jim_ExprOperator Jim_ExprOperators[] = { static int JimParseExpression(struct JimParserCtx *pc) { - /* Discard spaces and quoted newline */ - while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) { - if (*pc->p == '\n') { - pc->linenr++; + while (1) { + /* Discard spaces and quoted newline */ + while (isspace(UCHAR(*pc->p)) || (*(pc->p) == '\\' && *(pc->p + 1) == '\n')) { + if (*pc->p == '\n') { + pc->linenr++; + } + pc->p++; + pc->len--; } - pc->p++; - pc->len--; + /* Discard comments */ + if (*pc->p == '#') { + JimParseComment(pc); + /* Go back to discarding white space */ + continue; + } + break; } /* Common case */ diff --git a/jim_tcl.txt b/jim_tcl.txt index f07ca14..73615c6 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -3,7 +3,7 @@ Jim Tcl(n) NAME ---- -Jim Tcl v0.80 - reference manual for the Jim Tcl scripting language +Jim Tcl v0.80+ - reference manual for the Jim Tcl scripting language SYNOPSIS -------- @@ -52,6 +52,10 @@ Some notable differences with Tcl 8.5/8.6/8.7 are: RECENT CHANGES -------------- +Changes since 0.80 +~~~~~~~~~~~~~~~~~~ +1. TIP 582, comments allowed in expressions + Changes between 0.79 and 0.80 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. `regsub` now fully supports +{backslash}A+ @@ -725,6 +729,9 @@ White space may be used between the operands and operators and parentheses; it is ignored by the expression processor. Where possible, operands are interpreted as integer values. +Comments are allowed in expressions, beginning with the '#' character +and continuing until the end of line or end of expression. + Integer values are interpreted as decimal, binary, octal or hexadecimal if prepended with '0d', '0b', '0o' or '0x' respectively. Otherwise they are interpreted as decimal by default. diff --git a/tests/expr-new.test b/tests/expr-new.test index 6f62586..09a7143 100644 --- a/tests/expr-new.test +++ b/tests/expr-new.test @@ -710,6 +710,27 @@ test expr-22.12 {expr} { expr {inf} } {Inf} +test expr-23.1 {expr TIP 582 comments} { + expr {1 + # comment on line 1 + 2} +} {3} + +test expr-23.2 {expr TIP 582 comments} { + expr {1 + + # comment on line 2 + 2 + } +} {3} + +test expr-23.3 {expr TIP 582 comments} { + expr {1 + + # Multiple lines + # of comments + 2 + } +} {3} + + # cleanup if {[info exists a]} { diff --git a/tests/expr-old.test b/tests/expr-old.test index f5422eb..796ae3f 100644 --- a/tests/expr-old.test +++ b/tests/expr-old.test @@ -443,9 +443,11 @@ test expr-old-26.9 {error conditions} { test expr-old-26.10 {error conditions} { expr 2.0/0.0 } {Inf} -test expr-old-26.11 {error conditions} { - list [catch {expr 2#} msg] -} {1} +# Note that this is no longer an error with TIP 582 +# +#test expr-old-26.11 {error conditions} { +# list [catch {expr 2#} msg] +#} {1} test expr-old-26.12 {error conditions} { list [catch {expr a.b} msg] } {1} |