...

Package parser

import "github.com/zylisp/zylisp/core/parser"
Overview
Index

Overview ▾

Constants

Errors specific to the parser package

const (
    RightCurvedBracketError string = "Unexpected \")\" [%d]"
    RightSquareBracketError string = "Unexpected \"]\" [%d]"
    AtomTypeError           string = "Bad Atom type"
    UnspecifiedAtomError    string = "Unspecified Atom error %#v: %#v"
)

func NodeName

func NodeName(nodeType NodeType) string

NodeName returns the name of the node for a given node value

type CallNode

CallNode object

type CallNode struct {
    // Pos
    NodeType
    Callee Node
    Args   []Node
}

func (*CallNode) Copy

func (node *CallNode) Copy() Node

Copy creates a copy of a call node

func (*CallNode) String

func (node *CallNode) String() string

String returns the string value for a call node

type IdentNode

IdentNode defines the identity node for use in identity operations

type IdentNode struct {
    // Pos
    NodeType
    Ident string
}

func NewIdentNode

func NewIdentNode(name string) *IdentNode

NewIdentNode creates a new identity node

func (*IdentNode) Copy

func (node *IdentNode) Copy() Node

Copy creates a copy of an IdentNode instance

func (*IdentNode) String

func (node *IdentNode) String() string

String returns a string represnetation of IdentNode

type Node

Node holds data for parsed AST nodes

type Node interface {
    Type() NodeType
    // Position() Pos
    String() string
    Copy() Node
}

func Parse

func Parse(l *lexer.Lexer) []Node

Parse takes lexed data and returns a tree of parsed nodes. This function is

a convenience wrapper around ParseAtoms.

func ParseAtom

func ParseAtom(l *lexer.Lexer, item lexer.Atom, lookingFor rune) (Node, error)

ParseAtom takes a given lexed item, determines its type, and then create a

corresponding and appropriate node for that atom.

func ParseAtoms

func ParseAtoms(l *lexer.Lexer, tree []Node, lookingFor rune) []Node

ParseAtoms iterates over the items in the given lexed data and adds parsed

nodes to the given tree.

func ParseFromString

func ParseFromString(name, program string) []Node

ParseFromString parses code and returns a collection of nodes.

type NodeType

NodeType defines a dedicated type for node types

type NodeType int

Constants for the parser package

const (
    NodeIdent NodeType = iota
    NodeString
    NodeNumber
    NodeCall
    NodeVector
)

func (NodeType) Type

func (t NodeType) Type() NodeType

Type is a convenience method for getting the NodeType

type NumberNode

NumberNode object

type NumberNode struct {
    // Pos
    NodeType
    Value      string
    NumberType token.Token
}

func (*NumberNode) Copy

func (node *NumberNode) Copy() Node

Copy creates a copy of a number node

func (*NumberNode) String

func (node *NumberNode) String() string

String returns the string value for a number node

type Pos

Pos type

type Pos int

func (Pos) Position

func (p Pos) Position() Pos

Position returns a pos type

type StringNode

StringNode object

type StringNode struct {
    // Pos
    NodeType
    Value string
}

func (*StringNode) Copy

func (node *StringNode) Copy() Node

Copy creates a copy of a string node

func (*StringNode) String

func (node *StringNode) String() string

String returns the string represnetation of a string node

type VectorNode

VectorNode object

type VectorNode struct {
    // Pos
    NodeType
    Nodes []Node
}

func (*VectorNode) Copy

func (node *VectorNode) Copy() Node

Copy creates a copy of a vector node

func (*VectorNode) String

func (node *VectorNode) String() string

String returns the string value of a vector node