Skip to content

ptr1120/Antlr4.CodeGenerator.Tool

Repository files navigation

Antlr4 CodeGenerator tool

License

Latest Release Latest pre Release

Build Status master Build Status develop

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.

Dependencies

  • Java runtime

Installation

  • 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

Usage

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 &quot;$(_Generated)&quot; -visitor -listener -package $(_Namespace) &quot;$(_GrammarFile)&quot;" />
    </Target>