Documentation ¶
Overview ¶
Package ast contains types that are contained within the abstract syntax tree for the language
Index ¶
- Constants
- type AST
- type ArrayLiteral
- type AsyncStatement
- type AtomicStatement
- type AwaitStatement
- type BlockStatement
- type BooleanLiteral
- type CallExpression
- type CharacterLiteral
- type Comment
- type ConstStatement
- type ExpressionStatement
- type FunctionLiteral
- type HashLiteral
- type Identifier
- type IfExpression
- type IndexExpression
- type InfixExpression
- type Node
- type NumberLiteral
- type PostfixExpression
- type PrefixExpression
- type ReturnStatement
- type StringLiteral
- type VarStatement
Constants ¶
const ( // NodeTypeStatement denotes a statement node NodeTypeStatement = iota // NodeTypeExpression denotes an expression node NodeTypeExpression // NodeTypeAST denotes the root node of an AST NodeTypeAST )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AST ¶
type AST struct {
Nodes []Node
}
The AST type contains the tree representation of the source code.
type ArrayLiteral ¶
The ArrayLiteral type represents a literal array object in source code. For example: const arr = [1, 2, 3, 4]
func (*ArrayLiteral) String ¶
func (al *ArrayLiteral) String() string
type AsyncStatement ¶
The AsyncStatement type represents an async function declaration in therce code.
Example: async func add(a, b) { return a + b }
func (*AsyncStatement) String ¶
func (as *AsyncStatement) String() string
type AtomicStatement ¶
type AtomicStatement struct { Token *token.Token Name *Identifier Value Node }
The AtomicStatement type represents a atomicant variable assignment in the source code.
Example:
atomic x = 1
func (*AtomicStatement) String ¶
func (vs *AtomicStatement) String() string
type AwaitStatement ¶
The AwaitStatement type represents an awaited call in the source code
Example: await add(1, 2)
func (*AwaitStatement) String ¶
func (aw *AwaitStatement) String() string
type BlockStatement ¶
The BlockStatement type represents statements wrapped in braces.
func (*BlockStatement) String ¶
func (bl *BlockStatement) String() string
type BooleanLiteral ¶
The BooleanLiteral type represents a literal bool within the source code. For example, in a variable assignment:
var x = true
func (*BooleanLiteral) String ¶
func (bl *BooleanLiteral) String() string
type CallExpression ¶
The CallExpression type represents a function call in the abstract syntax tree. For example: add(1, 2)
func (*CallExpression) String ¶
func (ce *CallExpression) String() string
type CharacterLiteral ¶
The CharacterLiteral type represents a literal character within the source code. For example, in a variable assignment:
var x = 't'
The literal value of 't' is stored in the CharacterLiteral type.
func (*CharacterLiteral) String ¶
func (cl *CharacterLiteral) String() string
type ConstStatement ¶
type ConstStatement struct { Token *token.Token Name *Identifier Value Node }
The ConstStatement type represents a constant variable assignment in the source code.
Example:
const x = 1
func (*ConstStatement) String ¶
func (vs *ConstStatement) String() string
type ExpressionStatement ¶
The ExpressionStatement type represents a statement in the source code that contains an expression. For example, assigning a value to an existing variable:
a = 1
func (*ExpressionStatement) String ¶
func (es *ExpressionStatement) String() string
type FunctionLiteral ¶
type FunctionLiteral struct { Token *token.Token Name *Identifier Parameters []*Identifier Body *BlockStatement }
The FunctionLiteral type represents a function declaration in the abstract syntax tree. For example: function add(a, b) { return a + b }
func (*FunctionLiteral) String ¶
func (fl *FunctionLiteral) String() string
type HashLiteral ¶
The HashLiteral type represents a literal hash object in source code. For example:
const hash = { "a": "b", "b": "c" }
func (*HashLiteral) String ¶
func (hl *HashLiteral) String() string
type Identifier ¶
The Identifier type represents an identifier in source code. For example, a variable name or keyword.
func (*Identifier) String ¶
func (i *Identifier) String() string
type IfExpression ¶
type IfExpression struct { Token *token.Token Condition Node Consequence *BlockStatement Alternative *BlockStatement }
The IfExpression type represents an if statement in the source code. It consists of a condition, consequence and optional consequence. For example: if (a == 0) { <-- Condition
return -1 <-- Consequence } else {
return a <-- Alternative }
func (*IfExpression) String ¶
func (ie *IfExpression) String() string
type IndexExpression ¶
The IndexExpression type represents an index expression in the source code. For example: var test = "test" var e = test[1]
func (*IndexExpression) String ¶
func (ie *IndexExpression) String() string
type InfixExpression ¶
The InfixExpression type represents an infix expression in the source code. This is where an operator exists between two expressions, such as 1 + 1 or 2 * 2.
func (*InfixExpression) String ¶
func (ie *InfixExpression) String() string
type Node ¶
type Node interface {
String() string
}
The Node interface defines methods used by types that can be found in the abstract syntax tree.
type NumberLiteral ¶
The NumberLiteral type represents a literal number within the source code. For example, in a variable assignment:
var x = 1
The literal value of '1' is stored in the NumberLiteral type.
func (*NumberLiteral) String ¶
func (nl *NumberLiteral) String() string
type PostfixExpression ¶
type PostfixExpression struct { Token *token.Token Left *Identifier Operator string }
The PostfixExpression type represents a postfix expression in the source code. For example: var a = 1 a++ a--
func (*PostfixExpression) String ¶
func (pe *PostfixExpression) String() string
type PrefixExpression ¶
The PrefixExpression type represents a prefix expression within the source code. For example: var a = true var b = !a
func (*PrefixExpression) String ¶
func (pe *PrefixExpression) String() string
type ReturnStatement ¶
The ReturnStatement type represents a return statement in the abstract syntax tree. For example return 1 + 1
func (*ReturnStatement) String ¶
func (rs *ReturnStatement) String() string
type StringLiteral ¶
The StringLiteral type represents a literal string within the source code. For example, in a variable assignment:
var x = "test"
The literal value of 'test' is stored in the StringLiteral type.
func (*StringLiteral) String ¶
func (nl *StringLiteral) String() string
type VarStatement ¶
type VarStatement struct { Token *token.Token Name *Identifier Value Node }
The VarStatement type represents a mutable variable assignment in the source code.
Example:
var x = 1
func (*VarStatement) String ¶
func (vs *VarStatement) String() string
Source Files ¶
- array_literal.go
- ast.go
- async_statement.go
- atomic_statement.go
- await_statement.go
- block_statement.go
- boolean_literal.go
- call_expression.go
- character_literal.go
- comment.go
- const_statement.go
- expression_statement.go
- function_literal.go
- hash_literal.go
- identifier.go
- if_expression.go
- index_expression.go
- infix_expression.go
- number_literal.go
- postfix_expression.go
- prefix_expression.go
- return_statement.go
- string_literal.go
- var_statement.go