Ticket UUID: | 1201589 | |||
Title: | bareword madness in expr parser | |||
Type: | Bug | Version: | obsolete: 8.4.14 | |
Submitter: | dgp | Created on: | 2005-05-13 18:31:45 | |
Subsystem: | 45. Parsing and Eval | Assigned To: | dgp | |
Priority: | 5 Medium | Severity: | ||
Status: | Open | Last Modified: | 2008-03-12 22:43:46 | |
Resolution: | Fixed | Closed By: | dgp | |
Closed on: | 2005-05-25 16:09:05 | |||
Description: |
dgp% if {yes} {puts foo} foo % if {!no} {puts foo} foo % if {y} {puts foo} foo % if {!n} {puts foo} syntax error in expression "!n": the word "n" requires a preceding $ if it's a variable or function arguments if it's a function kbkdgp - You have the appropriate logic in the 'n' case in tclParseExpr.c(GetLexeme)? kbkHmmm, ok, I see that you did it farther down, in the 'default' branch, but look for those literals exactly, not with unique-prefix matching. [14:22]kbkHmm. I don't really like unique-prefix matching in this context. [14:23]kbkbut if we do it, we should do it only if all else fails. [14:23]dgpwell, the parser doesn't (can't?) check the validity of function names. [14:23]kbkwhich is to say, *don't* do it if the bareword is followed by optional whitespace and a left paren. [14:24]kbkbecause false() isn't a valid expr. [14:24]dgphmmm.... parens... [14:24]kbkunless there's a function so named. [14:25]kbkeq, ne, in, ni, would need further handling somehow, though, becase $a eq("stuff") is valid, and is not a function call. [14:27]kbkand *that* interpretation depends on left context; the eq, ne, in, ni operators are operators only if they follow a constant, a variable, or a right paren. [14:27]kbkUgh. [14:27]kbkI'm starting to think that expr has outgrown a recursive-descent parser. | |||
User Comments: |
hobbs added on 2006-11-08 00:40:27:
Logged In: YES user_id=72656 FWIW, users find the single char bareword handling of booleans surprising: http://bugs.activestate.com/show_bug.cgi?id=59177 While I could see the pattern straight off, not even other expert Tcl'ers could, and it is eyebrow raising. This needs at least clear exception docs in expr.n, if not other consideration for correction. dgp added on 2005-05-25 23:09:04: Logged In: YES user_id=80530 TIP 182 implementation includes tests for the improved bareword parser. dgp added on 2005-05-20 22:30:02: Logged In: YES user_id=80530 Committed for 8.4.10 and 8.5a3. Leaving report open because some tests really ought to be added to the test suite for this. (Volunteers invited!) dgp added on 2005-05-20 22:19:42: File Added - 135280: 1201589-84.patch dgp added on 2005-05-20 22:19:41: Logged In: YES user_id=80530 and here's a version suitable for application to the 8.4 branch. dgp added on 2005-05-20 22:04:58: File Added - 135277: 1201589-2.patch dgp added on 2005-05-20 22:04:57: Logged In: YES user_id=80530 second version of the patch is limited to just fixing the boolean literal prefix problem, as well as accepting as function names "eq" "ne" "in" and "ni" when they appear in the context for a function name rather than an operator. Treatment of other barewords is left unchanged. dgp added on 2005-05-20 21:29:58: File Added - 135271: 1201589.patch dgp added on 2005-05-20 21:29:55: Logged In: YES user_id=80530 Attached patch makes expr parser accept *all* barewords as literals, which then includes the reported problem of accepting boolean value prefix barewords as literals. |