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

jaskell.parsec.common.SepBy1 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 jaskell.parsec.ParsecException;

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

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

    public SepBy1(Parsec p, Parsec by) {
        this.by = new Try<>(by);
        this.p = p;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy