Just 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.
- Java runtime
-
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):
- See also sample project
- Enable local dotnet tools for your project by the following command on solution file directory level:
dotnet new tool-manifest
- Install as local tool to your project:
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:
- See also sample project
<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>