kaby76 / Antlr4BuildTasks

Third-party build tool for 'Official' Antlr4 tool and runtime parsers using .Net. Drop-in replacement for 'Antlr4cs' Antlr4 tool and build rules.
MIT License
73 stars 10 forks source link

Trying to update #45

Closed renzosilv closed 1 year ago

renzosilv commented 1 year ago

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"+
kaby76 commented 1 year ago

First, remove the reference to Antlr4 v4.6.6 in the .csproj. You really should not use both. I thought I only allowed it in very special situations and with a flag set. I will check that, and fix the code if the check is not working.

renzosilv commented 1 year ago

Sorry - I copied the wrong state of my code.

The error above happens when that isn't there.

kaby76 commented 1 year ago

It might have something to do with the path names. I'll check it out.

kaby76 commented 1 year ago

Looks like that code that's generated is old 4.6.6 code. Antr4BuildTasks may not have cleaned the obj/bin out. Not sure why. Do an "rm -rf bin obj" and then "dotnet build". Also, make sure that every .g4 that you have mentioned in your .csproj is a top-level grammar. In other words, make sure it's not "import" in one of the other .g4 files. Make sure you don't have any old atpLexer.cs sitting around either.

renzosilv commented 1 year ago

That got me passed that error and I ended up with this one. Doing some online research says is because I'm referencing two assemblies that share types with the exact same name and namespace Should I just alias them to get passed it or is there an option I can pass to antlr ?


  StilFileType.cs(20, 19): [CS0433] The type 'GZipStream' exists in both 'Antlr4BuildTasks, Version=11.1.0.0, Culture=neutral, PublicKeyToken=null' and 'SharpCompress, Version=0.32.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96'
``
kaby76 commented 1 year ago

I'm sort of surprised that "privateassets" isn't working. You could try adding an "alias" in one or the other packagereference in the .csproj, e.g., <Aliases>HideZip</Aliases>

renzosilv commented 1 year ago

Thank you - that worked. I added this to my csproj

 <PackageReference Include="SharpCompress" Version="0.32.2" >
        <Aliases>HideZip</Aliases>
      </PackageReference>

And then used it on my code with

extern alias HideZip;
using HideZip.SharpCompress.Compressors;
using HideZip.SharpCompress.Compressors.Deflate;

using HideZip.SharpCompress.Compressors.Deflate.GZipStream zip = new(reader,HideZip.SharpCompress.Compressors.CompressionMode.Decompress);

I was able to compile and deploy - my program is running but my rules are not longer working. Is that to be expected? Has there been an update which would affect that?

I get a lot of things like this

line 6:76 missing '\t' at '\n'

or this

line 20:20 mismatched input '0' expecting {STRING, KEYWORD}
line 24:19 extraneous input ':' expecting KEYWORD
kaby76 commented 1 year ago

Start printing out the tokens in the program and verify they are what you expect. Compare to the old program if you can.

renzosilv commented 1 year ago

Tokens fixed and I'm now running