ast

package
v0.0.0-...-eb82b58 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ast contains the definitions of the abstract-syntax tree that our parse produces, and our interpreter executes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	// Token is the token
	Token token.Token

	// Elements holds the members of the array.
	Elements []Expression
}

ArrayLiteral holds an inline array

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

String returns this object as a string.

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type AssignStatement

type AssignStatement struct {
	Token    token.Token
	Name     *Identifier
	Operator string
	Value    Expression
}

AssignStatement is generally used for a (let-less) assignment, such as "x = y", however we allow an operator to be stored ("=" in that example), such that we can do self-operations.

Specifically "x += y" is defined as an assignment-statement with the operator set to "+=". The same applies for "+=", "-=", "*=", and "/=".

func (*AssignStatement) String

func (as *AssignStatement) String() string

String returns this object as a string.

func (*AssignStatement) TokenLiteral

func (as *AssignStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type BacktickLiteral

type BacktickLiteral struct {
	// Token is the actual token
	Token token.Token

	// Value is the name of the command to execute.
	Value string
}

BacktickLiteral holds details of a command to be executed

func (*BacktickLiteral) String

func (bl *BacktickLiteral) String() string

String returns this object as a string.

func (*BacktickLiteral) TokenLiteral

func (bl *BacktickLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type BlockStatement

type BlockStatement struct {
	// Token holds the actual token
	Token token.Token

	// Statements contain the set of statements within the block
	Statements []Statement
}

BlockStatement holds a group of statements, which are treated as a block. (For example the body of an `if` expression.)

func (*BlockStatement) String

func (bs *BlockStatement) String() string

String returns this object as a string.

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type Boolean

type Boolean struct {
	// Token holds the actual token
	Token token.Token

	// Value stores the bools' value: true, or false.
	Value bool
}

Boolean holds a boolean type

func (*Boolean) String

func (b *Boolean) String() string

String returns this object as a string.

func (*Boolean) TokenLiteral

func (b *Boolean) TokenLiteral() string

TokenLiteral returns the literal token.

type CallExpression

type CallExpression struct {
	// Token stores the literal token
	Token token.Token

	// Function is the function to be invoked.
	Function Expression

	// Arguments are the arguments to be applied
	Arguments []Expression
}

CallExpression holds the invokation of a method-call.

func (*CallExpression) String

func (ce *CallExpression) String() string

String returns this object as a string.

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type CaseExpression

type CaseExpression struct {
	// Token is the actual token
	Token token.Token

	// Default branch?
	Default bool

	// The thing we match
	Expr []Expression

	// The code to execute if there is a match
	Block *BlockStatement
}

CaseExpression handles the case within a switch statement

func (*CaseExpression) String

func (ce *CaseExpression) String() string

String returns this object as a string.

func (*CaseExpression) TokenLiteral

func (ce *CaseExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type ConstStatement

type ConstStatement struct {
	// Token is the token
	Token token.Token

	// Name is the name of the variable we're setting
	Name *Identifier

	// Value contains the value which is to be set
	Value Expression
}

ConstStatement is the same as let-statement, but the value can't be changed later.

func (*ConstStatement) String

func (ls *ConstStatement) String() string

String returns this object as a string.

func (*ConstStatement) TokenLiteral

func (ls *ConstStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type Expression

type Expression interface {
	// Node is the node holding the expression.
	Node
	// contains filtered or unexported methods
}

Expression represents a single expression.

type ExpressionStatement

type ExpressionStatement struct {
	// Token is the literal token
	Token token.Token

	// Expression holds the expression
	Expression Expression
}

ExpressionStatement is an expression

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

String returns this object as a string.

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type FloatLiteral

type FloatLiteral struct {
	// Token is the literal token
	Token token.Token

	// Value holds the floating-point number.
	Value float64
}

FloatLiteral holds a floating-point number

func (*FloatLiteral) String

func (fl *FloatLiteral) String() string

String returns this object as a string.

func (*FloatLiteral) TokenLiteral

func (fl *FloatLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type ForLoopExpression

type ForLoopExpression struct {
	// Token is the actual token
	Token token.Token

	// Condition is the expression used to determine if the loop
	// is still running.
	Condition Expression

	// Consequence is the set of statements to be executed for the
	// loop body.
	Consequence *BlockStatement
}

ForLoopExpression holds a for-loop

func (*ForLoopExpression) String

func (fle *ForLoopExpression) String() string

String returns this object as a string.

func (*ForLoopExpression) TokenLiteral

func (fle *ForLoopExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type ForeachStatement

type ForeachStatement struct {
	// Token is the actual token
	Token token.Token

	// Index is the variable we'll set with the index, for the blocks' scope
	//
	// This is optional.
	Index string

	// Ident is the variable we'll set with each item, for the blocks' scope
	Ident string

	// Value is the thing we'll range over.
	Value Expression

	// Body is the block we'll execute.
	Body *BlockStatement
}

ForeachStatement holds a foreach-statement.

func (*ForeachStatement) String

func (fes *ForeachStatement) String() string

String returns this object as a string.

func (*ForeachStatement) TokenLiteral

func (fes *ForeachStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type FunctionDefineLiteral

type FunctionDefineLiteral struct {
	// Token holds the token
	Token token.Token

	// Paremeters holds the function parameters.
	Parameters []*Identifier

	// Defaults holds any default-arguments.
	Defaults map[string]Expression

	// Body holds the set of statements in the functions' body.
	Body *BlockStatement
}

FunctionDefineLiteral holds a function-definition.

See-also FunctionLiteral.

func (*FunctionDefineLiteral) String

func (fl *FunctionDefineLiteral) String() string

String returns this object as a string.

func (*FunctionDefineLiteral) TokenLiteral

func (fl *FunctionDefineLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type FunctionLiteral

type FunctionLiteral struct {
	// Token is the actual token
	Token token.Token

	// Parameters is the list of parameters the function receives.
	Parameters []*Identifier

	// Defaults holds any default values for arguments which aren't
	// specified
	Defaults map[string]Expression

	// Body contains the set of statements within the function.
	Body *BlockStatement
}

FunctionLiteral holds a function-definition

See-also FunctionDefineLiteral.

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

String returns this object as a string.

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type HashLiteral

type HashLiteral struct {
	// Token holds the token
	Token token.Token // the '{' token

	// Pairs stores the name/value sets of the hash-content
	Pairs map[Expression]Expression
}

HashLiteral holds a hash definition

func (*HashLiteral) String

func (hl *HashLiteral) String() string

String returns this object as a string.

func (*HashLiteral) TokenLiteral

func (hl *HashLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type Identifier

type Identifier struct {
	// Token is the literal token
	Token token.Token

	// Value is the name of the identifier
	Value string
}

Identifier holds a single identifier.

func (*Identifier) String

func (i *Identifier) String() string

String returns this object as a string.

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

TokenLiteral returns the literal token.

type IfExpression

type IfExpression struct {
	// Token is the actual token
	Token token.Token

	// Condition is the thing that is evaluated to determine
	// which block should be executed.
	Condition Expression

	// Consequence is the set of statements executed if the
	// condition is true.
	Consequence *BlockStatement

	// Alternative is the set of statements executed if the
	// condition is not true (optional).
	Alternative *BlockStatement
}

IfExpression holds an if-statement

func (*IfExpression) String

func (ie *IfExpression) String() string

String returns this object as a string.

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type IndexExpression

type IndexExpression struct {
	// Token is the actual token
	Token token.Token

	// Left is the thing being indexed.
	Left Expression

	// Index is the value we're indexing
	Index Expression
}

IndexExpression holds an index-expression

func (*IndexExpression) String

func (ie *IndexExpression) String() string

String returns this object as a string.

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type InfixExpression

type InfixExpression struct {
	// Token holds the literal expression
	Token token.Token

	// Left holds the left-most argument
	Left Expression

	// Operator holds the operation to be carried out (e.g. "+", "-" )
	Operator string

	// Right holds the right-most argument
	Right Expression
}

InfixExpression stores an infix expression.

func (*InfixExpression) String

func (ie *InfixExpression) String() string

String returns this object as a string.

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type IntegerLiteral

type IntegerLiteral struct {
	// Token is the literal token
	Token token.Token

	// Value holds the integer.
	Value int64
}

IntegerLiteral holds an integer

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

String returns this object as a string.

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type LetStatement

type LetStatement struct {
	// Token holds the token
	Token token.Token

	// Name is the name of the variable to which we're assigning
	Name *Identifier

	// Value is the thing we're storing in the variable.
	Value Expression
}

LetStatement holds a let-statemnt

func (*LetStatement) String

func (ls *LetStatement) String() string

String returns this object as a string.

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type Node

type Node interface {
	// TokenLiteral returns the literal of the token.
	TokenLiteral() string

	// String returns this object as a string.
	String() string
}

Node reresents a node.

type NullLiteral

type NullLiteral struct {
	// Token holds the actual token
	Token token.Token
}

NullLiteral represents a literal null

func (*NullLiteral) String

func (n *NullLiteral) String() string

String returns this object as a string.

func (*NullLiteral) TokenLiteral

func (n *NullLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type ObjectCallExpression

type ObjectCallExpression struct {
	// Token is the literal token
	Token token.Token

	// Object is the object against which the call is invoked.
	Object Expression

	// Call is the method-name.
	Call Expression
}

ObjectCallExpression is used when calling a method on an object.

func (*ObjectCallExpression) String

func (oce *ObjectCallExpression) String() string

String returns this object as a string.

func (*ObjectCallExpression) TokenLiteral

func (oce *ObjectCallExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type PostfixExpression

type PostfixExpression struct {
	// Token holds the token we're operating upon
	Token token.Token
	// Operator holds the postfix token, e.g. ++
	Operator string
}

PostfixExpression holds a postfix-based expression

func (*PostfixExpression) String

func (pe *PostfixExpression) String() string

String returns this object as a string.

func (*PostfixExpression) TokenLiteral

func (pe *PostfixExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type PrefixExpression

type PrefixExpression struct {
	// Token holds the token.  e.g. "!"
	Token token.Token

	// Operator holds the operator being invoked (e.g. "!" ).
	Operator string

	// Right holds the thing to be operated upon
	Right Expression
}

PrefixExpression holds a prefix-based expression

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

String returns this object as a string.

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type Program

type Program struct {
	// Statements is the set of statements which the program is comprised
	// of.
	Statements []Statement
}

Program represents a complete program.

func (*Program) String

func (p *Program) String() string

String returns this object as a string.

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral returns the literal token of our program.

type RegexpLiteral

type RegexpLiteral struct {
	// Token is the token
	Token token.Token

	// Value is the value of the regular expression.
	Value string

	// Flags contains any flags associated with the regexp.
	Flags string
}

RegexpLiteral holds a regular-expression.

func (*RegexpLiteral) String

func (rl *RegexpLiteral) String() string

String returns this object as a string.

func (*RegexpLiteral) TokenLiteral

func (rl *RegexpLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type ReturnStatement

type ReturnStatement struct {
	// Token contains the literal token.
	Token token.Token

	// ReturnValue is the value whichis to be returned.
	ReturnValue Expression
}

ReturnStatement stores a return-statement

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

String returns this object as a string.

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

TokenLiteral returns the literal token.

type Statement

type Statement interface {
	// Node is the node holding the actual statement
	Node
	// contains filtered or unexported methods
}

Statement represents a single statement.

type StringLiteral

type StringLiteral struct {
	// Token is the token
	Token token.Token

	// Value is the value of the string.
	Value string
}

StringLiteral holds a string

func (*StringLiteral) String

func (sl *StringLiteral) String() string

String returns this object as a string.

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

TokenLiteral returns the literal token.

type SwitchExpression

type SwitchExpression struct {
	// Token is the actual token
	Token token.Token

	// Value is the thing that is evaluated to determine
	// which block should be executed.
	Value Expression

	// The branches we handle
	Choices []*CaseExpression
}

SwitchExpression handles a switch statement

func (*SwitchExpression) String

func (se *SwitchExpression) String() string

String returns this object as a string.

func (*SwitchExpression) TokenLiteral

func (se *SwitchExpression) TokenLiteral() string

TokenLiteral returns the literal token.

type TernaryExpression

type TernaryExpression struct {
	// Token is the actual token.
	Token token.Token

	// Condition is the thing that is evaluated to determine
	// which expression should be returned
	Condition Expression

	// IfTrue is the expression to return if the condition is true.
	IfTrue Expression

	// IFFalse is the expression to return if the condition is not true.
	IfFalse Expression
}

TernaryExpression holds a ternary-expression.

func (*TernaryExpression) String

func (te *TernaryExpression) String() string

String returns this object as a string.

func (*TernaryExpression) TokenLiteral

func (te *TernaryExpression) TokenLiteral() string

TokenLiteral returns the literal token.

Jump to

Keyboard shortcuts

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