I have been successfully using my code with the javascript library in the ANTLR javascript target in a few browsers, but now I want to use Rhino on the server and I am having some trouble. I have some simple java code that references the Rhino 1.7R2 release's js-14.jar file.
Context context = Context.enter();
Scriptable scope = context.initStandardObjects();
context.evaluateReader(scope, new FileReader("C:\\antlr3-all.js"), "antlr", 1, null);
This fails with an EcmaError
whose message is:
TypeError: Cannot call property namespace in object [JavaPackage org.antlr].
It is not a function, it is "object". (antlr#259)
The javascript line that it's referring to is:
org.antlr.namespace("org.antlr.runtime.tree");
This org.antlr.namespace
was declared as a function earlier in the file, so I am not sure what to think of this. I also don't see that "namespace" is a reserved word in javascript or in Rhino in particular.
Here's the declaration of org.antlr.namespace
at 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 target page mentions that Rhino is a tested platform, so I am thinking that I might just be misusing Rhino. Does anyone have any tips?