jaskell.parsec.Option 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 java.io.EOFException;
import java.util.Optional;
/**
* Created by Mars Liu on 16/9/18.
* Option accept a parsec<E, T, Status, Tran> and
* return new one parsec<Optional<T>, E, Status, Tran>.
* If the parser fail, Option parsec just return option.empty without Exception thrown.
*/
public class Option
implements Parsec, Status, Tran> {
private final Parsec parser;
public Option(Parsec parser) {
this.parser = parser;
}
@Override
public Optional parse(State s)
throws EOFException, ParsecException {
Status status = s.status();
try{
return Optional.of(parser.parse(s));
} catch (Exception e) {
if(status.equals(s.status())) {
return Optional.empty();
}else{
throw e;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy