Navigation Menu

Skip to content

Commit

Permalink
Added support for Float options in the command line parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickynils committed Apr 7, 2012
1 parent c593c3a commit 7685cba
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/scala/org/scalacheck/util/CmdLineParser.scala
Expand Up @@ -26,6 +26,7 @@ trait CmdLineParser extends Parsers {
}
trait Flag extends Opt[Unit]
trait IntOpt extends Opt[Int]
trait FloatOpt extends Opt[Float]
trait StrOpt extends Opt[String]

class OptMap {
Expand Down Expand Up @@ -68,11 +69,17 @@ trait CmdLineParser extends Parsers {
case s if s != null && s.length > 0 && s.forall(_.isDigit) => s.toInt
})

private val floatVal: Parser[Float] = accept("float", {
case s if s != null && s.matches("[0987654321]+\\.?[0987654321]*")
=> s.toFloat
})

private case class OptVal[T](o: Opt[T], v: T)

private val optVal: Parser[OptVal[Any]] = opt into {
case o: Flag => success(OptVal(o, ()))
case o: IntOpt => intVal ^^ (v => OptVal(o, v))
case o: FloatOpt => floatVal ^^ (v => OptVal(o, v))
case o: StrOpt => strVal ^^ (v => OptVal(o, v))
}

Expand Down

0 comments on commit 7685cba

Please sign in to comment.