jaskell.parsec.common.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.common;
import static jaskell.parsec.common.Combinator.attempt;
import jaskell.parsec.ParsecException;
import java.io.EOFException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Mars Liu on 2016-01-03.
* ManyTil 尝试匹配 parser 0 到多次,直到终结算子成功,它是饥饿模式.
*/
public class ManyTill
implements Parsec> {
private final Parsec parser;
private final Parsec end;
@Override
public List parse(State s)
throws EOFException, ParsecException {
List 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