parsing

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEOF = errors.New("eof")

ErrEOF indicates EOF was reached during lexing or parsing

View Source
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

View Source
var ErrNoLexer = errors.New("no lexer provided")

ErrNoLexer indicates that no lexer was specified to be used by the parser

View Source
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

View Source
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)

View Source
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

View Source
var ParsingError error = &parsingError{}

ParsingError represents a Parsing Error

Functions

func ParserError

func ParserError(err error, t *token.Token) error

ParserError decorates an error with parser positioning information for troubleshooting context

Types

type DecisionSet

type DecisionSet map[token.Typ]StateFn

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 New

func New(
	entryFunc StateFn,
	lexer lex.Lexer,
	lo *lex.Options,
) *Options

New returns a new Options with the provided parameters

func (*Options) EntryFunc

func (o *Options) EntryFunc() StateFn

EntryFunc returns the entryFunc

func (*Options) GetDecisions

func (o *Options) GetDecisions(name string) DecisionSet

GetDecisions returns the named DS

func (*Options) Lexer

func (o *Options) Lexer() (lex.Lexer, *lex.Options)

Lexer returns the Lexer

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

func (o *Options) WithEntryFunc(f StateFn) *Options

WithEntryFunc sets the Parser's entryFunc

func (*Options) WithLexer

func (o *Options) WithLexer(l lex.Lexer, lo *lex.Options) *Options

WithLexer sets the Lexer for the Parser

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

func NewRunState(ctx context.Context, tokens token.Tokens) *RunState

NewRunState returns a new RunState object for the parser

func (*RunState) Context

func (rs *RunState) Context() context.Context

Context returns the RunState's context

func (*RunState) Current

func (rs *RunState) Current() *token.Token

Current returns the current token

func (*RunState) Error

func (rs *RunState) Error() error

Error returns the RunState's error condition

func (*RunState) GetResultsCollection

func (rs *RunState) GetResultsCollection(collectionName string) (any, bool)

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) IsPeeked

func (rs *RunState) IsPeeked() bool

IsPeeked returns true if the RunState has peeked to the next token

func (*RunState) Next

func (rs *RunState) Next() *token.Token

Next retrieves the next location by peeking and then advancing the state

func (*RunState) Peek

func (rs *RunState) Peek() *token.Token

Peek looks at the next token and saves it to Next, but does not advance the state location

func (*RunState) Previous

func (rs *RunState) Previous() *token.Token

Previous returns the previous Token

func (*RunState) Results

func (rs *RunState) Results() ts.Lookup

Results returns the results objecxt from the RunState

func (*RunState) SetResultsCollection

func (rs *RunState) SetResultsCollection(collectionName string, val any)

SetResultsCollection places a collection of results into the results map

func (*RunState) WithContext

func (rs *RunState) WithContext(ctx context.Context) *RunState

WithContext attaches the provided context to the RunState

func (*RunState) WithError

func (rs *RunState) WithError(err error) *RunState

WithError attaches an error to the RunState and aborts the run

func (*RunState) WithNextOverride

func (rs *RunState) WithNextOverride(f StateFn) *RunState

WithNextOverride attaches an override func for the next RunState invocation

type StateFn

type StateFn func(Parser, Parser, *RunState) StateFn

StateFn is a state function that represents the processing of a group of similar tokens

func Noop

func Noop(_, _ Parser, _ *RunState) StateFn

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

func StateUnexpectedToken(_, _ Parser, rs *RunState) StateFn

StateUnexpectedToken is a convenience state function that breaks the main loop by returning a nil function while attaching ErrUnexpectedToken to the RunState

Directories

Path Synopsis
lex
sql
Package sql provides a basic SQL SQLParser that can be extended by individual implementations.
Package sql provides a basic SQL SQLParser that can be extended by individual implementations.

Jump to

Keyboard shortcuts

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