jaskell.parsec.ManyTill 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.ArrayList;
import java.util.List;
import static jaskell.parsec.Combinator.attempt;
/**
* Created by Mars Liu on 2016-01-03.
* ManyTil 尝试匹配 parser 0 到多次,直到终结算子成功,它是饥饿模式.
*/
public class ManyTill
implements Parsec, Status, Tran> {
private final Parsec parser;
private final Parsec end;
@Override
public List parse(State s)
throws EOFException, ParsecException {
ArrayList re = new ArrayList<>();
while (true) {
try {
attempt(end).parse(s);
return re;
} catch (EOFException | ParsecException e) {
re.add(parser.parse(s));
}
}
}
public ManyTill(Parsec parser, Parsec end) {
this.parser = new Try<>(parser);
this.end = end;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy