Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-10-05
01:54 • Ticket [817048ffff] Backslashes inside curly braces status still Closed with... artifact: c598e1a89e user: dgp
2003-10-04
14:19 • Ticket [817048ffff]: 4 changes artifact: d37640608a user: pascalscheffers
05:04 • Closed ticket [817048ffff]. artifact: f416a2f2ee user: dgp
2003-10-03
20:27 • Ticket [817048ffff]: 1 change artifact: e9f4f69ae3 user: dgp
18:30 • Ticket [817048ffff]: 1 change artifact: cd3140f935 user: rmax
10:33 • New ticket [817048ffff]. artifact: 15d945b90d user: rmax

Backslashes inside curly braces

Closed817048ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-10-03 10:33:09
According to rule 5 of the Tcl syntax the sequence \\}
would have to be treated as one literal backslash
followed by an escaped closing brace when it appears
between curly braces. But instead the parser treats it
as two literal backslashes followed by an unescaped
closing brace. So either the documentation or the
implementation is wrong.
rmax Ticket [817048ffff]: 1 change [History diff]2003-10-03 18:30:27
dgp Ticket [817048ffff]: 1 change [History diff]2003-10-03 20:27:02
dgpplain2003-10-04 05:04:58
Logged In: YES 
user_id=80530


When scanning a brace quoted word,
backslash substitution is not performed,
but each backslash sequence is scanned
as a unit.  This detail might not be
completely obvious from the documentation,
but it is required in order to only do
backslash-newline substitution in the
correct places.

proc foo {} {
    set backslash \\
}

We don't want the backslash-newline
here converted to a space.  So the second
backslash has to be tied to the first as a unit
during parsing.

If you have a proposed improvement to the
docs to make this clearer without making it
confusing, I'd consider it.
pascalscheffersplain2003-10-04 14:19:14
Logged In: YES 
user_id=582857

If it is just a docs update, I think it is important to note
there that it is not possible to construct a string that
ends in a single or any odd number of backslashes. Meaning
you cannot make a DOS path ending in a backslash in curly
braces: {c:\somewhere\} doesn't work. Nor does
{c:\somewhere\\}, which produces c:\somewhere\\ 

I know you should not do it this way, but it has bit me before.
dgpplain2003-10-05 01:54:53
Logged In: YES 
user_id=80530


Just to clarify, there's no limit on your ability
to construct a string in Tcl that ends in an
odd number of backslashes.

You just can't brace-quote such a string.
(Because it would escape the closing } )
You also can't ""-quote such a string for
the same reason.  So in this corner case,
you're stuck either using all \-quoting or,
more likely, using substitution to generate
the string you need.

set bs \\
set myString "foo bar$bs"
Log in (anonymous is fine) to add a comment.