Documentation ¶
Index ¶
- Variables
- func ApplyResults[T interface{ ... }, R any](parent T, elems []R, err error, fn ModifyFn[T, R]) ([]T, error)
- func HasTree[N interface{ ... }](results []Result[N], target *slpx.ParseTree) bool
- func MakeEvaluate[N interface{ ... }](lexer *sllx.Lexer, parser slpx.Parser, ast slast.AST[N]) (evrsl.ApplyOnValidsFn[Result[N]], error)
- type ModifyFn
- type Result
- func (r Result[N]) AST(ast_fn ast.AST[N]) ([]Result[N], error)
- func (r Result[N]) Data() ([]byte, error)
- func (r Result[N]) Err() error
- func (r Result[N]) HasError() bool
- func (r Result[N]) Lex(lexer *sllx.Lexer) ([]Result[N], error)
- func (r Result[N]) LexerErr() (error, error)
- func (r Result[N]) Node() (N, error)
- func (r Result[N]) Parse(parser slpx.Parser) ([]Result[N], error)
- func (r Result[N]) ParseTree() (*slpx.Result, error)
- func (r Result[N]) SetError(err error) Result[N]
- func (r Result[N]) Tokens() ([]*slgr.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.
Types ¶
type Result ¶ added in v0.1.11
type Result[N interface { Child() iter.Seq[N] ast.Noder }] 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[N]: The new result.
func (Result[N]) 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.
func (Result[N]) 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[N]) Err ¶ added in v0.1.11
Err returns the error of the result.
Returns:
- error: The error of the result.
func (Result[N]) 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[N]) 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[N]) Node ¶ added in v0.1.11
Node returns the node of the result.
Returns:
- N: The node of the result.
- error: An error if the node is not set.
func (Result[N]) 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[T, N]: 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[N]) 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.