Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Critique on comment syntax and suggestions


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: RE: Critique on comment syntax and suggestions
Date   Sat, 29 Jan 2011 01:03:42 -0500

On Fri, Jan 28, 2011 at 4:10 PM, Nick Winter <[email protected]> wrote:
> Two points:
>
> First: The command *is* part of the comment, as far as Stata is concerned,
> because (1) the delimiter is ";", and (2) there is no ";" on the prior line.
>  That one does not intend it to be part of the comment does not change the
> fact that by Stata's consistent rules, it is in fact part of the comment.
>
> Second, The question is why the syntax highlighting does not color it as a
> comment.  Here I think things are a bit more complicated.  If a .do file
> explicitly sets the delimiter to ; and then later sets it back to cr
> (carriage return), then the syntax highlighting function could, in theory,
> track that and highlight comments accordingly.
>
> However, a user can set the delimiter outside the do file. In this case, the
> delimiter for a Stata session might be ; even though the do file makes no
> mention of #delimit.  In this case the syntax highlighting function would
> have no way to know what the delimiter is (or would need even more complex
> logic to check the current state of the delimiter at any given moment.)
>
> That the delimiter can change seems like it presents a fundamental ambiguity
> for syntax highlighting.


Nick, I couldn't find the beginning of this discussion, but regarding
the above, please note that the user can not set the delimiter from
outside of the file. Refer to Stata's manual:

    "Commands in a do-file, however, may be delimited with a carriage
return or a semicolon.  When a do-file begins,
    the delimiter is a carriage return.  The command "#delimit ;"
changes the delimiter to a semicolon.  To restore
    the carriage return delimiter inside a file, use #delimit cr.

    When a do-file begins execution, the delimiter is automatically
set to carriage return, even if it was called
    from another do-file that set the delimiter to semicolon.  Also,
the current do-file need not worry about
    restoring the delimiter to what it was because Stata will do that
automatically."

http://www.stata.com/help.cgi?delimit

So one can clearly determine what is a comment and what is not. Note
also, that it appears to be impossible to trick Stata, by placing the
#-directives into, say, locals, and then try to execute them - the
preprocessor directives will not be valid at the stage when the locals
are expanded, and Stata will report "unknown command" error.

I think at some point (still before syntax highlighting was introduced
in Stata) I was raising the question that the wording was not
unambiguous in the Stata manual, when saying "till the end of the
current line" -- for me it was not clear whether it is the line of
code or until the end of the current text-line in an ASCII file (which
is the same when the delimiter is CR, but not the same when delimiter
is ;). Also it would be good to have explicitly stated whether /* */
can be recursive, or /* /* /* /* /* /* /* comment */ code  ---
non-recursive (one "*/" terminates any number of preceding "/*").

Best, Sergiy Radyakin





>
> Nick winter
>
> On 1/28/2011 3:04 PM, Steven Samuels wrote:
>>
>> As I look at Stata's output, I do think I see a small bug in the results
>> display.
>> *****************************
>> sysuse auto, clear
>> # delimit ;
>> // This next line won't get processed because I forgot to put a semicolon
>> drop if mpg ==.;
>> ******************************
>>
>> Output (SMCL or text)
>> ****************************
>> sysuse auto, clear
>> . # delimit ;
>> delimiter now ;
>> . // This next line won't get processed because I forgot to put a
>> semicolon
>>  > drop if mpg ==.;
>> (0 observations deleted)
>> *****************************
>>
>> Notice that the line beginning the valid command is started by a
>> continuation character ">". I would call this a bug, but it does not
>> mean that the line is part of the comment!
>>
>> Steve
>>
>>
>>
>> I think there is a small inconsistency, as Joseph pointed out. A
>>
>> You are not correct, Daniel; the following line is _not_ a part of the
>> comment. Take a look at Joseph's message, especially his example 3 at
>> http://www.stata.com/statalist/archive/2008-09/msg01271.html
>>
>> Steve
>>
>> On Jan 28, 2011, at 2:34 PM, Daniel Feenberg wrote:
>>
>>
>> On Fri, 28 Jan 2011, Steven Samuels wrote:
>>
>>> --
>>>
>>>
>>> --
>>>
>>>
>>> I've been bitten in the past by omitting semicolons. I now use
>>> continuation characters, and reserve the semicolon to delimit single
>>> commands, especially for graphs, that have many, often long, options.
>>> I find such commands easier to read and modify if each option is on a
>>> single line. If I use continuation characters in such commands, the
>>> lines look messy unless I line the characters up. For me that's too
>>> much work. As Nick said, it's personal taste.
>>>
>>> Bryce, you are asking Stata's do-file editor to find syntax errors, and I
>>
>> Not really - the line:
>>
>> drop if criticalvar=1;
>>
>> is stricktly speaking part of the comment, and he is asking that it be
>> colored as a comment, to match the view that Stata will take. Currently
>> the editor is treating it as executable, which is clearly an incorrect
>> parsing of the code.
>>
>>> don't think that's its function. After reading the second post David
>>> referred to (it's by Joseph Coveney), I don't really see a bug. Off
>>> topic, "Stata" is spelled "Stata." See the FAQ Section 8.2.
>>>
>>> Steve
>>>
>>
>>
>>
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>>
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/statalist/faq
>> * http://www.ats.ucla.edu/stat/stata/
>
> --
> --------------------------------------------------------------
> Nicholas Winter                                 434.924.6994 t
> Assistant Professor                             434.924.3359 f
> Department of Politics                  [email protected] e
> University of Virginia          faculty.virginia.edu/nwinter w
> S385 Gibson Hall, South Lawn
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index