when i try to generate the listener/visitor ... for my Grammar I get the following error : ANTLR cannot generate Javascript code as of version 4.5
Does anybody knows how to fix it? I still can generate C# and Java Code.
when i try to generate the listener/visitor ... for my Grammar I get the following error : ANTLR cannot generate Javascript code as of version 4.5
Does anybody knows how to fix it? I still can generate C# and Java Code.
From the docs:
This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:
$ antlr4 -Dlanguage=JavaScript MyGrammar.g4
For a full list of antlr4 tool options, please visit the tool documentation page.
It is possible that you are targeting Javascript
instead of the required JavaScript
(note the case); observe the difference when I execute the two:
╭─{ yaauie@celeborn:~/Desktop/tmp-20160108 }
╰─○ antlr4 -Dlanguage=JavaScript Hello.g4
[success]
╭─{ yaauie@celeborn:~/Desktop/tmp-20160108 }
╰─○ antlr4 -Dlanguage=Javascript Hello.g4
error(31): ANTLR cannot generate Javascript code as of version 4.5.1
[error: 1]
You need "JavaScript", not "Javascript".
The exact language values for supported languages are:
Java:
antlr4 -Dlanguage=Java MyGrammar.g4
JavaScript:
antlr4 -Dlanguage=JavaScript MyGrammar.g4
C#:
antlr4 -Dlanguage=CSharp MyGrammar.g4
Python 3:
antlr4 -Dlanguage=Python3 MyGrammar.g4
Python 2:
antlr4 -Dlanguage=Python2 MyGrammar.g4
Go:
antlr4 -Dlanguage=Go MyGrammar.g4
C++:
antlr4 -Dlanguage=Cpp MyGrammar.g4
Swift:
antlr4 -Dlanguage=Swift MyGrammar.g4
PHP:
antlr4 -Dlanguage=PHP MyGrammar.g4
Source: https://github.com/antlr/antlr4/blob/master/doc/targets.md and follow the language-specific links.
I was working with ATNLR to parse hive queries in java and had a similar issue. It turns out that I was missing the case. Instead of Java I was writing java
$>antlr -Dlanguage=java Hplsql.g4
-->error(31): ANTLR cannot generate java code as of version 4.7.1
$>antlr -Dlanguage=Java Hplsql.g4
-->Success
I was trying to execute:
antlr4 Arithmetic.g4 -Dlanguage=cSharp
I was getting a message:
ANTLR cannot generate cSharp code as of version 4.12.0
Just found the issue. Antlr language is CASE SENSITIVE
This works:
antlr4 Arithmetic.g4 -Dlanguage=CSharp
I hope this helps someone else.