syntax parser in tcl8.1 - wrong usage of braces in comments or strings 
Author Message
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Hello,

it's me once again - maybe I'm still on the wrong track when using
tcl's curly braces - but have a look at the following shell session:

a.) I'm defining a function called test. It has one comment line
which contains a "}" closing curly brace. It seems like the
syntax parser does not really care to much about the fact that
the whole line is a comment and brags something about wrong syntax

% proc test {} {
# comment line which fails: } <- because of this character
wrong # args: should be "proc name args body"

b.) When I'm leaving out that curly brace (or masking it with
backslash: \} ) the result will be just fine as shown below)

% proc test {} {
# another comment line
puts "dies ist ein test"

Quote:
}

% test
dies ist ein test
%

So as far as I'm concerned this is a bug - any comments (or it
my problem? why do I have comments if I can't use them like I want??)

Thanks in advance and

best regards,

Sven

  Sven.vcf
< 1K Download


Sun, 18 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> Hello,

> it's me once again - maybe I'm still on the wrong track when using
> tcl's curly braces - but have a look at the following shell session:

> a.) I'm defining a function called test. It has one comment line
> which contains a "}" closing curly brace. It seems like the
> syntax parser does not really care to much about the fact that
> the whole line is a comment and brags something about wrong syntax

[snip]

Quote:
> So as far as I'm concerned this is a bug - any comments (or it
> my problem? why do I have comments if I can't use them like I want??)

We beat this one to death every six months or so. It's a known feature.
Search through dejanews for long threads on this subject.

--

ChannelPoint, Inc.              http://purl.oclc.org/net/oakley



Sun, 18 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings
Unfortunately tcl doesn't have comments in the ordinary sense.
It has a '#' command which does nothing. However the "arguments" to the
'#'
command are still passed thru some parsing stages.
The Tcl man page says everything after the '#' is ignored - that is
wrong.

I think it's a defect also.

Roy

Quote:

> Hello,

> it's me once again - maybe I'm still on the wrong track when using
> tcl's curly braces - but have a look at the following shell session:

> a.) I'm defining a function called test. It has one comment line
> which contains a "}" closing curly brace. It seems like the
> syntax parser does not really care to much about the fact that
> the whole line is a comment and brags something about wrong syntax

> % proc test {} {
> # comment line which fails: } <- because of this character
> wrong # args: should be "proc name args body"

> b.) When I'm leaving out that curly brace (or masking it with
> backslash: \} ) the result will be just fine as shown below)

> % proc test {} {
> # another comment line
> puts "dies ist ein test"
> }
> % test
> dies ist ein test
> %

> So as far as I'm concerned this is a bug - any comments (or it
> my problem? why do I have comments if I can't use them like I want??)

> Thanks in advance and

> best regards,

> Sven



Sun, 18 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings


:I think it's a defect also.
:> So as far as I'm concerned this is a bug - any comments (or it

Many people have made this claim - many people have denied it is a bug.
Many postings have been made proposing possible alternatives.  To date,
I don't believe anyone has submitted a Tcl patch to Scriptics which a)
_guarantees_ that the majority of existing code isn't broken (I myself do not
see a need to guarantee that NO code breaks - few Tcl releases guarantee
that <smile>), b) presents a new model whose behavior is generally acceptable,
c) has no negative side effects...

--

<*> O- <URL: http://www.purl.org/NET/lvirden/>
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.



Sun, 18 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

>> % proc test {} {
>> # comment line which fails: } <- because of this character
>> wrong # args: should be "proc name args body"

Pop quiz:  Q: What is the third argument to the [proc] command above?

A: "\n# comment line which fails: "

Once that answer makes sense to you, then you'll have this issue
with Tcl comments{*filter*}ed.  Review the Tcl(n) page, point [5] to
see that that's the way it's supposed to work.


Quote:
> Unfortunately tcl doesn't have comments in the ordinary sense.

True, for certain values of "ordinary".

Quote:
> It has a '#' command which does nothing.

Thinking about Tcl comments as if they were the command created
by this [proc] command:

proc # args {}

is closer to the truth than thinking of them as if they were like
comments in other languages.  However, that description is not
accurate.  For details on the differences see <URL:
http://www.*-*-*.com/ ;

Quote:
> However the "arguments" to the '#'
> command are still passed thru some parsing stages.

No, that description has nothing to do with the difficulties
encountered above.  It is the parsing of the [proc] command
which is generating the unexpected result, because its third
argument is improperly delimited.  There are no "arguments"
to any "'#' command" causing any trouble.

Quote:
> The Tcl man page says everything after the '#' is ignored - that is
> wrong.

Tcl(n) actually says:

       [9]    If a hash character  (``#'')  appears  at  a  point
              where  Tcl  is expecting the first character of the
              first word of a command, then  the  hash  character
              and  the  characters that follow it, up through the
              next newline, are treated as a comment and ignored.
              The comment character only has significance when it
              appears at the beginning of a command.

No false statements that I can see.

If Tcl actually ignored all characters on a line following a '#',
it would be awfully difficult to use the command

uplevel #0 $cmd

to quote just one example.

--
| Don Porter, D.Sc.   Mathematical and Computational Sciences Division |

| http://www.*-*-*.com/ ;                      NIST |
|______________________________________________________________________|



Sun, 18 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:


> :I think it's a defect also.

> :> So as far as I'm concerned this is a bug - any comments (or it

> Many people have made this claim - many people have denied it is a bug.
> Many postings have been made proposing possible alternatives.  To date,
> I don't believe anyone has submitted a Tcl patch to Scriptics which a)
> _guarantees_ that the majority of existing code isn't broken (I myself do not
> see a need to guarantee that NO code breaks - few Tcl releases guarantee
> that <smile>), b) presents a new model whose behavior is generally acceptable,
> c) has no negative side effects...

Another way to look at this: many newbies (coming from, say, C) stumble
on this, because of a fundamental misunderstanding of Tcl's simple,
deterministic, and devoid-of-special-cases, processing. Basically they
have a preprocessor-based method in mind, while Tcl does not have a
preprocessor. I have posted a suggestion to add a Tcl way of
experimenting with real preprocessing, so that people can try out
alternate/additional schemes (like the so-called 'bang' comment). Still,
I (and I believe, most of the Tcl programmers past the newbie state)
think that the current '#' behavior is (1) consistent with Tcl's spirit
and the rest of its implementation, (2) bug-free, not to speak (3) about
backward compatibility. Hence it is not subject to debate, esp. majority
vote !

-Alex



Mon, 19 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings
Hello Alex,

Quote:
> Another way to look at this: many newbies (coming from, say, C) stumble
> on this, because of a fundamental misunderstanding of Tcl's simple,
> deterministic, and devoid-of-special-cases, processing. Basically the
> have a preprocessor-based method in mind, while Tcl does not have a
> preprocessor. I have posted a suggestion to add a Tcl way of
> experimenting with real preprocessing, so that people can try out
> alternate/additional schemes (like the so-called 'bang' comment). Still,
> I (and I believe, most of the Tcl programmers past the newbie state)
> think that the current '#' behavior is (1) consistent with Tcl's spirit
> and the rest of its implementation, (2) bug-free, not to speak (3) about
> backward compatibility. Hence it is not subject to debate, esp. majority
> vote !

First of all I'm not newbie - I know tcl for quite a while now and I
also
know this any some other behaviours of tcl which can be problems for
usual C programmers. What I really wanted to know is - is there any
advantage at all of using this kind of syntax parsing. (Everybody who
has answered stated I could look up those discussions in earlier posting
but I did not find any posings)

Ok, it is no-special-cases processing for interpreter - to be quite
honest
I like this idea, but as programmer (and customer of a "language
producer")
I have to say - thanks, but no thanks.

Well, I don't want to start any flame-throwing discussions and probably
most of you are tired of this. I don't like it - you do like the
behaviour
and that's it. (I wish they would change it for heaven's sake)

Quote:
> -Alex

rgds,

sven



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> What I really wanted to know is - is there any
> advantage at all of using this kind of syntax parsing. (Everybody who
> has answered stated I could look up those discussions in earlier posting
> but I did not find any posings)

Please use DejaNews. Look for 'bang' (bang-comment, a suggestion for a
more preprocessor-like behavior).

Quote:
> Ok, it is no-special-cases processing for interpreter - to be quite
> honest
> I like this idea, but as programmer (and customer of a "language
> producer")
> I have to say - thanks, but no thanks.

In that case why didn't you respond positively to my suggestion of
opening a door to preprocessors in

        http://www.deja.com/=dnc/getdoc.xp?AN=461112541

-Alex



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings
Hey Alex!

Quote:
> Please use DejaNews. Look for 'bang' (bang-comment, a suggestion for a
> more preprocessor-like behavior).

Well.. ok - I haven't tried this (why 'bang'? - well I'll find out).
Thank
you for the advice.

Quote:

> In that case why didn't you respond positively to my suggestion of
> opening a door to preprocessors in

>         http://www.deja.com/=dnc/getdoc.xp?AN=461112541

Well - obviously because a.) I haven't used the tcl newsgroup at that
particular time and b.) haven't found anything about comments at all
when searching for it.

Well, do you happen to know if there is any kind of movement in the
sector of tcl preprocessing (I like you idea of stripping comments
with a preprocessore before evaluating)?

rgds,

sven



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> First of all I'm not newbie - I know tcl for quite a while now and I
> also
> know this any some other behaviours of tcl which can be problems for
> usual C programmers. What I really wanted to know is - is there any
> advantage at all of using this kind of syntax parsing. (Everybody who
> has answered stated I could look up those discussions in earlier posting
> but I did not find any posings)

Ok, consider this fairly simple case of using if to simulate a switch
statement

    if {$foo == "a"} {#do nothing}
    if {$foo == "b" {
         <really clever code>
    }

If comments were more "pure" (taking everything up to the end of the
line) the first if statement would be impossible to write on a single
line.

It is a bit of a contrived example, but it illustrates the point.
Perhaps a more real-world example might be in a binding script to ignore
a particular event:

    bind Somewidgetclass <Double-1> {# do nothing}

Code almost like this exists in the tcl core in listbox.tcl, though it
puts the comments on a line by itself; but that's a matter of style.
With the way parsing is done today, you are allowed to put it all on a
single line if you wish.

Quote:

> Ok, it is no-special-cases processing for interpreter - to be quite
> honest
> I like this idea, but as programmer (and customer of a "language
> producer")
> I have to say - thanks, but no thanks.

Personally, I've never had a problem with it. Except for the fact it is
sometimes difficult to explain to folks. But in practice it has never
caused me problems.

Quote:

> Well, I don't want to start any flame-throwing discussions and probably
> most of you are tired of this. I don't like it - you do like the
> behaviour
> and that's it. (I wish they would change it for heaven's sake)

I think I would tolerate a change, but I'm not sure I would actually
vote for it.

--

ChannelPoint, Inc.              http://purl.oclc.org/net/oakley



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> Ok, consider this fairly simple case of using if to simulate a switch
> statement

>     if {$foo == "a"} {#do nothing}
>     if {$foo == "b" {
>          <really clever code>
>     }

Well, that does happen to be "bad style", but the point is well taken.
I really hadn't thought of that issue before.

In a sense, then, that consolidates my gripes with Tcl syntax into one:
        Using newlines to separate statements sucks.
Think of all the nonsense one has to worry about when making sure that a
Tcl command has been properly grouped, as in using braces at the right
time, or adding trailing "\"'s, or making sure not to, etc.

Of course, I've had all this etched pretty deeply into my synapses by
now, but I do remember my initial disgust vividly ("What is this,
JavaScript?").

I guess my suggestion is a pact between Tcl documenters to make the
first chapter of every manual and book "You Can't Put Braces in Tcl
Comments:".  That would probably suffice.

Quote:

> If comments were more "pure" (taking everything up to the end of the
> line) the first if statement would be impossible to write on a single
> line.

> It is a bit of a contrived example, but it illustrates the point.
> Perhaps a more real-world example might be in a binding script to ignore
> a particular event:

>     bind Somewidgetclass <Double-1> {# do nothing}

Sure, sure, but can anyone explain to me why they don't work in switch
statements?
Quote:

> ChannelPoint, Inc.              http://purl.oclc.org/net/oakley



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> Well, do you happen to know if there is any kind of movement in the
> sector of tcl preprocessing (I like you idea of stripping comments
> with a preprocessore before evaluating)?

Here is a set of regexps that I use to crunch
tclets before serving them via http from a cgi program
(well, actually its from a tcl http server, but it could be a cgi).

This script eliminates simple # comments, but not:

        #!...
        ... ;# ...
        #define
        ##...

( I use ## when I really want comments in the tclet,
e.g for copyright notices )

It also elimates blank lines, leading whitespace
and consolidates trailing }'s

Don't use this script blindly.  Its possible to write tcl
that will be damaged by this script.

John Ellson

#######################################################

# crunch the tcletcode in data for faster transfers
    # eliminate leading whitespace
regsub -all "\n\[ \t\r\n]*" $data "\n" data
    # eliminate comments except #! and ##
    # (doesn't work right for \n#\n or for \n#d except \n#define)
regsub -all "\n#\[^!#d]\[^\n]*" $data {} data
    # bunch trailing }
regsub -all "\n\}" $data "\}" data



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings


                        .
                        .
                        .
Quote:
>Sure, sure, but can anyone explain to me why they don't work in switch
>statements?

                        .
                        .
                        .
Bryan already has:  <URL:http://x35.deja.com/getdoc.xp?AN=445442698>.
--

Cameron Laird           http://starbase.neosoft.com/~claird/home.html



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:

> In a sense, then, that consolidates my gripes with Tcl syntax into one:
>         Using newlines to separate statements sucks.

Now we're talkin' *serious* religion.

I happen to like it. I hate having to terminate every command with some
magical character. But again, that's just religion. Though, come to
think of it, I *do* terminate every command with a magical character --
the newline. So it's just a matter of perspective.

Quote:
> Think of all the nonsense one has to worry about when making sure that a
> Tcl command has been properly grouped, as in using braces at the right
> time, or adding trailing "\"'s, or making sure not to, etc.

Never had a problem. Think of the nonsense one has to worry about when
making sure each and every command is properly terminated in C :)

I guess this is more painful if you don't use an editor that can balance
braces and quotes and such. I use a tool that makes it almost impossible
to misbalance braces.

Quote:
> Of course, I've had all this etched pretty deeply into my synapses by
> now, but I do remember my initial disgust vividly ("What is this,
> JavaScript?").

I found it liberating. The world is a facinating place, no?

Quote:

> I guess my suggestion is a pact between Tcl documenters to make the
> first chapter of every manual and book "You Can't Put Braces in Tcl
> Comments:".  That would probably suffice.

You can, but you shouldn't. Just one of those things. No language is
completely free of warts. At least most (all?) of tcl's warts are very
easily worked around.

Quote:

> > If comments were more "pure" (taking everything up to the end of the
> > line) the first if statement would be impossible to write on a single
> > line.

> > It is a bit of a contrived example, but it illustrates the point.
> > Perhaps a more real-world example might be in a binding script to ignore
> > a particular event:

> >     bind Somewidgetclass <Double-1> {# do nothing}

> Sure, sure, but can anyone explain to me why they don't work in switch
> statements?

I made a big exposition about this a year or so ago. If you know the way
a switch command works, it becomes quite obvious. Cameron Laird has been
kind enough to archive the discussion here:

http://starbase.neosoft.com/~claird/comp.lang.tcl/fmm.html#comments

--

ChannelPoint, Inc.              http://purl.oclc.org/net/oakley



Tue, 20 Nov 2001 03:00:00 GMT  
 syntax parser in tcl8.1 - wrong usage of braces in comments or strings

Quote:


> Now we're talkin' *serious* religion.

Uh-oh.

Quote:
> think of it, I *do* terminate every command with a magical character --
> the newline. So it's just a matter of perspective.

I guess I still think in terms of "whitespace is whitespace" from C.

Quote:
> I guess this is more painful if you don't use an editor that can balance
> braces and quotes and such. I use a tool that makes it almost impossible
> to misbalance braces.

I'm using NEdit 5.02 on IRIX.  When I have to port something to Mac or
NT I tend to test, run back to my SGI and edit some lines, run back to
the other and ftp the changed code...

Any editor recommendations?  NEdit is pretty good, but makes a lot of
mistakes in highlighting (well, not too many).

Quote:
> You can, but you shouldn't. Just one of those things. No language is
> completely free of warts. At least most (all?) of tcl's warts are very
> easily worked around.

Now, now, it's a feature, not a wart.  But a feature that is going to
astonish a lot of people at least once.  Somehow I managed to program
for about a month before stumbling on it, and I was working right out of
Welch.

Quote:

> http://starbase.neosoft.com/~claird/comp.lang.tcl/fmm.html#comments

Got it.  Too lazy to figure it out for myself.  Thanks!


Tue, 20 Nov 2001 03:00:00 GMT  
 
 [ 29 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Extended syntax string parser

2. regsub (tcl8.1) - strange behaviour for backslashes/braces

3. Problem of comment including an open brace.

4. Curly braces and comments

5. unmatched braces in comments

6. braces and comments: bug?

7. possible bugs with comments containing braces

8. Brace/Bracket-levels are counted even in comments

9. Parsing comments with braces

10. tcl finds close braces when they are in commented lines

11. source counts braces in comment lines

12. open braces in comments

 

 
Powered by phpBB® Forum Software