Documentation
¶
Overview ¶
Package ast defines structs and interfaces for building and evaluating an abstract syntax tree.
Abstract Syntax Tree ¶
ASTs can have different types of nodes. * A terminal node (leaf node) can contain a token and a value. * A nil node (leaf node) only contains a position and evaluates to nil * A non-terminal node (branch node) can contain a token and multiple child nodes.
Interpreters ¶
Interpreters get a list of nodes and return with a single value.
Index ¶
- Constants
- func AppendNode(n1, n2 parsley.Node) parsley.Node
- func SetReaderPos(node parsley.Node, f func(parsley.Pos) parsley.Pos) parsley.Node
- func WalkNode(node parsley.Node, f func(i int, n parsley.Node) bool)
- type InterpreterFunc
- type NilNode
- type NodeList
- type NonTerminalNode
- func (n *NonTerminalNode) Children() []parsley.Node
- func (n *NonTerminalNode) Pos() parsley.Pos
- func (n *NonTerminalNode) ReaderPos() parsley.Pos
- func (n *NonTerminalNode) SetReaderPos(f func(parsley.Pos) parsley.Pos)
- func (n *NonTerminalNode) String() string
- func (n *NonTerminalNode) Token() string
- func (n *NonTerminalNode) Value(ctx interface{}) (interface{}, parsley.Error)
- type ReaderPosSetter
- type TerminalNode
- func (t *TerminalNode) Pos() parsley.Pos
- func (t *TerminalNode) ReaderPos() parsley.Pos
- func (t *TerminalNode) SetReaderPos(f func(parsley.Pos) parsley.Pos)
- func (t *TerminalNode) String() string
- func (t *TerminalNode) Token() string
- func (t *TerminalNode) Value(ctx interface{}) (interface{}, parsley.Error)
- type Walkable
Constants ¶
const EOF = "EOF"
EOF is the end of file token
const NIL = "NIL"
NIL is the nil token
Variables ¶
This section is empty.
Functions ¶
func AppendNode ¶ added in v0.6.0
AppendNode appends
func SetReaderPos ¶ added in v0.6.0
SetReaderPos sets the reader position on a node
Types ¶
type InterpreterFunc ¶
InterpreterFunc defines a helper to implement the Interpreter interface with functions
type NilNode ¶ added in v0.6.0
NilNode represents an nil node
type NodeList ¶ added in v0.6.0
NodeList contains a list of nodes, should be used when a parser returns with multiple results
func (NodeList) Pos ¶ added in v0.6.0
Pos returns the value of the first pos (all nodes should have the same position)
type NonTerminalNode ¶
type NonTerminalNode struct {
// contains filtered or unexported fields
}
NonTerminalNode represents a branch node in the AST
func NewEmptyNonTerminalNode ¶ added in v0.6.0
func NewEmptyNonTerminalNode(token string, pos parsley.Pos, interpreter parsley.Interpreter) *NonTerminalNode
NewEmptyNonTerminalNode creates a new NonTerminalNode without children
func NewNonTerminalNode ¶
func NewNonTerminalNode(token string, children []parsley.Node, interpreter parsley.Interpreter) *NonTerminalNode
NewNonTerminalNode creates a new NonTerminalNode instance
func (*NonTerminalNode) Children ¶
func (n *NonTerminalNode) Children() []parsley.Node
Children returns with the children
func (*NonTerminalNode) ReaderPos ¶ added in v0.6.0
func (n *NonTerminalNode) ReaderPos() parsley.Pos
ReaderPos returns the position of the first character immediately after this node
func (*NonTerminalNode) SetReaderPos ¶ added in v0.6.0
func (n *NonTerminalNode) SetReaderPos(f func(parsley.Pos) parsley.Pos)
SetReaderPos amends the reader position using the given function
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{}, parsley.Error)
Value returns with the value of the node
type ReaderPosSetter ¶ added in v0.6.0
ReaderPosSetter allows to change the reader position on a 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, value interface{}, pos parsley.Pos, readerPos parsley.Pos) *TerminalNode
NewTerminalNode creates a new TerminalNode instance
func (*TerminalNode) ReaderPos ¶ added in v0.6.0
func (t *TerminalNode) ReaderPos() parsley.Pos
ReaderPos returns the position of the first character immediately after this node
func (*TerminalNode) SetReaderPos ¶ added in v0.6.0
func (t *TerminalNode) SetReaderPos(f func(parsley.Pos) parsley.Pos)
SetReaderPos changes the reader position
func (*TerminalNode) String ¶
func (t *TerminalNode) String() string
String returns with a string representation of the node
func (*TerminalNode) Token ¶
func (t *TerminalNode) Token() string
Token returns with the node token
func (*TerminalNode) Value ¶
func (t *TerminalNode) Value(ctx interface{}) (interface{}, parsley.Error)
Value returns with the value of the node