All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaskell.parsec.common.Try Maven / Gradle / Ivy

Go to download

This is a utils library for java 8 project. It include parsec combinators and sql generators library.

There is a newer version: 2.9.2
Show newest version
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