mattiasnordin / StataEditor

Stata Editor for Sublime Text 3
47 stars 18 forks source link

Comments bug #6

Closed NickOtis closed 6 years ago

NickOtis commented 8 years ago

I think I've found a discrepancy in the way StataEditor vs the Stata .do file editor demarcates comments. Given: /* /*
A */ B Stata .do file editor will have B in green, since the comment is still open, as there is only one close comment sign. However, in StataEditor, it will appear as though B is not commented out, even though B will not be run. It is as though StataEditor recognizes that B is commented out, but does not demarcate it as such.

mattiasnordin commented 8 years ago

You are right. Unfortunately, Sublime Text is not very flexible when it comes to allowing for nested multiline regular expressions which would be needed in this case. If anyone has a suggestion for how to fix this issue I would be very grateful. Nonetheless, I think the issue is minor, given that one really wouldn't want to open a comment section without also closing it.

guilhemc commented 7 years ago

Hi, thanks for this very useful package. Note that the issue spotted by Nickotis also seem to apply in the following case: / / A / B / B would appear as if not commented out, which is obviously more annoying that in the example provided above.

Best,

mattiasnordin commented 7 years ago

That is indeed annoying! Unfortunately, I don't think anything can be done about it. See, for instance, https://stackoverflow.com/questions/32440333/regex-in-sublime-text-tmlanguage-file-doesnt-use-multiline and https://forum.sublimetext.com/t/multiline-regex-for-tmlanguage/853/3. If someone has a suggestion for a workaround please let me know!

kylebarron commented 6 years ago

This is, in fact, quite easy to fix. This is not a multi-line match; it only needs to match characters /* and */, each of which are on their own line.

The issue here is that here in your syntax highlighting code you have:

<dict>
    <key>begin</key>
    <string>/\*</string>
    <key>end</key>
    <string>\*/</string>
    <key>name</key>
    <string>comment.block.stata</string>
</dict>

This looks for the first /*, then the first following */, and tags all of that as a comment. What you need is to let the block comments be recursive, so that if it finds another /*, it begins an inner comment block, ends the inner comment block on the first */, and ends the outer comment block at the second */. See here in SublimeStataEnhanced for how to support infinite recursion, and I'll submit a PR allowing for once-nested comment blocks. (You need to add a repository file to support infinite recursion, and I hate dealing with plist files.)

I wrote an expansive syntax highlighter for Stata for Atom and Visual Studio code (it accurately highlights regular expression strings, macros, notifies you if you try to write some types of illegal syntax, etc.), and am working on porting it to Sublime, but Sublime doesn't support a key feature of the full tmLanguage format, so I have to transfer it to the new .sublime-syntax format, and that takes a little while. I'll submit a PR once that's finished.

mattiasnordin commented 6 years ago

This should be working now, thanks to kylebarron!