ast

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 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 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 CurrentArgsLiteral added in v0.1.0

type CurrentArgsLiteral struct {
	Token token.Token // ...
}

CurrentArgsLiteral holds the current args token

func (*CurrentArgsLiteral) String added in v0.1.0

func (cal *CurrentArgsLiteral) String() string

String returns a string representation of the literal

func (*CurrentArgsLiteral) TokenLiteral added in v0.1.0

func (cal *CurrentArgsLiteral) TokenLiteral() string

TokenLiteral returns the literal token

type DocStringLiteral added in v0.1.0

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

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

DocStringLiteral holds a string

func (*DocStringLiteral) String added in v0.1.0

func (sl *DocStringLiteral) String() string

String returns this object as a string.

func (*DocStringLiteral) TokenLiteral added in v0.1.0

func (sl *DocStringLiteral) 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 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

	// DocString
	DocString *DocStringLiteral
}

FunctionLiteral holds a function-definition

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 ImportExpression

type ImportExpression struct {
	Token token.Token // The 'import' token
	Name  Expression
}

ImportExpression represents an `import` expression and holds the name of the module being imported.

func (*ImportExpression) String

func (ie *ImportExpression) String() string

String returns a stringified version of the AST for debugging

func (*ImportExpression) TokenLiteral

func (ie *ImportExpression) TokenLiteral() string

TokenLiteral prints the literal value of the token associated with this node

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 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
}

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

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 MutableStatement

type MutableStatement 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
}

MutableStatement holds a mutable-statemnt

func (*MutableStatement) String

func (ls *MutableStatement) String() string

String returns this object as a string.

func (*MutableStatement) TokenLiteral

func (ls *MutableStatement) 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 added in v0.6.0

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

NullLiteral represents a literal null

func (*NullLiteral) String added in v0.6.0

func (n *NullLiteral) String() string

String returns this object as a string.

func (*NullLiteral) TokenLiteral added in v0.6.0

func (n *NullLiteral) 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 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 SpreadLiteral added in v0.8.1

type SpreadLiteral struct {
	// Token is ....
	Token token.Token

	// Right is the value being spread out of
	Right Expression
}

SpreadLiteral holds a spread node

func (*SpreadLiteral) String added in v0.8.1

func (s *SpreadLiteral) String() string

String returns a string representation of the literal

func (*SpreadLiteral) TokenLiteral added in v0.8.1

func (s *SpreadLiteral) TokenLiteral() string

TokenLiteral returns the spread 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.

Jump to

Keyboard shortcuts

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