antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

Missing Nuget 4.13.2

Open jeffpatton1971 opened this issue 11 months ago • 1 comments
trafficstars

I'm targeting c# and the latest available version of the antlr.runtime is 4.6.6, there is no 4.13.2 available in the nuget repository, the documentation points to a nugget gallery that does not exist.

https://www.nuget.org/packages/Antlr4.Runtime.Standard/4.13.2

I attempted to download 4.6.6 of antlr to recompile my libraries but that's not available or at least I cannot find it from the downloads page.

jeffpatton1971 avatar Dec 13 '24 17:12 jeffpatton1971

Don't use Antlr4, Antlr4.Runtime, Antlr4.CodeGenerator! The ancient "Antlr4cs" nuget packages were forked from "Official" Antlr many years ago. They are now incompatible with "Official Antlr4", which is the code and packages published from this repo.

Use the "Official Antlr 4.13.2" Tool .jar from https://github.com/antlr/website-antlr4/tree/gh-pages/download with the Antlr4.Runtime.Standard.

Note, there is a 4.13.2 Antlr Tool jar, but there is NOT a 4.13.2 Antlr4.Runtime.Standard because there were no significant changes in the Antlr4 CSharp runtime. To avoid thinking about compatibility issues, just use Antlr 4.13.1 Tool jar with 4.13.1 Antlr4.Runtime.Standard.

However, I just recommend you avoid trying to mix and match tool with runtime, trying to run the Antlr tool manually at the command line, and just use Antlr4BuildTasks, which I wrote. This Nuget package replaces the old Antlr4 Nuget package, integrating the "Official" Antlr tool directly into the build.

Antlr4BuildTasks downloads and installs compatible versions of the Antlr tool .jar with Antlr4.Runtime.Standard. It also downloads not only the right Antlr tool jar, but a Java Runtime Environment (JRE) so you avoid all those issues as well. It generates the .cs for parser and lexer, and puts them into the obj/ directory. They are generated files, just like .obj's, just like .exe's. You don't check in generated code, just like you don't check in .objs and .exes into a version control system: it's just bad practice.

To work with Antlr4BuildTasks, just place your .g4's in a directory with the driver code. Then, create a .csproj with an <Antlr4> element, like so:

<Project Sdk="Microsoft.NET.Sdk" >
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
  </PropertyGroup>

  <ItemGroup>
   <Antlr4 Include="Arithmetic.g4"></Antlr4>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version ="4.13.1" />
    <PackageReference Include="Antlr4BuildTasks" Version="12.8" PrivateAssets="all" />
  </ItemGroup>


  <PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" >
    <NoWarn>1701;1702;3021</NoWarn>
  </PropertyGroup>

</Project>

The Antlr4BuildTasks also has a properties specification for use with Visual Studio 2022, so you can set the options for the Antlr4 tool through a nice UI. In VS2022, go to the "Solution Explorer", then right-click on the .g4 file you want to select, then click on "Properties". It'll open with a window to set up the options for running the Antlr Tool.

Screenshot 2024-12-13 133917

kaby76 avatar Dec 13 '24 18:12 kaby76