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

jaskell.parsec.SepBy 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;

import java.io.EOFException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mars Liu on 2016-01-03.
 * SepBy 尝试匹配由给定规则分隔开的0到多次重复匹配.
 */
public class SepBy
    implements Parsec, Status, Tran>{
    private final Parsec by;
    private final Parsec p;
    @Override
    public List parse(State s)
            throws EOFException, ParsecException {
        ArrayList re = new ArrayList<>();
        try {
            re.add(this.p.parse(s));
            while (true) {
                this.by.parse(s);
                re.add(this.p.parse(s));
            }
        } catch (EOFException|ParsecException e) {
            return re;
        }
    }
    public SepBy(Parsec p, Parsec by) {
        this.by = new Try<>(by);
        this.p = new Try<>(p);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy