Replies: 1 comment
-
The javascript/javascript parser for the CSharp target works. But, all that is given is the grammar (JavaScriptLexer.g4, JavaScriptParser.g4) and some support code for the parser (JavaScriptLexerBase.cs, JavaScriptParserBase.cs). A driver is required. And, the grammar has to be processed by the Antlr tool to generate JavaScriptParser. There is a lexer grammar, and the tool must process that as well to generate the JavaScriptLexer class, which is used by the parser. You can write the driver code yourself, but I find that laborious. I recommend that you install my Trash toolkit, and generate a driver program. After working with that, you can fit the parser in where you need. Requirements
Test requirementsMake sure all is working. Check.
Generate a driverThen, in a command-line shell type the following commands. I generally use Msys (Cygwin) since cmd.exe is such a terrible shell. You can use pwsh.exe (Powershell) if you prefer.
You can then open the .csproj in Visual Studio, then open Test.cs and read how it works. I would recommend that you use an up-to-date version of Visual Studio. VS2019 is many years old. And, as far as I know, there is no extension for VS2019 or VS2022 that supports Antlr. Run
NotesDo not reference antlr4.runtime. That is OLD OLD OLD code. Remove that package reference. Read the .csproj file generated. It uses antlr4.runtime.standard, the current, official, supported Antlr4 code. For dotnet/msbuild support of the .g4's (ie, processing the .g4's by the tool to generate .cs recognizers), use Antlr4BuildTasks. Attached is a zip file for the parser. Just type "dotnet build" to rebuild. |
Beta Was this translation helpful? Give feedback.
-
Hi all, I'm trying to build a Javascript parser in C# VS 2019
At a high level, I see that there is code in the C# directory which does some work. Do I still need to process the .g4 files into code?\
Also, This class is missing:
using static JavaScriptParser;
where can I find that reference ?
I've got antlr4.runtime installed via nuget
thanks
John Mott
CTO Surgepays
[email protected]
Beta Was this translation helpful? Give feedback.
All reactions