kaby76 / Antlr4BuildTasks

Third-party build tool for 'Official' Antlr4 tool and runtime parsers using .Net. Drop-in replacement for 'Antlr4cs' Antlr4 tool and build rules.
MIT License
73 stars 10 forks source link

How to determine interface for the result of a build? #37

Closed asfarley closed 2 years ago

asfarley commented 2 years ago

I've followed the tutorials and successfully built a lexer/parser using the Readme guide, in VS2022.

I have basically only done the absolute minimum to get the project building:

Is there any guidance on how to use the generated output? For example, I see some classes have been created:

LanguageLexer LanguageParser

It appears that LanguageLexer accepts an input of Anltr4.Runtime.ICharStream; is there a function to convert an input file to this type?

asfarley commented 2 years ago

Nevermind, I found an answer on the main Antlr4 repo.

kaby76 commented 2 years ago

Now that you have the build environment working, I would recommend that you try the Antlr4Templates package I wrote to create a basic Antlr parser with driver e.g. dotnet new csharp-combine. You can then open the project in VS2022, build, and single step through the program to see how it works. That should help start to answer some of your questions on how to use Antlr. Let me know how it goes.

asfarley commented 2 years ago

Thank you, looks like Antlr4Templates had exactly what I needed.

asfarley commented 2 years ago

One thought - while the example does show how to set up an ErrorListener, I would also be interested in seeing examples of setting up custom listeners and visitors.

The Antlr4 documentation does provide a very loose example of how to do this, but it's written in fragments as opposed to a single compile-able project. Having this included in the templates could be helpful to clarify any ambiguities.

kaby76 commented 2 years ago

I agree. There should be examples of listeners, visitors, recovery, error messages, etc.