Documentation
¶
Index ¶
- Constants
- func AssertSliceType[T any](input any) ([]T, error)
- func AssertType[T any](input any) (T, error)
- func IsValue(arg QueryArg) bool
- type Parser
- type ParserOption
- type QueryArg
- type QueryArgFunc
- type QueryArgValue
- type QueryFunc
- type QueryFuncHandler
- type QueryFuncSet
- type Set
- type Token
- type TokenSet
- type Tokenizer
Constants ¶
const ( TokenFunc = "FUNC" TokenValue = "VALUE" TokenFuncClose = "FUNC-CLOSE" // RootFunc serves as a seed function that represents the initial state // when there is no parent function. It can be useful for indicating // the top level of a query structure. RootFunc = "ROOT" )
Variables ¶
This section is empty.
Functions ¶
func AssertSliceType ¶
AssertSliceType asserts that each element of the input slice is of type T and returns a slice of type T.
func AssertType ¶
AssertType attempts to assert the input to the specified type T
Types ¶
type Parser ¶
type Parser interface { // Parse takes an input query and a variadic number of parameters, processes the input // based on these parameters, and returns the parsed result, additional extracted // data, and any error encountered during parsing. // // # Parameters: // - ctx: A context to manage deadlines, cancellations, and other request-scoped values. // - input: The input to be parsed. // - params: A variadic number of additional parameters that influence the parsing process. // // # Returns: // - string: The parsed query. // - []any: Additional data extracted during parsing. // - error: An error object providing details if the parsing fails. Parse(ctx context.Context, input any, params ...string) (string, []any, error) }
Parser defines an interface for parsing input queries with additional parameters within a given context, returning a parsed query, additional extracted data, and any errors encountered during the process.
type ParserOption ¶
type ParserOption func(*queryParser) error
func WithFunctions ¶
func WithFunctions(funcs QueryFuncSet) ParserOption
WithFunctions sets a list of query functions for the query parser. This allows for defining the set of functions that the query parser will use.
func WithParams ¶
func WithParams(params []string) ParserOption
WithParams sets a list of query parameters for the query parser. This allows for a specified number of additional parameters that influence the parsing process by replacing value placeholders. Placeholders in the query input (e.g., func($1, $2)) will be replaced with the corresponding values from the provided parameters.
func WithTokenizer ¶
func WithTokenizer(tokenizer Tokenizer) ParserOption
WithTokenizer sets a custom tokenizer for the query parser. This allows for overriding the default tokenization behavior with a user-provided tokenizer
type QueryArg ¶
type QueryArg interface { }
QueryArg is an interface that represents an argument in a query.
type QueryArgFunc ¶
type QueryArgFunc struct {
// contains filtered or unexported fields
}
QueryArgFunc represents a function argument in a query.
func (*QueryArgFunc) Value ¶
func (qa *QueryArgFunc) Value() *QueryFunc
Value returns the underlying QueryFunc associated with the QueryArgFunc.
type QueryArgValue ¶
type QueryArgValue struct {
// contains filtered or unexported fields
}
QueryArgValue represents a value argument in a query.
func (*QueryArgValue) Value ¶
func (qa *QueryArgValue) Value() any
Value returns the value of the QueryArgValue.
type QueryFunc ¶
type QueryFunc struct {
// contains filtered or unexported fields
}
QueryFunc represents a function in the query. It holds the function's name, its arguments, and the result of its execution.
func Parse ¶
Parse process the input query with the provided options and returns a structured QueryFuncHandler representation.
func (*QueryFunc) Args ¶
A slice of QueryArg that contains the arguments passed to the function. Each argument can be a value or another function.
type QueryFuncHandler ¶
QueryFuncHandler represents a query function that includes an invocation method and a set of allowed functions that can call this function.
type QueryFuncSet ¶
type QueryFuncSet map[string]QueryFuncHandler
QueryFuncSet is a map of query function names to their corresponding QueryFuncHandler.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a generic set implementation using a map where the keys are of type T and the values are empty structs to save memory. It includes a mutex for thread safety.
func NewSet ¶
func NewSet[T comparable]() *Set[T]
NewSet creates and returns a new empty Set of type T.
func (*Set[T]) Add ¶
Add inserts one or more values into the Set. It returns the modified Set to allow for method chaining.
func (*Set[T]) List ¶
func (s *Set[T]) List() []T
List returns a slice containing all elements in the Set.
type TokenSet ¶
type TokenSet []Token
TokenSet represents a collection of tokens.
func NewTokenSet ¶
NewTokenSet creates and initializes a new TokenSet with an optional capacity.
func Tokenize ¶
Tokenize breaks the input into tokens. It recognizes function names and values.
Example Input: "AND(EQ(key1, val1), OR(NOTEQ(key2, val2), NOTEQ(key3, val3)))"
This input contains:
- Function names: AND, EQ, OR, NOTEQ
- Literals: key1, key2, key3, val1, val2, val3
The function will return tokens representing these elements, allowing further processing of the query.
func (TokenSet) AddFunctionToken ¶
AddFunctionToken adds a function token with the specified name to the TokenSet. If the addTokens function is provided, it will be called to add additional tokens between the function tokens.
func (TokenSet) AddValueToken ¶
AddValueToken adds a value token with the specified value to the TokenSet.