jaskell.parsec.Int 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.ArrayList;
import java.util.List;
/**
* Created by Mars Liu on 2016-01-07.
* Int 算子尝试将后续的信息项组成一个整数,如果获得的信息不足以组成一个整数,抛出异常.
*/
public class Int
implements Parsec {
private final Parsec, Status, Tran> parser =
s -> {
List re = new ArrayList<>();
Option sign = new Option<>(new Try<>(new Ch<>('-')));
sign.parse(s).ifPresent(re::add);
re.addAll(new Many1(new Digit<>()).parse(s));
return re;
};
@Override
public String parse(State s)
throws EOFException, ParsecException {
List buffer = parser.parse(s);
StringBuilder sb = new StringBuilder();
buffer.forEach(sb::append);
return sb.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy