Open chenzimin opened 7 months ago
VB6 does not have classes. Not sure why it's even in the examples/ directory if it's not VB6 valid. Perhaps we need a new version for VB.NET?
You are right, I was confused between VB6 and VB.NET. I wrongly thought that vb6/examples/form1.vb
should be correctly parsed by VB6.
Do you know that if ANTLR4 have a grammar for VB.NET?
Do you know that if ANTLR4 have a grammar for VB.NET?
Pretty sure we don't have one. It should be added to the "to do" list.
If you can, rename the title of the issue to something like "New grammar request: VB.NET".
I have a mostly complete grammar for VBA 7.1, which might be close to .Net https://github.com/Beakerboy/grammars-v4/tree/coverage/vba/vba7_1
PYPI has a python module for the Lexer and Parser as well: https://pypi.org/project/antlr4-vba/
I’m using this to create a Linting tool and precompiler for Office VBA.
I tried to parse vb6/examples/form1.vb
with https://github.com/Beakerboy/grammars-v4/tree/coverage/vba/vba7_1, it failed with a different error message:
line 1:0 extraneous input 'Public' expecting {'ATTRIBUTE', 'VERSION', NEWLINE, REMCOMMENT, COMMENT, WS}
line 1:7 no viable alternative at input ' Class'
https://pypi.org/project/antlr4-vba/ seems to use the same vba grammar as in this repository, and parsing vb6/examples/form1.vb
file with vba.g4 will also return line 1:13 mismatched input 'Form1' expecting <EOF>
VBA files have a required module header similar to:
Attribute VB_Name = “Foo”
since the example is missing that, it will not parse. You can try it in lab.antlr.org with turning the header as optional instead of required
Thanks for the tip, but adding the header Attribute VB_Name = "Foo"
to vb6/examples/form1.vb
still results in line 3:13 mismatched input 'Form1' expecting <EOF>
.
~Is the file missing a newline character at the end?~ Ah, it’s a class. In VBA, class files have a different header.
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Foo”
and the module portion of the file does not start with the word class.
maybe this won’t work, sorry.
I tried to parse the
vb6/examples/form1.vb
file and got the same error invb6/examples/form1.vb.errors
, which is:The
vb6/examples/form1.vb
file contains:Anyway we can fix this?