Documentation
¶
Overview ¶
Package ast defines abstract syntax tree types that represent Tamarin code.
Index ¶
- type Assign
- func (a *Assign) Index() *Index
- func (a *Assign) IsExpression() bool
- func (a *Assign) Literal() string
- func (a *Assign) Name() string
- func (a *Assign) Operator() string
- func (a *Assign) StatementNode()
- func (a *Assign) String() string
- func (a *Assign) Token() token.Token
- func (a *Assign) Value() Expression
- 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) Init() Node
- func (f *For) IsExpression() bool
- func (f *For) IsIteratorLoop() bool
- func (f *For) IsSimpleLoop() bool
- func (f *For) Literal() string
- func (f *For) Post() Node
- func (f *For) StatementNode()
- func (f *For) String() string
- func (f *For) Token() token.Token
- type Func
- func (f *Func) Body() *Block
- func (f *Func) Defaults() map[string]Expression
- func (f *Func) ExpressionNode()
- func (f *Func) IsExpression() bool
- func (f *Func) Literal() string
- func (f *Func) Name() *Ident
- func (f *Func) ParameterNames() []string
- func (f *Func) Parameters() []*Ident
- func (f *Func) String() string
- func (f *Func) Token() token.Token
- 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
- func (s *String) ExpressionNode()
- func (s *String) IsExpression() bool
- func (s *String) Literal() string
- func (s *String) String() string
- func (s *String) Template() *tmpl.Template
- func (s *String) TemplateExpressions() []Expression
- func (s *String) Token() token.Token
- func (s *String) Value() 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 ¶
type Assign struct {
// contains filtered or unexported fields
}
Assign is a statement node used to describe a variable assignment.
func NewAssign ¶
func NewAssign(operator token.Token, name *Ident, value Expression) *Assign
NewAssign creates a new Assign node.
func NewAssignIndex ¶
func NewAssignIndex(operator token.Token, index *Index, value Expression) *Assign
NewAssignIndex creates a new Assign node for an index assignment.
func (*Assign) IsExpression ¶
func (*Assign) StatementNode ¶
func (a *Assign) StatementNode()
func (*Assign) Value ¶
func (a *Assign) Value() Expression
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block is a node that holds a sequence of statements. This is used to represent the body of a function, loop, or a conditional.
func (*Block) EndsWithReturn ¶
func (*Block) IsExpression ¶
func (*Block) StatementNode ¶
func (b *Block) StatementNode()
func (*Block) Statements ¶
type Bool ¶
type Bool struct {
// contains filtered or unexported fields
}
Bool is an expression node that holds a boolean literal.
func (*Bool) ExpressionNode ¶
func (b *Bool) ExpressionNode()
func (*Bool) IsExpression ¶
type Call ¶
type Call struct {
// contains filtered or unexported fields
}
Call is an expression node that describes the invocation of a function.
func NewCall ¶
func NewCall(token token.Token, function Expression, arguments []Node) *Call
NewCall creates a new Call node.
func (*Call) ExpressionNode ¶
func (c *Call) ExpressionNode()
func (*Call) Function ¶
func (c *Call) Function() Expression
func (*Call) IsExpression ¶
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case is an expression node that describes one case within a switch expression.
func NewCase ¶
func NewCase(token token.Token, expressions []Expression, block *Block) *Case
NewCase creates a new Case node.
func NewDefaultCase ¶
NewDefaultCase represents the default case within a switch expression.
func (*Case) ExpressionNode ¶
func (c *Case) ExpressionNode()
func (*Case) Expressions ¶
func (c *Case) Expressions() []Expression
func (*Case) IsExpression ¶
type Const ¶
type Const struct {
// contains filtered or unexported fields
}
Const is a statement that defines a named constant.
func NewConst ¶
func NewConst(token token.Token, name *Ident, value Expression) *Const
NewConst creates a new Const node.
func (*Const) IsExpression ¶
func (*Const) StatementNode ¶
func (c *Const) StatementNode()
func (*Const) Value ¶
func (c *Const) Value() (string, Expression)
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Control defines a return, break, or continue statement.
func NewControl ¶
func NewControl(token token.Token, value Expression) *Control
NewControl creates a new Control node.
func (*Control) IsExpression ¶
func (*Control) StatementNode ¶
func (c *Control) StatementNode()
func (*Control) Value ¶
func (c *Control) Value() Expression
type Expression ¶
type Expression interface {
// Node is embedded here to indicate that all expressions are AST nodes.
Node
// ExpressionNode signals that this Node is an expression.
ExpressionNode()
}
Expression represents a snippet of Tamarin code that evaluates to a value. Expressions may be embedded within other expressions.
type Float ¶
type Float struct {
// contains filtered or unexported fields
}
Float is an expression node that holds a floating point literal.
func (*Float) ExpressionNode ¶
func (f *Float) ExpressionNode()
func (*Float) IsExpression ¶
type For ¶
type For struct {
// contains filtered or unexported fields
}
For is a statement node that defines a for loop.
func NewSimpleFor ¶
NewSimpleFor creates a new For node with no condition, init, or post.
func (*For) Consequence ¶
func (*For) IsExpression ¶
func (*For) IsIteratorLoop ¶
func (*For) IsSimpleLoop ¶
func (*For) StatementNode ¶
func (f *For) StatementNode()
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func is an expression node that holds a function literal.
func NewFunc ¶
func NewFunc(token token.Token, name *Ident, parameters []*Ident, defaults map[string]Expression, body *Block) *Func
NewFunc creates a new Func node.
func (*Func) Defaults ¶
func (f *Func) Defaults() map[string]Expression
func (*Func) ExpressionNode ¶
func (f *Func) ExpressionNode()
func (*Func) IsExpression ¶
func (*Func) ParameterNames ¶
func (*Func) Parameters ¶
type GetAttr ¶
type GetAttr struct {
// contains filtered or unexported fields
}
GetAttr is an expression node that describes the access of an attribute on an object.
func NewGetAttr ¶
func NewGetAttr(token token.Token, object Expression, attribute *Ident) *GetAttr
NewGetAttr creates a new GetAttr node.
func (*GetAttr) ExpressionNode ¶
func (e *GetAttr) ExpressionNode()
func (*GetAttr) IsExpression ¶
func (*GetAttr) Object ¶
func (e *GetAttr) Object() Expression
type Ident ¶
type Ident struct {
// contains filtered or unexported fields
}
Ident is an expression node that refers to a variable by name.
func (*Ident) ExpressionNode ¶
func (i *Ident) ExpressionNode()
func (*Ident) IsExpression ¶
type If ¶
type If struct {
// contains filtered or unexported fields
}
If is an expression node that represents an if/else expression
func (*If) Alternative ¶
func (*If) Condition ¶
func (i *If) Condition() Expression
func (*If) Consequence ¶
func (*If) ExpressionNode ¶
func (i *If) ExpressionNode()
func (*If) IsExpression ¶
type Import ¶
type Import struct {
// contains filtered or unexported fields
}
Import is a statement node that describes a module import statement.
func (*Import) IsExpression ¶
func (*Import) StatementNode ¶
func (i *Import) StatementNode()
type In ¶
type In struct {
// contains filtered or unexported fields
}
In is an expression node that checks whether a value is present in a container.
func NewIn ¶
func NewIn(token token.Token, left Expression, right Expression) *In
NewIn creates a new In node.
func (*In) ExpressionNode ¶
func (i *In) ExpressionNode()
func (*In) IsExpression ¶
func (*In) Left ¶
func (i *In) Left() Expression
func (*In) Right ¶
func (i *In) Right() Expression
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index as an expression node that describes indexing on an object.
func NewIndex ¶
func NewIndex(token token.Token, left Expression, index Expression) *Index
NewIndex creates a new Index node.
func (*Index) ExpressionNode ¶
func (i *Index) ExpressionNode()
func (*Index) Index ¶
func (i *Index) Index() Expression
func (*Index) IsExpression ¶
func (*Index) Left ¶
func (i *Index) Left() Expression
type Infix ¶
type Infix struct {
// contains filtered or unexported fields
}
Infix is an operator expression where the operator is between the operands. Examples include "x + y" and "5 - 1".
func NewInfix ¶
func NewInfix(token token.Token, left Expression, operator string, right Expression) *Infix
NewInfix creates a new Infix node.
func (*Infix) ExpressionNode ¶
func (i *Infix) ExpressionNode()
func (*Infix) IsExpression ¶
func (*Infix) Left ¶
func (i *Infix) Left() Expression
func (*Infix) Right ¶
func (i *Infix) Right() Expression
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int is an expression node that holds an integer literal.
func (*Int) ExpressionNode ¶
func (i *Int) ExpressionNode()
func (*Int) IsExpression ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is an expression node that builds a list data structure.
func NewList ¶
func NewList(tok token.Token, items []Expression) *List
NewList creates a new List node.
func (*List) ExpressionNode ¶
func (l *List) ExpressionNode()
func (*List) IsExpression ¶
func (*List) Items ¶
func (l *List) Items() []Expression
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is an expression node that builds a map data structure.
func NewMap ¶
func NewMap(token token.Token, items map[Expression]Expression) *Map
NewMap creates a new Map node.
func (*Map) ExpressionNode ¶
func (m *Map) ExpressionNode()
func (*Map) IsExpression ¶
func (*Map) Items ¶
func (m *Map) Items() map[Expression]Expression
type MultiVar ¶
type MultiVar struct {
// contains filtered or unexported fields
}
MultiVar is a statement that assigns values to more than one variable. The right hand side must be a container type, with the same number of elements as the number of variables on the left hand side.
func NewMultiVar ¶
func (*MultiVar) IsExpression ¶
func (*MultiVar) StatementNode ¶
func (s *MultiVar) StatementNode()
func (*MultiVar) Value ¶
func (s *MultiVar) Value() ([]string, Expression)
type Nil ¶
type Nil struct {
// contains filtered or unexported fields
}
Nil is an expression node that holds a nil literal.
func (*Nil) ExpressionNode ¶
func (n *Nil) ExpressionNode()
func (*Nil) IsExpression ¶
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
// IsExpression returns true if this Node evalutes to a value.
IsExpression() bool
}
Node reresents a portion of the syntax tree. All nodes have a token, which is the token that begins the node. A Node may be an Expression, in which case it evaluates to a value.
type ObjectCall ¶
type ObjectCall struct {
// contains filtered or unexported fields
}
ObjectCall is an expression node that describes the invocation of a method on an object.
func NewObjectCall ¶
func NewObjectCall(token token.Token, object Expression, call Expression) *ObjectCall
NewObjectCall creates a new ObjectCall node.
func (*ObjectCall) Call ¶
func (c *ObjectCall) Call() Expression
func (*ObjectCall) ExpressionNode ¶
func (c *ObjectCall) ExpressionNode()
func (*ObjectCall) IsExpression ¶
func (c *ObjectCall) IsExpression() bool
func (*ObjectCall) Literal ¶
func (c *ObjectCall) Literal() string
func (*ObjectCall) Object ¶
func (c *ObjectCall) Object() Expression
func (*ObjectCall) String ¶
func (c *ObjectCall) String() string
func (*ObjectCall) Token ¶
func (c *ObjectCall) Token() token.Token
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe is an expression node that describes a sequence of transformations applied to an initial value.
func NewPipe ¶
func NewPipe(token token.Token, exprs []Expression) *Pipe
NewPipe creates a new Pipe node.
func (*Pipe) ExpressionNode ¶
func (p *Pipe) ExpressionNode()
func (*Pipe) Expressions ¶
func (p *Pipe) Expressions() []Expression
func (*Pipe) IsExpression ¶
type Postfix ¶
type Postfix struct {
// contains filtered or unexported fields
}
Postfix is a statement node that describes a postfix expression like "x++".
func NewPostfix ¶
NewPostfix creates a new Postfix node.
func (*Postfix) IsExpression ¶
func (*Postfix) StatementNode ¶
func (p *Postfix) StatementNode()
type Prefix ¶
type Prefix struct {
// contains filtered or unexported fields
}
Prefix is an operator expression where the operator precedes the operand. Examples include "!false" and "-x".
func NewPrefix ¶
func NewPrefix(token token.Token, right Expression) *Prefix
NewPrefix creates a new Prefix node.
func (*Prefix) ExpressionNode ¶
func (p *Prefix) ExpressionNode()
func (*Prefix) IsExpression ¶
func (*Prefix) Right ¶
func (p *Prefix) Right() Expression
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program represents a complete Tamarin program, which consists of a series of statements.
func NewProgram ¶
func (*Program) IsExpression ¶
func (*Program) Statements ¶
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range is an expression node that describes iterating over a container.
func (*Range) ExpressionNode ¶
func (r *Range) ExpressionNode()
func (*Range) IsExpression ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is an expression node that builds a set data structure.
func NewSet ¶
func NewSet(token token.Token, items []Expression) *Set
NewSet creates a new Set node.
func (*Set) ExpressionNode ¶
func (s *Set) ExpressionNode()
func (*Set) IsExpression ¶
func (*Set) Items ¶
func (s *Set) Items() []Expression
type Slice ¶
type Slice struct {
// contains filtered or unexported fields
}
Slice is an expression node that describes a slicing operation on an object.
func NewSlice ¶
func NewSlice(token token.Token, left Expression, fromIndex Expression, toIndex Expression) *Slice
NewSlice creates a new Slice node.
func (*Slice) ExpressionNode ¶
func (s *Slice) ExpressionNode()
func (*Slice) FromIndex ¶
func (s *Slice) FromIndex() Expression
func (*Slice) IsExpression ¶
func (*Slice) Left ¶
func (s *Slice) Left() Expression
func (*Slice) ToIndex ¶
func (s *Slice) ToIndex() Expression
type Statement ¶
type Statement interface {
// Node is embedded here to indicate that all statements are AST nodes.
Node
// StatementNode signals that this Node is a statement.
StatementNode()
}
Statement represents a snippet of Tamarin code that causes a side effect, but does not evaluate to a value.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an expression node that holds a string literal.
func NewTemplatedString ¶
NewTemplatedString creates a new String node defined by a template.
func (*String) ExpressionNode ¶
func (s *String) ExpressionNode()
func (*String) IsExpression ¶
func (*String) TemplateExpressions ¶
func (s *String) TemplateExpressions() []Expression
type Switch ¶
type Switch struct {
// contains filtered or unexported fields
}
Switch is an expression node that describes a switch between multiple cases.
func NewSwitch ¶
func NewSwitch(token token.Token, value Expression, choices []*Case) *Switch
NewSwitch creates a new Switch node.
func (*Switch) ExpressionNode ¶
func (s *Switch) ExpressionNode()
func (*Switch) IsExpression ¶
func (*Switch) Value ¶
func (s *Switch) Value() Expression
type Ternary ¶
type Ternary struct {
// contains filtered or unexported fields
}
Ternary is an expression node that defines a ternary expression and evaluates to one of two values based on a condition.
func NewTernary ¶
func NewTernary(token token.Token, condition Expression, ifTrue Expression, ifFalse Expression) *Ternary
NewTernary creates a new Ternary node.
func (*Ternary) Condition ¶
func (t *Ternary) Condition() Expression
func (*Ternary) ExpressionNode ¶
func (t *Ternary) ExpressionNode()
func (*Ternary) IfFalse ¶
func (t *Ternary) IfFalse() Expression
func (*Ternary) IfTrue ¶
func (t *Ternary) IfTrue() Expression
func (*Ternary) IsExpression ¶
type Var ¶
type Var struct {
// contains filtered or unexported fields
}
Var is a statement that assigns a value to a variable. It may be a declaration or an assignment. If it's a declaration, isWalrus is true.
func NewDeclaration ¶
func NewDeclaration(token token.Token, name *Ident, value Expression) *Var
NewDeclaration creates a new Var node that is a declaration.
func NewVar ¶
func NewVar(token token.Token, name *Ident, value Expression) *Var
NewVar creates a new Var node.
func (*Var) IsExpression ¶
func (*Var) StatementNode ¶
func (s *Var) StatementNode()
func (*Var) Value ¶
func (s *Var) Value() (string, Expression)