jaskell.parsec.Between 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;
/**
* 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