Documentation
¶
Index ¶
- Variables
- func NewUnsupportedValue(kind, expected string) error
- type Active
- func (active *Active) ApplyEvent(event *internal.Event) error
- func (active Active) DebugInputStreamString() string
- func (active Active) DebugStackString() string
- func (active *Active) Forest() []*ParseTree
- func (active Active) GetError() error
- func (active Active) HasError() bool
- func (active *Active) NextEvents() ([]*internal.Event, error)
- func (active Active) Shadow() (*Active, error)
- type Builder
- type Iterator
- type ParseTree
- type Parser
- type PhaseType
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrExhausted occurs when an iterator is exhausted. // This can be checked with the == operator. // // Format: // // "iterator is exhausted" ErrExhausted error )
Functions ¶
func NewUnsupportedValue ¶ added in v0.1.11
NewUnsupportedValue creates a new errors.Err error with the code InvalidOperation and the message "value of <expected> is not a supported <kind> type".
Parameters:
- kind: The kind of the value. Ignored if not provided.
- expected: The expected value. Ignored if not provided.
Returns:
- *errors.Err[ErrorCode]: The new error. Never returns nil.
Types ¶
type Active ¶ added in v0.1.11
type Active struct {
// contains filtered or unexported fields
}
Active is the active parser.
func NewActive ¶ added in v0.1.11
NewActive creates a new parser based on the given parser and tokens.
Parameters:
- global: The parser to use. Must not be nil.
- tokens: The tokens to parse. Must not be nil.
Returns:
- *Active[T]: The new parser.
- error: An error if the initial shift failed.
func (*Active) ApplyEvent ¶ added in v0.1.11
ApplyEvent implements the history.Subject interface.
func (Active) DebugInputStreamString ¶ added in v0.1.11
DebugInputStreamString returns a string representation of the input stream in a human-readable format. It constructs a slice of strings by iterating over the input stream and calling the String() method on each token. The resulting strings are reversed to reflect the original order of the input stream and concatenated with " <- " separators.
Returns:
- string: A human-readable string representation of the input stream.
func (Active) DebugStackString ¶ added in v0.1.11
DebugStackString returns a string representation of the parse stack in a human-readable format. It constructs a parse forest by popping all tokens from the stack, creating a parse tree for each token, and then converting each parse tree to a string. The resulting strings are reversed to reflect the original order of the parse stack and concatenated with newline separators.
Returns:
- string: A human-readable string representation of the parse stack.
func (*Active) Forest ¶ added in v0.1.11
Forest returns the parse forest of the parser. The parse forest is a slice of parse trees, where each parse tree is a tree of tokens. The parse forest is constructed by popping all the tokens from the parse stack and constructing a parse tree for each one. The parse forest is useful for debugging and for visualizing the parse tree.
The function never returns an error. If the parse stack is empty, the function returns a slice with a single element, which is a parse tree with a single token, which is the end of file token.
Returns:
- []*ParseTree[T]: A slice of parse trees. The slice is never empty, since the parser always has a parse stack.
func (*Active) NextEvents ¶ added in v0.1.11
NextEvents implements the history.Subject interface.
func (Active) Shadow ¶ added in v0.1.11
Shadow creates a shadow of the active parser. The shadow is a new parser that is a copy of the original parser. The shadow is useful for debugging and for testing the parser. The function never returns an error. If the function fails, it panics.
The function returns a pointer to the shadow parser. The pointer is never nil.
Returns:
- *Active[T]: A pointer to the shadow parser.
- error: An error if the function failed.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
type Iterator ¶ added in v0.1.11
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is an iterator over the results of an active parser.
func NewIterator ¶ added in v0.1.11
NewIterator creates a new iterator over the results of an active parser.
Parameters:
- init_fn: A function that creates the initial active parser.
Returns:
- *Iterator: An iterator over the results of the active parser.
- error: An error if the init_fn returns an error.
type ParseTree ¶ added in v0.1.11
type ParseTree struct {
// contains filtered or unexported fields
}
ParseTree the parse tree output by the parser.
func NewParseTree ¶ added in v0.1.11
NewParseTree creates a new parse tree from a token.
Parameters:
- tk: The root token of the parse tree. Must not be nil.
Returns:
- *ParseTree: The new parse tree.
- error: An error if the token is nil.
func (ParseTree) Equals ¶ added in v0.1.11
Equals checks whether the given parse tree is equal to the current parse tree.
Parameters:
- other: The parse tree to compare with. May be nil.
Returns:
- bool: True if the parse trees are equal, false otherwise.
func (ParseTree) Root ¶ added in v0.1.11
Root returns the root token of the parse tree.
Returns:
- *slgr.Token: The root token of the parse tree.
type Parser ¶
type Result ¶ added in v0.1.11
type Result struct {
// contains filtered or unexported fields
}
Result is the result of an evaluation.
func (Result) Emulate ¶ added in v0.1.11
Emulate emulates the parse process. It returns a sequence of all the active trees that were generated during the parse process.
Returns:
- iter.Seq[*Active]: The sequence of active trees. Never returns nil.
func (Result) Forest ¶ added in v0.1.11
Forest returns the parse forest of the parser. The parse forest is a slice of parse trees, where each parse tree is a tree of tokens. The parse forest is constructed by popping all the tokens from the parse stack and constructing a parse tree for each one. The parse forest is useful for debugging and for visualizing the parse tree.
Returns:
- []*ParseTree: A slice of parse trees. The slice is never empty, since the parser always has a parse stack.