GithubHelp home page GithubHelp logo

kaby76 / antlr4buildtasks Goto Github PK

View Code? Open in Web Editor NEW
72.0 72.0 10.0 56.31 MB

Third-party build tool for 'Official' Antlr4 tool and runtime parsers using .Net. Drop-in replacement for 'Antlr4cs' Antlr4 tool and build rules.

License: MIT License

C# 98.76% Shell 0.58% Makefile 0.01% ANTLR 0.65%

antlr4buildtasks's Introduction

Ken Domino - kaby76

Codinggorilla -- down for rebuilding

Current Work

Connect with me:

KenDomino | Twitter kenneth-e-domino | LinkedIn




Machine Instruction Sets

CIL PTX JVM 390 68k x86 Vax z80 6502 PDP8




Languages

Kotlin C# Java C++ Perl Pascal C Lisp BCPL Algol W Fortran APL




Tools

Antlr Bash Bison Blender dotCover dotMemory dotPeek Git GitHub Google Play Inkscape NET Core Resharper VirtualBox Xamarin




Editors

Android Studio Eclipse Emacs Intellij-Idea NetBeans PhpStorm PyCharm Rider Vim Visual Studio Code Visual Studio IDE Webstorm




Operating Systems

Android Ubuntu Windows 10




Online Presence

Gitter Reddit Stack Overflow





⚡ Github Stats kaby76's Github Stats

antlr4buildtasks's People

Contributors

andreadistefano avatar cx-ricardop avatar dependabot[bot] avatar kaby76 avatar lextm avatar mrfootoyou avatar viceice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

antlr4buildtasks's Issues

Suggest PrivateAssets option set to all by default

Hi, yesterday I exported an executable which uses under the hood ANTLR and generates parser, lexer and visitor code with the targets provided by this package and I noticed that also Antlr4BuildTasks.dll is exported in the publish folder.

Does this package also export code that should be bundled with the application?
If not, I think it would be better to suggest in the documentation to set PrivateAssets option to all in the package reference:

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

This applies to README but also to Antlr4BuildTasks.Templates and to kaby76/testantlr.

Also, I don't know if it is possible to configure the NuGet package to install itself with this default when installed via GUI, in a similar way analyzers do.

Feature request: Not include generated files in Compile

I would prefer to have the generated files as a part of a git repository insted of being ephemeral.

I tried to set the output path for the .g4 file to '.' and it works perfectly, the sdk project format picks it up immediately. However, since the task adds it as compile items it produces duplicate definition errors.

Would it be possible to add an option to the Antlr4 item to not include the files in Compile list and let the project handle it?

I also removed *.interop and *.tokens files, since they are not compiled and presumably used only during code generation.

<PropertyGroup>
  <DefaultItemExcludes>$(DefaultItemExcludes);**\*.interp;**\*.tokens</DefaultItemExcludes>
</PropertyGroup>

Trying to update

Hello -

Apologies in advance as this is not a bug but I was trying to switch from using antlrcs.

I made the changes listed on the info:

From:

    <ItemGroup>
      <PackageReference Include="Antlr4" Version="4.6.6">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      </PackageReference>
      <PackageReference Include="Antlr4.CodeGenerator" Version="4.6.6">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      </PackageReference>
      <PackageReference Include="Antlr4.Runtime" Version="4.6.6" />
<ItemGroup/>

To:

<ItemGroup>
      <PackageReference Include="Antlr4" Version="4.6.6">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      </PackageReference>
      <PackageReference Include="Antlr4BuildTasks" Version="11.1" PrivateAssets="all" />
      <PackageReference Include="Antlr4.Runtime.Standard" Version="4.11.1" />
<ItemGroup/>

And:

    <ItemGroup>
      <Content Include="AsciiTestPattern\Grammar\atp.g4" />
      <Content Include="StandardTestInterfaceLanguage\Grammar\stil.g4" />
      <Content Include="UniversalPinTable\Grammar\upt.g4" />
    </ItemGroup>

to:

    <ItemGroup>
      <Antlr4  Include="AsciiTestPattern\Grammar\atp.g4" />
      <Antlr4  Include="StandardTestInterfaceLanguage\Grammar\stil.g4" />
      <Antlr4  Include="UniversalPinTable\Grammar\upt.g4" />
    </ItemGroup>

and I'm getting this error

  atpLexer.cs(151, 25): [CS1715] 'atpLexer.SerializedAtn': type must be 'int[]' to match overridden member 'Recognizer<int, LexerATNSimulator>.SerializedAtn'

Wondering if you are familiar with it ? The array which this error asks to convert to int is a string array which I didn't generate.

	public static readonly string _serializedATN =
		"\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x2[\x3D2\b\x1\x4\x2"+
		"\t\x2\x4\x3\t\x3\x4\x4\t\x4\x4\x5\t\x5\x4\x6\t\x6\x4\a\t\a\x4\b\t\b\x4"+

How to determine interface for the result of a build?

I've followed the tutorials and successfully built a lexer/parser using the Readme guide, in VS2022.

I have basically only done the absolute minimum to get the project building:

  • Create a grammar file
  • Add an empty .CS file
  • Add appropriate nuget packages (Antlr4.Runtime.Standard, Antlr4BuildTasks)
  • Build project
  • Generated files appear

Is there any guidance on how to use the generated output? For example, I see some classes have been created:

LanguageLexer
LanguageParser

It appears that LanguageLexer accepts an input of Anltr4.Runtime.ICharStream; is there a function to convert an input file to this type?

Task GetAntlrJar fails with a ANTLR 4.9

After updating my dependency from Antlr4.Runtime.Standard 4.8 to 4.9, I get this error.

Antlr4BuildTasks.targets(143, 3): [MSB4018] errore imprevisto dell'attività "GetAntlrJar".
System.Exception: Unhandled version of Antlr4.Runtime.Standard. Make sure you add to your csproj file.
in Antlr4.Build.Tasks.GetAntlrJar.Execute()
in Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
in Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

Is there some hard-coded version check?

"Build" triggered unexpectedly

Using Visual Studio 2022 17.2.3

I'm noticing some unusual behavior. When I set the path for generated files in File Properties (for my grammar), it appears that the files are generated immediately, as if modifying this field is a trigger for the build itself.

Is this intentional?

Then, if I "Build Solution" manually, I get 97 error messages indicating duplicate definitions:
image

Here is a repository to reproduce this issue:
https://github.com/asfarley/antlrbuilddemo

Please let me know if I've done something incorrectly or if you need more information.

Build Errors Since > 8.16.0

Hi, we have encountered an issue since trying to update this package on our repo from 8.16.0 to 8.17.0/8.18.0/8.20.0. The error we get is:

Severity Code Description Project File Line Suppression State
Error MSB4018 The "GetAntlrJar" task failed unexpectedly.
System.Exception: Antlr4BuildTasks is going to return an empty UsingToolPath, but it should never do that.
at Antlr4.Build.Tasks.GetAntlrJar.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() DirectoryService.Core.ODataFilterParser C:\Users**.nuget\packages\antlr4buildtasks\8.20.0\build\Antlr4BuildTasks.targets 170

You don't happen to know why this would happen?

CI builds failing

The CI builds are failing for this repo. While the tool seems to "work", this really needs to be fixed because it looks bad.

Add probe list for Antlr jar location

From #9, NiccoMlt mentioned that the Antlr jar should be fetched from Maven Central. I think this is the right thing to do because the Antlr build scripts in Java do that. So, the location should do this.

However, there are several issues:

  • If the Maven Central (https://repo1.maven.org/maven2/org/antlr/antlr4/) is down, then it should be able to fetch from the Antlr downloads area instead (https://www.antlr.org/download/index.html).
  • The jar and path are inconsistently named, so the code will need to be robust. The Nuget repository has Antlr4.Runtime.Standard version 4.7.1.1, but there is no 4.7.1.1 version of the .jar file. Similarly, there is 4.8-1 jar version in Maven Central, but no such version in the Antlr download area nor the NuGet repository. The downloads in the Antlr Download area are named "antlr-..." not "antlr4-...".

AntOutDir not working

Hi,

for reasons I need to set the output directory for the generated files. In an older issue I found the tag "AntOutDir", however, that doesn't seem to work anymore. My code is always generated in obj/Release.

I hope you can help me.

Thanks
Hannes

"dotnet new antlr" should accept additional arguments

When creating a new Antlr application from the template, it currently does not accept any arguments. And, it generates an app with the namespace based on the current directory. Some source assumes apriori a namespace (see kaby76/AntlrVSIX#125). The workflow to using the template up to this point was that (1) you'd first "mkdir directory", (2) "cd directory", then (3) copy all the sources into this directory, (4) "dotnet restore; dotnet build". If you needed to change the namespace or add options to the build, you'd have to manually do that using VS2019 or edit the .csproj file. This is not good because of Trash builds.

With Trash, the driver I am generating isn't using Antlr4BuildTasks.Templates. In fact, I was duplicating a bit of code from Antlr4BuildTasks. This is wrong because I shouldn't introduce any hacks to modify the driver program. "Generate" is already dependent on Antlr4BuildTasks. I just now need to accept additional parameters to set up the .csproj file correctly with a namespace or other information.

error ANT02: Cannot find Java executable, currently set to '/usr/bin/java'

This is happening trying to update to version 10 and running this package in a docker container with a .net solution.

Typical build instruction would be :

RUN dotnet build *****.csproj -c "*****" -o /app/build -p:AntlrvsixJavaExec="${JAVA_HOME}/bin/java"

AntlrvsixJavaExec is a path we are using that points to the java executable and this works with previous changes. Has this property changed at all do you know?

Big performance hit after switch from `Antlr4.CodeGenerator` to `Antlr4BuildTasks` and `Antlr4.Runtime.Standard`

Hey @kaby76,

I've just recently discovered your work around ANTLR and C#, and I'm impressed! Thank you very much, first of all.

So I was pretty excited to be able to move to the newer targets, and had good results in some project. However, I had a very big performance regression in one grammar, and I can't understand why.

The grammar is pretty simple. Essentially, some texts can have square brackets denoting some placeholders, which we try to parse so that we can build a data model around it.

The grammar looks like this:

grammar GAEB2000PlainTextTextAdditions;

@parser::members
{
    protected const int EOF = Eof;
}

@lexer::members
{
    protected const int EOF = Eof;
    protected const int HIDDEN = Hidden;
}

/*
 * Parser Rules
 */

text         : ( textAddition | plainText | brackets )* compileUnit ;
textAddition : OpenBrack (buyer=TA | bidder=TB) identifier+=Digit+ content=textContent CloseBrack ;
plainText    : ( Digit | Text | textAddLike )+ ;
textAddLike  : TA | TB ;
brackets     : OpenBrack | CloseBrack ;
textContent  : heading=plainText? OpenBrack body=plainText CloseBrack tail=plainText? ;
compileUnit    :    EOF ;

/*
 * Lexer Rules
 */

TA          : 'TA'  ;
TB          : 'TB'  ;
OpenBrack   : '['   ;
CloseBrack  : ']'   ;
Digit       : [0-9] ;
Text        : .     ;

Now, we're building a Lexer and a Parser from it and try it out it with the following test:

        [Fact]
        public void CheckAntlrPerformance()
        {
            var inputString = @"There is some text before
 
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

[TA11Offered Type: [....................................................] 
]
 

Location   : [TA12[.......]]";

            for (var i = 0; i < 10_000; i++)
            {
                PerformAntlrParsing(inputString);
            }
        }

        private void PerformAntlrParsing(string inputString)
        {
            var inputStream = new AntlrInputStream(inputString);
            var lexer = new GAEB2000PlainTextTextAdditionsLexer(inputStream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser = new GAEB2000PlainTextTextAdditionsParser(tokenStream);

            parser.Interpreter.PredictionMode = PredictionMode.SLL;
            TextContext result;
            result = parser.text();
        }

I was hoping for a bit of a performance improvement, but it actually went from around 2.4 seconds to 29.2 seconds, so roughly an order of magnitude slower. Profiling a few runs doesn't give me a lot of information. The memory allocation is pretty small throughout the test, and there's not a lot of GCs happening either. I see this after a few thousand iterations:

image

So, I'm a bit at a loss here how to proceed. I've checked the grammar also with tranalyze, but if I understand it correctly, the output is just statistics or telling me a rule is fine (NotEmpty):

trparse GAEB2000PlainTextTextAdditions.g4 | tranalyze -s text
7 occurrences of Antlr - nonterminal def
23 occurrences of Antlr - nonterminal ref
6 occurrences of Antlr - terminal def
3 occurrences of Antlr - keyword
5 occurrences of Antlr - literal
Rule text is NonEmpty
Rule textAddition is NonEmpty
Rule plainText is NonEmpty
Rule textAddLike is NonEmpty
Rule brackets is NonEmpty
Rule textContent is NonEmpty
Rule compileUnit is NonEmpty
Rule TA is NonEmpty
Rule TB is NonEmpty
Rule OpenBrack is NonEmpty
Rule CloseBrack is NonEmpty
Rule Digit is NonEmpty
Rule Text is NonEmpty

For reference, the strings we usually encounter in the wild are at most on the order of a kilobyte size or so, and usually just contain one or very few such tags.

Build failure using Antlr4.Runtime.Standard 4.10.1 but not 4.9.3

I don't know if this bug is in Antlr4.Runtime.Standard or Antlr4BuildTasks. If this is the wrong repository for the bug then I can raise it in the appropriate repository instead.

Create a class library project containing just the 2 files below:

ClassLibrary1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version="4.9.3" />
    <PackageReference Include="Antlr4BuildTasks" Version="10.3.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <Antlr4 Include="HelloWorldGrammar.g4" />
  </ItemGroup>
</Project>

HelloWorldGrammar.g4

grammar HelloWorldGrammar;
r   : 'hello' ID;
ID  : [a-z]+ ;
WS  : [ \t\r\n]+ -> skip ;

Run dotnet build and you will get a bunch of warnings about not needing CLSCompliant attribute but otherwise the build is successful.

Now change Antlr4.Runtime.Standard version to either 4.10.0 or 4.10.1, run dotnet build and get the following build errors:

...\ClassLibrary1\obj\Debug\net6.0\HelloWorldGrammarParser.cs(67,25): error CS1715: 'HelloWorldGrammarParser.SerializedAtn': type must be 'int[]' to match overridden member 'Recognizer<IToken, ParserATNSimulator>.SerializedAtn' [...\ClassLibrary1\ClassLibrary1.csproj]
...\ClassLibrary1\obj\Debug\net6.0\HelloWorldGrammarLexer.cs(84,25): error CS1715: 'HelloWorldGrammarLexer.SerializedAtn': type must be 'int[]' to match overridden member 'Recognizer<int, LexerATNSimulator>.SerializedAtn' [...\ClassLibrary1\ClassLibrary1.csproj]

In both HelloWorldGrammarParser.cs and HelloWorldGrammarLexer.cs the errors are in public override string SerializedAtn { get { return new string(_serializedATN); } } where SerializedAtn should return int[] rather than string type.

Getting error inside VS2019, but `dotnet build` runs fine

C:\Users\Nick\.nuget\packages\antlr4buildtasks\8.14.0\build\Antlr4BuildTasks.targets(195,3): error MSB4181: The "RunAntlrTool" task returned false but did not log an error.

Tried restarting VS, updating to latest minor patch, restarting Windows, and clearing the NuGet cache.

The weird thing is, it works fine in the template generated project but not my own solution.

Building first project - help needed

Hi,

I am just starting with Antlr4 and trying to compile my first project.
Not sure how should I organize the solution and what is the exact procedure for generating parser code
Perhaps you could provide some guildlines. I have done the following

  1. I am using Visual Studio 2019 Professional (latest version 16.7.3)

  2. I have installed VS extension AntlrVSIX 8.0 (using the Extension Manager)

  3. In my solution I have created a .NET Standard 2.1 Library project

  4. Created a dummy .cs class

  5. I have referenced the following packages using NuGet
    a. Antlr4.Runtime.Standard Version 4.8
    b. Antlr4BuildTasks Version 8.3.0

  6. I have added grammar files, TSqlParser.g4 and TSqlLexer.g4 found here (I am trying to create a TSQL Parser)
    https://github.com/antlr/grammars-v4/tree/master/sql/tsql

  7. My .csproj project file looks as follows:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>   
  
  <ItemGroup>
    <Antlr4 Include="TSqlLexer.g4">
      <Package>MyLib.SQLParser</Package>
      <Visitor>false</Visitor>
      <Error>false</Error>
      <Listener>false</Listener>      
    </Antlr4>
    <Antlr4 Include="TSqlParser.g4">
      <Package>MyLib.SQLParser</Package>
      <Visitor>false</Visitor>
      <Error>false</Error>
      <Listener>false</Listener>      
    </Antlr4>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version="4.8.0" />
    <PackageReference Include="Antlr4BuildTasks" Version="8.3.0" />
  </ItemGroup>

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

</Project>
  1. Files TSqlParser.cs and TSqlLexer.cs get created in the folder
    \MyLib.SQLParser\bin\Debug\netstandard2.1

My questions are as follows:

  • How should be the solution organized?
  • Should I create a separate project (referencing Antlr4BuildTasks and Antlr4.Runtime.Standard) only with grammar files that after rebuild would create .cs files
  • Should I copy these files later on to my other project (or reference them by adding existing items from ...bin\Debug\netstandard2.1 folder)
    or maybe it all should be a part of a single library project (the library will also include other classes, functionality, etc. ?

Mutating "info" messages to error is very annoying

I think I'm changing my mind--info messages should not be mutated to errors. I think the problem I had is that when there is a "throw", I need to print out the error stack. But, I don't have code to change a stack trace back into one error message, in particular if Antlr tool itself performs outputs that stack trace.

The "GetJava" task failed unexpectedly

Hello

I have created a .Net Core 3.1 project in Visual Studio 2019 (16.5.1) with the following NuGet packages:
Antlr4.Runtime.Standard (4.9.2)
Antlr4BuildTasks (8.14.0)

I have then created a grammar file and amended the csproj file like this:

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

When I try to compile the project I get the following Error:
The "GetJava" task failed unexpectedly

Can you help please?
Thanks

Stack overflow in error listener

I've been putting this off, but there is a bug in the error reporter code I wrote for the Antlr program template. I'm checking in the code to reproduce it.

ANT02 Cannot find Java executable'' With csproj multitargeting

In csproj files, we are using multiple targets <TargetFrameworks>net472;net6.0-windows</TargetFrameworks>.
This is not working with antlr4buildtasks when it downloads automatically java.
Msbuild compile both targets at the same time and I suspect that antl4builtasks is trying to download and unzip java in the same folder at the same time which is not working.
If I remove one target, it builds fine.

You should change the way you manage ".jre" folder to handle multiple projects building in parallel.

error ANT02: Cannot find Java executable''   à Antlr4.Build.Tasks.RunAntlrTool.SetupJava()
error ANT02:    à Antlr4.Build.Tasks.RunAntlrTool.Execute()
error ANT02: The Antlr4 tool failed.

64 bit version of functions?

This is more of a general question as opposed to an issue - I am using antlr4 and your build tasks library. I am however running out of memory on large files which are more than 1G while zipped. I was wondering if there is a way to force the libraries to use more memory - by perhaps using 64 bit equivalents?

This is the error

FATAL: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at System.IO.StreamReader.ReadToEnd()
   at Antlr4.Runtime.AntlrInputStream.Load(TextReader r, Int32 size, Int32 readChunkSize)
   at Antlr4.Runtime.AntlrInputStream..ctor(TextReader r, Int32 initialSize, Int32 readChunkSize)
   at Antlr4.Runtime.AntlrInputStream..ctor(TextReader r, Int32 initialSize)
   at Antlr4.Runtime.AntlrInputStream..ctor(Stream input)

error ANT02: Cannot find Java executable'' on MacOS

<TargetFramework>netstandard2.1</TargetFramework>

https://github.com/rstm-sf/qsharp-compiler/blob/infra/use_Antlr4BuildTasks/src/QsFmt/Parser/Parser.csproj

16>Antlr4Compile:
    Running the Java Antlr Tool over the grammar files '/Users/runner/work/1/s/src/QsFmt/Parser/../../../qsharp-language/Specifications/Language/5_Grammar/QSharpLexer.g4;/Users/runner/work/1/s/src/QsFmt/Parser/../../../qsharp-language/Specifications/Language/5_Grammar/QSharpParser.g4'.
    Starting Antlr4 Build Tasks.
    Placing generated files in IntermediateOutputPath /Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/
    Antlr4BuildTasks identified that you are looking for version 4.11.1 of the Antlr4 tool jar.
    Version '4.11.1' v2 match='', v3 match='4.11.1'
    Location to stuff Antlr tool jar, if not found, is /Users/runner/.m2/
    Paths to search for Antlr4 jar, in order, are: file:////Users/runner/.m2/;file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/
    path is file:////Users/runner/.m2/
    place_path is /Users/runner/.m2/
    Probing file:////Users/runner/.m2/antlr4-4.11.1-complete.jar
    Local path \\users\runner\.m2\antlr4-4.11.1-complete.jar
    path is file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/
    place_path is /Users/runner/.m2/
    Probing file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/antlr4-4.11.1-complete.jar
    Local path \\users\runner\work\1\s\src\QsFmt\Parser\obj\Release\netstandard2.1\antlr4-4.11.1-complete.jar
    path is https://repo1.maven.org/maven2/org/antlr/antlr4/
    place_path is /Users/runner/.m2/
    Probing https://repo1.maven.org/maven2/org/antlr/antlr4/4.11.1/antlr4-4.11.1-complete.jar
    archive_name is /Users/runner/.m2/antlr4-4.11.1-complete.jar
    place_path is /Users/runner/.m2/
    Downloading https://repo1.maven.org/maven2/org/antlr/antlr4/4.11.1/antlr4-4.11.1-complete.jar
    archive_name is /Users/runner/.m2/antlr4-4.11.1-complete.jar
    place_path is /Users/runner/.m2/
    Found /Users/runner/.m2/antlr4-4.11.1-complete.jar
    AntlrToolJar is "/Users/runner/.m2/antlr4-4.11.1-complete.jar"
    Location to stuff JRE, if not found, is /Users/runner/.jre/
    Paths to search for the java executable, in order, are: PATH;DOWNLOAD
    path is PATH
    Executing command: "/usr/bin/java" --version
    Unrecognized option: --version
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    java found at '/usr/bin/java', but it doesn't work.
    path is DOWNLOAD
    Probing DOWNLOAD
    Downloading OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Completed downloading of OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Found /Users/runner/.jre/OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Java should be here /Users/runner/.jre/jdk-11.0.15+10-jre/bin/java
    Decompressing
    full path "/Users/runner/.jre/jdk-11.0.15+10-jre/"
    Executing command: "/usr/bin/chmod" 755 /Users/runner/.jre/jdk-11.0.15+10-jre/
16>/Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02: Cannot find Java executable''   at Antlr4.Build.Tasks.RunAntlrTool.SetupJava() [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
    /Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02:    at Antlr4.Build.Tasks.RunAntlrTool.Execute() [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
16>/Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed. [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
16>Done Building Project "/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj" (default targets) -- FAILED.

https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_build/results?buildId=46269&view=results

Small suggestions re. my StackOverflow post

Hi, from https://stackoverflow.com/questions/63191238/antlr4-runtime-problem-in-visual-studio-2019, trivial stuff but still.

  1. I didn't know what the "dotnet new -i ..." was intended to do so I didn't know if it needed admin privileges (it doesn't).
  2. It needs a working connection (some installs don't because they are shipped with components disabled but that's not what happens here).
  3. It installs templates not immediately-executable code -- again, I didn't know this. It's why it doesn't need admin privs.
    These are small points but simple clarification would be helpful.
  4. And when it actually ran, I got errors. Looking at the code that was deliberate, but it was yet another moment of "Oh no, what now" (it had been a long day). Simply adding in a print() statement above saying something like "the following are deliberate parsing errors, see the code" would be very nice indeed.

bug: Cannot build on *nix systems when the Intermediate Output folder is outside the source project

Cannot build on *nix systems (Ubuntu, MacOS) when the $(BaseIntermediateOutputPath), e.g. obj folder, is located outside the project folder.

  • Antlr4BuildTasks 8.9
  • Ubuntu 18.04, MacOS 10.15 (Github workers)
  • .NET 3.1

An example repo can be found here. Notice that the Directory.Build.props has configured the $(BaseIntermediateOutputPath) to a location outside the project located in .\src\TestProj.

Cause

The MakeRelativeList task is converting the correct absolute path to an incorrect relative path. The following log snippet shows the error occurring. Notice that the absolute paths are being "un-rooted", causing MSBuild to treat them as relative paths:

2021-01-04T18:50:36.1796840Z                    Using "MakeRelativeList" task from assembly "/home/runner/.nuget/packages/antlr4buildtasks/8.8.0/build/../lib/netstandard2.0/Antlr4BuildTasks.dll".
2021-01-04T18:50:36.1797861Z                    Task "MakeRelativeList" (TaskId:27)
2021-01-04T18:50:36.1798479Z                      Task Parameter:
2021-01-04T18:50:36.1798864Z                          List1=
2021-01-04T18:50:36.1800527Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarParser.cs
2021-01-04T18:50:36.1802417Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarLexer.cs
2021-01-04T18:50:36.1804161Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarListener.cs
2021-01-04T18:50:36.1817787Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarBaseListener.cs
2021-01-04T18:50:36.1820094Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarVisitor.cs
2021-01-04T18:50:36.1822122Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarBaseVisitor.cs
2021-01-04T18:50:36.1824191Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarLexer.cs
2021-01-04T18:50:36.1826224Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParser.cs
2021-01-04T18:50:36.1828183Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserListener.cs
2021-01-04T18:50:36.1831121Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserBaseListener.cs
2021-01-04T18:50:36.1833370Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserVisitor.cs
2021-01-04T18:50:36.1835809Z                              /home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserBaseVisitor.cs (TaskId:27)
2021-01-04T18:50:36.1838406Z                      Yo I just entered MakeRelativeList (TaskId:27)
2021-01-04T18:50:36.1838982Z                      Output Item(s): 
2021-01-04T18:50:36.1839525Z                          FixedToCompileFiles=
2021-01-04T18:50:36.1840939Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarParser.cs
2021-01-04T18:50:36.1843385Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarLexer.cs
2021-01-04T18:50:36.1845610Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarListener.cs
2021-01-04T18:50:36.1847660Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarBaseListener.cs
2021-01-04T18:50:36.1849714Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarVisitor.cs
2021-01-04T18:50:36.1851708Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/CombinedGrammarBaseVisitor.cs
2021-01-04T18:50:36.1853642Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarLexer.cs
2021-01-04T18:50:36.1855995Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParser.cs
2021-01-04T18:50:36.1858830Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserListener.cs
2021-01-04T18:50:36.1861212Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserBaseListener.cs
2021-01-04T18:50:36.1863272Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserVisitor.cs
2021-01-04T18:50:36.1865297Z                              home/runner/work/antlr4-linux-bug/antlr4-linux-bug/artifacts/builds/TestProj/obj/Release/netstandard2.0/SplitGrammarParserBaseVisitor.cs (TaskId:27)
2021-01-04T18:50:36.1866600Z                    Done executing task "MakeRelativeList". (TaskId:27)

Workaround

A workaround is to override the solution/repo's Directory.Build.props with a local, project-specific Directory.Build.props such as this.

error ANT02: Went through the complete probe list looking for an Antlr4 tool jar, but could not find anything. Fail!

I've tried to use the Antlr4BuildTasks-Nuget-Package (12.2.0) in a C#-Project with Visual Studio 2022 on Windows 10.

Then I've got the following error messages:
error ANT02: Went through the complete probe list looking for an Antlr4 tool jar, but could not find anything. Fail!
error ANT02: Cannot find Antlr4 jar file, currently set to '' at Antlr4.Build.Tasks.RunAntlrTool.SetupAntlrToolJar()
error ANT02: at Antlr4.Build.Tasks.RunAntlrTool.Execute()
error ANT02: The Antlr4 tool failed.

As I understood, the package tries to download a JRE and the Antlr4 tool jar file:
Antlr4BuildTasks downloads a JRE for your OS and places it in $USERPROFILE/.jre/ on Windows and $HOME/.jre/ on Linux. The package also downloads the Antlr4 tool JAR file and places it in $USERPROFILE/.m2/ on Windows and $HOME/.m2/ on Linux.

But these folders don't exist on my machine after the build was running.

Any ideas of what could be wrong?

Error with Visual Studio 17.3.1

The nuget package antlr4buildtasks 10.7.0 has a warning icon in Visual Studio.
I got this error message

C:\Users\philippe.laval.nuget\packages\antlr4buildtasks\10.7.0\build\Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed.

Ungraceful crash if Antlr4.Runtime.Standard is not referenced

I forgot to include the antlr runtime packagereference in a csproj file once. When I did a build, Antlr4BuildTasks crashed, and gave a strange error message. The tool should give a better error message. Also, it's unclear what would happen if I reference some other antlr runtime.

Concurrency access to JAR file

Is also possible to have a tag to set the location to download and execute the Antlr4 tool JAR file as have to the JRE?
I have multiple projects building at the same time and this causes problems with concurrency access to JAR file (Error : Could not find or load main class org.antlr.v4.Tool). I believe that during the execution a project tries to use the file but another project has already used and deleted it. The idea is to set a different location for each project and I believe that solving the problem, unless, you have a different approach to solve this problem.

Thanks in advance

Cannot handle spaces in project path

Thanks for all your hard work on these Antlr repositories. I am not sure if this is a problem with Antlr4Templates, or Antlr4BuildTasks.

I used Antlr4Templates, specifically the antlr4 template, to create a new project in a new directory. This built fine.

Then I opened the project in Visual Studio and upgraded the nuget package Antlr4BuildTasks to version 9.2.0. Now the project does not build. I have spaces in the project path, and this seems to cause the problem: when processing "Visual Studio Projects" it is breaking up the path at "Studio":

                     Starting Antlr4 Build Tasks. (TaskId:55)
                     Placing generated files in IntermediateOutputPath D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\ (TaskId:55)
                     AntOutDir is "D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\" (TaskId:55)
                     JavaExec is "D:/Frank/Visual Studio Projects/DASH/NGAW2/AntlrTest/obj/Debug/net6.0/Java/jre/bin/java.exe" (TaskId:55)
                     Antlr4BuildTasks identified that you are looking for version 4.9.3 of the Antlr4 tool jar. (TaskId:55)
                     Paths to search for Antlr4 jar, in order, are: file:///D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\;https://repo1.maven.org/maven2/org/antlr/antlr4/4.9.3/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.9.2/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.9.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.9/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.8-1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.8/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.7.2/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.7.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.7/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.6/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5.3/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5.2-1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5.2/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5.1-1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.5/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.3/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.2.2/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.2.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.2/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/4.0/ (TaskId:55)
                     path is file:///D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\ (TaskId:55)
                     Probing file:///D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\antlr4-4.9.3-complete.jar (TaskId:55)
                     Local path D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\antlr4-4.9.3-complete.jar (TaskId:55)
                     Found. (TaskId:55)
                     ToolPath is "D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\antlr4-4.9.3-complete.jar" (TaskId:55)
                     Executing command: "D:/Frank/Visual Studio Projects/DASH/NGAW2/AntlrTest/obj/Debug/net6.0/Java/jre/bin/java.exe" -cp "D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\antlr4-4.9.3-complete.jar" org.antlr.v4.Tool -depend -o "D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\obj\Debug\net6.0\" -encoding UTF-8 -listener -visitor -package AntlrTest -Dlanguage=CSharp "D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\Arithmetic.g4" (TaskId:55)
14:58:01.187   2:6>C:\Users\frank\.nuget\packages\antlr4buildtasks\9.2.0\build\Antlr4BuildTasks.targets(131,3): error ANT02: error(7):  cannot find or open file: Studio [D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\AntlrTest.csproj]
14:58:01.187   2:6>C:\Users\frank\.nuget\packages\antlr4buildtasks\9.2.0\build\Antlr4BuildTasks.targets(131,3): error ANT02: error(7):  cannot find or open file: Projects\DASH\NGAW2\AntlrTest\Arithmetic.g4 [D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\AntlrTest.csproj]
                     Finished executing Antlr jar command. (TaskId:55)
                     The generated file list contains 0 items. (TaskId:55)
14:58:01.187   2:6>C:\Users\frank\.nuget\packages\antlr4buildtasks\9.2.0\build\Antlr4BuildTasks.targets(131,3): error ANT02: The Antlr4 tool failed. [D:\Frank\Visual Studio Projects\DASH\NGAW2\AntlrTest\AntlrTest.csproj]
                   Done executing task "RunAntlrTool" -- FAILED. (TaskId:55)
14:58:01.188   2:6>Done building target "Antlr4Compile" in project "AntlrTest.csproj" -- FAILED.: (TargetId:64)

The "SubtractList" task failed unexpectedly

When trying to build a project I get an error The "SubtractList" task failed unexpectedly.
This seems to be an issue with the msbuild task Antlr4.

1>C:\Users\emphasis\.nuget\packages\antlr4buildtasks\8.2.0\build\Antlr4BuildTasks.targets(262,3): error MSB4018: The "SubtractList" task failed unexpectedly.
1>C:\Users\emphasis\.nuget\packages\antlr4buildtasks\8.2.0\build\Antlr4BuildTasks.targets(262,3): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
1>C:\Users\emphasis\.nuget\packages\antlr4buildtasks\8.2.0\build\Antlr4BuildTasks.targets(262,3): error MSB4018:    at Antlr4.Build.Tasks.SubtractList.Execute()
1>C:\Users\emphasis\.nuget\packages\antlr4buildtasks\8.2.0\build\Antlr4BuildTasks.targets(262,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Users\emphasis\.nuget\packages\antlr4buildtasks\8.2.0\build\Antlr4BuildTasks.targets(262,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Antlr4 Include="Fluent.g4">
      <Visitor>true</Visitor>
      <Listener>false</Listener>
    </Antlr4>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version="4.8.0" />
    <PackageReference Include="Antlr4BuildTasks" Version="8.2.0" />
  </ItemGroup>

</Project>

Fluent.g4

grammar Fluent;

/*
 * Parser Rules
 */

chat                : line line EOF ;
line                : name SAYS opinion NEWLINE;
name                : WORD ;
opinion             : TEXT ;

/*
 * Lexer Rules
 */

fragment A          : ('A'|'a') ;
fragment S          : ('S'|'s') ;
fragment Y          : ('Y'|'y') ;
fragment LOWERCASE  : [a-z] ;
fragment UPPERCASE  : [A-Z] ;

SAYS                : S A Y S ;
WORD                : (LOWERCASE | UPPERCASE)+ ;
TEXT                : '"' .*? '"' ;
WHITESPACE          : (' '|'\t')+ -> skip ;
NEWLINE             : ('\r'? '\n' | '\r')+ ;

Is there a F# target?

In th project file there is the option <DOptions>language=CSharp</DOptions>
Setting it to <DOptions>language=FSharp</DOptions>
results in the error:

The "RunAntlrTool" task returned false but did not log an error

Is it possible to set it to F# / to generate F# code with ANTLR? Or is the only option to create a separate C# project in which the code is generated?

Move downloads of JRE and .jar to a standard directory.

Right now, everything is downloaded to c:/users/name/.nuget/packages/antlr4buildtasks/10.5.0/build/, but it should be pan build tool, not specifically for Antlr4BuildTasks. See antlr/antlr4#3702
The JRE is placed in c:/users/name/.jre for Windows, ~/.jre elsewhere. The .jar is place c:/users/name/.m2 for Windows, ~/.m2 elsewhere.

Cannot use both Antlr4.Runtime and Antlr4.Runtime.Standard in same project

I was using Antlr4BuildTasks 8.17.0 with Antlr4.Runtime.Standard 4.9.3 in a project that also referenced the "old" Antlr4.Runtime 4.6.6 and everything worked fine. I was able to maintain both nugets without namespace conflicts in the code by using an alias with the later:

<PackageReference Include="Antlr4.Runtime" Version="4.6.6">
   <Aliases>Antlr4Legacy</Aliases>
   <PrivateAssets>contentfiles;analyzers;build;compile</PrivateAssets>
</PackageReference>

I wont get into the reasons why I have such setup, but it used to work.
When trying to update to Antlr4.Runtime.Standard 4.10.1 and Antlr4BuildTasks 10.3.0 this stopped working and I have the following message:

You are referencing Antlr4.Runtime in your .csproj file. This build tool can only reference the NET Standard library https://www.nuget.org/packages/Antlr4.Runtime.Standard/. You can only use either the 'official' Antlr4 or the 'tunnelvision' fork, but not both. You have to choose one.

Since there is a way for this to work, can you remove such error? Or provide a way to make it still work?

Thanks!

Spaces in file path not accepted.

Antlr4BuildTasks does not currently allow spaces in file paths.

$ dotnet build
Microsoft (R) Build Engine version 16.7.0-preview-20360-03+188921e2f for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj (in 493 ms).
NumberListener.cs(9,26): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
NumberListener.cs(10,48): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
CalculatorVisitor.cs(65,59): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
OperatorListener.cs(9,26): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
OperatorListener.cs(10,50): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]

Build FAILED.

NumberListener.cs(9,26): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
NumberListener.cs(10,48): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
CalculatorVisitor.cs(65,59): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
OperatorListener.cs(9,26): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
OperatorListener.cs(10,50): error CS0426: The type name 'FileContext' does not exist in the type 'arithmeticParser' [C:\Users\kenne\Downloads\rith\foo bar\rith\rith.csproj]
    0 Warning(s)
    5 Error(s)

Time Elapsed 00:00:03.84

bug: GetAntlrJar fails to locate jar file on (some?) *nix systems

The GetAntlrJar task fails to locate the Antlr .jar file when compiling on *nix systems, specifically Ubuntu and MacOS.

  • Antlr4BuildTasks 8.9
  • Ubuntu 18.04, 20.04, MacOS 10.15 (Github workers)
  • .NET 3.1, 5.0

I've created a repo which demonstrates the error via Github actions. This run shows the build failure and its proximate cause: System.IO.File.Exists(uri.LocalPath) returns false. You can also view the detailed build output here. Also note that the attempts to download the package directly from maven all failed. I'm not sure if that is expected or not. Perhaps the same error is preventing the downloaded files from being detected??

Unfortunately I don't know enough about *nix systems to offer a specific solution to the problem, but I would recommend that you allow the user to specify the UsingToolPath via an optional MSBuild parameter -- had this existed I could have manually computed the correct path as a workaround.

On a related topic, it might be a good idea to use the JAVA_HOME environment variable, if defined, for UsingJavaExec instead of hardcoding it to /usr/bin/java. Also allow the user to override the path via an optional MSBuild parameter just in case.

Error MSB3231: Directory %documents%/.jre cannot be deleted

Hi
When trying to build a project that contains:

  • a desktop app that uses AntlrBuildTasks to compile antlr grammar
  • a xamarin android app that depends on this desktop app

I get an error MSB3231 regarding the process cannot access/delete the JRE zip file.
Unfortunately I only have the german error notification:

0>C:\Users\burdo\.nuget\packages\antlr4buildtasks\11.5.0\build\Antlr4BuildTasks.targets(192,3): Error MSB3231 : Das Verzeichnis "C:/Users/burdo/.jre/" kann nicht entfernt werden. Der Prozess kann nicht auf die Datei "OpenJDK11U-jre_x64_windows_hotspot_11.0.15_10.zip" zugreifen, da sie von einem anderen Prozess verwendet wird.

For further notice; this is the project in question (the Antlr4BuildTasks plugin is currently disabled)

Cannot find Java executable when building Antlr project in Docker

I am running on Windows 10 Enterprise (Version 10.0.19043.1348). I have the following .Net SDKs installed (dotnet --list-sdks)

3.1.415 [C:\Program Files\dotnet\sdk]
5.0.203 [C:\Program Files\dotnet\sdk]
5.0.209 [C:\Program Files\dotnet\sdk]
5.0.300 [C:\Program Files\dotnet\sdk]
5.0.400 [C:\Program Files\dotnet\sdk]
5.0.403 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]

I am trying to build a container image with a .Net 6 application to run on AWS Graviton instances using ARM64 architecture but currently I am unable to build the image. I have installed the Antlr templates using

dotnet new -i Antlr4BuildTasks.Templates

To reproduce the error, create a new console application under .\AntlrTesting

md AntlrTesting
cd AntlrTesting
dotnet new antlr

Update AntlrTesting\AntlrTesting.csproj

  • change TargetFramework to net6.0
  • change Antlr4.Runtime.Standard version to 4.9.3
  • change Antlr4BuildTasks version to 8.17

Create .\dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim-arm64v8 AS base

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /solution
COPY ["AntlrTesting/AntlrTesting.csproj", "AntlrTesting/"]
WORKDIR /solution/AntlrTesting
RUN dotnet restore --runtime linux-arm64

COPY ./AntlrTesting .
RUN dotnet build -c Release -o /app/build/AntlrTesting --no-self-contained --runtime linux-arm64

FROM build AS publish
WORKDIR /solution/AntlrTesting
RUN dotnet publish -c Release -o /app/publish/AntlrTesting --no-self-contained --runtime linux-arm64

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

Build Docker image

docker build .

Docker's error message when running dotnet build ... says Antlr4BuildTasks.targets cannot find Java executable in /usr/bin/java

 => ERROR [build 7/7] RUN dotnet build -c Release -o /app/build/AntlrTesting --no-self-contained --runtime linux-  2.6s
------
 > [build 7/7] RUN dotnet build -c Release -o /app/build/AntlrTesting --no-self-contained --runtime linux-arm64:
#14 0.592 Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
#14 0.592 Copyright (C) Microsoft Corporation. All rights reserved.
#14 0.592
#14 0.889   Determining projects to restore...
#14 1.246   Restored /solution/AntlrTesting/AntlrTesting.csproj (in 193 ms).
#14 2.534 /root/.nuget/packages/antlr4buildtasks/8.17.0/build/Antlr4BuildTasks.targets(197,3): error ANT02: Cannot find Java executable, currently set to '/usr/bin/java'   at Antlr4.Build.Tasks.RunAntlrTool.Execute() [/solution/AntlrTesting/AntlrTesting.csproj]
#14 2.535
#14 2.535 Build FAILED.
#14 2.535
#14 2.535 /root/.nuget/packages/antlr4buildtasks/8.17.0/build/Antlr4BuildTasks.targets(197,3): error ANT02: Cannot find Java executable, currently set to '/usr/bin/java'   at Antlr4.Build.Tasks.RunAntlrTool.Execute() [/solution/AntlrTesting/AntlrTesting.csproj]
#14 2.535     0 Warning(s)
#14 2.535     1 Error(s)
#14 2.535
#14 2.535 Time Elapsed 00:00:01.90
------
executor failed running [/bin/sh -c dotnet build -c Release -o /app/build/AntlrTesting --no-self-contained --runtime linux-arm64]: exit code: 1

Project rebuild fails but build succeeds using Antlr4BuildTasks 10.5.0

I am using .Net SDK 6.0.300 on Windows 10. After upgrading Antlr4BuildTasks to 10.5.0, my projects fail to rebuild where previously 10.4.0 was successful. To reproduce, create a project with the following 2 files:

ClassLibrary1.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <NoWarn>3021</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Antlr4.Runtime.Standard" Version="4.10.1" />
    <PackageReference Include="Antlr4BuildTasks" Version="10.4.0">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <Antlr4 Include="HelloWorldGrammar.g4" />
  </ItemGroup>
</Project>

HelloWorldGrammar.g4

grammar HelloWorldGrammar;
r   : 'hello' ID;
ID  : [a-z]+ ;
WS  : [ \t\r\n]+ -> skip ;

Cleaning and building the project is successful:

dotnet clean
dotnet build

Cleaning and rebuilding the project is also successful:

dotnet clean
dotnet build --no-incremental

Now update Antlr4BuildTasks package reference from 10.4.0 to 10.5.0. Cleaning and building will still be succesful but dotnet build --no-incremental fails with

C:\Users\El-Gor-do\.nuget\packages\antlr4buildtasks\10.5.0\build\Antlr4BuildTasks.targets(132,3): error ANT02: You are using <Reference> for Antlr4.Runtime.Standard in your .csproj file. You can only use <PackageReference> for the package, never a link to the dll.   at Antlr4.Build.Tasks.RunAntlrTool.SetupAntlrToolJar() [D:\dev\bugs\Antlr410BuildFailure\ClassLibrary1\ClassLibrary1.csproj]
C:\Users\El-Gor-do\.nuget\packages\antlr4buildtasks\10.5.0\build\Antlr4BuildTasks.targets(132,3): error ANT02:    at Antlr4.Build.Tasks.RunAntlrTool.Execute() [D:\dev\bugs\Antlr410BuildFailure\ClassLibrary1\ClassLibrary1.csproj]
C:\Users\El-Gor-do\.nuget\packages\antlr4buildtasks\10.5.0\build\Antlr4BuildTasks.targets(132,3): error ANT02: The Antlr4 tool failed. [D:\dev\bugs\Antlr410BuildFailure\ClassLibrary1\ClassLibrary1.csproj]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.