Documentation
¶
Overview ¶
Package tsl describe and parse the Tree Search Language (TSL), TSL is a wonderful search language, With similar grammar to SQL's where part.
TSL grammar examples:
"name = 'joe' or name = 'jane'" "city in ('paris', 'rome', 'milan') and state != 'spane'" "pages between 100 and 200 and author.name ~= 'Hilbert'"
The package provide the ParseTSL method to convert TSL string into TSL tree.
Usage:
// Parse input string into a TSL tree. tree, err := tsl.ParseTSL("user.name like 'Joe'") if err != nil { log.Fatal(err) }
TSL tree can be used to generate SQL and MongoDB query filters, see the walkers package for TSL tree walking examples.
https://pkg.go.dev/github.com/yaacov/tree-search-language/v6/pkg/walkers
Index ¶
- type BetweenOperatorError
- type DivisionByZeroError
- type KeyNotFoundError
- type Kind
- type Operator
- type SyntaxError
- type TSLArrayLiteral
- type TSLExpressionOp
- type TSLNode
- func (n *TSLNode) AttachChild(child *TSLNode) bool
- func (n *TSLNode) AttachLeft(child *TSLNode) bool
- func (n *TSLNode) AttachRight(child *TSLNode) bool
- func (n *TSLNode) Clone() *TSLNode
- func (n *TSLNode) DetachChild() *TSLNode
- func (n *TSLNode) DetachLeft() *TSLNode
- func (n *TSLNode) DetachRight() *TSLNode
- func (n *TSLNode) Free()
- func (n *TSLNode) MarshalJSON() ([]byte, error)
- func (n *TSLNode) MarshalYAML() (interface{}, error)
- func (n *TSLNode) Type() Kind
- func (n *TSLNode) Value() interface{}
- type TypeMismatchError
- type UnexpectedLiteralError
- type UnexpectedOperatorError
- type UnexpectedTypeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BetweenOperatorError ¶
type BetweenOperatorError struct {
Message string
}
BetweenOperatorError is returned when BETWEEN operator is used incorrectly
func (BetweenOperatorError) Error ¶
func (e BetweenOperatorError) Error() string
type DivisionByZeroError ¶
type DivisionByZeroError struct {
Operation string
}
DivisionByZeroError is returned when attempting to divide by zero
func (DivisionByZeroError) Error ¶
func (e DivisionByZeroError) Error() string
type KeyNotFoundError ¶
type KeyNotFoundError struct {
Key string
}
KeyNotFoundError is returned when a requested key is not found in the data
func (KeyNotFoundError) Error ¶
func (e KeyNotFoundError) Error() string
type Kind ¶
type Kind int
Kind represents the kind of node in the AST These values must match the ast_node_type enum in tsl_ast.h
const ( KindNumericLiteral Kind = 0 // AST_NUMBER KindStringLiteral Kind = 1 // AST_STRING KindIdentifier Kind = 2 // AST_IDENTIFIER KindBinaryExpr Kind = 3 // AST_BINARY_OP KindUnaryExpr Kind = 4 // AST_UNARY_OP KindDateLiteral Kind = 5 // AST_DATE KindTimestampLiteral Kind = 6 // AST_RFC3339 KindArrayLiteral Kind = 7 // AST_ARRAY KindBooleanLiteral Kind = 8 // AST_BOOL KindNullLiteral Kind = 9 // AST_NULL )
type Operator ¶
type Operator int
Operator represents the type definitions. These values must match the yytokentype enum tsl_parser.tab.h
const ( OpLike Operator = 258 // K_LIKE (SQL LIKE) OpILike Operator = 259 // K_ILIKE (SQL ILIKE) OpAnd Operator = 260 // K_AND OpOr Operator = 261 // K_OR OpBetween Operator = 262 // K_BETWEEN OpIn Operator = 263 // K_IN OpIs Operator = 264 // K_IS (Only for NULL and NOT NULL) // 265 K_NULL OpNot Operator = 266 // K_NOT // 267 K_TRUE // 268 K_FALSE OpLen Operator = 269 // K_LEN OpAny Operator = 270 // K_ANY OpAll Operator = 271 // K_ALL OpSum Operator = 272 // K_SUM (Sum operator) // Arithmetic Operators OpPlus Operator = 278 // PLUS OpMinus Operator = 279 // MINUS OpStar Operator = 280 // STAR (MULTIPLY) OpSlash Operator = 281 // SLASH (DIVIDE) OpPercent Operator = 282 // PERCENT (MODULUS) // Comparison Operators OpEQ Operator = 288 // EQ OpNE Operator = 289 // NE OpLT Operator = 290 // LT OpLE Operator = 291 // LE OpGT Operator = 292 // GT OpGE Operator = 293 // GE OpREQ Operator = 294 // REQ (Regular expression equals) OpRNE Operator = 295 // RNE (Regular expression not equals) // Unary Operators OpUMinus Operator = 296 // UMINUS )
type SyntaxError ¶
SyntaxError represents a TSL parsing error with context
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Error implements the error interface
type TSLArrayLiteral ¶
type TSLArrayLiteral struct {
Values []*TSLNode
}
TSLArrayLiteral represents an array of nodes
type TSLExpressionOp ¶
TSLExpressionOp represents both unary and binary operations
type TSLNode ¶
type TSLNode struct {
// contains filtered or unexported fields
}
TSLNode represents an tree search language AST (Abstract Syntax Tree) node
func (*TSLNode) AttachChild ¶
AttachChild safely attaches a child node to a unary expression node
func (*TSLNode) AttachLeft ¶
AttachLeft safely attaches a child node as the left child of a binary expression node
func (*TSLNode) AttachRight ¶
AttachRight safely attaches a child node as the right child of a binary expression node
func (*TSLNode) DetachChild ¶
DetachChild safely detaches and returns the child of a unary expression node
func (*TSLNode) DetachLeft ¶
DetachLeft safely detaches and returns the left child of a binary expression node
func (*TSLNode) DetachRight ¶
DetachRight safely detaches and returns the right child of a binary expression node
func (*TSLNode) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface
func (*TSLNode) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler interface
type TypeMismatchError ¶
type TypeMismatchError struct { Expected string Got interface{} }
TypeMismatchError is returned when operand types don't match the operator
func (TypeMismatchError) Error ¶
func (e TypeMismatchError) Error() string
type UnexpectedLiteralError ¶
type UnexpectedLiteralError struct {
Literal interface{}
}
UnexpectedLiteralError is returned when encountering an unexpected literal or operator
func (UnexpectedLiteralError) Error ¶
func (e UnexpectedLiteralError) Error() string
type UnexpectedOperatorError ¶
type UnexpectedOperatorError struct {
Operator interface{}
}
UnexpectedOperatorError is returned when encountering an unexpected operator
func (UnexpectedOperatorError) Error ¶
func (e UnexpectedOperatorError) Error() string
type UnexpectedTypeError ¶
type UnexpectedTypeError struct {
Type interface{}
}
UnexpectedTypeError is returned when encountering an unexpected type in the AST
func (UnexpectedTypeError) Error ¶
func (e UnexpectedTypeError) Error() string