rubberduck-vba / Rubberduck

Every programmer needs a rubberduck. COM add-in for the VBA & VB6 IDE (VBE).
https://rubberduckvba.com
GNU General Public License v3.0
1.92k stars 301 forks source link

Modify grammar to get comments into the parse tree #167

Closed retailcoder closed 8 years ago

retailcoder commented 9 years ago

Related: #163 (rename grammar rules to follow C# naming conventions); closing this issue should also close #166.

rubberduck203 commented 9 years ago

I'll take a look at this. Theoretically, a comment node begins with a comment identifier (an apostrophe or REM) and ends on a newline, unless there is a line continuation.

retailcoder commented 9 years ago

Yes. Grammar knows this... and skips them. I tried a parser that un-skipped them and didn't get the expected comment nodes. Trial-and-error is not a fun thing to do here - need a tool to run the generated parser against some VBA code, before saying "ok that's the one" and overwriting the files in Rubberduck.

rubberduck203 commented 9 years ago

Yup. Just spotted it. https://github.com/retailcoder/Rubberduck/blob/LexicalTokens/RetailCoder.VBE/VBA/Grammar/VisualBasic6.g4#L876

Comments on their own lines shouldn't be a problem, but I have a feeling that basically all of the other "statements" will need to be modified for situations like this.

If foo Then ` this comment tosses wrenches
    bar
End If

Do you have a VB6 file that you were working with to test the parser? I will probably create a new project to work with this.