jaskell.parsec.OneOf 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.Set;
import static java.util.stream.Collectors.joining;
/**
* Created by Mars Liu on 2016-01-03.
* OneOf 即 one of ,给定项中任何一个匹配成功即视为成功,否则抛出错误.
*/
public class OneOf implements Parsec {
private final Set items;
@Override
public E parse(State s)
throws EOFException, ParsecException {
E data = s.next();
if(items.contains(data)) {
return data;
}
String message = String.format("Expect %s in [%s]", data,
this.items.stream().map(E::toString).collect(joining(", ")));
throw s.trap(message);
}
public OneOf(Set items){
this.items = items;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy