I have successfully used my javascript library code in the ANTLR javascript target in several browsers, but now I want to use Rhino on the server and I am having problems. I have simple Java code that references a js-14.jar file of Rhino version 1.7R2.
Context context = Context.enter(); Scriptable scope = context.initStandardObjects(); context.evaluateReader(scope, new FileReader("C:\\antlr3-all.js"), "antlr", 1, null);
This does not work with EcmaError whose message is:
TypeError: Cannot call property namespace in object [JavaPackage org.antlr]. It is not a function, it is "object". (antlr
In the javascript line it refers to is:
org.antlr.namespace("org.antlr.runtime.tree");
This org.antlr.namespace was declared as a function earlier in the file, so I'm not sure what to think about it. I also do not see that the "namespace" is a reserved word in javascript or in Rhino in particular.
Here's the declaration of org.antlr.namespace on line 56:
org.antlr.namespace = function() { var a=arguments, o=null, i, j, d; for (i=0; i<a.length; i=i+1) { d=a[i].split("."); o=org.antlr.global; // ANTLR is implied, so it is ignored if it is included for (j=0; j<d.length; j=j+1) { o[d[j]]=o[d[j]] || {}; o=o[d[j]]; } } return o; };
The ANTLR javascript landing page mentions that Rhino is a proven platform, so I think I can just abuse Rhino. Does anyone have any clues?