transcendental-lisp/src/main/LispMain.java

60 lines
1.9 KiB
Java
Raw Normal View History

package main;
2017-02-11 13:33:34 -05:00
import java.util.function.Function;
import interpreter.*;
2017-03-17 16:07:25 -04:00
import terminal.LispTerminal;
public class LispMain {
2017-02-11 13:33:34 -05:00
private static final String ANSI_RESET = "\u001B[0m";
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_GREEN = "\u001B[32m";
private static final String ANSI_YELLOW = "\u001B[33m";
private static final String ANSI_PURPLE = "\u001B[35m";
private LispMain() {}
public static void main(String[] args) {
2017-03-17 16:07:25 -04:00
LispTerminal terminal = new LispTerminal();
terminal.run();
// LispInterpreter interpreter = buildInterpreter(args);
// interpreter.interpret();
}
private static LispInterpreter buildInterpreter(String[] args) {
LispInterpreterBuilder builder = LispInterpreterBuilderImpl.getInstance();
2017-02-11 13:33:34 -05:00
configureInput(args, builder);
builder.setOutput(System.out);
builder.setErrorOutput(System.err);
builder.setTerminationFunction(() -> System.exit(0));
builder.setErrorTerminationFunction(() -> System.exit(1));
2017-02-11 13:33:34 -05:00
builder.setValueOutputDecorator(makeColorDecorator(ANSI_GREEN));
builder.setWarningOutputDecorator(makeColorDecorator(ANSI_YELLOW));
builder.setErrorOutputDecorator(makeColorDecorator(ANSI_RED));
builder.setCriticalOutputDecorator(makeColorDecorator(ANSI_PURPLE));
return builder.build();
}
private static void configureInput(String[] args, LispInterpreterBuilder builder) {
if (args.length > 0)
builder.useFile(args[0]);
else
builder.setInput(System.in, "stdin");
}
2017-02-11 13:33:34 -05:00
private static Function<String, String> makeColorDecorator(String color) {
return new Function<String, String>() {
@Override
public String apply(String s) {
return color + s + ANSI_RESET;
}
};
}
}