Rubberduck: Parse error on mutiple `WithEvents` vars

Created on 1 Dec 2018  路  6Comments  路  Source: rubberduck-vba/Rubberduck

Grammar chokes on this

Private WithEvents a As VB.Form, WithEvents b As VB.Form

Btw, it just says Parse Error on the toolbar. Where can I see the actual error?

antlr bug difficulty-02-ducky

Most helpful comment

The spec covers these in 5.2.3.1 Module Variable Declaration Lists

module-variable-declaration-list = (withevents-variable-dcl / variable-dcl)
*( "," (withevents-variable-dcl / variable-dcl) )

Our grammar doesn't make a distinction between variable declarations in modules and procedure bodies (and we're already parsing non-compilable declarations inside procedures) but this syntax is clearly defined as legal.

Based on how module-variable-declaration-list is defined, I'd be more inclined to say that it belongs to variableSubStmt instead of variableListStmt though:

variableStmt : (DIM | STATIC | visibility) whiteSpace variableListStmt;
variableListStmt : variableSubStmt (whiteSpace? COMMA whiteSpace? variableSubStmt)*;
variableSubStmt : (WITHEVENTS whiteSpace)? identifier (whiteSpace? LPAREN whiteSpace? (subscripts whiteSpace?)? RPAREN)? (whiteSpace asTypeClause)?;

All 6 comments

The actual error message will be in the logfiles. Assuming this code compiles, we'd need to look at how WithEvents is treated in the grammar.

https://github.com/rubberduck-vba/Rubberduck/blob/87f612bc3b15fd0d7b0a321b6afc19749b001a29/Rubberduck.Parsing/Grammar/VBAParser.g4#L552-L554

The relevant grammar section is visible above. Quick, untested and unverified patch suggestion:

- variableStmt : (DIM | STATIC | visibility) whiteSpace (WITHEVENTS whiteSpace)? variableListStmt;
+ variableStmt : (DIM | STATIC | visibility) whiteSpace variableListStmt;
- variableListStmt : variableSubStmt (whiteSpace? COMMA whiteSpace? variableSubStmt)*;
+ variableListStmt : (WITHEVENTS whiteSpace)? variableSubStmt (whiteSpace? COMMA whiteSpace? (WITHEVENTS whiteSpace)? variableSubStmt)*;

This would move the WITHEVENTS from the variableStmt to the variableListStmt. One could argue that it should instead belong to variableSubStmt. I have not consulted the spec for this.

nb that this change will most likely necessitate resolver changes to correctly flag the variables as "with events"

Regarding, seeing the parser error(s), there should be a little red error icon right next to the refresh button stating _Parser Error_. When you click it, a window with the parser error(s) will open.

The spec covers these in 5.2.3.1 Module Variable Declaration Lists

module-variable-declaration-list = (withevents-variable-dcl / variable-dcl)
*( "," (withevents-variable-dcl / variable-dcl) )

Our grammar doesn't make a distinction between variable declarations in modules and procedure bodies (and we're already parsing non-compilable declarations inside procedures) but this syntax is clearly defined as legal.

Based on how module-variable-declaration-list is defined, I'd be more inclined to say that it belongs to variableSubStmt instead of variableListStmt though:

variableStmt : (DIM | STATIC | visibility) whiteSpace variableListStmt;
variableListStmt : variableSubStmt (whiteSpace? COMMA whiteSpace? variableSubStmt)*;
variableSubStmt : (WITHEVENTS whiteSpace)? identifier (whiteSpace? LPAREN whiteSpace? (subscripts whiteSpace?)? RPAREN)? (whiteSpace asTypeClause)?;

there should be a little red error icon right next to the refresh button stating Parser Error. When you click it, a window with the parser error(s) will open.

Oh, I see I'm missing the icons here and the button next to Refresh/Parse Error is not apparent

image

Probably something with my installation (I'm not filing a bug here:-))

Hm, that the icon does not appear might actually be a bug. The system for the buttons works a bit different in the VB6 editor compared to the VBE. So, we might have missed to implement that the button appears.

It's #3952.

Was this page helpful?
0 / 5 - 0 ratings