jaskell.parsec.common.Try 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.common;
import jaskell.parsec.ParsecException;
import java.io.EOFException;
/**
* Created by Mars Liu on 2016-01-03.
* Try 尝试执行给定算子,如果失败,先将state复位,再抛出异常.
*/
public class Try
implements Parsec {
private final Parsec parsec;
@Override
public T parse(State s) throws EOFException, ParsecException {
Integer tran = s.begin();
try{
T re = this.parsec.parse(s);
s.commit(tran);
return re;
} catch (Exception e) {
s.rollback(tran);
throw e;
}
}
public Try(Parsec parsec){
this.parsec = parsec;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy