Fix parsing nested expressions

Since whitespace is used as a separator, it cannot be consumed by
and/or parens.
This commit is contained in:
Eike Kettner 2021-03-01 20:26:30 +01:00
parent 889e4f4fb0
commit 489581d90b
3 changed files with 29 additions and 3 deletions

View File

@ -21,13 +21,13 @@ object BasicParser {
(('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '9') ++ "-_.").toSet
val parenAnd: P[Unit] =
P.stringIn(List("(&", "(and")).void.surroundedBy(ws0)
P.stringIn(List("(&", "(and")).void <* ws0
val parenClose: P[Unit] =
P.char(')').surroundedBy(ws0)
ws0.soft.with1 *> P.char(')')
val parenOr: P[Unit] =
P.stringIn(List("(|", "(or")).void.surroundedBy(ws0)
P.stringIn(List("(|", "(or")).void <* ws0
val identParser: P[String] =
P.charsWhile(identChars.contains)

View File

@ -67,4 +67,26 @@ class ExprParserTest extends FunSuite with ValueHelper {
)
)
}
test("nest and/ with simple expr") {
val p = ExprParser.exprParser
assertEquals(
p.parseAll("(& (& f:usd=\"4.99\" ) source:*test* )"),
Right(
Expr.and(
Expr.and(Expr.CustomFieldMatch("usd", Operator.Eq, "4.99")),
Expr.string(Operator.Like, Attr.ItemSource, "*test*")
)
)
)
assertEquals(
p.parseAll("(& (& f:usd=\"4.99\" ) (| source:*test*) )"),
Right(
Expr.and(
Expr.and(Expr.CustomFieldMatch("usd", Operator.Eq, "4.99")),
Expr.or(Expr.string(Operator.Like, Attr.ItemSource, "*test*"))
)
)
)
}
}

View File

@ -173,6 +173,10 @@ class SimpleExprParserTest extends FunSuite with ValueHelper {
p.parseAll("f:usd=26.66"),
Right(Expr.CustomFieldMatch("usd", Operator.Eq, "26.66"))
)
assertEquals(
p.parseAll("f:usd=\"26.66\""),
Right(Expr.CustomFieldMatch("usd", Operator.Eq, "26.66"))
)
}
}