tsl

package
v5.2.12 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

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/v5/pkg/walkers

Index

Constants

View Source
const (
	IdentOp      = "$ident"   // Empty operator for itentifiers
	ArrayOp      = "$array"   // Empty operator for arrays
	StringOp     = "$string"  // Empty operator for strings
	NumberOp     = "$number"  // Empty operator for numbers
	BooleanOp    = "$boolean" // Empty operator for booleans
	DateOp       = "$date"    // Empty operator for dates
	NullOp       = "$null"    // Empty operator for nulls
	LtOp         = "$lt"
	LteOp        = "$lte"
	GtOp         = "$gt"
	GteOp        = "$gte"
	EqOp         = "$eq"
	NotEqOp      = "$ne"
	RegexOp      = "$regex"
	NotRegexOp   = "$nregex"
	LikeOp       = "$like"
	ILikeOp      = "$ilike"
	InOp         = "$in"
	NotInOp      = "$nin"
	BetweenOp    = "$between"
	NotBetweenOp = "$nbetween"
	NotOp        = "$not"
	AndOp        = "$and"
	OrOp         = "$or"
	IsNilOp      = "$nexists"
	IsNotNilOp   = "$exists"
	AddOp        = "$add"
	SubtractOp   = "$subtract"
	MultiplyOp   = "$multiply"
	DivideOp     = "$divide"
	ModuloOp     = "$modulo"
)

TLS operators.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorListener

type ErrorListener struct {
	*antlr.DefaultErrorListener
	Err error
}

ErrorListener an error listener for antlr parser.

func NewErrorListener

func NewErrorListener() *ErrorListener

NewErrorListener create a new error listener.

func (*ErrorListener) SyntaxError

func (d *ErrorListener) SyntaxError(
	recognizer antlr.Recognizer,
	offendingSymbol interface{},
	line, column int,
	msg string,
	e antlr.RecognitionException)

SyntaxError handle an error.

type Listener

type Listener struct {
	*parser.BaseTSLListener

	Stack []Node
	Errs  []error
}

Listener is a Tree search listener.

func (*Listener) ExitAddOps

func (l *Listener) ExitAddOps(c *parser.AddOpsContext)

ExitAddOps is called when production add op is exited.

func (*Listener) ExitAnd

func (l *Listener) ExitAnd(c *parser.AndContext)

ExitAnd is called when production And is exited.

func (*Listener) ExitBetween

func (l *Listener) ExitBetween(c *parser.BetweenContext)

ExitBetween is called when production Between is exited.

func (*Listener) ExitBooleanLiteral added in v5.2.0

func (l *Listener) ExitBooleanLiteral(c *parser.BooleanLiteralContext)

ExitBooleanLiteral is called when exiting the BooleanLiteral production.

func (*Listener) ExitColumnIdentifier

func (l *Listener) ExitColumnIdentifier(c *parser.ColumnIdentifierContext)

ExitColumnIdentifier is called when exiting the ColumnIdentifier production.

func (*Listener) ExitDateLiteral added in v5.2.0

func (l *Listener) ExitDateLiteral(c *parser.DateLiteralContext)

ExitDateLiteral is called when exiting the DateLiteral production.

func (*Listener) ExitDivOps

func (l *Listener) ExitDivOps(c *parser.DivOpsContext)

ExitDivOps is called when production div op is exited.

func (*Listener) ExitIn

func (l *Listener) ExitIn(c *parser.InContext)

ExitIn is called when production In is exited.

func (*Listener) ExitIsLiteral

func (l *Listener) ExitIsLiteral(c *parser.IsLiteralContext)

ExitIsLiteral is called when production IsLiteral is exited.

func (*Listener) ExitIsNull

func (l *Listener) ExitIsNull(c *parser.IsNullContext)

ExitIsNull is called when production IsNull is exited.

func (*Listener) ExitLike

func (l *Listener) ExitLike(c *parser.LikeContext)

ExitLike is called when production Like is exited.

func (*Listener) ExitLiteralOps

func (l *Listener) ExitLiteralOps(c *parser.LiteralOpsContext)

ExitLiteralOps is called when production LiteralOps is exited.

func (*Listener) ExitModOps

func (l *Listener) ExitModOps(c *parser.ModOpsContext)

ExitModOps is called when production modulo op is exited.

func (*Listener) ExitMulOps

func (l *Listener) ExitMulOps(c *parser.MulOpsContext)

ExitMulOps is called when production multiply op is exited.

func (*Listener) ExitNot

func (l *Listener) ExitNot(c *parser.NotContext)

ExitNot is called when production Not is exited.

func (*Listener) ExitNumberLiteral

func (l *Listener) ExitNumberLiteral(c *parser.NumberLiteralContext)

ExitNumberLiteral is called when exiting the NumberLiteral production.

func (*Listener) ExitOr

func (l *Listener) ExitOr(c *parser.OrContext)

ExitOr is called when production Or is exited.

func (*Listener) ExitShortDateLiteral added in v5.2.8

func (l *Listener) ExitShortDateLiteral(c *parser.ShortDateLiteralContext)

ExitShortDateLiteral is called when exiting the ShortDateLiteral production.

func (*Listener) ExitStringLiteral

func (l *Listener) ExitStringLiteral(c *parser.StringLiteralContext)

ExitStringLiteral is called when exiting the StringLiteral production.

func (*Listener) ExitStringOps

func (l *Listener) ExitStringOps(c *parser.StringOpsContext)

ExitStringOps is called when production StringOps is exited.

func (*Listener) ExitSubOps

func (l *Listener) ExitSubOps(c *parser.SubOpsContext)

ExitSubOps is called when production subtract op is exited.

func (*Listener) GetTree

func (l *Listener) GetTree() (n Node, err error)

GetTree return the parsed tree, if exist.

type Node

type Node struct {
	Func  string      `json:"func"`
	Left  interface{} `json:"left,omitempty"`
	Right interface{} `json:"right,omitempty"`
}

Node is a Tree search node.

func ParseTSL

func ParseTSL(input string) (tree Node, err error)

ParseTSL parses the input string into TSL tree.

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

ParseError is raised on parser error.

func (ParseError) Error

func (e ParseError) Error() string

type StackError

type StackError struct{}

StackError is raised when the parser stack has unexpected size.

func (StackError) Error

func (e StackError) Error() string

type UnexpectedLiteralError

type UnexpectedLiteralError struct {
	ExpectedType string      // the expected literal type.
	Literal      interface{} // the literal found.
}

UnexpectedLiteralError is raised when an unexpected literal is found.

func (UnexpectedLiteralError) Error

func (e UnexpectedLiteralError) Error() string

Jump to

Keyboard shortcuts

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