ast

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: MPL-2.0 Imports: 2 Imported by: 6

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

This section is empty.

Variables

This section is empty.

Functions

func AppendNode added in v0.6.0

func AppendNode(n1, n2 parsley.Node) parsley.Node

AppendNode appends

func SetReaderPos added in v0.6.0

func SetReaderPos(node parsley.Node, f func(parsley.Pos) parsley.Pos) parsley.Node

SetReaderPos sets the reader position on a node

Types

type EmptyNode added in v0.17.0

type EmptyNode parsley.Pos

EmptyNode represents an empty node

func (EmptyNode) Pos added in v0.17.0

func (e EmptyNode) Pos() parsley.Pos

Pos returns with the position of the node

func (EmptyNode) ReaderPos added in v0.17.0

func (e EmptyNode) ReaderPos() parsley.Pos

ReaderPos returns the reader position

func (EmptyNode) Schema added in v0.17.0

func (e EmptyNode) Schema() interface{}

Schema returns nil

func (EmptyNode) String added in v0.17.0

func (e EmptyNode) String() string

String returns with a string representation of the node

func (EmptyNode) Token added in v0.17.0

func (e EmptyNode) Token() string

Token returns with EMPTY

type InterpreterFunc

type InterpreterFunc func(userCtx interface{}, node parsley.NonTerminalNode) (interface{}, parsley.Error)

InterpreterFunc defines a helper to implement the Interpreter interface with functions

func (InterpreterFunc) Eval

func (f InterpreterFunc) Eval(userCtx interface{}, node parsley.NonTerminalNode) (interface{}, parsley.Error)

Eval evaluates the given nodes and returns with a single result.

type NodeList added in v0.6.0

type NodeList []parsley.Node

NodeList contains a list of nodes, should be used when a parser returns with multiple results If you call any of the parsley.Node methods on it then it will behave as it would be the first node.

func (*NodeList) Append added in v0.6.0

func (nl *NodeList) Append(node parsley.Node)

Append appends a new node to the list

func (NodeList) Pos added in v0.6.0

func (nl NodeList) Pos() parsley.Pos

Pos returns the value of the first node

func (NodeList) ReaderPos added in v0.6.0

func (nl NodeList) ReaderPos() parsley.Pos

ReaderPos returns the reader position for the first node

func (NodeList) Schema added in v0.17.0

func (nl NodeList) Schema() interface{}

Schema returns nil

func (NodeList) SetReaderPos added in v0.17.0

func (nl NodeList) SetReaderPos(f func(parsley.Pos) parsley.Pos)

SetReaderPos amends the reader position for all nodes

func (NodeList) Token added in v0.6.0

func (nl NodeList) Token() string

Token returns with NODE_LIST

func (NodeList) Walk added in v0.6.0

func (nl NodeList) Walk(f func(n parsley.Node) bool) bool

Walk runs the given function on the first node

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) Pos

func (n *NonTerminalNode) Pos() parsley.Pos

Pos returns the position

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) Schema added in v0.17.0

func (n *NonTerminalNode) Schema() interface{}

Schema returns the schema for the node's value

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) StaticCheck added in v0.17.0

func (n *NonTerminalNode) StaticCheck(userCtx interface{}) parsley.Error

StaticCheck runs a static analysis if the interpreter has static analysis capabilities

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) Transform added in v0.17.0

func (n *NonTerminalNode) Transform(userCtx interface{}) (parsley.Node, parsley.Error)

Transform runs the given transformer on all children and returns the original node

func (*NonTerminalNode) Value

func (n *NonTerminalNode) Value(userCtx interface{}) (interface{}, parsley.Error)

Value returns with the value of the node

type ReaderPosSetter added in v0.6.0

type ReaderPosSetter interface {
	SetReaderPos(f func(parsley.Pos) parsley.Pos)
}

ReaderPosSetter allows to change the reader position on a node

type ReaderPosSetterNode added in v0.17.0

type ReaderPosSetterNode interface {
	parsley.Node
	ReaderPosSetter
}

ReaderPosSetterNode defines a node which also implements the ReaderPosSetter interface

type TerminalNode

type TerminalNode struct {
	// contains filtered or unexported fields
}

TerminalNode is a leaf node in the AST

func NewTerminalNode

func NewTerminalNode(
	schema interface{},
	token string,
	value interface{},
	pos parsley.Pos,
	readerPos parsley.Pos,
) *TerminalNode

NewTerminalNode creates a new TerminalNode instance

func (*TerminalNode) Pos

func (t *TerminalNode) Pos() parsley.Pos

Pos returns the position

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) Schema added in v0.17.0

func (t *TerminalNode) Schema() interface{}

Schema returns the schema for the node's value

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() interface{}

Value returns with the value of the node

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL