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

jaskell.parsec.ManyTill 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;
import static jaskell.parsec.Combinator.attempt;

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