Documentation
¶
Index ¶
- type BlockStatement
- type BooleanExpression
- type CallExpression
- type Expression
- type ExpressionStatement
- type FuncExpression
- type IdentifierExpression
- type IfExpression
- type InfixExpression
- type IntegerExpression
- type LetStatement
- type Node
- type PrefixExpression
- type Program
- type ReturnStatement
- type Statement
- type StringExpression
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockStatement ¶
type BlockStatement struct { // the { token Token token.Token // a series of statements grouped by {} Statements []Statement }
BlockStatement represents a series of statments grouped by {}
func NewBlockStatement ¶
func NewBlockStatement(statements ...Statement) *BlockStatement
NewBlockStatement creates a BlockStatement node
func (*BlockStatement) String ¶
func (bs *BlockStatement) String() string
func (*BlockStatement) TokenLiteral ¶
func (bs *BlockStatement) TokenLiteral() string
type BooleanExpression ¶
BooleanExpression implements the Expression interface
func NewBooleanExpression ¶
func NewBooleanExpression(value bool) *BooleanExpression
NewBooleanExpression creates a Boolean node
func (*BooleanExpression) String ¶
func (be *BooleanExpression) String() string
func (*BooleanExpression) TokenLiteral ¶
func (be *BooleanExpression) TokenLiteral() string
type CallExpression ¶
type CallExpression struct { // the first token (fn or the identifier) Token token.Token // function literal or identifier bound to function Func Expression // function call arguments Arguments []Expression }
CallExpression implements the Expression interface
func NewCallExpression ¶
func NewCallExpression(fn Expression, args []Expression) *CallExpression
NewCallExpression creates a CallExpression node
func (*CallExpression) String ¶
func (ce *CallExpression) String() string
func (*CallExpression) TokenLiteral ¶
func (ce *CallExpression) TokenLiteral() string
type Expression ¶
type Expression interface { Node // contains filtered or unexported methods }
Expression is a node that produces a value
type ExpressionStatement ¶
type ExpressionStatement struct { // the expression Expression }
ExpressionStatement represents a statement consisting of only one expression
func NewExpressionStatement ¶
func NewExpressionStatement(exp Expression) *ExpressionStatement
NewExpressionStatement creates an ExpressionStatement node
type FuncExpression ¶
type FuncExpression struct { // the fn token Token token.Token // function parameters Parameters []*IdentifierExpression // function body Body *BlockStatement }
FuncExpression implements the Expression interface
func NewFuncExpression ¶
func NewFuncExpression(params []*IdentifierExpression, body *BlockStatement) *FuncExpression
NewFuncExpression creates a FuncExpression node
func (*FuncExpression) String ¶
func (fe *FuncExpression) String() string
func (*FuncExpression) TokenLiteral ¶
func (fe *FuncExpression) TokenLiteral() string
type IdentifierExpression ¶
IdentifierExpression implements the Expression interface
func NewIdentifierExpression ¶
func NewIdentifierExpression(literal string) *IdentifierExpression
NewIdentifierExpression creates an Identifier node
func (*IdentifierExpression) String ¶
func (ie *IdentifierExpression) String() string
func (*IdentifierExpression) TokenLiteral ¶
func (ie *IdentifierExpression) TokenLiteral() string
type IfExpression ¶
type IfExpression struct { // the if token Token token.Token // the condition expression Condition Expression // consequence when the condition is true Consequence *BlockStatement Alternative *BlockStatement }
IfExpression implements the Expression interface
func NewIfExpression ¶
func NewIfExpression(condition Expression, consequence *BlockStatement, alternative *BlockStatement) *IfExpression
NewIfExpression creates an IfExpression node
func (*IfExpression) String ¶
func (ie *IfExpression) String() string
func (*IfExpression) TokenLiteral ¶
func (ie *IfExpression) TokenLiteral() string
type InfixExpression ¶
type InfixExpression struct { // a token representation of the infix operator Token token.Token // the string literal of the infix operator Operator string // the expression to the left of the infix expression LeftOperand Expression // the expression to the right of the infix expression RightOperand Expression }
InfixExpression implements the Expression interface
func NewInfixExpression ¶
func NewInfixExpression(literal string, leftOperand, rightOperand Expression) *InfixExpression
NewInExpression creates an InfixExpression node
func (*InfixExpression) String ¶
func (ie *InfixExpression) String() string
func (*InfixExpression) TokenLiteral ¶
func (ie *InfixExpression) TokenLiteral() string
type IntegerExpression ¶
IntegerExpression implements the Expression interface
func NewIntegerExpression ¶
func NewIntegerExpression(literal string, value int64) *IntegerExpression
NewIntegerExpression creates an Integer node
func (*IntegerExpression) String ¶
func (ie *IntegerExpression) String() string
func (*IntegerExpression) TokenLiteral ¶
func (ie *IntegerExpression) TokenLiteral() string
type LetStatement ¶
type LetStatement struct { // the let token Token token.Token // the identifier Identifier *IdentifierExpression // the expression value on the right side of the statement Value Expression }
LetStatement represents the let statement
func NewLetStatement ¶
func NewLetStatement(identifier *IdentifierExpression, value Expression) *LetStatement
NewLetStatement creates a LetStatement node
func (*LetStatement) String ¶
func (ls *LetStatement) String() string
func (*LetStatement) TokenLiteral ¶
func (ls *LetStatement) TokenLiteral() string
type PrefixExpression ¶
type PrefixExpression struct { // a token representation of the prefix operator Token token.Token // the string literal of the prefix operator Operator string // the expression following the prefix operator Operand Expression }
PrefixExpression implements the Expression interface a prefix expression consists of a prefix (-/!) and an operator
func NewPrefixExpression ¶
func NewPrefixExpression(literal string, operand Expression) *PrefixExpression
NewPrefixExpression creates a PrefixExpression node
func (*PrefixExpression) String ¶
func (pe *PrefixExpression) String() string
func (*PrefixExpression) TokenLiteral ¶
func (pe *PrefixExpression) TokenLiteral() string
type Program ¶
type Program struct {
Statements []Statement
}
Program is a representation of the AST. It implements the Node interface (root node of AST)
func NewProgram ¶
NewProgram creates a Program node
func (*Program) TokenLiteral ¶
type ReturnStatement ¶
type ReturnStatement struct { // the return token Token token.Token // the expression value on the right of the return keyword Value Expression }
ReturnStatement represents the return statement
func NewReturnStatement ¶
func NewReturnStatement(value Expression) *ReturnStatement
NewReturnStatement creates a ReturnStatement node
func (*ReturnStatement) String ¶
func (rs *ReturnStatement) String() string
func (*ReturnStatement) TokenLiteral ¶
func (rs *ReturnStatement) TokenLiteral() string
type Statement ¶
type Statement interface { Node // contains filtered or unexported methods }
Statement is a node that does not produce a value
type StringExpression ¶
StringExpression implements the Expression interface
func NewStringExpression ¶
func NewStringExpression(literal string) *StringExpression
NewStringExpression creates a String node
func (*StringExpression) String ¶
func (se *StringExpression) String() string
func (*StringExpression) TokenLiteral ¶
func (se *StringExpression) TokenLiteral() string