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

com.phasmidsoftware.number.misc.FuzzyParser.scala Maven / Gradle / Ivy

The newest version!
package com.phasmidsoftware.number.misc

import scala.util.parsing.combinator._

/**
  * @author scalaprof
  */
class FuzzyParser extends JavaTokenParsers {
  self =>
  def fuzzy: Parser[Fuzzy] = wholeNumber ~ opt(fraction) ~ opt(fuzz) ~ opt(exponent) ^^ { case i ~ x ~ f ~ e => Fuzzy(i, x, f, e) }

  def fraction: Parser[String] = """\.\d*""".r

  def exponent: Parser[String] = ("E" | "e") ~> """[+-]?\d+""".r

  def fuzz: Parser[String] = "(" ~> """\d+""".r <~ ")"

  // The following are for testing purposes
  def fuzzyRep: Parser[(String, Option[String], Option[String], Option[String])] = wholeNumber ~ opt(fraction) ~ opt(fuzz) ~ opt(exponent) ^^ { case i ~ x ~ f ~ e => (i, x, f, e) }

  def nominal: Parser[(String, Option[String], Option[String])] = wholeNumber ~ opt(fraction) ~ opt(exponent) ^^ { case i ~ x ~ e => (i, x, e) }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy