diff options
author | timgushue <tim@driver.xyz> | 2017-09-27 09:34:45 -0700 |
---|---|---|
committer | timgushue <tim@driver.xyz> | 2017-09-27 09:34:45 -0700 |
commit | e9d3e19f637614809aab39d9df2d1fcc6c78916e (patch) | |
tree | 29560b9b5bfb1b235c6429506f56fa9dab8d4510 /src/main/scala/xyz/driver/pdsuicommon/parsers | |
parent | 0ef0059e9b47430e52d6bad4ced5b1be7f3b1a0d (diff) | |
parent | c24679f1ae7d7ccc4e6693535b0aa3ac0e1ca225 (diff) | |
download | rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.tar.gz rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.tar.bz2 rest-query-e9d3e19f637614809aab39d9df2d1fcc6c78916e.zip |
Merge branch 'master' into add-slot-eligibility-arms
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/parsers')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala b/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala index 8aff397..e0adeb8 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/parsers/SearchFilterParser.scala @@ -13,10 +13,15 @@ import scala.util.Try object SearchFilterParser { private object BinaryAtomFromTuple { - def unapply(input: (SearchFilterExpr.Dimension, (String, String))): Option[SearchFilterExpr.Atom.Binary] = { + def unapply(input: (SearchFilterExpr.Dimension, (String, Any))): Option[SearchFilterExpr.Atom.Binary] = { val (dimensionName, (strOperation, value)) = input + val updatedValue = value match { + case s: String => s.safeTrim + case a => a + } + parseOperation(strOperation.toLowerCase).map { op => - SearchFilterExpr.Atom.Binary(dimensionName, op, value.safeTrim) + SearchFilterExpr.Atom.Binary(dimensionName, op, updatedValue.asInstanceOf[AnyRef]) } } } @@ -68,7 +73,7 @@ object SearchFilterParser { } private val numericOperatorParser: Parser[String] = { - P((IgnoreCase("gt") | IgnoreCase("lt")) ~ IgnoreCase("eq").?).! + P(IgnoreCase("eq") | ((IgnoreCase("gt") | IgnoreCase("lt")) ~ IgnoreCase("eq").?)).! } private val naryOperatorParser: Parser[String] = P(IgnoreCase("in")).! @@ -91,10 +96,12 @@ object SearchFilterParser { private val nAryValueParser: Parser[String] = P(CharPred(_ != ',').rep(min = 1).!) + private val longParser: Parser[Long] = P(CharIn('0' to '9').rep(1).!.map(_.toLong)) + private val binaryAtomParser: Parser[SearchFilterExpr.Atom.Binary] = P( dimensionParser ~ whitespaceParser ~ ( - (commonOperatorParser.! ~/ whitespaceParser ~/ AnyChar.rep(min = 1).!) - | (numericOperatorParser.! ~/ whitespaceParser ~/ numberParser.!) + (numericOperatorParser.! ~ whitespaceParser ~ (longParser | numberParser.!)) | + (commonOperatorParser.! ~ whitespaceParser ~ AnyChar.rep(min = 1).!) ) ~ End ).map { case BinaryAtomFromTuple(atom) => atom |