mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 14:15:59 +00:00
Fix parsing nested expressions
Since whitespace is used as a separator, it cannot be consumed by and/or parens.
This commit is contained in:
parent
889e4f4fb0
commit
489581d90b
@ -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)
|
||||
|
@ -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*"))
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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"))
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user