ast

package
v0.1.1-0...-8b6b0d7 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: MIT Imports: 4 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tree

func Tree(node Node, indent int, name string) string

Tree returns a tree representation of a node

Types

type Argument

type Argument struct {
	Tok   token.Token
	Value Expression
}

Argument is an argument to a function

func (Argument) Expr

func (n Argument) Expr()

Expr tells the compiler this node is an expression

func (Argument) Token

func (n Argument) Token() token.Token

Token returns the node's token

type Array

type Array struct {
	Tok      token.Token
	Elements []Expression
}

Array is an array literal

func (Array) Expr

func (n Array) Expr()

Expr tells the compiler this node is an expression

func (Array) Token

func (n Array) Token() token.Token

Token returns the node's token

type AssignExpression

type AssignExpression struct {
	Tok         token.Token
	Name, Value Expression
}

AssignExpression assigns an expression to a name

func (AssignExpression) Expr

func (n AssignExpression) Expr()

Expr tells the compiler this node is an expression

func (AssignExpression) Token

func (n AssignExpression) Token() token.Token

Token returns the node's token

type BlockLiteral

type BlockLiteral struct {
	Tok    token.Token
	Body   Statement
	Params []Expression
}

BlockLiteral is a block literal

func (BlockLiteral) Expr

func (n BlockLiteral) Expr()

Expr tells the compiler this node is an expression

func (BlockLiteral) Token

func (n BlockLiteral) Token() token.Token

Token returns the node's token

type BlockStatement

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

BlockStatement is a list of statements

func (BlockStatement) Stmt

func (n BlockStatement) Stmt()

Stmt tells the compiler this node is a statement

func (BlockStatement) Token

func (n BlockStatement) Token() token.Token

Token returns this node's token

type Boolean

type Boolean struct {
	Tok   token.Token
	Value bool
}

Boolean is a boolean literal

func (Boolean) Expr

func (n Boolean) Expr()

Expr tells the compiler this node is an expression

func (Boolean) Token

func (n Boolean) Token() token.Token

Token returns the node's token

type BreakStatement

type BreakStatement struct {
	Tok token.Token
}

BreakStatement breaks a loop

func (BreakStatement) Stmt

func (n BreakStatement) Stmt()

Stmt tells the compiler this node is a statement

func (BreakStatement) Token

func (n BreakStatement) Token() token.Token

Token returns this node's token

type Char

type Char struct {
	Tok   token.Token
	Value byte
}

Char is a character literal

func (Char) Expr

func (n Char) Expr()

Expr tells the compiler this node is an expression

func (Char) Token

func (n Char) Token() token.Token

Token returns the node's token

type DotExpression

type DotExpression struct {
	Tok         token.Token
	Left, Right Expression
}

DotExpression gets a value from a container

func (DotExpression) Expr

func (n DotExpression) Expr()

Expr tells the compiler this node is an expression

func (DotExpression) Token

func (n DotExpression) Token() token.Token

Token returns the node's token

type EmissionExpression

type EmissionExpression struct {
	Tok   token.Token
	Items []EmittedItem
}

EmissionExpression emits some raw bytecode

func (EmissionExpression) Expr

func (n EmissionExpression) Expr()

Expr tells the compiler this node is an expression

func (EmissionExpression) Token

func (n EmissionExpression) Token() token.Token

Token returns the node's token

type EmittedItem

type EmittedItem struct {
	IsInstruction bool

	// This will be defined if !IsInstruction
	Exp Expression

	// These things will be defined if IsInstruction
	Instruction string
	Argument    rune
}

EmittedItem is an item inside an emission expression

type Expression

type Expression interface {
	Node
	Expr()
}

Expression is an expression AST node

type ExpressionStatement

type ExpressionStatement struct {
	Tok  token.Token
	Expr Expression
}

ExpressionStatement is an expression which acts a statement

func (ExpressionStatement) Stmt

func (n ExpressionStatement) Stmt()

Stmt tells the compiler this node is a statement

func (ExpressionStatement) Token

func (n ExpressionStatement) Token() token.Token

Token returns this node's token

type ForLoop

type ForLoop struct {
	Tok token.Token

	// for (Init; Condition; Increment) { Body }
	Init      Expression
	Condition Expression
	Increment Expression
	Body      Statement
}

ForLoop executes Body for each element in a collection

func (ForLoop) Stmt

func (n ForLoop) Stmt()

Stmt tells the compiler this node is a statement

func (ForLoop) Token

func (n ForLoop) Token() token.Token

Token returns this node's token

type FunctionCall

type FunctionCall struct {
	Tok     token.Token
	Pattern []Expression
}

FunctionCall calls a function

func (FunctionCall) Expr

func (n FunctionCall) Expr()

Expr tells the compiler this node is an expression

func (FunctionCall) Token

func (n FunctionCall) Token() token.Token

Token returns the node's token

type FunctionDefinition

type FunctionDefinition struct {
	Tok     token.Token
	Pattern []Expression
	Body    Statement
}

FunctionDefinition defines a function

func (FunctionDefinition) Stmt

func (n FunctionDefinition) Stmt()

Stmt tells the compiler this node is a statement

func (FunctionDefinition) Token

func (n FunctionDefinition) Token() token.Token

Token returns this node's token

type Identifier

type Identifier struct {
	Tok   token.Token
	Value string
}

Identifier is an identifier

func (Identifier) Expr

func (n Identifier) Expr()

Expr tells the compiler this node is an expression

func (Identifier) Token

func (n Identifier) Token() token.Token

Token returns the node's token

type IfExpression

type IfExpression struct {
	Tok                      token.Token
	Condition                Expression
	Consequence, Alternative Statement
}

IfExpression executes Consequence or Alternative based on Condition

func (IfExpression) Expr

func (n IfExpression) Expr()

Expr tells the compiler this node is an expression

func (IfExpression) Token

func (n IfExpression) Token() token.Token

Token returns the node's token

type IndexExpression

type IndexExpression struct {
	Tok               token.Token
	Collection, Index Expression
}

IndexExpression gets a value from a collection

func (IndexExpression) Expr

func (n IndexExpression) Expr()

Expr tells the compiler this node is an expression

func (IndexExpression) Token

func (n IndexExpression) Token() token.Token

Token returns the node's token

type InfixExpression

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

InfixExpression is an infix operator expression

func (InfixExpression) Expr

func (n InfixExpression) Expr()

Expr tells the compiler this node is an expression

func (InfixExpression) Token

func (n InfixExpression) Token() token.Token

Token returns the node's token

type Map

type Map struct {
	Tok   token.Token
	Pairs map[Expression]Expression
}

Map is a map literal

func (Map) Expr

func (n Map) Expr()

Expr tells the compiler this node is an expression

func (Map) Token

func (n Map) Token() token.Token

Token returns the node's token

type NextStatement

type NextStatement struct {
	Tok token.Token
}

NextStatement goes to the next iteration of a loop

func (NextStatement) Stmt

func (n NextStatement) Stmt()

Stmt tells the compiler this node is a statement

func (NextStatement) Token

func (n NextStatement) Token() token.Token

Token returns this node's token

type Node

type Node interface {
	Token() token.Token
}

Node is the base AST node struct

type Null

type Null struct {
	Tok token.Token
}

Null is the null literal

func (Null) Expr

func (n Null) Expr()

Expr tells the compiler this node is an expression

func (Null) Token

func (n Null) Token() token.Token

Token returns the node's token

type Number

type Number struct {
	Tok   token.Token
	Value float64
}

Number is a number literal

func (Number) Expr

func (n Number) Expr()

Expr tells the compiler this node is an expression

func (Number) Token

func (n Number) Token() token.Token

Token returns the node's token

type Parameter

type Parameter struct {
	Tok  token.Token
	Name string
}

Parameter is shorthand for putting an identifier into a pattern call

func (Parameter) Expr

func (n Parameter) Expr()

Expr tells the compiler this node is an expression

func (Parameter) Token

func (n Parameter) Token() token.Token

Token returns the node's token

type PrefixExpression

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

PrefixExpression is a prefix operator expression

func (PrefixExpression) Expr

func (n PrefixExpression) Expr()

Expr tells the compiler this node is an expression

func (PrefixExpression) Token

func (n PrefixExpression) Token() token.Token

Token returns the node's token

type Program

type Program struct {
	Statements []Statement
}

Program is a program, containing a list of statements

func (*Program) Tree

func (p *Program) Tree() string

Tree returns a tree representation of a program.

type QualifiedFunctionCall

type QualifiedFunctionCall struct {
	Tok     token.Token
	Base    Expression
	Pattern []Expression
}

QualifiedFunctionCall calls a function from a package

func (QualifiedFunctionCall) Expr

func (n QualifiedFunctionCall) Expr()

Expr tells the compiler this node is an expression

func (QualifiedFunctionCall) Token

func (n QualifiedFunctionCall) Token() token.Token

Token returns the node's token

type ReturnStatement

type ReturnStatement struct {
	Tok   token.Token
	Value Expression
}

ReturnStatement returns an expression from a BlockStatement

func (ReturnStatement) Stmt

func (n ReturnStatement) Stmt()

Stmt tells the compiler this node is a statement

func (ReturnStatement) Token

func (n ReturnStatement) Token() token.Token

Token returns this node's token

type Statement

type Statement interface {
	Node
	Stmt()
}

Statement is a statement AST node

type String

type String struct {
	Tok   token.Token
	Value string
}

String is a string literal

func (String) Expr

func (n String) Expr()

Expr tells the compiler this node is an expression

func (String) Token

func (n String) Token() token.Token

Token returns the node's token

type Tuple

type Tuple struct {
	Tok   token.Token
	Value []Expression
}

Tuple is a tuple literal

func (Tuple) Expr

func (n Tuple) Expr()

Expr tells the compiler this node is an expression

func (Tuple) Token

func (n Tuple) Token() token.Token

Token returns the node's token

type UseStatement

type UseStatement struct {
	Tok     token.Token
	Package string
}

UseStatement imports a package into the current scope

func (UseStatement) Stmt

func (n UseStatement) Stmt()

Stmt tells the compiler this node is a statement

func (UseStatement) Token

func (n UseStatement) Token() token.Token

Token returns this node's token

type WhileLoop

type WhileLoop struct {
	Tok       token.Token
	Condition Expression
	Body      Statement
}

WhileLoop executes Body while Condition holds true

func (WhileLoop) Stmt

func (n WhileLoop) Stmt()

Stmt tells the compiler this node is a statement

func (WhileLoop) Token

func (n WhileLoop) Token() token.Token

Token returns this node's token

Jump to

Keyboard shortcuts

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