Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New grammar request: VB.NET #3967

Open
chenzimin opened this issue Feb 15, 2024 · 8 comments
Open

New grammar request: VB.NET #3967

chenzimin opened this issue Feb 15, 2024 · 8 comments
Labels

Comments

@chenzimin
Copy link
Contributor

chenzimin commented Feb 15, 2024

I tried to parse the vb6/examples/form1.vb file and got the same error in vb6/examples/form1.vb.errors, which is:

line 1:13 mismatched input 'Form1' expecting <EOF>

The vb6/examples/form1.vb file contains:

Public Class Form1

   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      ' Create two buttons to use as the accept and cancel buttons. 
      Dim button1 As New Button()
      Dim button2 As New Button()
      ' Set the text of button1 to "OK".
      button1.Text = "OK"
      ' Set the position of the button on the form.
      button1.Location = New Point(10, 10)
      ' Set the text of button2 to "Cancel".
      button2.Text = "Cancel"
      ' Set the position of the button based on the location of button1.
      button2.Location = _
         New Point(button1.Left, button1.Height + button1.Top + 10)
      ' Set the caption bar text of the form.   
      Me.Text = "tutorialspoint.com"
      ' Display a help button on the form.
      Me.HelpButton = True
     ' Define the border style of the form to a dialog box.
      Me.FormBorderStyle = FormBorderStyle.FixedDialog
      ' Set the MaximizeBox to false to remove the maximize box.
      Me.MaximizeBox = False
      ' Set the MinimizeBox to false to remove the minimize box.
      Me.MinimizeBox = False
      ' Set the accept button of the form to button1.
      Me.AcceptButton = button1
      ' Set the cancel button of the form to button2.
      Me.CancelButton = button2
      ' Set the start position of the form to the center of the screen.
      Me.StartPosition = FormStartPosition.CenterScreen
      ' Set window width and height
      Me.Height = 300
      Me.Width = 560
      ' Add button1 to the form.
      Me.Controls.Add(button1)
      ' Add button2 to the form.
      Me.Controls.Add(button2)
   End Sub
End Class

Anyway we can fix this?

@KvanTTT KvanTTT added the vb label Feb 15, 2024
@kaby76
Copy link
Contributor

kaby76 commented Feb 15, 2024

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?

@chenzimin
Copy link
Contributor Author

chenzimin commented Feb 15, 2024

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?

@kaby76
Copy link
Contributor

kaby76 commented Feb 15, 2024

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".

@chenzimin chenzimin changed the title [VB6] Failed to parse the class name New grammar request: VB.NET Feb 15, 2024
@Beakerboy
Copy link
Contributor

Beakerboy commented Feb 15, 2024

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.

@chenzimin
Copy link
Contributor Author

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>

@Beakerboy
Copy link
Contributor

Beakerboy commented Feb 15, 2024

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

@chenzimin
Copy link
Contributor Author

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>.

@Beakerboy
Copy link
Contributor

Beakerboy commented Feb 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants