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

jaskell.parsec.common.OneOf 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 static java.util.stream.Collectors.joining;

import jaskell.parsec.ParsecException;

import java.io.EOFException;
import java.util.Set;

/**
 * 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