kaby76 / Trash

Toolkit for grammars

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trparse -- antlr3.dll missing on Linux

philip-h-dye opened this issue · comments

On Ubuntu 20.04:

$ trparse gUnit.g3
System.IO.FileNotFoundException: Could not load file or assembly '/home/phdyex/.dotnet/tools/.store/trparse/0.20.12/trparse/0.20.12/tools/net7.0/any/antlr3.dll'. The system cannot find the file specified.
File name: '/home/phdyex/.dotnet/tools/.store/trparse/0.20.12/trparse/0.20.12/tools/net7.0/any/antlr3.dll'
at System.Reflection.Assembly.LoadFile(String path)
at Trash.Grun.DoParse(String parser_type, String txt, String prefix, String input_name, Int32 row_number, List`1 data) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 189
at Trash.Grun.Run(String parser_type) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 123

Please advise. Thanks

This issue still persist. With the main branch I get:

System.IO.FileNotFoundException: Could not load file or assembly '/home/nikos/projects/grammar/Domemtech.Trash/bin/Debug/net7.0/Antlr4.Runtime.Standard.dll'. The system cannot find the file specified.
File name: '/home/nikos/projects/grammar/Domemtech.Trash/bin/Debug/net7.0/Antlr4.Runtime.Standard.dll'
   at System.Reflection.Assembly.LoadFile(String path)
   at Trash.Grun.DoParse(String parser_type, String txt, String prefix, String input_name, Int32 row_number, List`1 data) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 202
   at Trash.Grun.Run(String parser_type) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 144

I managed to download and place Antlr4.Runtime.Standard.dll to the expected place, but then I get Test.dll missing.

There were a few hardwired references to paths with "Debug". These are being corrected. The tools are published in "Release" configuration, which is now the default when typing "make" at the root directory of the cloned repo. All the most recent changes are going to be in the "dev" branch, which gets merged into "master" when I make a release.

Make sure you don't have multiple .dotnet directories, and the ~/.dotnet/tools/tr* tools are removed and the ~/.dotnet/tools/.store/tr* files are also removed. Best, again, to use the uninstall commands from the command line Bash shell, then run the install commands.

For now, you can work around the problem by setting the type of the parse: trparse -t ANTLRv3 foobar.whateversuffix. The problem is that when it does not know the extension, trparse wants to parse the file using a parser that has been generated and built using CSharp as the target, which involves the path "Generated-CSharp/". If there's no code built code, it fails to do the parse.

The normal procedure for using the tools is to perform "trgen" with a .g4 in the current directory. That creates a Generated-CSharp/ directory with a driver for parsing. Then, building that, trparse will default to using the generated parser.

Thank you for the instructions. I moved past the error into a new one. Forgive me if I am clueless, but this what I do:

  • First clone the repo anew
  • switch to the dev branch
  • run the install commands from the README (I have uninstalled everything first)
  • Then, I run trparse -t ebnf my-grammar.ebnf.

But I get this error:

System.Exception: Unknown file extension, cannot load in a built-in parser.
at Trash.Grun.DoParse(String parser_type, String txt, String prefix, String input_name, Int32 row_number, List`1 data) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 220
at Trash.Grun.Run(String parser_type) in C:\Users\Kenne\Documents\GitHub\Domemtech.Trash\src\trparse\Grun.cs:line 144


This means I think that I need to generate sth to pass to trparse via the `-p` flag. I read on trparse help:

-p, --parser Location of pre-built parser (aka the trgen Generated/
directory)


So, I suspect I need to use `trgen` to generate sth. But now I am lost. Why is the built-in parser not found? How can I create it?

If it helps, my use case is that I want to convert a ebnf grammar to antrl4.

trparse uses stand-alone CSharp programs generated from trgen. trparse does not interpret the grammar--and it can't usually, because many grammars have "C# actions". trparse loads the driver program, and calls the program to parse some input. trparse then outputs the parse tree in a standardized manner to stdout, which can then be read by other tools in the Trash toolkit.

As a convenience, I package some of these parser programs along with trparse to simplify the trgen/dotnet build/trparse process. Most of the time, however, you need to generate a parser driver program and build it using dotnet so trparse can parse and output parse trees.

There is no straight "ebnf" grammar in trparse. The closest EBNF grammar, which is pretty simple (I am working on new BNF and EBNF grammars), is here.

This is how you would build a parser for the grammar, and use trparse.

git clone https://github.com/antlr/grammars-v4.git
cd grammars-v4/bnf
trgen -t CSharp
cd Generated-CSharp
dotnet build Test.csproj
cat ../examples/postal.bnf | trparse | trtext
cat ../examples/postal.bnf | trparse | trtree
trparse ../examples/postal.bnf | trtext
trparse ../examples/postal.bnf | trtree
cat ../examples/postal.bnf | ./bin/Debug/net7.0/Test
cat ../examples/postal.bnf | ./bin/Debug/net7.0/Test -tree -tokens
./bin/Debug/net7.0/Test ../examples/postal.bnf

You shouldn't ever have to clone https://github.com/kaby76/Domemtech.Trash.git
and build it. Use the Nuget published tools. To install, just go https://github.com/kaby76/Domemtech.Trash#install then click on the "copy" icon
to copy the "dotnet" commands and paste at a prompt.