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.
Index ¶
- Constants
- type ErrorListener
- type Listener
- func (l *Listener) ExitAddOps(c *parser.AddOpsContext)
- func (l *Listener) ExitAnd(c *parser.AndContext)
- func (l *Listener) ExitBetween(c *parser.BetweenContext)
- func (l *Listener) ExitColumnIdentifier(c *parser.ColumnIdentifierContext)
- func (l *Listener) ExitDivOps(c *parser.DivOpsContext)
- func (l *Listener) ExitIn(c *parser.InContext)
- func (l *Listener) ExitIsLiteral(c *parser.IsLiteralContext)
- func (l *Listener) ExitIsNull(c *parser.IsNullContext)
- func (l *Listener) ExitLike(c *parser.LikeContext)
- func (l *Listener) ExitLiteralOps(c *parser.LiteralOpsContext)
- func (l *Listener) ExitModOps(c *parser.ModOpsContext)
- func (l *Listener) ExitMulOps(c *parser.MulOpsContext)
- func (l *Listener) ExitNot(c *parser.NotContext)
- func (l *Listener) ExitNumberLiteral(c *parser.NumberLiteralContext)
- func (l *Listener) ExitOr(c *parser.OrContext)
- func (l *Listener) ExitStringLiteral(c *parser.StringLiteralContext)
- func (l *Listener) ExitStringOps(c *parser.StringOpsContext)
- func (l *Listener) ExitSubOps(c *parser.SubOpsContext)
- func (l *Listener) GetTree() (n Node, err error)
- type Node
- type ParseError
- type StackError
- type UnexpectedLiteralError
Constants ¶
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 LtOp = "$lt" LteOp = "$lte" GtOp = "$gt" GteOp = "$gte" EqOp = "$eq" NotEqOp = "$ne" RegexOp = "$regex" NotRegexOp = "$nregex" LikeOp = "$like" NotLikeOp = "$nlike" 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) ExitColumnIdentifier ¶
func (l *Listener) ExitColumnIdentifier(c *parser.ColumnIdentifierContext)
ExitColumnIdentifier is called when exiting the ColumnIdentifier production.
func (*Listener) ExitDivOps ¶
func (l *Listener) ExitDivOps(c *parser.DivOpsContext)
ExitDivOps is called when production div op 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) 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.
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.
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