Question

I've been building parsers using a Maven Plugin (i.e. calling PEG.js from Java code) successfully using PEG.js version 0.6.1, but now while trying to upgrade to the new version, it's failing with the error message:

sun.org.mozilla.javascript.internal.EcmaError: SyntaxError: missing ; before statement (#3213(eval)#1) in #3213(eval) at line number 1

While debugging I've noticed that the parser that comes out of the PEG.buildParser() function call looks syntactically wrong, whereas of course it doesn't happen while calling it from a browser.

Here is how I'm calling it:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsEngine = manager.getEngineByName("JavaScript");

jsEngine.eval(new InputStreamReader(this.getClass().getResourceAsStream(PEGJS_LIB)));

Invocable invok = (Invocable) jsEngine;
Object peg = jsEngine.get("PEG");

invok.invokeMethod(peg, "buildParser", grammarSource);

Where, grammarSource, in my test-case, is the basic grammar used as an example in the website, and PEGJS_LIB = peg-0.7.0.js.

Any ideas are welcome! I've run out of them here...

Was it helpful?

Solution

I tracked down the cause for this issue. 'PEG.compiler.emitter.Codie.pushRaw.unindent()' line 3681 destroys the templates. I have not fully determined how important this function is for the parser, but it seems like a 'nice to have'. I replaced the body of the function locally and Rhino worked as expected.

function unindent(code, level, unindentFirst) {
  return code
}

I know David is not interested in supporting Rhino, but I thought I should share this on this thread so others might be able to solve the problem as needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top