com.github.leeonky.interpreter.TokenScanner Maven / Gradle / Ivy
The newest version!
package com.github.leeonky.interpreter;
import java.util.Optional;
import java.util.function.Function;
public interface TokenScanner, E extends Expression,
O extends Operator, P extends Procedure> {
static , N extends Node, C extends RuntimeContext,
O extends Operator, S extends Procedure> Mandatory tokenScanner(
boolean trimStart, TriplePredicate endsWith) {
return sourceCode -> sourceCode.fetchToken(trimStart, endsWith);
}
Optional scan(SourceCode sourceCode);
default NodeParser nodeParser(Function mapper) {
return procedure -> scan(procedure.getSourceCode()).map(token ->
mapper.apply(token).setPositionBegin(token.getPosition()));
}
interface Mandatory, E extends Expression,
O extends Operator, P extends Procedure> {
Token scan(SourceCode sourceCode);
default NodeParser.Mandatory nodeParser(Function mapper) {
return procedure -> {
Token token = scan(procedure.getSourceCode());
return mapper.apply(token).setPositionBegin(token.getPosition());
};
}
}
}