Documentation
¶
Index ¶
Examples ¶
Constants ¶
const (
StepJoin
)
parser's state machine steps
Variables ¶
var ErrEmpty = errors.New("empty filter expression")
var ErrIncomplete = errors.New("invalid or incomplete filter expression")
var ErrInvalidComment = errors.New("invalid comment")
Functions ¶
This section is empty.
Types ¶
type Expr ¶
Expr represents an individual tokenized expression consisting of left operand, operator and a right operand.
type ExprGroup ¶
type ExprGroup struct {
Item interface{}
Join JoinOp
}
ExprGroup represents a wrapped expression and its join type.
The group's Item could be either an `Expr` instance or `[]ExprGroup` slice (for nested expressions).
func Parse ¶
Parse parses the provided text and returns its processed AST in the form of `ExprGroup` slice(s).
Comments and whitespaces are ignored.
Example ¶
package main
import (
"fmt"
"github.com/ganigeorgiev/fexpr"
)
func main() {
result, _ := fexpr.Parse("id > 123")
fmt.Println(result)
}
Output: [{{{<nil> identifier id} > {<nil> number 123}} &&}]
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner represents a filter and lexical scanner.
func NewScanner ¶
NewScanner creates and returns a new scanner instance loaded with the specified data.
func (*Scanner) Scan ¶
Scan reads and returns the next available token value from the scanner's buffer.
Example ¶
package main
import (
"fmt"
"github.com/ganigeorgiev/fexpr"
)
func main() {
s := fexpr.NewScanner([]byte("id > 123"))
for {
t, err := s.Scan()
if t.Type == fexpr.TokenEOF || err != nil {
break
}
fmt.Println(t)
}
}
Output: {<nil> identifier id} {<nil> whitespace } {<nil> sign >} {<nil> whitespace } {<nil> number 123}
type SignOp ¶
type SignOp string
SignOp represents an expression sign operator.
const ( SignEq SignOp = "=" SignNeq SignOp = "!=" SignLike SignOp = "~" SignNlike SignOp = "!~" SignLt SignOp = "<" SignLte SignOp = "<=" SignGt SignOp = ">" SignGte SignOp = ">=" // array/any operators SignAnyEq SignOp = "?=" SignAnyNeq SignOp = "?!=" SignAnyLike SignOp = "?~" SignAnyNlike SignOp = "?!~" SignAnyLt SignOp = "?<" SignAnyLte SignOp = "?<=" SignAnyGt SignOp = "?>" SignAnyGte SignOp = "?>=" )
supported expression sign operators
type TokenType ¶
type TokenType string
TokenType represents a Token type.
const ( TokenUnexpected TokenType = "unexpected" TokenEOF TokenType = "eof" TokenWS TokenType = "whitespace" TokenJoin TokenType = "join" TokenSign TokenType = "sign" TokenIdentifier TokenType = "identifier" // variable, column name, placeholder, etc. TokenFunction TokenType = "function" // function TokenNumber TokenType = "number" TokenText TokenType = "text" // ' or " quoted string TokenGroup TokenType = "group" // groupped/nested tokens TokenComment TokenType = "comment" )
token type constants