Tcl Source Code

View Ticket
Login
Ticket UUID: e1053b00394c6ed4bd9446e521fe17a9002a156d
Title: Need clarification on syntax ambiguity: double quotes vs command substitution
Type: Bug Created on: 2025-09-09 07:15:20
Submitter: anonymous Assigned to: nobody
Subsystem: None Severity: Minor
Priority: 5 Medium Last modified: 2025-09-09 19:08:43
Status: Closed Closed by: oehhar
Resolution: Rejected Closed on: 2025-09-09 19:08:43
Version:
Description:
[ My apologies if this is the wrong place to report this, I'm not familiar with the TCL dev infrastructure. ]

In our project I wrote a TCL line:
...
        verbose -log "$fmt [get_line_1 $y "" $attrs]" 
...
and there was some discussion on whether this is valid TCL syntax, so it got changed ( https://sourceware.org/pipermail/gdb-patches/2025-July/219538.html ) to:
...
        verbose -log "$fmt [get_line_1 $y {} $attrs]" 
...

The TCL interpreter seems to handle the two lines the same, so I'm assuming it's valid syntax.

Regardless, it's not clear from the syntax definition whether it's valid or not.

The syntax definition states:
...
If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character.
...

So the question is, what is the "next double-quote character" in this case.  This:
...
        verbose -log "$fmt [get_line_1 $y "" $attrs]"
                                          ^
...
or this:
...
        verbose -log "$fmt [get_line_1 $y "" $attrs]"
                                                    ^
...
?

If it is the latter, then the use of the term "next double-quote character" is misleading.

I think the same problem exists more or less for:
...
   "foo \" bar"
...
but in this case the definition of backslash substitution explains that \" is treated as an ordinary character, which explains why \" doesn't terminate the string.

But in the case of the command substitution definition, there's no such explanation, though one could argue that it can be inferred from "invokes the Tcl interpreter recursively to process the characters following the open bracket as a Tcl script". 

My guess at an improved formulation would be something like:
...
Double quotes.

    If the first character of a word is double-quote (“"”) then the word is terminated by the next double-quote character (that is not substituted by backslash or command substitution). If semi-colons, close brackets, or white space characters (including newlines) appear between the quotes then they are treated as ordinary characters and included in the word. Command substitution, variable substitution, and backslash substitution are performed on the characters between the quotes as described below.  The double-quotes are not retained as part of the word. 
...
User Comments:
oehhar added on 2025-09-09 19:08:43:
It is the 2nd possibility.
Within the argument '"$fmt [get_line_1 $y "" $attrs]"', the square bracket expression is evaluated first. So, the '""' disappears before the closing '"' is searched for.

Closing, not a bug.
Take care,
Harald