andrewheiss / SublimeStataEnhanced

Plugin that adds support for Stata 11–15 for Sublime Text 2 and 3
55 stars 22 forks source link

Error when removing line continuation (///) #22

Closed ewancarr closed 9 years ago

ewancarr commented 9 years ago

text_2_stata.py strips line continuation syntax (i.e. /// followed by \n) from commands before sending to Stata. This is in line 17-18:

# Take care of line continuation
clean = re.sub("/{3,}\\n", "", clean)

However, if there are no spaces between this command and the next line, the resulting syntax will be invalid. For example, the following Stata code:

cap label drop ses4
label define ses4           ///
        1 "Professional"    ///
        2 "Intermediate"    ///
        3 "Non-manual"      ///
        4 "Manual/other"
label values ses4 ses4

Will be appear in Stata as:

. label define ses41 "Professional"2 "Intermediate"3 "Non-manual"4 "Manual/other"
invalid syntax
r(198);

This is an error, because ses4 and 1 have been concatenated.

To fix this, I edited text_2_stata.py such that line continuation marks are replaced by a single space:

clean = re.sub("/{3,}\\n", " ", clean)

This seems to work.

andrewheiss commented 9 years ago

Thanks!