jaskell.parsec.Parsec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaskell-java8 Show documentation
Show all versions of jaskell-java8 Show documentation
This is a utils library for java 8 project.
It include parsec combinators and sql generators library.
package jaskell.parsec;
import jaskell.sql.Equal;
import jaskell.util.Result;
import java.io.EOFException;
/**
* Created by Mars Liu on 2016-01-02.
* Parsec defined base functions of parsec parsers.
*/
@FunctionalInterface
public interface Parsec {
T parse(State s)
throws EOFException, ParsecException;
default Result exec(State s) {
try {
return new Result<>(Parsec.this.parse(s));
} catch (Exception e) {
return new Result<>(e);
}
}
default Parsec bind(Binder binder) {
return s -> {
T value = Parsec.this.parse(s);
return binder.bind(value).parse(s);
};
}
default Parsec then(Parsec parsec) {
return s -> {
Parsec.this.parse(s);
return parsec.parse(s);
};
}
default Parsec over(Parsec parsec) {
return s -> {
T value = Parsec.this.parse(s);
parsec.parse(s);
return value;
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy