javax0.jamal.prog.Program Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jamal-prog Show documentation
Show all versions of jamal-prog Show documentation
Jamal module for Programmatic Extension
package javax0.jamal.prog;
import javax0.jamal.api.BadSyntax;
import javax0.jamal.api.Input;
import javax0.jamal.api.Macro;
import javax0.jamal.api.Processor;
import javax0.jamal.prog.analyzer.Block;
import javax0.jamal.prog.analyzer.Lexer;
import javax0.jamal.prog.commands.Context;
import javax0.jamal.tools.Scanner;
@Macro.Name({"program", "prog", "do", "run"})
public class Program implements Macro, Scanner.FirstLine {
@Override
public String evaluate(final Input in, final Processor processor) throws BadSyntax {
final int stepLimit = getStepLimit(in, processor, this);
return Block.analyze(new Lexer().analyze(in)).execute(new Context(processor, stepLimit));
}
static int getStepLimit(final Input in, final Processor processor, final Scanner.FirstLine it) throws BadSyntax {
final var scanner = it.newScanner(in, processor);
final var limit = scanner.number("stepLimit").defaultValue(100_000);
scanner.done();
return limit.get();
}
}