A new module with the following code:
Public Sub EraseTwoArrays()
Dim someArray() As String
Dim someOtherArray() as String
Erase someArray(), someOtherArray()
End Sub
yeilds the following error:
msg: "extraneous input ',' expecting {
offending symbol: {[@33,109:109=',',<7>,6:17]}
Line 6, character 17 + 1 (character 18)
A workaround to
Public Sub EraseTwoArrays()
Dim someArray() As String
Dim someOtherArray() As String
Erase someArray()
Erase someOtherArray()
End Sub
fixes the issue temporarily
The parser rule that defines the Erase statement syntax simply doesn't handle it - congratulations, you've found one of the [very] few bugs left in the grammar!
eraseStmt : ERASE WS valueStmt;
The fix is pretty simple: we need to allow multiple valueStmt's.
soo fix would be:
eraseStmt : ERASE WS valueStmtList
valueStmtList : valueStmt (WS? "," WS? valueStmtList)
Or is that basic recursion again a problem for ANTLR?
Why are built-in functions like these treated specially? Couldn't we just treat them as normal function calls ? That is, get rid of the eraseStmt and let it be parsed as a normal procedure call. What are the reasons against such an approach?
@autoboosh very good question. might need to ask the original author for that, @uwol - I believe Rubberduck _is_ using _some_ of these "special-cased" parser rules to implement inspections, but I can't think of one off the top of my head ATM.
@autoboosh well they _could_ be treated as function calls, but they're not part of the VBA standard library (AFAIK), so they wouldn't resolve to a known function anyway. It doesn't hurt either way, but having it in the grammar gives us a handle if we ever want to inspect things.
The grammar distinguishes statements and functions. For each statement, there is a specific parser rule in the grammar according to the official Visual Basic language reference
https://msdn.microsoft.com/en-us/library/aa338153%28v=vs.60%29.aspx
In contrast, functions are not defined as parts of the language and thus not part of the grammar.
E. g. the Erase Statement is defined in
https://msdn.microsoft.com/en-us/library/aa243360%28v=vs.60%29.aspx
just next to typical control structures and in contrast to functions such as the Format function
https://msdn.microsoft.com/en-us/library/aa262745%28v=vs.60%29.aspx
which therefore is not part of the grammar.
A non-recursive fix would be
eraseStmt : ERASE WS valueStmtList
valueStmtList : valueStmt (WS? "," WS? valueStmt)*
Most helpful comment
The grammar distinguishes statements and functions. For each statement, there is a specific parser rule in the grammar according to the official Visual Basic language reference
https://msdn.microsoft.com/en-us/library/aa338153%28v=vs.60%29.aspx
In contrast, functions are not defined as parts of the language and thus not part of the grammar.
E. g. the Erase Statement is defined in
https://msdn.microsoft.com/en-us/library/aa243360%28v=vs.60%29.aspx
just next to typical control structures and in contrast to functions such as the Format function
https://msdn.microsoft.com/en-us/library/aa262745%28v=vs.60%29.aspx
which therefore is not part of the grammar.