Search in sources :

Example 1 with HaltException

use of com.googlecode.prolog_cafe.exceptions.HaltException in project gerrit by GerritCodeReview.

the class PrologShell method run.

@Override
public int run() {
    banner();
    BufferingPrologControl pcl = new BufferingPrologControl();
    pcl.setPrologClassLoader(new PrologClassLoader(getClass().getClassLoader()));
    pcl.setEnabled(Prolog.Feature.IO, true);
    pcl.setEnabled(Prolog.Feature.STATISTICS, true);
    pcl.configureUserIO(System.in, System.out, System.err);
    pcl.initialize(Prolog.BUILTIN);
    for (String file : fileName) {
        String path;
        try {
            path = new File(file).getCanonicalPath();
        } catch (IOException e) {
            path = new File(file).getAbsolutePath();
        }
        pcl.execute(Prolog.BUILTIN, "consult", SymbolTerm.create(path));
        System.err.println();
        System.err.flush();
    }
    try {
        pcl.execute(Prolog.BUILTIN, "cafeteria");
        write("% halt\n");
        return 0;
    } catch (HaltException halt) {
        write("% halt(" + halt.getStatus() + ")\n");
        return halt.getStatus();
    }
}
Also used : HaltException(com.googlecode.prolog_cafe.exceptions.HaltException) BufferingPrologControl(com.googlecode.prolog_cafe.lang.BufferingPrologControl) IOException(java.io.IOException) File(java.io.File) PrologClassLoader(com.googlecode.prolog_cafe.lang.PrologClassLoader)

Aggregations

HaltException (com.googlecode.prolog_cafe.exceptions.HaltException)1 BufferingPrologControl (com.googlecode.prolog_cafe.lang.BufferingPrologControl)1 PrologClassLoader (com.googlecode.prolog_cafe.lang.PrologClassLoader)1 File (java.io.File)1 IOException (java.io.IOException)1