boolexpr is a lightweight library designed for validating strings against patterns using a simple, intuitive syntax. Unlike regular expressions, boolexpr uses straightforward logical operators to combine patterns, making it easier to write and understand complex validation rules. Syntax
boolexpr patterns are constructed using the following symbols:
- AND: & (both conditions must be true)
- OR: | (at least one condition must be true)
- Grouping: () (used to control the precedence of operations)
The syntax of boolexpr is defined by the following Backus-Naur Form (BNF) grammar:
<exp> ::=
<group> "&" <exp>
| <group> "|" <exp>
| <group>
<group> ::=
"(" <exp> ")"
| <data>
<data> ::=
[a-z]+
The following code must return false
from the Eval()
since there is no x
in the string validated.
l := b.Init("(((b&x|x)&x|x&q&q|x)&((x|(o&(o&x)))&q)&(q&b)&(((o&q)&a|l)))")
data := "Qualquer dado"
c, err := l.Eval(data)
if err != nil {
fmt.Panic(err.Error())
}
The following code must return true
since the string validated has a
.
l := b.Init("a | z")
data := "Qualquer dado"
c, err := l.Eval(data)
if err != nil {
fmt.Panic(err.Error())
}
The grammar must generate the following sentences.
((xy&g)|g|(vhs&tp)&e&h)&s|mb|b
(m&jua)
((wiaae|(r&dj&h)&(i&p))|((i&g|r)))
((o|b|b&b)&(l))|(a)|o
((b&b|l)&o|l&q&q|l)&((q|(o))&q)|(q&b)&(((o&q)&a|l))
https://www.inf.ufpr.br/lesoliveira/download/c-completo-total.pdf