Search in sources :

Example 1 with ParserEOFException

use of com.github.anba.es6draft.parser.ParserEOFException in project es6draft by anba.

the class Repl method read.

/**
     * REPL: Read
     * 
     * @param realm
     *            the realm instance
     * @param line
     *            the current line
     * @return the parsed script node or {@coden null} if the end of stream has been reached
     */
private com.github.anba.es6draft.ast.Script read(Realm realm, int[] line) {
    StringBuilder sourceBuffer = new StringBuilder();
    for (String prompt = PROMPT; ; prompt = "") {
        String s = console.readLine(prompt);
        if (s == null) {
            return null;
        }
        sourceBuffer.append(s).append('\n');
        String sourceCode = sourceBuffer.toString();
        Source source = new Source(Paths.get(".").toAbsolutePath(), "typein", line[0]);
        try {
            com.github.anba.es6draft.ast.Script script = parse(realm, source, sourceCode);
            line[0] += script.getEndLine() - script.getBeginLine();
            return script;
        } catch (ParserEOFException e) {
            continue;
        } catch (ParserException e) {
            throw new ParserExceptionWithSource(e, source, sourceCode);
        }
    }
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) ParserEOFException(com.github.anba.es6draft.parser.ParserEOFException) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource)

Aggregations

ParserEOFException (com.github.anba.es6draft.parser.ParserEOFException)1 ParserException (com.github.anba.es6draft.parser.ParserException)1 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)1