ast

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	token.Token // "["
	Elements    []Expression
}

ArrayLiteral is a expression represting an array.

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

TokenLiteral returns array's starting token - "["

type BlockStatement

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

BlockStatement holds multiple statements together

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

TokenLiteral returns the BlockStatement's token.

type BooleanLiteral

type BooleanLiteral struct {
	Token token.Token
	Value bool
}

BooleanLiteral is a AST node representing boolean token.

func (*BooleanLiteral) String

func (bl *BooleanLiteral) String() string

func (*BooleanLiteral) TokenLiteral

func (bl *BooleanLiteral) TokenLiteral() string

TokenLiteral returns the BooleanLiteral's token.

type CallExpression

type CallExpression struct {
	Token     token.Token // LPAREN token
	Function  Expression  // Identifier or FunctionLiteral
	Arguments []Expression
}

CallExpression is a AST node representing call expression.

func (*CallExpression) String

func (ce *CallExpression) String() string

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

TokenLiteral returns the CallExpression's token.

type ConstStatement

type ConstStatement struct {
	Token token.Token
	Name  *Identifier
	Value Expression
}

ConstStatement is a AST node representing "const" token.

func (*ConstStatement) String

func (cs *ConstStatement) String() string

func (*ConstStatement) TokenLiteral

func (cs *ConstStatement) TokenLiteral() string

TokenLiteral returns the ConstStatement's token.

type Expression

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

Expression implements the Node interface.

type ExpressionStatement

type ExpressionStatement struct {
	Token      token.Token
	Expression Expression
}

ExpressionStatement is a AST node representing expression. It is needed for expression to be part of program's Statements list.

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

TokenLiteral returns the ExpressionStatement's token.

type FunctionLiteral

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

FunctionLiteral is a AST node representing function literal.

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

TokenLiteral returns the FunctionLiteral's token.

type HashLiteral

type HashLiteral struct {
	token.Token // "{"
	Pairs       map[Expression]Expression
}

HashLiteral expression node

func (*HashLiteral) String

func (hl *HashLiteral) String() string

func (*HashLiteral) TokenLiteral

func (hl *HashLiteral) TokenLiteral() string

TokenLiteral returns hash's token

type Identifier

type Identifier struct {
	Token token.Token
	Value string
}

Identifier is a AST node representing identifier token.

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

TokenLiteral returns the Identifier's token.

type IfStatement

type IfStatement struct {
	Token       token.Token
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

IfStatement is a AST node representing if statement // if (a < b) { print(a); } else { print(b); }

func (*IfStatement) String

func (is *IfStatement) String() string

func (*IfStatement) TokenLiteral

func (is *IfStatement) TokenLiteral() string

TokenLiteral returns the IfStatement's token.

type IndexExpression

type IndexExpression struct {
	Token token.Token // "["
	Left  Expression
	Right Expression
}

IndexExpression expression for gettting elements from array

func (*IndexExpression) String

func (ie *IndexExpression) String() string

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

TokenLiteral returns IndexExpression "[" token

type InfixExpression

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

InfixExpression is a AST node representing infix expression, e.g. 1 + 2.

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

TokenLiteral returns the InfixExpression's token.

type IntegerLiteral

type IntegerLiteral struct {
	Token token.Token
	Value int64
}

IntegerLiteral is a AST node representing integer token.

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

TokenLiteral returns the IntegerLiteral's token.

type Node

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

Node is the node element of AST tree.

type PrefixExpression

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

PrefixExpression is a AST node representing prefix expression, e.g. -1.

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

TokenLiteral returns the PrefixExpression's token.

type Program

type Program struct {
	Statements []Statement
}

Program is the root of ast it holds a list of statements, because that's what the program actually is if you think about it.

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral returns root element of the AST tree.

type ReturnStatement

type ReturnStatement struct {
	Token       token.Token
	ReturnValue Expression
}

ReturnStatement is a AST node representing "return" token.

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

TokenLiteral returns the ReturnStatement's token.

type Statement

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

Statement implements the Node interface.

type StringLiteral

type StringLiteral struct {
	Token token.Token
	Value string
}

StringLiteral is a node representing a string.

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

TokenLiteral returns the string value

Jump to

Keyboard shortcuts

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