expression

package
v0.0.0-...-2bc12df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parenthesize

func Parenthesize(parser Parser) predicate.Parser

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.

func NewParser

func NewParser(predicateParser predicate.Parser, andOp predicate.BinaryOp, orOp predicate.BinaryOp) Parser

NewParser returns a new predicate expression parser. The passed-in predicateParser must be able to parse the "Predicate" nonterminal in the expression grammar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL