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

jaskell.parsec.common.ScNumber 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 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