Search in sources :

Example 1 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project hackpad by dropbox.

the class ParserTest method parse.

private AstRoot parse(String string, boolean jsdoc) {
    CompilerEnvirons environment = new CompilerEnvirons();
    TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
    environment.setErrorReporter(testErrorReporter);
    environment.setRecordingComments(true);
    environment.setRecordingLocalJsDocComments(jsdoc);
    Parser p = new Parser(environment, testErrorReporter);
    AstRoot script = p.parse(string, null, 0);
    assertTrue(testErrorReporter.hasEncounteredAllErrors());
    assertTrue(testErrorReporter.hasEncounteredAllWarnings());
    return script;
}
Also used : TestErrorReporter(org.mozilla.javascript.testing.TestErrorReporter) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) Parser(org.mozilla.javascript.Parser)

Example 2 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project hackpad by dropbox.

the class ParserTest method parseAsReader.

private AstRoot parseAsReader(String string) throws IOException {
    CompilerEnvirons environment = new CompilerEnvirons();
    TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
    environment.setErrorReporter(testErrorReporter);
    environment.setRecordingComments(true);
    environment.setRecordingLocalJsDocComments(true);
    Parser p = new Parser(environment, testErrorReporter);
    AstRoot script = p.parse(new StringReader(string), null, 0);
    assertTrue(testErrorReporter.hasEncounteredAllErrors());
    assertTrue(testErrorReporter.hasEncounteredAllWarnings());
    return script;
}
Also used : TestErrorReporter(org.mozilla.javascript.testing.TestErrorReporter) StringReader(java.io.StringReader) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) Parser(org.mozilla.javascript.Parser)

Example 3 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project pentaho-kettle by pentaho.

the class ScriptDialog method parseVariables.

// This could be useful for further improvements
public static ScriptNode parseVariables(Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain) {
    // Interpreter compiler = new Interpreter();
    CompilerEnvirons evn = new CompilerEnvirons();
    // evn.setLanguageVersion(Context.VERSION_1_5);
    evn.setOptimizationLevel(-1);
    evn.setGeneratingSource(true);
    evn.setGenerateDebugInfo(true);
    ErrorReporter errorReporter = new ToolErrorReporter(false);
    Parser p = new Parser(evn, errorReporter);
    // IOException
    ScriptNode tree = p.parse(source, "", 0);
    new NodeTransformer().transform(tree);
    // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
    return tree;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ErrorReporter(org.mozilla.javascript.ErrorReporter) NodeTransformer(org.mozilla.javascript.NodeTransformer) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ScriptNode(org.mozilla.javascript.ast.ScriptNode) Parser(org.mozilla.javascript.Parser)

Example 4 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project pentaho-kettle by pentaho.

the class ScriptValuesModDialog method parseVariables.

// This could be useful for further improvements
public static ScriptNode parseVariables(Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain) {
    // Interpreter compiler = new Interpreter();
    CompilerEnvirons evn = new CompilerEnvirons();
    // evn.setLanguageVersion(Context.VERSION_1_5);
    evn.setOptimizationLevel(-1);
    evn.setGeneratingSource(true);
    evn.setGenerateDebugInfo(true);
    ErrorReporter errorReporter = new ToolErrorReporter(false);
    Parser p = new Parser(evn, errorReporter);
    // IOException
    ScriptNode tree = p.parse(source, "", 0);
    new NodeTransformer().transform(tree);
    // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
    return tree;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ErrorReporter(org.mozilla.javascript.ErrorReporter) NodeTransformer(org.mozilla.javascript.NodeTransformer) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ScriptNode(org.mozilla.javascript.ast.ScriptNode) Parser(org.mozilla.javascript.Parser)

Example 5 with CompilerEnvirons

use of org.mozilla.javascript.CompilerEnvirons in project whole by wholeplatform.

the class RhinoTransformerVisitor method transform.

public static IEntity transform(IPersistenceProvider pp) throws Exception {
    CompilerEnvirons compilerEnvirons = CompilerEnvirons.ideEnvirons();
    compilerEnvirons.setLanguageVersion(Context.VERSION_1_8);
    Parser parser = new Parser(compilerEnvirons);
    AstRoot astRoot = parser.parse(new InputStreamReader(pp.getInputStream(), pp.getEncoding()), "http://whole.sourceforge.net/test.js", 0);
    ModelBuilderOperation mop = new ModelBuilderOperation();
    RhinoTransformerVisitor visitor = new RhinoTransformerVisitor(mop);
    astRoot.visit(visitor);
    return mop.wGetResult();
}
Also used : ModelBuilderOperation(org.whole.lang.builders.ModelBuilderOperation) InputStreamReader(java.io.InputStreamReader) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) Parser(org.mozilla.javascript.Parser)

Aggregations

CompilerEnvirons (org.mozilla.javascript.CompilerEnvirons)6 Parser (org.mozilla.javascript.Parser)6 ErrorReporter (org.mozilla.javascript.ErrorReporter)2 NodeTransformer (org.mozilla.javascript.NodeTransformer)2 ScriptNode (org.mozilla.javascript.ast.ScriptNode)2 TestErrorReporter (org.mozilla.javascript.testing.TestErrorReporter)2 ToolErrorReporter (org.mozilla.javascript.tools.ToolErrorReporter)2 InputStreamReader (java.io.InputStreamReader)1 StringReader (java.io.StringReader)1 AstRoot (org.mozilla.javascript.ast.AstRoot)1 ErrorCollector (org.mozilla.javascript.ast.ErrorCollector)1 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)1