Search in sources :

Example 1 with Parser

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

the class ScriptLoader method evalScript.

/**
 * Parses and compiles the javascript eval-script.
 *
 * @param source
 *            the script source descriptor
 * @param sourceCode
 *            the source code
 * @param evalOptions
 *            the eval parser options
 * @return the compiled script
 * @throws ParserException
 *             if the source contains any syntax errors
 * @throws CompilationException
 *             if the parsed source could not be compiled
 */
public Script evalScript(Source source, String sourceCode, EnumSet<Parser.Option> evalOptions) throws ParserException, CompilationException {
    Parser parser = new Parser(context, source, evalOptions);
    com.github.anba.es6draft.ast.Script parsedScript = parser.parseScript(sourceCode);
    if (parsedScript.getStatements().isEmpty()) {
        return null;
    }
    return load(parsedScript, nextEvalName());
}
Also used : Parser(com.github.anba.es6draft.parser.Parser)

Example 2 with Parser

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

the class ScriptLoader method asyncFunction.

/**
 * Parses and compiles the javascript async function.
 *
 * @param source
 *            the script source descriptor
 * @param formals
 *            the formal parameters
 * @param bodyText
 *            the async function body
 * @return the compiled async function
 * @throws ParserException
 *             if the source contains any syntax errors
 * @throws CompilationException
 *             if the parsed source could not be compiled
 */
public CompiledFunction asyncFunction(Source source, String formals, String bodyText) throws ParserException, CompilationException {
    Parser parser = new Parser(context, source);
    AsyncFunctionDefinition asyncDef = parser.parseAsyncFunction(formals, bodyText);
    return compile(asyncDef, nextFunctionName());
}
Also used : AsyncFunctionDefinition(com.github.anba.es6draft.ast.AsyncFunctionDefinition) Parser(com.github.anba.es6draft.parser.Parser)

Example 3 with Parser

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

the class ScriptLoader method generator.

/**
 * Parses and compiles the javascript generator function.
 *
 * @param source
 *            the script source descriptor
 * @param formals
 *            the formal parameters
 * @param bodyText
 *            the generator function body
 * @return the compiled generator function
 * @throws ParserException
 *             if the source contains any syntax errors
 * @throws CompilationException
 *             if the parsed source could not be compiled
 */
public CompiledFunction generator(Source source, String formals, String bodyText) throws ParserException, CompilationException {
    Parser parser = new Parser(context, source);
    GeneratorDefinition generatorDef = parser.parseGenerator(formals, bodyText);
    return compile(generatorDef, nextFunctionName());
}
Also used : AsyncGeneratorDefinition(com.github.anba.es6draft.ast.AsyncGeneratorDefinition) GeneratorDefinition(com.github.anba.es6draft.ast.GeneratorDefinition) Parser(com.github.anba.es6draft.parser.Parser)

Example 4 with Parser

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

the class ScriptLoader method function.

/**
 * Parses and compiles the javascript function.
 *
 * @param source
 *            the script source descriptor
 * @param formals
 *            the formal parameters
 * @param bodyText
 *            the function body
 * @return the compiled function
 * @throws ParserException
 *             if the source contains any syntax errors
 * @throws CompilationException
 *             if the parsed source could not be compiled
 */
public CompiledFunction function(Source source, String formals, String bodyText) throws ParserException, CompilationException {
    Parser parser = new Parser(context, source);
    FunctionDefinition functionDef = parser.parseFunction(formals, bodyText);
    return compile(functionDef, nextFunctionName());
}
Also used : AsyncFunctionDefinition(com.github.anba.es6draft.ast.AsyncFunctionDefinition) FunctionDefinition(com.github.anba.es6draft.ast.FunctionDefinition) Parser(com.github.anba.es6draft.parser.Parser)

Example 5 with Parser

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

the class Test262TestRealm method executeStrict.

/**
 * Executes the supplied test object.
 *
 * @param test
 *            the test-info object
 * @throws ParserException
 *             if the module source contains any syntax errors
 * @throws CompilationException
 *             if the parsed module source cannot be compiled
 */
void executeStrict(Test262Info test) throws ParserException, CompilationException {
    // Return early if no source code is available.
    if (sourceCode == null) {
        return;
    }
    assert !test.isAsync() || async != null;
    assert !(test.isModule() || test.isRaw());
    Realm realm = get();
    // Parse the test-script
    Source source = new Source(test.toFile(), test.getScript().toString(), 1);
    ScriptLoader scriptLoader = realm.getScriptLoader();
    EnumSet<Parser.Option> parserOptions = EnumSet.copyOf(realm.getRuntimeContext().getParserOptions());
    parserOptions.add(Parser.Option.Strict);
    Parser parser = new Parser(realm.getRuntimeContext(), source, parserOptions);
    com.github.anba.es6draft.ast.Script parsedScript = parser.parseScript(sourceCode);
    // Evaluate the test-script
    Script script = scriptLoader.load(parsedScript);
    script.evaluate(realm);
    // Wait for pending jobs to finish
    waitForPendingJobs(realm, test);
}
Also used : Script(com.github.anba.es6draft.Script) Realm(com.github.anba.es6draft.runtime.Realm) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) Source(com.github.anba.es6draft.runtime.internal.Source) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) Parser(com.github.anba.es6draft.parser.Parser)

Aggregations

Parser (com.github.anba.es6draft.parser.Parser)6 AsyncFunctionDefinition (com.github.anba.es6draft.ast.AsyncFunctionDefinition)2 AsyncGeneratorDefinition (com.github.anba.es6draft.ast.AsyncGeneratorDefinition)2 Script (com.github.anba.es6draft.Script)1 FunctionDefinition (com.github.anba.es6draft.ast.FunctionDefinition)1 GeneratorDefinition (com.github.anba.es6draft.ast.GeneratorDefinition)1 Realm (com.github.anba.es6draft.runtime.Realm)1 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)1 Source (com.github.anba.es6draft.runtime.internal.Source)1 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)1 StringModuleSource (com.github.anba.es6draft.runtime.modules.loader.StringModuleSource)1