Documentation
¶
Overview ¶
Package ast contains the definitions of the abstract syntax tree that our parser produces and that our interpreter executes.
Index ¶
- type Assign
- type Block
- type Bool
- type Call
- type Case
- type Const
- type Control
- type Expression
- type Float
- type For
- func (f *For) Condition() Node
- func (f *For) Consequence() *Block
- func (f *For) ExpressionNode()
- func (f *For) Init() Node
- func (f *For) IsIteratorLoop() bool
- func (f *For) IsSimpleLoop() bool
- func (f *For) Literal() string
- func (f *For) Post() Expression
- func (f *For) String() string
- func (f *For) Token() token.Token
- type Func
- type GetAttr
- type Ident
- type If
- type Import
- type In
- type Index
- type Infix
- type Int
- type List
- type Map
- type MultiVar
- type Nil
- type Node
- type ObjectCall
- type Pipe
- type Postfix
- type Prefix
- type Program
- type Range
- type Set
- type Slice
- type Statement
- type String
- type Switch
- type Ternary
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assign ¶ added in v0.0.13
type Assign struct {
// contains filtered or unexported fields
}
Assign is generally used for a simple assignment like "x = y". We also support other operators like "+=", "-=", "*=", and "/=".
func NewAssign ¶ added in v0.0.13
func NewAssign(operator token.Token, name *Ident, value Expression) *Assign
func NewAssignIndex ¶ added in v0.0.13
func NewAssignIndex(operator token.Token, index *Index, value Expression) *Assign
func (*Assign) ExpressionNode ¶ added in v0.0.13
func (a *Assign) ExpressionNode()
func (*Assign) Value ¶ added in v0.0.13
func (a *Assign) Value() Expression
type Block ¶ added in v0.0.13
type Block struct {
// contains filtered or unexported fields
}
Block holds a sequence of statements, which are treated as a group. This may represent the body of a function, loop, or a conditional block.
func (*Block) StatementNode ¶ added in v0.0.13
func (b *Block) StatementNode()
func (*Block) Statements ¶ added in v0.0.13
type Bool ¶ added in v0.0.11
type Bool struct {
// contains filtered or unexported fields
}
Bool holds the boolean "true" or "false"
func (*Bool) ExpressionNode ¶ added in v0.0.13
func (b *Bool) ExpressionNode()
type Call ¶ added in v0.0.13
type Call struct {
// contains filtered or unexported fields
}
Call holds the invocation of a method.
func NewCall ¶ added in v0.0.13
func NewCall(token token.Token, function Expression, arguments []Expression) *Call
func (*Call) Arguments ¶ added in v0.0.13
func (c *Call) Arguments() []Expression
func (*Call) ExpressionNode ¶ added in v0.0.13
func (c *Call) ExpressionNode()
func (*Call) Function ¶ added in v0.0.13
func (c *Call) Function() Expression
type Case ¶ added in v0.0.13
type Case struct {
// contains filtered or unexported fields
}
Case handles the case within a switch statement
func NewCase ¶ added in v0.0.13
func NewCase(token token.Token, expressions []Expression, block *Block) *Case
func (*Case) ExpressionNode ¶ added in v0.0.13
func (c *Case) ExpressionNode()
func (*Case) Expressions ¶ added in v0.0.13
func (c *Case) Expressions() []Expression
type Const ¶ added in v0.0.13
type Const struct {
// contains filtered or unexported fields
}
Const defines a named constant containing a constant value.
func NewConst ¶ added in v0.0.13
func NewConst(token token.Token, name *Ident, value Expression) *Const
func (*Const) StatementNode ¶ added in v0.0.13
func (c *Const) StatementNode()
func (*Const) Value ¶ added in v0.0.13
func (c *Const) Value() (string, Expression)
type Control ¶ added in v0.0.13
type Control struct {
// contains filtered or unexported fields
}
Control defines a return, break, or continue statement.
func NewControl ¶ added in v0.0.13
func NewControl(token token.Token, value Expression) *Control
func (*Control) StatementNode ¶ added in v0.0.13
func (c *Control) StatementNode()
func (*Control) Value ¶ added in v0.0.13
func (c *Control) Value() Expression
type Expression ¶
type Expression interface {
// Node is embedded here to indicate that all expressions are AST nodes.
Node
ExpressionNode()
}
Expression represents a snippet of Tamarin code that evaluates to a value. Expressions are used in statements, as well as in other expressions.
type Float ¶ added in v0.0.13
type Float struct {
// contains filtered or unexported fields
}
Float holds a floating point number
func (*Float) ExpressionNode ¶ added in v0.0.13
func (f *Float) ExpressionNode()
type For ¶ added in v0.0.13
type For struct {
// contains filtered or unexported fields
}
For defines a for loop.
func (*For) Consequence ¶ added in v0.0.13
func (*For) ExpressionNode ¶ added in v0.0.13
func (f *For) ExpressionNode()
Should be StatementNode only?
func (*For) IsIteratorLoop ¶ added in v0.0.13
func (*For) IsSimpleLoop ¶ added in v0.0.13
func (*For) Post ¶ added in v0.0.13
func (f *For) Post() Expression
type Func ¶ added in v0.0.13
type Func struct {
// contains filtered or unexported fields
}
Func holds a function definition.
func (*Func) Defaults ¶ added in v0.0.13
func (f *Func) Defaults() map[string]Expression
func (*Func) ExpressionNode ¶ added in v0.0.13
func (f *Func) ExpressionNode()
func (*Func) Parameters ¶ added in v0.0.13
type GetAttr ¶ added in v0.0.13
type GetAttr struct {
// contains filtered or unexported fields
}
GetAttr
func NewGetAttr ¶ added in v0.0.13
func NewGetAttr(token token.Token, object Expression, attribute *Ident) *GetAttr
func (*GetAttr) ExpressionNode ¶ added in v0.0.13
func (e *GetAttr) ExpressionNode()
func (*GetAttr) Object ¶ added in v0.0.13
func (e *GetAttr) Object() Expression
type Ident ¶ added in v0.0.13
type Ident struct {
// contains filtered or unexported fields
}
Ident holds a single identifier.
func (*Ident) ExpressionNode ¶ added in v0.0.13
func (i *Ident) ExpressionNode()
type If ¶ added in v0.0.13
type If struct {
// contains filtered or unexported fields
}
If holds an if statement.
func (*If) Alternative ¶ added in v0.0.13
func (*If) Condition ¶ added in v0.0.13
func (i *If) Condition() Expression
func (*If) Consequence ¶ added in v0.0.13
func (*If) ExpressionNode ¶ added in v0.0.13
func (i *If) ExpressionNode()
type Import ¶ added in v0.0.13
type Import struct {
// contains filtered or unexported fields
}
Import holds an import statement
func (*Import) ExpressionNode ¶ added in v0.0.13
func (i *Import) ExpressionNode()
type In ¶ added in v0.0.13
type In struct {
// contains filtered or unexported fields
}
In holds an "in" expression
func NewIn ¶ added in v0.0.13
func NewIn(token token.Token, left Expression, right Expression) *In
func (*In) ExpressionNode ¶ added in v0.0.13
func (i *In) ExpressionNode()
func (*In) Left ¶ added in v0.0.13
func (i *In) Left() Expression
func (*In) Right ¶ added in v0.0.13
func (i *In) Right() Expression
type Index ¶ added in v0.0.13
type Index struct {
// contains filtered or unexported fields
}
Index holds an index expression
func NewIndex ¶ added in v0.0.13
func NewIndex(token token.Token, left Expression, index Expression) *Index
func (*Index) ExpressionNode ¶ added in v0.0.13
func (i *Index) ExpressionNode()
func (*Index) Index ¶ added in v0.0.13
func (i *Index) Index() Expression
func (*Index) Left ¶ added in v0.0.13
func (i *Index) Left() Expression
type Infix ¶ added in v0.0.13
type Infix struct {
// contains filtered or unexported fields
}
Infix defines an infix expression like "x + y" or "5 - 1".
func NewInfix ¶ added in v0.0.13
func NewInfix(token token.Token, left Expression, operator string, right Expression) *Infix
func (*Infix) ExpressionNode ¶ added in v0.0.13
func (i *Infix) ExpressionNode()
func (*Infix) Left ¶ added in v0.0.13
func (i *Infix) Left() Expression
func (*Infix) Right ¶ added in v0.0.13
func (i *Infix) Right() Expression
type Int ¶ added in v0.0.13
type Int struct {
// contains filtered or unexported fields
}
Int holds an integer number
func (*Int) ExpressionNode ¶ added in v0.0.13
func (i *Int) ExpressionNode()
type List ¶ added in v0.0.13
type List struct {
// contains filtered or unexported fields
}
List holds an inline list
func (*List) ExpressionNode ¶ added in v0.0.13
func (l *List) ExpressionNode()
func (*List) Items ¶ added in v0.0.13
func (l *List) Items() []Expression
type Map ¶ added in v0.0.13
type Map struct {
// contains filtered or unexported fields
}
Map holds a map
func NewMap ¶ added in v0.0.13
func NewMap(token token.Token, items map[Expression]Expression) *Map
func (*Map) ExpressionNode ¶ added in v0.0.13
func (m *Map) ExpressionNode()
func (*Map) Items ¶ added in v0.0.13
func (m *Map) Items() map[Expression]Expression
type MultiVar ¶ added in v0.0.13
type MultiVar struct {
// contains filtered or unexported fields
}
MultiVar holds a variable assignment statement for >1 variables.
func NewMultiVar ¶ added in v0.0.13
func (*MultiVar) StatementNode ¶ added in v0.0.13
func (s *MultiVar) StatementNode()
func (*MultiVar) Value ¶ added in v0.0.13
func (s *MultiVar) Value() ([]string, Expression)
type Nil ¶ added in v0.0.13
type Nil struct {
// contains filtered or unexported fields
}
Nil represents a literal nil
func (*Nil) ExpressionNode ¶ added in v0.0.13
func (n *Nil) ExpressionNode()
type Node ¶
type Node interface {
// Token returns the token where this Node begins.
Token() token.Token
// Literal returns the string from the first token that defines the Node.
Literal() string
// String returns a human friendly representation of the Node. This should
// be similar to the original source code, but not necessarily identical.
String() string
}
Node reresents a node.
type ObjectCall ¶ added in v0.0.13
type ObjectCall struct {
// contains filtered or unexported fields
}
ObjectCall is used when calling a method on an object.
func NewObjectCall ¶ added in v0.0.13
func NewObjectCall(token token.Token, object Expression, call Expression) *ObjectCall
func (*ObjectCall) Call ¶ added in v0.0.13
func (c *ObjectCall) Call() Expression
func (*ObjectCall) ExpressionNode ¶ added in v0.0.13
func (c *ObjectCall) ExpressionNode()
func (*ObjectCall) Literal ¶ added in v0.0.13
func (c *ObjectCall) Literal() string
func (*ObjectCall) Object ¶ added in v0.0.13
func (c *ObjectCall) Object() Expression
func (*ObjectCall) String ¶ added in v0.0.13
func (c *ObjectCall) String() string
func (*ObjectCall) Token ¶ added in v0.0.13
func (c *ObjectCall) Token() token.Token
type Pipe ¶ added in v0.0.13
type Pipe struct {
// contains filtered or unexported fields
}
Pipe holds a series of calls
func (*Pipe) ExpressionNode ¶ added in v0.0.13
func (p *Pipe) ExpressionNode()
func (*Pipe) Expressions ¶ added in v0.0.13
func (p *Pipe) Expressions() []Expression
type Postfix ¶ added in v0.0.13
type Postfix struct {
// contains filtered or unexported fields
}
Postfix defines a postfix expression like "x++".
func (*Postfix) ExpressionNode ¶ added in v0.0.13
func (p *Postfix) ExpressionNode()
type Prefix ¶ added in v0.0.13
type Prefix struct {
// contains filtered or unexported fields
}
Prefix defines a prefix expression like "!false" or "-x".
func (*Prefix) ExpressionNode ¶ added in v0.0.13
func (p *Prefix) ExpressionNode()
func (*Prefix) Right ¶ added in v0.0.13
func (p *Prefix) Right() Expression
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program represents a complete program.
func NewProgram ¶ added in v0.0.13
func (*Program) Statements ¶
type Range ¶ added in v0.0.13
type Range struct {
// contains filtered or unexported fields
}
Range is used to iterator over a container
func (*Range) Container ¶ added in v0.0.13
func (r *Range) Container() Expression
func (*Range) ExpressionNode ¶ added in v0.0.13
func (r *Range) ExpressionNode()
type Set ¶ added in v0.0.13
type Set struct {
// contains filtered or unexported fields
}
Set holds a set definition
func (*Set) ExpressionNode ¶ added in v0.0.13
func (s *Set) ExpressionNode()
func (*Set) Items ¶ added in v0.0.13
func (s *Set) Items() []Expression
type Slice ¶ added in v0.0.13
type Slice struct {
// contains filtered or unexported fields
}
Index holds an index expression
func NewSlice ¶ added in v0.0.13
func NewSlice(token token.Token, left Expression, fromIndex Expression, toIndex Expression) *Slice
func (*Slice) ExpressionNode ¶ added in v0.0.13
func (i *Slice) ExpressionNode()
func (*Slice) FromIndex ¶ added in v0.0.13
func (i *Slice) FromIndex() Expression
func (*Slice) Left ¶ added in v0.0.13
func (i *Slice) Left() Expression
func (*Slice) ToIndex ¶ added in v0.0.13
func (i *Slice) ToIndex() Expression
type String ¶ added in v0.0.13
type String struct {
// contains filtered or unexported fields
}
String holds a string
func NewTemplatedString ¶ added in v0.0.13
func (*String) ExpressionNode ¶ added in v0.0.13
func (s *String) ExpressionNode()
func (*String) TemplateExpressions ¶ added in v0.0.13
func (s *String) TemplateExpressions() []Expression
type Switch ¶ added in v0.0.13
type Switch struct {
// contains filtered or unexported fields
}
Switch represents a switch statement and its cases
func NewSwitch ¶ added in v0.0.13
func NewSwitch(token token.Token, value Expression, choices []*Case) *Switch
func (*Switch) ExpressionNode ¶ added in v0.0.13
func (s *Switch) ExpressionNode()
func (*Switch) Value ¶ added in v0.0.13
func (s *Switch) Value() Expression
type Ternary ¶ added in v0.0.13
type Ternary struct {
// contains filtered or unexported fields
}
Ternary holds a ternary expression.
func NewTernary ¶ added in v0.0.13
func NewTernary(token token.Token, condition Expression, ifTrue Expression, ifFalse Expression) *Ternary
func (*Ternary) Condition ¶ added in v0.0.13
func (t *Ternary) Condition() Expression
func (*Ternary) ExpressionNode ¶ added in v0.0.13
func (t *Ternary) ExpressionNode()
func (*Ternary) IfFalse ¶ added in v0.0.13
func (t *Ternary) IfFalse() Expression
func (*Ternary) IfTrue ¶ added in v0.0.13
func (t *Ternary) IfTrue() Expression
type Var ¶ added in v0.0.13
type Var struct {
// contains filtered or unexported fields
}
Var holds a variable declaration statement.
func NewDeclaration ¶ added in v0.0.13
func NewDeclaration(token token.Token, name *Ident, value Expression) *Var
func (*Var) StatementNode ¶ added in v0.0.13
func (s *Var) StatementNode()
func (*Var) Value ¶ added in v0.0.13
func (s *Var) Value() (string, Expression)