Beakerboy / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
0 stars 0 forks source link

[BUG] On Error GoTo -1 #44

Open SSlinky opened 5 months ago

SSlinky commented 5 months ago

Parser should interpret On Error GoTo -1 as valid VBA. I shortcut fixed the problem by simply allowing a negative sign in front of INTEGERLITERAL. Unsure if this has breaking ripple effects and you may wish to update the rule to allow -1 or lineNumberLabel. My use case prefers a more tolerant parser though.

INTEGERLITERAL
    : [-]? (DIGIT DIGIT*
    | '&H' [0-9A-F]+
    | '&' [O]? [0-7]+) [%&^]?
    ;

Example ripple effect, the literalExpression would normally be split into a MINUS and INTEGERLITERAL. The result is essentially the same in this case.

image

Beakerboy commented 5 months ago

Thanks! I’ve been trying to follow Microsoft’s lead as much as possible, mainly to ensure that their documentation is valid. This presents a difficult situation though. It seems the only negative integer that is acceptible is ‘-1’. I’ve reported this bug to Microsoft, and they have been quite helpful in clarifying these discrepancies.

SSlinky commented 5 months ago

The only valid negative integer in an On Error statement. They're perfectly valid elsewhere, like in my example above. When used in an expression, though, you'll see the IDE throw in a space for you. For example. Debug.Print 1-4 will automatically adjust to Debug.Print 1 - 4.