Documentation ¶
Index ¶
- Variables
- func ApplyResults[T interface{ ... }, R any](parent T, elems []R, err error, fn ModifyFn[T, R]) ([]T, error)
- func HasTree(results []Result, target *slpx.ParseTree) bool
- func MakeEvaluate(lexer *sllx.Lexer, parser slpx.Parser, ast map[string]gr.ToASTFn) (evrsl.ApplyOnValidsFn[Result], error)
- type ModifyFn
- type Result
- func (r Result) AST(table map[string]gr.ToASTFn) ([]Result, error)
- func (r Result) Data() ([]byte, error)
- func (r Result) Err() error
- func (r Result) HasError() bool
- func (r Result) Lex(lexer *sllx.Lexer) ([]Result, error)
- func (r Result) LexerErr() (error, error)
- func (r Result) Node() (*gr.Node, error)
- func (r Result) Parse(parser slpx.Parser) ([]Result, error)
- func (r Result) ParseTree() (*slpx.Result, error)
- func (r Result) SetError(err error) Result
- func (r Result) Tokens() ([]*gr.Token, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMissingData is the error that is returned when data is missing. ErrMissingData error // ErrMissingTokens is the error that is returned when tokens are missing. ErrMissingTokens error // ErrMissingParseTree is the error that is returned when the parse tree is missing. ErrMissingParseTree error )
Functions ¶
func ApplyResults ¶ added in v0.1.11
func ApplyResults[T interface { SetError(err error) T }, R any](parent T, elems []R, err error, fn ModifyFn[T, R]) ([]T, error)
ApplyResults applies a function to each element in the slice and returns a new slice of results.
Parameters:
- parent: The parent result.
- elems: The slice of elements to apply the function to.
- err: The error to set on each result.
- fn: The function to apply to each element.
Returns:
- []Result[T, N]: A slice of results with the function applied to each element.
- error: An error if the function is nil.
func MakeEvaluate ¶ added in v0.1.11
func MakeEvaluate(lexer *sllx.Lexer, parser slpx.Parser, ast map[string]gr.ToASTFn) (evrsl.ApplyOnValidsFn[Result], error)
MakeEvaluate makes an evaluator function that evaluates a sequence of SlParser results. The evaluator function takes a sequence of SlParser results and returns a new sequence of SlParser results. The new sequence of SlParser results is computed by first attempting to lex the input, then attempting to parse the lexer output, and finally attempting to convert the parse output to an AST.
Parameters:
- lexer: The lexer to use for lexing.
- parser: The parser to use for parsing.
- ast: The AST maker to use for converting the parse output to an AST.
Returns:
- evrsl.ApplyOnValidsFn[Result]: The evaluator function.
- error: An error if the operation fails.
Types ¶
type Result ¶ added in v0.1.11
type Result struct {
// contains filtered or unexported fields
}
Result holds all the information regarding the parsing process.
func NewResult ¶ added in v0.1.11
NewResult creates a new result.
Parameters:
- data: The data to create the result from.
Returns:
- Result: The new result.
func (Result) AST ¶ added in v0.1.11
AST transforms the parse tree into an abstract syntax tree.
The `ast` function must return one abstract syntax tree node for each parse tree root node. If the `ast` function returns an error, the entire result is marked as invalid.
If the `ast` function is nil, an error is returned.
If the parse tree is missing, an error is returned.
If the `ast` function returns more or less than one abstract syntax tree node, an error is returned.
Parameters:
- table: The AST maker to use for transforming the parse tree into an abstract syntax tree.
Returns:
- []Result: A slice containing the result of the transformation process. If successful, it contains the abstract syntax tree nodes generated from the parse tree. Otherwise, it contains the error that occurred during the transformation process.
- error: An error if the evaluation failed.
func (Result) Data ¶ added in v0.1.11
Data returns the data of the result.
Returns:
- []byte: The data of the result.
- error: An error if the data is not set.
Errors:
- ErrMissingData: If the data is not set.
func (Result) Err ¶ added in v0.1.11
Err returns the error of the result.
Returns:
- error: The error of the result.
func (Result) Lex ¶ added in v0.1.11
Lex processes the input data using the provided lexer and returns a slice of results.
Parameters:
- lexer: The lexer to use for processing the input data.
Returns:
- []*Result[T, N]: A slice containing the result of the lexing process. If successful, it contains the tokens generated from the input data. Otherwise, it contains the error that occurred during the lexing process.
- error: An error if the evaluation failed.
Errors:
- ErrMissingData: If the Lex function is called before the data is set.
- any other error: When the lexer is nil or any other error occurs during the lexing process.
func (Result) LexerErr ¶ added in v0.1.11
LexerErr returns the lexer error of the result.
Returns:
- error: The lexer error of the result.
- error: An error if the lexer error is not set.
func (Result) Node ¶ added in v0.1.11
Node returns the node of the result.
Returns:
- grammar.Node: The node of the result.
- error: An error if the node is not set.
func (Result) Parse ¶ added in v0.1.11
Parse processes the input data using the provided parser and returns a slice of results.
Parameters:
- parser: The parser to use for processing the input data.
Returns:
- []*Result A slice containing the result of the parsing process. If successful, it contains the parse trees generated from the input data. Otherwise, it contains the error that occurred during the parsing process.
- error: An error if the evaluation failed.
Errors:
- ErrMissingTokens: If the Parse function is called before the tokens are set.
- any other error: When the parser is nil or any other error occurs during the parsing process.
func (Result) ParseTree ¶ added in v0.1.11
ParseTree returns the parse tree of the result.
Returns:
- *slpx.Result: The parse tree of the result.
- error: An error if the parse tree is not set.