ANTLR 4 parser generator command line tool.
$ dotnet add package Antlr4CodeGenerator.ToolJust a commandline wrapper around the ANTLR (Java) tool (Version 4.13.1) for generating grammar artifacts.
The ANTLR (Java) tool is bundled, so no need to download it.
Install as dotnet global tool:
dotnet tool install --global Antlr4CodeGenerator.Tool
Install as dotnet local tool (inside a dotnet project where you want to generate language artifacts):
dotnet new tool-manifest
dotnet tool install Antlr4CodeGenerator.Tool
This tool only proxies the arguments to the ANTLR (Java) tool. (See also ANTLR (Java) tool arguments documentation)
global tool:
dotnet antlr4-tool -Dlanguage=CSharp MyGrammar.g4
local tool via MsBuild target:
<Target Name="GenerateAntlrArtifacts" BeforeTargets="BeforeResolveReferences">
<PropertyGroup>
<_GrammarFile>$(ProjectDir)calculator.g4</_GrammarFile>
<_Generated>$(ProjectDir).generated\</_Generated>
<_Namespace>MyCalculator</_Namespace>
</PropertyGroup>
<Exec Command="dotnet antlr4-tool -Dlanguage=CSharp -o "$(_Generated)" -visitor -listener -package $(_Namespace) "$(_GrammarFile)"" />
</Target>