Search in sources :

Example 1 with Launcher

use of php.runtime.launcher.Launcher in project jphp by jphp-compiler.

the class CLI method checkSyntax.

protected void checkSyntax(String filename) throws Throwable {
    Launcher launcher = new Launcher("jphp.conf", args);
    launcher.run(false, true);
    File file = new File(filename);
    Environment environment = new Environment(launcher.getCompileScope(), output);
    Context context = new Context(file);
    try {
        SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, new Tokenizer(context));
        analyzer.getTree();
        output.println(String.format("No syntax errors detected in %s", filename));
    } catch (Exception e) {
        environment.catchUncaught(e);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    } finally {
        try {
            environment.doFinal();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
}
Also used : Context(php.runtime.env.Context) SyntaxAnalyzer(org.develnext.jphp.core.syntax.SyntaxAnalyzer) Launcher(php.runtime.launcher.Launcher) Environment(php.runtime.env.Environment) File(java.io.File) Tokenizer(org.develnext.jphp.core.tokenizer.Tokenizer)

Example 2 with Launcher

use of php.runtime.launcher.Launcher in project jphp by jphp-compiler.

the class CLI method executeFile.

protected void executeFile(String filename) throws Throwable {
    Launcher launcher = new Launcher("jphp.conf", args);
    launcher.run(false);
    File file = new File(filename);
    Environment environment = new Environment(launcher.getCompileScope(), output);
    environment.getDefaultBuffer().setImplicitFlush(true);
    try {
        Context context = new Context(file);
        ModuleEntity module = environment.importModule(context);
        module.include(environment);
    } catch (Exception e) {
        environment.catchUncaught(e);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    } finally {
        try {
            environment.doFinal();
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
}
Also used : Context(php.runtime.env.Context) Launcher(php.runtime.launcher.Launcher) Environment(php.runtime.env.Environment) ModuleEntity(php.runtime.reflection.ModuleEntity) File(java.io.File)

Aggregations

File (java.io.File)2 Context (php.runtime.env.Context)2 Environment (php.runtime.env.Environment)2 Launcher (php.runtime.launcher.Launcher)2 SyntaxAnalyzer (org.develnext.jphp.core.syntax.SyntaxAnalyzer)1 Tokenizer (org.develnext.jphp.core.tokenizer.Tokenizer)1 ModuleEntity (php.runtime.reflection.ModuleEntity)1