10
votes

I have been using ANTLR to generate a parser + tree grammar for a mark up language with Java target which works fine. Now I am trying to get the target in JavaScript to use it in my web browser.

However, I have not been able to locate any good documentation on how to go about doing this. I am using eclipse with ANTLR IDE, and when i specify the language as JavaScript, I get the following errors.

Multiple markers at this line

  • (10): internal error: group JavaScript does not satisfy interface ANTLRCore: mismatched arguments on these templates [treeParser(grammar, name, scopes, tokens, tokenNames, globalAction, rules, numRules, bitsets, labelType, ASTLabelType, superClass, members, filterMode)]

  • (10): internal error: java.util.NoSuchElementException: no such attribute: filterMode in template context [treeParser]

If anyone could help me out with this or point me to some material which I could read about the JavaScript target with ANTLR, it would be great.

Thanks

4
I am actually now able to generate the parser in JavaScript, and it recognizes things just fine . But when I try to generate the tree walker in JavaScript target, it is not able to. And I think the main reason for this is the error 2 listed above.Gunner4Life
I'm not sure which version of the ANTLR build you were trying to use, but I was seeing the same errors with the official builds I tried to use. I just got the ANTLR tar from the perforce server and built it with maven, and the javascript stuff seemed to work for me -- with my admittedly trivial grammar, at least.Chris Farmer
I figured out what the error was. The JavaScript Target was broken in the latest releases of ANTLR, which caused the issue. The solution is to either build the source code, or use an earlier version.Gunner4Life

4 Answers

4
votes

There is a new JS Lang target for ANTLR4 that was posted to GitHub almost 3 months ago:

antlr/antlr4-javascript

It's not integrated into an official release yet, but you can probably just throw it into the latest ANTLR4 codebase and recompile ANTLR yourself.

0
votes

You should use the latest version (3.3), in previous versions the javascript target was not properly integrated. There still some bugs, but you can see a working example with some guidance and links on http://blog.barvinograd.com/2011/03/online-function-grapher-formula-parser-part-2/

0
votes

It appears as though the JavaScript target is broken again in the 3.4 distribution. 3.3 is working fine for me though.

0
votes

I have been trying to get this working, and have only just managed to generate .js files succesfully after reading this:

http://www.antlr3.org/pipermail/antlr-interest/2011-August/042417.html

From the post:

Here's how to get started with ANTLR and the JavaScript back-end:

  1. Download ANTLRWorks 1.2.2: < http://antlr.org/download/antlrworks-1.2.2.jar>. The JavaScript target only works when the IDE generates the lexer and parser code (see < http://antlr.1301665.n2.nabble.com/maven-plugin-and-javascript-target-td3647109.html>). If you try to run ANTLR v3.1 from the command line, you will see the error message "error(10): internal error: group JavaScript does not satisfy interface ANTLRCore".
  2. Download the JS runtime distribution: http://antlr.org/download/antlr-javascript-runtime-3.1.zip

From then on you can use ANTLRWorks 1.2.2 to generate the lexer and parser code by selecting "Generate Code" from the "Generate" menu. ANTLRWorks will place the generated files into an output directory in the folder in which the grammar file resides.

Note that if an error occurs in the generation process, then for some reason the "Generate Code" action no longer works. Simply close the grammar and re-open it from the "Open Recent" menu.