Documentation
¶
Index ¶
- Variables
- func ParserError(err error, t *token.Token) error
- type DecisionSet
- type Options
- func (o *Options) EntryFunc() StateFn
- func (o *Options) GetDecisions(name string) DecisionSet
- func (o *Options) Lexer() (lex.Lexer, *lex.Options)
- func (o *Options) WithDecisions(name string, ds DecisionSet) *Options
- func (o *Options) WithEntryFunc(f StateFn) *Options
- func (o *Options) WithLexer(l lex.Lexer, lo *lex.Options) *Options
- type Parser
- type RunState
- func (rs *RunState) Context() context.Context
- func (rs *RunState) Current() *token.Token
- func (rs *RunState) Error() error
- func (rs *RunState) GetResultsCollection(collectionName string) (any, bool)
- func (rs *RunState) GetReturnFunc(f StateFn, ds DecisionSet, exitOnEOF bool) StateFn
- func (rs *RunState) IsPeeked() bool
- func (rs *RunState) Next() *token.Token
- func (rs *RunState) Peek() *token.Token
- func (rs *RunState) Previous() *token.Token
- func (rs *RunState) Results() ts.Lookup
- func (rs *RunState) SetResultsCollection(collectionName string, val any)
- func (rs *RunState) WithContext(ctx context.Context) *RunState
- func (rs *RunState) WithError(err error) *RunState
- func (rs *RunState) WithNextOverride(f StateFn) *RunState
- type StateFn
Constants ¶
This section is empty.
Variables ¶
var ErrEOF = errors.New("eof")
ErrEOF indicates EOF was reached during lexing or parsing
var ErrInvalidKeywordOrder = errors.New("invalid keyword order")
ErrInvalidKeywordOrder is returned when the RunState's current token a keyword that whose type value is lower than the previous keyword, which indicates they are presented out-of-order in the input string
var ErrNoLexer = errors.New("no lexer provided")
ErrNoLexer indicates that no lexer was specified to be used by the parser
var ErrUnexpectedToken = errors.New("unexpected token")
ErrUnexpectedToken is returned when the next token provided to the parser does not have a value in the current DecisionSet
var ErrUnsupportedKeyword = errors.New("unsupported keyword")
ErrUnsupportedKeyword is returned when the RunState's current token is not a currently-supported keyword (e.g., UNION in a SQL query)
var ErrUnsupportedParser = errors.New("this state function is not supported by this parser")
ErrUnsupportedParser means the passed parser does not support the function being called
var ParsingError error = &parsingError{}
ParsingError represents a Parsing Error
Functions ¶
Types ¶
type DecisionSet ¶
DecisionSet is a map of token types to state func. DecisionSets are used to determine the next action when processing a token, based on the token (and possibly the next token's) type
type Options ¶
type Options struct {
Decisions map[string]DecisionSet
// contains filtered or unexported fields
}
Options represents the options for the parser
func (*Options) GetDecisions ¶
func (o *Options) GetDecisions(name string) DecisionSet
GetDecisions returns the named DS
func (*Options) WithDecisions ¶
func (o *Options) WithDecisions(name string, ds DecisionSet) *Options
WithDecisions merges the provided named DecisionSet into the root named DS
func (*Options) WithEntryFunc ¶
WithEntryFunc sets the Parser's entryFunc
type Parser ¶
type Parser interface {
// Run runs the parser.
// context is a context to associate with the query for tracking request-specific info
// that parser extension use to maintain separate state data from main parse (e.g.,
// information about time series in the query). The parser argument is required so that
// any structs extending the Parser (which may also be an extension) can infer the
// original struct's type when running custom parser functions that require access
// to private struct members. The string is the actual query/statement to parse
Run(context.Context, Parser, string) (*RunState, error)
}
Parser is the main parser interface tor Trickster
type RunState ¶
type RunState struct {
// contains filtered or unexported fields
}
RunState maintains the state of a unique parsing run
func NewRunState ¶
NewRunState returns a new RunState object for the parser
func (*RunState) GetResultsCollection ¶
GetResultsCollection retrieves a collection from the results map
func (*RunState) GetReturnFunc ¶
func (rs *RunState) GetReturnFunc(f StateFn, ds DecisionSet, exitOnEOF bool) StateFn
GetReturnFunc will check for an error or EOF, before returning the Override func, if present, otherwise returns the provided func f
func (*RunState) Peek ¶
Peek looks at the next token and saves it to Next, but does not advance the state location
func (*RunState) SetResultsCollection ¶
SetResultsCollection places a collection of results into the results map
func (*RunState) WithContext ¶
WithContext attaches the provided context to the RunState
func (*RunState) WithNextOverride ¶
WithNextOverride attaches an override func for the next RunState invocation
type StateFn ¶
StateFn is a state function that represents the processing of a group of similar tokens
func Noop ¶
Noop is a convenience state function that breaks the main loop by returning a nil function Useful for assigning a nil-returning StateFn to a variable
func StateUnexpectedToken ¶
StateUnexpectedToken is a convenience state function that breaks the main loop by returning a nil function while attaching ErrUnexpectedToken to the RunState