Closed zbagz closed 7 years ago
Yes, this is a known bug. To be able to parse the examples given by you, we would need a preprocessor based on its own grammar, wich parses those precompilation directives, executes them, and generates valid output VB6 source code. That output then could be parsed by the main parser/grammar.
I have implemented that exact process in case of cobol85parser, as COBOL heavily depends on COPY REPLACE statements, but unfortunately do not have time to implement the process for VB6 right now.
However, the VB6 parser should be able to cope with precompilation directives, if they contain valid VB6 code like such:
#If ReturnsByte = 1 Then
Public Function FirstFunction() As Byte
FirstFunction = 1
End Function
#ElseIf ReturnsByte = 0 Then
Public Function FirstFunction() As Integer
FirstFunction = 1
End Function
#End If
At the time of opening this issue I didn't realize this should be done with a preprocessor. I'm doing something very similar to what you proposed in my tool now: evaluating expressions and skipping those lines that aren't needed in a way that the parser receives, "normalized", valid vb6 code. Thank you Ulrich!
MyModule.bas
VB6Parser
Result
Result without #Const directive
Expected Result