Documentation
¶
Overview ¶
Package ast defines structs and interfaces for building and evaluating an abstract syntax tree.
Abstract Syntax Tree ¶
ASTs can have two types of nodes. A non-terminal node (branch node) can contain a token and multiple child nodes. A terminal node (leaf node) can contain a token and a value.
Builders ¶
Builder are used to build a node from multiple nodes.
Interpreters ¶
Interpreters get a list of nodes and return with a single value.
Index ¶
Constants ¶
const EOF = "EOF"
EOF is the end of file token
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interpreter ¶
Interpreter defines an interface to evaluate AST nodes
type InterpreterFunc ¶
InterpreterFunc defines a helper to implement the Interpreter interface with functions
type Node ¶
type Node interface {
Token() string
Value(ctx interface{}) (interface{}, reader.Error)
Pos() reader.Position
}
Node represents an AST node
type NodeBuilder ¶
NodeBuilder defines an interface to build a node from multiple nodes
type NodeBuilderFunc ¶
NodeBuilderFunc defines a helper to implement the NodeBuilder interface with functions
func (NodeBuilderFunc) BuildNode ¶
func (f NodeBuilderFunc) BuildNode(nodes []Node) Node
BuildNode combines the given nodes into a single node
type NonTerminalNode ¶
type NonTerminalNode struct {
// contains filtered or unexported fields
}
NonTerminalNode represents a branch node in the AST
func NewNonTerminalNode ¶
func NewNonTerminalNode(token string, children []Node, interpreter Interpreter) NonTerminalNode
NewNonTerminalNode creates a new NonTerminalNode instance
func (NonTerminalNode) Children ¶
func (n NonTerminalNode) Children() []Node
Children returns with the children
func (NonTerminalNode) Pos ¶
func (n NonTerminalNode) Pos() reader.Position
Pos returns the position
func (NonTerminalNode) String ¶
func (n NonTerminalNode) String() string
String returns with a string representation of the node
func (NonTerminalNode) Token ¶
func (n NonTerminalNode) Token() string
Token returns with the node token
func (NonTerminalNode) Value ¶
func (n NonTerminalNode) Value(ctx interface{}) (interface{}, reader.Error)
Value returns with the value of the node
type TerminalNode ¶
type TerminalNode struct {
// contains filtered or unexported fields
}
TerminalNode is a leaf node in the AST
func NewTerminalNode ¶
func NewTerminalNode(token string, pos reader.Position, value interface{}) TerminalNode
NewTerminalNode creates a new TerminalNode instance
func (TerminalNode) String ¶
func (t TerminalNode) String() string
String returns with a string representation of the node
func (TerminalNode) Value ¶
func (t TerminalNode) Value(ctx interface{}) (interface{}, reader.Error)
Value returns with the value of the node
Directories
¶
| Path | Synopsis |
|---|---|
|
Package builder defines functions for generating basic node builder functions
|
Package builder defines functions for generating basic node builder functions |
|
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
|
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 |