From: Gerhard Reithofer on
Hi TCLers,
I've studied Tcl language syntax several times, but I don't see my
fault:

% set obrace 3
3
% if {$obrace<0} {return "missing '}'"}
extra characters after close-brace

Why doest this code throw an error?
TCL-Rule [4]: If the first character of a word is double-quote (“"”)
then the word is terminated by the next double-quote character.

"missing '}'" is ONE word and the interpreter should not look "inside"
the string.

What did I oversee?

Nevertheless
return "missing '\}'"
is working as expected.

--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at
From: Mark Janssen on
On Nov 19, 5:22 pm, Gerhard Reithofer <gerhard.reitho...(a)tech-
edv.co.at> wrote:
> Hi TCLers,
> I've studied Tcl language syntax several times, but I don't see my
> fault:
>
>  % set obrace 3
>  3
>  % if {$obrace<0} {return "missing '}'"}
>  extra characters after close-brace
>
> Why doest this code throw an error?
> TCL-Rule [4]: If the first character of a word is double-quote (“"”)
> then the word is terminated by the next double-quote character.
>
>  "missing '}'" is ONE word and the interpreter should not look "inside"
> the string.
>
> What did I oversee?
>
> Nevertheless
>   return "missing '\}'"
> is working as expected.
>
> --
>  Gerhard Reithofer
>  Tech-EDV Support Forum -http://support.tech-edv.co.at

You are experiencing a common form of Tcl syntax blindness here. The
word doesn't start at the first ", it starts at the first { so the
actual word is:

{return "missing '}

Which indeed has characters after the close brace.

Regards,
Mark
From: Ronnie Brunner on
Gerhard Reithofer wrote:
> Hi TCLers,
> I've studied Tcl language syntax several times, but I don't see my
> fault:
>
> % set obrace 3
> 3
> % if {$obrace<0} {return "missing '}'"}
> extra characters after close-brace
>
> Why doest this code throw an error?
> TCL-Rule [4]: If the first character of a word is double-quote (“"”)
> then the word is terminated by the next double-quote character.
>
> "missing '}'" is ONE word and the interpreter should not look "inside"
> the string.
>
> What did I oversee?
>
> Nevertheless
> return "missing '\}'"
> is working as expected.
>

But Tcl-Rule [6] says: [6] Braces.
If the first character of a word is an open brace (“{”) and rule
[5] does not apply, then the word is terminated by the matching close
brace (“}”). Braces nest within the word: for each additional open brace
there must be an additional close brace (however, if an open brace or
close brace within the word is quoted with a backslash then it is not
counted in locating the matching close brace). No substitutions are
performed on the characters between the braces except for
backslash-newline substitutions described below, nor do semi-colons,
newlines, close brackets, or white space receive any special
interpretation. The word will consist of exactly the characters between
the outer braces, not including the braces themselves.


And since in Tcl-Rule [4] there is no talk about braces being treated as
ordinary characters within a quoted string, it's obvious that Tcl-Rule
[6] takes precedence as there was a word opened with '{' first

hth
Ronnie
--
Ronnie Brunner | ronnie.brunner(a)netcetera.ch
phone +41-44-247 79 79 | fax +41-44-247 70 75
Netcetera AG | 8040 Zürich | Switzerland | http://netcetera.ch
From: Elchonon Edelson on
Gerhard Reithofer wrote:
> Hi TCLers,
> I've studied Tcl language syntax several times, but I don't see my
> fault:
>
> % set obrace 3
> 3
> % if {$obrace<0} {return "missing '}'"}
> extra characters after close-brace
>
> Why doest this code throw an error?
> TCL-Rule [4]: If the first character of a word is double-quote (“"”)
> then the word is terminated by the next double-quote character.
>
> "missing '}'" is ONE word and the interpreter should not look "inside"
> the string.
>
> What did I oversee?
>
> Nevertheless
> return "missing '\}'"
> is working as expected.
>

What you overlooked is rule 6: If the first character of a word is an
open brace (“{”) ... then the word is terminated by the matching close
brace (“}”). Braces nest within the word ... (however, if an open brace
or close brace within the word is quoted with a backslash then it is not
counted in locating the matching close brace). No substitutions are
performed on the characters between the braces ... *nor do semi-colons,
newlines, close brackets, or white space* receive any special
interpretation. The word will consist of *exactly the characters between
the outer braces*, not including the braces themselves.

I have elided a few pieces of the rule, but the main point is still
clear: The word begins with “{”, the space after “return” received no
special interpretation and is simply part of the word. The double-quote
is therefore not the first character of anything, and is also simply
part of the word. The word ends at the close-brace that is enclosed in
single-quotes, and is the string “return "missing '”. This is
immediately followed by “'"}” with no intervening whitespace, which is
the error message that you're getting.

Your solution, “return "missing '\}'"” is, as you can see above, the
correct way to escape the close-brace.

-EE

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Bryan Oakley on
On Nov 19, 10:22 am, Gerhard Reithofer <gerhard.reitho...(a)tech-
edv.co.at> wrote:
> Hi TCLers,
> I've studied Tcl language syntax several times, but I don't see my
> fault:
>
> % set obrace 3
> 3
> % if {$obrace<0} {return "missing '}'"}
> extra characters after close-brace
>
> Why doest this code throw an error?
> TCL-Rule [4]: If the first character of a word is double-quote (“"”)
> then the word is terminated by the next double-quote character.
>
> "missing '}'" is ONE word and the interpreter should not look "inside"
> the string.
>
> What did I oversee?

First word: if
second word: {$obrace<0}
third word: {return "missing '}

immediately after that closing brace of the third word is the
character ', hence the error message.

Remember: when a word starts with a brace it continues to the closing
brace, and double quotes are ignored with the opening and closing
brace.