ast

package
v0.0.0-...-bf9f4d5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ast defines the various building blocks of the interpreter's abstract syntax tree (ast)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	Token    gitoken.Token
	Elements []Expression
}

ArrayLiteral is an ast node representing an array of the form: '[<ELEM1>, <ELEME2>, ..., <ELEMn>]'

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

TokenLiteral returns the literal string of the token

type BlockStatement

type BlockStatement struct {
	Token      gitoken.Token
	Statements []Statement
}

BlockStatement is an ast node representing a collection of statement and an initiating token

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Boolean

type Boolean struct {
	Token gitoken.Token
	Value bool
}

Boolean is an ast node representing a boolean value

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) TokenLiteral

func (b *Boolean) TokenLiteral() string

TokenLiteral returns the literal string of the token

type CallExpression

type CallExpression struct {
	Token     gitoken.Token
	Function  Expression
	Arguments []Expression
}

CallExpression is an ast node representing an expression of the form: 'FNIDENT(PARAMS)'

func (*CallExpression) String

func (ce *CallExpression) String() string

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression is an interface enclosing a node and to be implemented by the language's expression

type ExpressionStatement

type ExpressionStatement struct {
	Token      gitoken.Token
	Expression Expression
}

ExpressionStatement is an ast node representing a statement of the form: '<EXPR>'

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

TokenLiteral returns the literal string of the token

type FunctionLiteral

type FunctionLiteral struct {
	Token      gitoken.Token
	Parameters []*Identifier
	Body       *BlockStatement
}

FunctionLiteral is an ast node representing a function of the form: 'fn(<PARAMS>) ast.BlockStatement'

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

TokenLiteral returns the literal string of the token

type HashLiteral

type HashLiteral struct {
	Token gitoken.Token
	Pairs map[Expression]Expression
}

HashLiteral is an ast node representing a hash of the form: '{<KEY1>: <VAL1>, <KEY2>: <VAL2>, ..., <KEYn>: <VALn>}'

func (*HashLiteral) String

func (hl *HashLiteral) String() string

func (*HashLiteral) TokenLiteral

func (hl *HashLiteral) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Identifier

type Identifier struct {
	Token gitoken.Token
	Value string
}

Identifier is an identifier node

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

TokenLiteral returns the literal string of the token

type IfExpression

type IfExpression struct {
	Token       gitoken.Token
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

IfExpression is an ast node representing an expression of the form: 'if(<EXPR>) ast.BlockStatement else ast.BlockStatement '

func (*IfExpression) String

func (ie *IfExpression) String() string

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

TokenLiteral returns the literal string of the token

type IndexExpression

type IndexExpression struct {
	Token gitoken.Token
	Left  Expression
	Index Expression
}

IndexExpression is an ast node representing an expression of the form: 'ARRAY[<EXPR>]'

func (*IndexExpression) String

func (ie *IndexExpression) String() string

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

TokenLiteral returns the literal string of the token

type InfixExpression

type InfixExpression struct {
	Token    gitoken.Token
	Left     Expression
	Operator string
	Right    Expression
}

InfixExpression is an ast node representing an expression of the form: '<EXPR> <OPERATOR> <EXPR>'

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

TokenLiteral returns the literal string of the token

type IntegerLiteral

type IntegerLiteral struct {
	Token gitoken.Token
	Value int64
}

IntegerLiteral is an ast node representing an integer value

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

TokenLiteral returns the literal string of the token

type LetStatement

type LetStatement struct {
	Token gitoken.Token
	Name  *Identifier
	Value Expression
}

LetStatement is an ast node representing a statement of the form: 'let <IDENT> = <EXPR>

func (*LetStatement) String

func (ls *LetStatement) String() string

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Node

type Node interface {
	TokenLiteral() string
	String() string
}

Node is an interface that needs to be implemented by every element that the AST will contain

type PrefixExpression

type PrefixExpression struct {
	Token    gitoken.Token
	Operator string
	Right    Expression
}

PrefixExpression is an ast node representing an expression of the form: '<OPERATOR><EXPR>'

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Program

type Program struct {
	Statements []Statement
}

Program is a collection (slice) of statements that represents the input program

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral returns the literal string of the token

type ReturnStatement

type ReturnStatement struct {
	Token       gitoken.Token
	ReturnValue Expression
}

ReturnStatement is an ast node representing a statement of the form: 'return <EXPR>'

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

TokenLiteral returns the literal string of the token

type SetStatement

type SetStatement struct {
	Token gitoken.Token
	Name  *Identifier
	Value Expression
}

SetStatement is an ast node representing a statement of the form: 'set <KEYWORD> <LITTERAL>

func (*SetStatement) String

func (ls *SetStatement) String() string

func (*SetStatement) TokenLiteral

func (ls *SetStatement) TokenLiteral() string

TokenLiteral returns the literal string of the token

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement is an interface enclosing a node and to be implemented by the language's statements

type StringLiteral

type StringLiteral struct {
	Token gitoken.Token
	Value string
}

StringLiteral is an ast node representing a string value

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

TokenLiteral returns the literal string of the token

Jump to

Keyboard shortcuts

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