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

jaskell.parsec.common.Between 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.
 * Between 算子等效于 open.then(p).over(close); 若 (open, parser, close) 组合子顺序解析成功,返回 parser 的解析结果.
 * 遵循 Haskell Parsec 的定义,我们将参数顺序设定为 between(open, close, parser),并提供了 curry 化的 In 子类型.
 */
public class Between implements
    Parsec {
    private final Parsec open;
    private final Parsec close;
    private final Parsec parsec;

    @Override
    public T parse(State s)
            throws EOFException, ParsecException {
        open.parse(s);
        T re = parsec.parse(s);
        close.parse(s);
        return re;
    }

    public Between(Parsec open,
                   Parsec close,
                   Parsec parsec) {
        this.open = open;
        this.close = close;
        this.parsec = parsec;
    }

    static public class In> {
        private final Parsec open;
        private final Parsec close;

        public In(Parsec open, Parsec close) {
            this.open = open;
            this.close = close;
        }

        public Parsec pack(Parsec parser) {
            return new Between<>(this.open, this.close, parser);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy