jaskell.parsec.common.ScNumber 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.common;
import jaskell.parsec.ParsecException;
import jaskell.sql.Right;
import jaskell.util.Result;
import java.io.EOFException;
/**
* ScNumber Parser could parse scientific number text
*
* @author Mars Liu
* @version 1.0.0
* @since 2020/06/05 12:40
*/
public class ScNumber implements Parsec {
private final Decimal decimal = new Decimal();
private final Parsec ep = new Ch('e', false);
private final Parsec sp =
new Choice<>(new Try<>(new Text("+")), new Try<>(new Text("-")), new Return<>(""));
private final Parsec np = new UInt();
private final Parsec exp = new Try<>(s -> ep.parse(s) + sp.parse(s) + np.parse(s));
@Override
public String parse(State s) throws EOFException, ParsecException {
String mantissa = decimal.parse(s);
return exp.exec(s).flatMap(e -> new Result<>(mantissa + e)).orElse(mantissa);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy