ast

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 4 Imported by: 12

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.Token // the '[' token
	Elements []Expression
}

ArrayLiteral - holds the token: '[' and an array of expressions (Elements)

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

String - loops through the array literal's elements and prints them. Satisfies our Node interface

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

TokenLiteral returns the ArrayLiteral's Literal (the string) and satisfies the Node interface.

type BlockStatement

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

BlockStatement - holds the token "{", and a slice of statements

func (*BlockStatement) String

func (bs *BlockStatement) String() string

String - returns a string representation of the statements inside the block

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

TokenLiteral returns the BlockStatement's Literal and satisfies the Node interface.

type Boolean

type Boolean struct {
	Token token.Token
	Value bool
}

Boolean - holds the token and it's value (a boolean)

func (*Boolean) String

func (b *Boolean) String() string

String - returns a string representation of the boolean and satisfies our Node interface

func (*Boolean) TokenLiteral

func (b *Boolean) TokenLiteral() string

TokenLiteral returns the Boolean's Literal and satisfies the Node interface.

type CallExpression

type CallExpression struct {
	Token     token.Token // The '(' token
	Function  Expression
	Arguments []Expression
}

CallExpression - holds the token, the function expression, and its arguments ([]Expression). Structure: <expression>(<comma separated expressions>)

func (*CallExpression) String

func (ce *CallExpression) String() string

String - returns a string representation of the CallExpression. Prints the function and its arguments. Satisfies our Node interface

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

TokenLiteral returns the CallExpression's Literal and satisfies the Node interface.

type ConstStatement added in v0.2.0

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

ConstStatement - Name holds the identifier of the binding and Value for the expression that produces the value.

func (*ConstStatement) String added in v0.2.0

func (ls *ConstStatement) String() string

String - returns a string representation of the ConstStatement and satisfies our Node interface

func (*ConstStatement) TokenLiteral added in v0.2.0

func (ls *ConstStatement) TokenLiteral() string

TokenLiteral returns the ConstStatement's Literal and satisfies the Node interface.

type Expression

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

Expression - must provide expressionNode, TokenLiteral, and String methods. Expressions produce values.

type ExpressionStatement

type ExpressionStatement struct {
	Token      token.Token // The first token of the expression
	Expression Expression
}

ExpressionStatement - holds the first token of the expression and the expression

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

String - returns a string representation of the ExpressionStatement and satisfies our Node interface

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

TokenLiteral returns the ExpressionStatement's Literal and satisfies the Node interface.

type FunctionLiteral

type FunctionLiteral struct {
	Token      token.Token // The 'func' token
	Parameters []*Identifier
	Body       *BlockStatement
	Name       string
}

FunctionLiteral - holds the token, the function params (a slice of *Identifier), and the function Body (*BlockStatement). Structure: func <parameters> <block statement>

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

String - returns a string representation of the FunctionLiteral. Prints it's token, params, and body. Satisfies our Node interface

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

TokenLiteral returns the FunctionLiteral's Literal and satisfies the Node interface.

type HashLiteral

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

HashLiteral - holds the '{' token and the pairs in the hash

func (*HashLiteral) String

func (hl *HashLiteral) String() string

String - iterates over the hl's pairs and prints string representation of the hash. Satisfies our Node interface

func (*HashLiteral) TokenLiteral

func (hl *HashLiteral) TokenLiteral() string

TokenLiteral returns Token Literal and satisfies the Node interface.

type Identifier

type Identifier struct {
	Token token.Token // The token.Identifier token
	Value string
}

Identifier - holds IDENTIFIER token and it's value (add, foobar, x, y, ...)

func (*Identifier) String

func (i *Identifier) String() string

String - returns a string representation of the Identifier and satisfies our Node interface

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

TokenLiteral returns the Identifier's Literal and satisfies the Node interface.

type IfExpression

type IfExpression struct {
	Token       token.Token // The If token
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

IfExpression - holds the token, the condition expression and the consequence & alternative block statements. Structure: if (<condition>) <consequence> else <alternative>

func (*IfExpression) String

func (ie *IfExpression) String() string

String - returns a string representation of the IfExpression with the consequence and also the alteritive if it is not nil. Satisfies our Node interface

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

TokenLiteral returns the IfExpression's Literal and satisfies the Node interface.

type IndexExpression

type IndexExpression struct {
	Token token.Token // The '[' token
	Left  Expression  // The object being accessed
	Index Expression  // Can be any expression, but must produce an integer
}

IndexExpression - holds the '[' token, the object being accessed, and the index

func (*IndexExpression) String

func (ie *IndexExpression) String() string

String - returns string representation of the IndexExpression: (leftExpr[indexExpr]). Satisfies our Node interface

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

TokenLiteral returns the IndexExpression's Literal and satisfies the Node interface.

type InfixExpression

type InfixExpression struct {
	Token    token.Token // The operator token (+, -, *, etc)
	Left     Expression
	Operator string // string (examples: "+", "-", "*", etc)
	Right    Expression
}

InfixExpression - holds the token, the expression to the left of it, a string version of the operator, and the expression to the right of it

func (*InfixExpression) String

func (ie *InfixExpression) String() string

String - returns a string representation of the left side expression, the operator, and the right side expression (5 * 5) and satisfies our Node interface

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

TokenLiteral returns the InfixExpression's Literal and satisfies the Node interface.

type IntegerLiteral

type IntegerLiteral struct {
	Token token.Token
	Value int64
}

IntegerLiteral - holds the token and it's value (int64)

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

String - returns a string representation of the IntegerLiteral and satisfies our Node interface

func (*IntegerLiteral) TokenLiteral

func (il *IntegerLiteral) TokenLiteral() string

TokenLiteral returns the IntegerLiteral's Literal and satisfies the Node interface.

type LetStatement

type LetStatement struct {
	Token token.Token // The token.Let token
	Name  *Identifier
	Value Expression
}

LetStatement - Name holds the identifier of the binding and Value for the expression that produces the value.

func (*LetStatement) String

func (ls *LetStatement) String() string

String - returns a string representation of the LetStatement and satisfies our Node interface

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

TokenLiteral returns the LetStatement's Literal and satisfies the Node interface.

type Node

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

Node - nodes in our ast will provide a TokenLiteral method for debugging

type PostfixExpression added in v0.2.0

type PostfixExpression struct {
	Token    token.Token
	Operator string
}

PostfixExpression - holds the token we're operating on and postfix operator (--, ++)

func (*PostfixExpression) String added in v0.2.0

func (pe *PostfixExpression) String() string

String - returns a string representation of the left side expression, the operator, and the right side expression (5 * 5) and satisfies our Node interface

func (*PostfixExpression) TokenLiteral added in v0.2.0

func (pe *PostfixExpression) TokenLiteral() string

TokenLiteral returns the PostfixExpression's Literal and satisfies the Node interface.

type PrefixExpression

type PrefixExpression struct {
	Token    token.Token // The prefix token (! or -)
	Operator string      // String (either "!" or "-")
	Right    Expression  // The expression to the right of the operator
}

PrefixExpression - holds the token, a string version of the operator, and the expression to the right of it

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

String - returns a string representation of the operator followed by it's expression to the right (-5) and satisfies our Node interface

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

TokenLiteral returns the PrefixExpression's Literal and satisfies the Node interface.

type ReturnStatement

type ReturnStatement struct {
	Token       token.Token // The 'return' token
	ReturnValue Expression
}

ReturnStatement - pretty self explanatory, holds RETURN token and return value

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

String - returns a string representation of the ReturnStatement and satisfies our Node interface

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

TokenLiteral returns the ReturnStatement's Literal and satisfies the Node interface.

type RootNode

type RootNode struct {
	Statements []Statement
}

RootNode of every AST our parser produces.

func (*RootNode) String

func (p *RootNode) String() string

String returns a buffer containing the programs Statements as strings.

func (*RootNode) TokenLiteral

func (p *RootNode) TokenLiteral() string

TokenLiteral returns the RootNode's Literal and satisfies the Node interface.

type Statement

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

Statement - must provide statementNode, TokenLiteral, and String methods. Statements do not produce values.

type StringLiteral

type StringLiteral struct {
	Token token.Token
	Value string
}

StringLiteral - holds the token and it's value (string)

func (*StringLiteral) String

func (sl *StringLiteral) String() string

String - returns a string representation of the StringLiteral and satisfies our Node interface

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

TokenLiteral returns the StringLiteral's Literal (the string) and satisfies the Node interface.

Jump to

Keyboard shortcuts

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