Example usage for jdk.nashorn.internal.runtime ScriptEnvironment ScriptEnvironment

List of usage examples for jdk.nashorn.internal.runtime ScriptEnvironment ScriptEnvironment

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ScriptEnvironment ScriptEnvironment.

Prototype

@SuppressWarnings("unused")
public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) 

Source Link

Document

Constructor

Usage

From source file:edu.brown.cs.bubbles.nobase.NobaseNashorn.java

License:Open Source License

/********************************************************************************/

@Override//  w  w w . j  a  v  a  2s .  c  om
public ISemanticData parse(NobaseProject proj, NobaseFile fd, boolean lib) {
    Source src = new Source(fd.getFileName(), fd.getContents());
    Options opts = new Options("nashorn");
    PrintWriter pw = new PrintWriter(new StringWriter());
    ScriptEnvironment env = new ScriptEnvironment(opts, pw, pw);
    DeferredErrorManager em = new DeferredErrorManager(fd);
    if (fd.getFileName().endsWith(".json")) {
        JSONParser jsonparse = new JSONParser(src, em);
        Node nd = jsonparse.parse();
        if (do_debug) {
            System.err.println("WORKING ON " + fd.getFileName());
            try {
                ASTWriter pv = new ASTWriter(nd);
                System.err.println("PARSE: " + pv.toString());
            } catch (Throwable t) {
            }
        }
        return null;
    }

    Parser parser = new Parser(env, src, em);
    FunctionNode fn = parser.parse();
    if (fn == null) {
        NobaseMain.logE("Problem parsing " + fd.getFileName());
        return null;
    }
    if (do_debug) {
        System.err.println("WORKING ON " + fd.getFileName());
        try {
            ASTWriter pv = new ASTWriter(fn);
            System.err.println("PARSE: " + pv.toString());
        } catch (Throwable t) {
        }
    }
    ParseData rslt = new ParseData(proj, fd, em, fn.getBody(), lib);
    if (do_debug) {
        System.err.println("RESULT: " + rslt.getRootNode().dumpTree(fd));
    }
    return rslt;
}

From source file:org.netbeans.es.perftest.nashorn.NashornParser.java

License:Open Source License

@Override
public boolean parse(File file, ParserOptions options) throws IOException {
    final PrintWriter err = options.isPrintError() ? options.getProgressWriter()
            : new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()));
    final ScriptEnvironment env = new ScriptEnvironment(
            new jdk.nashorn.internal.runtime.options.Options(file.getAbsolutePath()), err, err);
    final Source src = Source.sourceFor(file.getName(), file);
    final ErrorManager em = new ErrorManager(err);
    final Parser p = new Parser(env, src, em);
    final FunctionNode node = p.parse();
    return !em.hasErrors();
}