Statalist


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

st: Bug in Stata's -syntax- command


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Bug in Stata's -syntax- command
Date   Wed, 21 Jan 2009 13:52:05 -0500

Dear All,

the following information might be of general interest.

Stata's -syntax- command is used by most of the .ado implemented
commands (both written within StataCorp and written by users) to parse
the command line and extract command's options and parameters. In case
the program allows "other" parameters (a star is included in the
syntax declaration) the options that the program does not declare in
syntax are supposed to be written to a special local "options" where
they can be later processed, e.g. forwarded down the stream to a
subroutine. A particular (but _not_ implausible) combination of
symbols causes a confusion within the -syntax- command, which leads to
doubling of options, which appear after the option containing this
combination.

The bug is observed in Stata SE 9.2.444 and Stata MP 10.1.545 (both
are latest) and perhaps applies to all Stata versions.

The bug can be reproduced in the following way:

/* BEGIN OF FILE foobar.ado */
program define foobar
    version 8
    syntax [, *]
    display as text `"`0'"'
    display as result `"`options'"'
end
/* END OF FILE foobar.ado */

/* BEGIN OF FILE foobar.do */
program drop _all
foobar, option0 option1("TEXT") option2
foobar, option0 option1(`"TEXT ("') option2
foobar, option0 option1("TEXT (") option2
foobar, option0 option1(`"TEXT (details) (other)"') option2
foobar, option0 option1("TEXT (details) (other)") option2
foobar, option0 option1(`"TEXT (details) ("') option2
foobar, option0 option1("TEXT (details) (") option2
foobar, option0 option1(`"TEXT (details) (other"') option2
foobar, option0 option1("TEXT (details) (other") option2
/* END OF FILE foobar.do */

Below is the output:

. do foobar.do

. /* BEGIN OF FILE foobar.do */
. program drop _all

.
. foobar, option0 option1("TEXT") option2
, option0 option1("TEXT") option2
option0 option1("TEXT") option2

. foobar, option0 option1(`"TEXT ("') option2
, option0 option1(`"TEXT ("') option2
option0 option1(`"TEXT ("') option2

. foobar, option0 option1("TEXT (") option2
, option0 option1("TEXT (") option2
option0 option1("TEXT (") option2 option2

. foobar, option0 option1(`"TEXT (details) (other)"') option2
, option0 option1(`"TEXT (details) (other)"') option2
option0 option1(`"TEXT (details) (other)"') option2

. foobar, option0 option1("TEXT (details) (other)") option2
, option0 option1("TEXT (details) (other)") option2
option0 option1("TEXT (details) (other)") option2

. foobar, option0 option1(`"TEXT (details) ("') option2
, option0 option1(`"TEXT (details) ("') option2
option0 option1(`"TEXT (details) ("') option2

. foobar, option0 option1("TEXT (details) (") option2
, option0 option1("TEXT (details) (") option2
option0 option1("TEXT (details) (") option2 option2

. foobar, option0 option1(`"TEXT (details) (other"') option2
, option0 option1(`"TEXT (details) (other"') option2
option0 option1(`"TEXT (details) (other"') option2

. foobar, option0 option1("TEXT (details) (other") option2
, option0 option1("TEXT (details) (other") option2
option0 option1("TEXT (details) (other") option2 option2

.
.
end of do-file

Notice that -option2- is doubled in the very last program call (and in
the pre-pre-last one). The other program calls illustrate the proper
behaviour with other, seemingly close values of the parameter. To
generalize: if the string argument of an option passed in single
quotes (but not compound quotes) contains a pair of parentheses,
followed by an unpaired parenthesis, all options after this option are
doubled. (which in my case caused a program accepting these options
down the stream to malfunction). The situation occured, when a
variable label containing parenthesis was truncated during data
conversion and closing parenthesis was lost.

The workaround seems to be to always use the compound quotes rather
than single quotes, when passing arbitrary text to an .ado file, but
there seems to be no easy way to enforce it in the syntax.

(a copy of this message is also send to Stata's tech support).

Thank you,
   Sergiy Radyakin
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index