Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Enumer ¶ added in v0.1.20
type Enumer interface { ~int // String returns the literal name of the token type. // This is used for debugging and error messages. // // Returns: // - string: The literal name of the token type. String() string }
Enumer is an interface for all token types. The 0th value is reserved for the EOF token.
type Token ¶
type Token[T Enumer] struct { // Type is the type of the token. Type T // Data is the value of the token. Data string // Pos is the position of the token in the input stream. Pos int // Lookahead is the next token in the input stream. Lookahead *Token[T] // Children are the children of the token. Children []*Token[T] }
Token represents a token in the grammar.
func NewTerminalToken ¶ added in v0.1.20
NewTerminalToken creates a new terminal token with the given type, data, and lookahead.
Parameters:
- type_: The type of the token.
- data: The value of the token.
Returns:
- *Token: The new token. Never returns nil.
func NewToken ¶
NewToken creates a new non-terminal token with the given type, data, and children.
Keep in mind that the last children must be the furthest in the input stream.
Parameters:
- type_: The type of the token.
- data: The value of the token.
- children: The children of the token.
Returns:
- *Token: The new token.
- error: An error of type *errors.ErrInvalidParameter if there is an empty list of children.
func (Token[T]) GetData ¶ added in v0.1.22
GetData returns the value of the token.
Returns:
- string: The value of the token.
Click to show internal directories.
Click to hide internal directories.