Documentation
¶
Overview ¶
Package ast contains the definitions of the abstract-syntax tree that our parse produces, and our interpreter executes.
Index ¶
- type AssignStatement
- type BlockStatement
- type Bool
- type BreakStatement
- type CallExpression
- type CaseExpression
- type ConstStatement
- type Expression
- type ExpressionStatement
- type FloatLiteral
- type ForLoopExpression
- type ForeachStatement
- type FunctionDefineLiteral
- type FunctionLiteral
- type GetAttributeExpression
- type HashLiteral
- type Identifier
- type IfExpression
- type ImportStatement
- type IndexExpression
- type InfixExpression
- type IntegerLiteral
- type ListLiteral
- type NilLiteral
- type Node
- type ObjectCallExpression
- type PipeExpression
- type PostfixExpression
- type PrefixExpression
- type Program
- type RegexpLiteral
- type ReturnStatement
- type SetLiteral
- type Statement
- type StringLiteral
- type SwitchExpression
- type TernaryExpression
- type VarStatement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AssignStatement ¶
type AssignStatement struct {
Token token.Token
Name *Identifier
Operator string
Value Expression
}
AssignStatement is generally used for a (var-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 Bool ¶ added in v0.0.11
type Bool struct {
// Token holds the actual token
Token token.Token
// Value stores the bools' value: true, or false.
Value bool
}
Bool holds a boolean type
func (*Bool) TokenLiteral ¶ added in v0.0.11
TokenLiteral returns the literal token.
type BreakStatement ¶
BreakStatement stores a break statement
func (*BreakStatement) String ¶
func (s *BreakStatement) String() string
func (*BreakStatement) TokenLiteral ¶
func (s *BreakStatement) TokenLiteral() string
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 var-statement, but the value can't be changed later.
func (*ConstStatement) String ¶
func (cs *ConstStatement) String() string
String returns this object as a string.
func (*ConstStatement) TokenLiteral ¶
func (cs *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
// Initialization statement which is executed once before evaluating the
// condition for the first iteration
InitStatement *VarStatement
// Statement which is executed after each execution of the block
// (and only if the block was executed)
PostStatement Expression
}
ForLoopExpression holds a for-loop
func (*ForLoopExpression) IsSimpleLoop ¶
func (fle *ForLoopExpression) IsSimpleLoop() bool
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 GetAttributeExpression ¶
type GetAttributeExpression struct {
// Token stores the literal token
Token token.Token
// Object whose attribute is being accessed
Object Expression
// The attribute itself
Attribute *Identifier
}
GetAttributeExpression
func (*GetAttributeExpression) String ¶
func (e *GetAttributeExpression) String() string
func (*GetAttributeExpression) TokenLiteral ¶
func (e *GetAttributeExpression) TokenLiteral() string
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 ImportStatement ¶
type ImportStatement struct {
// Token holds the token
Token token.Token
// Name of the module to import
Name *Identifier
}
ImportStatement holds an import statement
func (*ImportStatement) String ¶
func (i *ImportStatement) String() string
String returns this object as a string
func (*ImportStatement) TokenLiteral ¶
func (i *ImportStatement) 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 ListLiteral ¶ added in v0.0.10
type ListLiteral struct {
// Token is the token
Token token.Token
// Items holds the members of the list.
Items []Expression
}
ListLiteral holds an inline list
func (*ListLiteral) String ¶ added in v0.0.10
func (ll *ListLiteral) String() string
String returns this object as a string.
func (*ListLiteral) TokenLiteral ¶ added in v0.0.10
func (ll *ListLiteral) TokenLiteral() string
TokenLiteral returns the literal token.
type NilLiteral ¶ added in v0.0.11
NilLiteral represents a literal nil
func (*NilLiteral) String ¶ added in v0.0.11
func (n *NilLiteral) String() string
String returns this object as a string.
func (*NilLiteral) TokenLiteral ¶ added in v0.0.11
func (n *NilLiteral) 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 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 PipeExpression ¶
type PipeExpression struct {
// Token stores the literal token
Token token.Token
// Arguments are the arguments to be applied
Arguments []Expression
}
PipeExpression holds a series of calls
func (*PipeExpression) String ¶
func (pe *PipeExpression) String() string
func (*PipeExpression) TokenLiteral ¶
func (pe *PipeExpression) TokenLiteral() string
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) TokenLiteral ¶
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 SetLiteral ¶
type SetLiteral struct {
Token token.Token // the '{' token
Items []Expression
}
SetLiteral holds a set definition
func (*SetLiteral) String ¶
func (sl *SetLiteral) String() string
func (*SetLiteral) TokenLiteral ¶
func (sl *SetLiteral) TokenLiteral() string
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
// Template is the templatized version of the string, if any
Template *tmpl.Template
TemplateExpressions []*ExpressionStatement
}
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.
type VarStatement ¶ added in v0.0.12
type VarStatement 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
}
VarStatement holds a var-statemnt
func (*VarStatement) String ¶ added in v0.0.12
func (s *VarStatement) String() string
String returns this object as a string.
func (*VarStatement) TokenLiteral ¶ added in v0.0.12
func (s *VarStatement) TokenLiteral() string
TokenLiteral returns the literal token.