visual-studio-2019antlr.net-5

Which ANTLR Nuget packages are which?


I'm trying to install ANTLR 4 support in a .NET 5 project in Visual Studio 16.9.2, but I can't figure out which of the myriad ANTLR NuGet packages I should use. I want one that doesn't require Java at all (not just at runtime) and that doesn't require an extension.

I initially used the Antlr4 and Antlr4.Runtime packages, and they seem to work together, but then I found that they're missing the CharStreams class, which as far as I know is the intended way to get an ICharStream object.

I then tried Antlr4.Runtime.Standard instead of Antlr4.Runtime, but that doesn't appear to be compatible with the Antlr4 package. (It gave me many compile errors.) Then I tried switching out Antlr4 for other packages but couldn't find the one that works with Antlr4.Runtime.Standard.

Would someone point me to the valid combinations of generator + runtime, please? There are too many official packages to keep doing trial-and-error. I've looked to several online tutorials, but they tend to be for previous versions of VS that still use a VSIX.


Solution

  • Here is a rundown on the packages you could use:

    You should also be aware of the several other tools I have been writing (for years) to generate Antlr programs:

    I have an extension for VS2019 for Antlr but I recommend that you just use VSCode with my extension or Mike's extension if you need to actually see text colorization of the grammar in order to edit a frigging grammar. Note, VS2019 supports only an ancient version of LSP, and doesn't support semantic highlighting. I complained to MS, but they are extremely slow in updating VS2019. I had to write an LSP type library to work past the limited package MS wrote.

    Edit: The nuget package Antlr4.CodeGenerator is the package that actually encodes the parser generator (aka "tool") for Harwell's port of Antlr4 v4.6.6. It encodes the build rules for msbuild. The equivalent to this for the "official" Antlr4 tool is Antrl4BuildTasks.