Documentation
¶
Overview ¶
Package ast is an Abstract Syntax Tree, which will be used to represent Amoeba programs as data that we can later evaluate
Index ¶
- type ArrayLiteral
- type BlockStatement
- type BooleanLiteral
- type CallExpression
- type Expression
- type ExpressionStatement
- type FunctionLiteral
- type HashLiteral
- type Identifier
- type IfExpression
- type IndexExpression
- type InfixExpression
- type IntegerLiteral
- type LetStatement
- type Node
- type PrefixExpression
- type Program
- type ReturnStatement
- type Statement
- type StringLiteral
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayLiteral ¶
type ArrayLiteral struct {
Token token.Token // should be a [ token
Elements []Expression
}
ArrayLiteral is an Expression Node representing an array
func (*ArrayLiteral) String ¶
func (al *ArrayLiteral) String() string
func (*ArrayLiteral) TokenLiteral ¶
func (al *ArrayLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the array: [
type BlockStatement ¶
BlockStatement is a Statement Node that contains statements
func (*BlockStatement) String ¶
func (bs *BlockStatement) String() string
func (*BlockStatement) TokenLiteral ¶
func (bs *BlockStatement) TokenLiteral() string
TokenLiteral returns the token literal for the beginning of the block: {
type BooleanLiteral ¶
BooleanLiteral is an Expression Node consisting solely of a boolean
func (*BooleanLiteral) String ¶
func (b *BooleanLiteral) String() string
func (*BooleanLiteral) TokenLiteral ¶
func (b *BooleanLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the integer
type CallExpression ¶
type CallExpression struct {
Token token.Token // should be a ( token
Function Expression // Identifier or FunctionLiteral
Arguments []Expression
}
CallExpression is an Expression Node representing a function call
func (*CallExpression) String ¶
func (ce *CallExpression) String() string
func (*CallExpression) TokenLiteral ¶
func (ce *CallExpression) TokenLiteral() string
TokenLiteral returns the token literal for the (
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
Expression is a Node that tells the language to evaluate something
type ExpressionStatement ¶
type ExpressionStatement struct {
Token token.Token // first token of the expression
Expression Expression
}
ExpressionStatement is a Statement Node consisting solely of an expression
func (*ExpressionStatement) String ¶
func (es *ExpressionStatement) String() string
func (*ExpressionStatement) TokenLiteral ¶
func (es *ExpressionStatement) TokenLiteral() string
TokenLiteral returns the token literal for the first token in the expression statement
type FunctionLiteral ¶
type FunctionLiteral struct {
Token token.Token // should be an 'fn' token
Parameters []*Identifier
Body *BlockStatement
}
FunctionLiteral is an Expression Node representing a function
func (*FunctionLiteral) String ¶
func (fl *FunctionLiteral) String() string
func (*FunctionLiteral) TokenLiteral ¶
func (fl *FunctionLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the if
type HashLiteral ¶
type HashLiteral struct {
Token token.Token // should be a { token
Pairs map[Expression]Expression
}
HashLiteral is an Expression Node representing a hash (or object)
func (*HashLiteral) String ¶
func (hl *HashLiteral) String() string
func (*HashLiteral) TokenLiteral ¶
func (hl *HashLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the hash literal: {
type Identifier ¶
Identifier is an Expression Node that is bound to an expression, used to create a new variable or return a variables value
func (*Identifier) String ¶
func (i *Identifier) String() string
func (*Identifier) TokenLiteral ¶
func (i *Identifier) TokenLiteral() string
TokenLiteral returns the token literal for the identifier expression
type IfExpression ¶
type IfExpression struct {
Token token.Token // should be an IF token
Condition Expression
Consequence *BlockStatement
Alternative *BlockStatement
}
IfExpression is an Expression Node representing a conditional statement
func (*IfExpression) String ¶
func (ie *IfExpression) String() string
func (*IfExpression) TokenLiteral ¶
func (ie *IfExpression) TokenLiteral() string
TokenLiteral returns the token literal for the if
type IndexExpression ¶
type IndexExpression struct {
Token token.Token // should be a [ token
Left Expression
Index Expression
}
IndexExpression is an Expression Node representing the access of an array index
func (*IndexExpression) String ¶
func (ie *IndexExpression) String() string
func (*IndexExpression) TokenLiteral ¶
func (ie *IndexExpression) TokenLiteral() string
TokenLiteral returns the token literal for the index expression: [
type InfixExpression ¶
type InfixExpression struct {
Token token.Token // should be an infix token ("+", "/", "==", ">")
Left Expression
Operator string
Right Expression
}
InfixExpression is an Expression Node that applies an operator to the expressions on either side of it
func (*InfixExpression) String ¶
func (ie *InfixExpression) String() string
func (*InfixExpression) TokenLiteral ¶
func (ie *InfixExpression) TokenLiteral() string
TokenLiteral returns the token literal for the infix expression
type IntegerLiteral ¶
IntegerLiteral is an Expression Node consisting solely of an integer
func (*IntegerLiteral) String ¶
func (il *IntegerLiteral) String() string
func (*IntegerLiteral) TokenLiteral ¶
func (il *IntegerLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the integer
type LetStatement ¶
type LetStatement struct {
Token token.Token // should be a LET token
Name *Identifier
Value Expression
}
LetStatement is a Statement Node that assigns an expression to an identifier
func (*LetStatement) String ¶
func (ls *LetStatement) String() string
func (*LetStatement) TokenLiteral ¶
func (ls *LetStatement) TokenLiteral() string
TokenLiteral returns the token literal for the let statement
type PrefixExpression ¶
type PrefixExpression struct {
Token token.Token // should be a prefix token ("!" or "-")
Operator string
Right Expression
}
PrefixExpression is an Expression Node that applies a prefix to another expression
func (*PrefixExpression) String ¶
func (pe *PrefixExpression) String() string
func (*PrefixExpression) TokenLiteral ¶
func (pe *PrefixExpression) TokenLiteral() string
TokenLiteral returns the token literal for the prefix expression
type Program ¶
type Program struct {
Statements []Statement
}
Program is the root Node of all amoeba programs and contains all the statements for a given peice of code
func (*Program) TokenLiteral ¶
TokenLiteral returns the token literal for the next statement
type ReturnStatement ¶
type ReturnStatement struct {
Token token.Token // should be a RETURN token
ReturnValue Expression
}
ReturnStatement is a Statement Node that ends a function call and returns an expression to the caller
func (*ReturnStatement) String ¶
func (rs *ReturnStatement) String() string
func (*ReturnStatement) TokenLiteral ¶
func (rs *ReturnStatement) TokenLiteral() string
TokenLiteral returns the token literal for the return statement
type Statement ¶
type Statement interface {
Node
// contains filtered or unexported methods
}
Statement is a Node that tells the language to do something
type StringLiteral ¶
StringLiteral is an Expression Node consisting solely of a string
func (*StringLiteral) String ¶
func (sl *StringLiteral) String() string
func (*StringLiteral) TokenLiteral ¶
func (sl *StringLiteral) TokenLiteral() string
TokenLiteral returns the token literal for the string