Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parenthesize ¶
Parenthesize returns a predicate parser that only parses parenthesized expressions. The expressions themselves are parsed by the given parser. Note that the parser returned by Parenthesize mutates the passed-in parser's state.
If Parser#Parse returns an error for an empty expression, then Parenthesize also returns an error.
Types ¶
type BinaryOp ¶
type BinaryOp struct {
// contains filtered or unexported fields
}
BinaryOp represents a binary operator in a predicate expression
type Parser ¶
type Parser interface { predicate.Parser IsOp(token string) bool // SetUnknownTokenErrFunc sets a function to generate an error // message when the parser encounters an unknown token. SetUnknownTokenErrFunc(func(string) string) // SetEmptyExpressionErrMsg sets the error message that will be used // when the parser encounters an empty expression. SetEmptyExpressionErrMsg(string) // contains filtered or unexported methods }
Parser is a predicate parser that parses predicate expressions. Expressions have the following grammar:
Expression => Expression (-a|-and) Atom | Expression Atom | Expression (-o|-or) Atom | Atom Atom => (!|-not) Atom | '(' Expression ')' | Predicate
where 'Expression Atom' is semantically equivalent to 'Expression -a Atom'. The grammar for Predicate is caller-specific.
Operator precedence is (from highest to lowest):
() -not -and -or
The precedence of the () and -not operators is already enforced by the grammar. Precedence of the binary operators -and and -or is enforced by maintaining an evaluation stack.
Note that Parser is a sealed interface. Child classes must extend the parser returned by NewParser when overriding the interface's methods.