sun.org.mozilla.javascript.internal.EcmaError: SyntaxError: missing ; before statement (<Unknown source>#3213(eval)#1) in <Unknown source>#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...
Cheers,
Leo.
Thanks for your quick answer!I found a workaround by using Selenium's Firefox WebDriver: http://seleniumhq.org/docs/03_webdriver.htmlpublic void test() throws IOException {
FirefoxDriver exec = new FirefoxDriver();
exec.get("http://pegjs.majda.cz/online");
String grammar = IOUtils.toString(this.getClass().getResourceAsStream("myGrammar.pegjs"));
System.out.println( exec.executeScript("return PEG.buildParser(arguments[0])", grammar));
}
The thing is that you need an actual Firefox installed to run that :(
Do you see any other alternative to generating a parser headlessly, other than using Node.js?
Thanks again,
Leonardo.