ANTLR cannot generate ‘org.antlr.v4.codegen.CSharp_v4_5_1Target’ code as of version 4.1-SNAPSHOT
Today I tried to create an ANTLR 4 grammar and compile it to C#. Of course, I used Sam Harwell’s C# target for ANTLR 4. I followed all instructions, added my grammar file, compiled it and got the following error:
ANTLR cannot generate ‘org.antlr.v4.codegen.CSharp_v4_5_1Target’ code as of version 4.1-SNAPSHOT
So what’s the problem? I’m not sure about the technical details, but apparently, the C# target is does not support .NET framework 4.5.1, yet(?). So when I set my project’s target framework to .NET Framework 4.5 , the grammar was compiled successfully.
For the sake of completion, here are the error details:
Unknown build error: Executing command: “C:\Program Files (x86)\Java\jre7\bin\java.exe” -cp C:\…\packages\Antlr4.4.1.0-alpha003\build\…\tools\antlr4-csharp-4.1-SNAPSHOT-complete.jar org.antlr.v4.CSharpTool -o obj\Debug\ -listener -visitor -Dlanguage=CSharp_v4_5_1 -package mylanguage C:\…\mylanguage\mylanguage.g4
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC0031: ANTLR cannot generate ‘org.antlr.v4.codegen.CSharp_v4_5_1Target’ code as of version 4.1-SNAPSHOT
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: Exception in thread “main” java.lang.NullPointerException
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.codegen.CodeGenerator.getTemplates(CodeGenerator.java:96)
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.automata.LexerATNFactory.(LexerATNFactory.java:69)
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:405)
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.Tool.process(Tool.java:376)
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
C:\…\packages\Antlr4.4.1.0-alpha003\build\Antlr4.targets(132,5): error AC1000: Unknown build error: at org.antlr.v4.CSharpTool.main(CSharpTool.java:59)
Edit
Steve Cooper remarked the following:
Looks like the source has been updated to support 4.5.1 a week ago (https://github.com/tunnelvisionlabs/antlr4cs/commit/d206a6e00192eb471a60265faf962b9bc93b05a2) but the new source doesn’t seem to have been deployed to NuGet yet.
Until then, you can work on 4.5.1 by opening $(SolutionDir)\packages\Antlr4.4.2.2-alpha001\build\antlr4.targets and changing line 139 to
TargetFrameworkVersion=”v4.5″
I guess this file might need putting in source control, so that other users don’t get the original version on Package Restore.
Category: Code Generation