ast

package
v0.0.0-...-4b41b39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ast contains types that are contained within the abstract syntax tree for the language

Index

Constants

View Source
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.

func (*AST) String

func (ast *AST) String() string

type ArrayLiteral

type ArrayLiteral struct {
	Token    *token.Token
	Elements []Node
}

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

type AsyncStatement struct {
	Token *token.Token
	Value Node
}

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

type AwaitStatement struct {
	Token *token.Token
	Value Node
}

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

type BlockStatement struct {
	Token      *token.Token
	Statements []Node
}

The BlockStatement type represents statements wrapped in braces.

func (*BlockStatement) String

func (bl *BlockStatement) String() string

type BooleanLiteral

type BooleanLiteral struct {
	Token *token.Token
	Value bool
}

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

type CallExpression struct {
	Token     *token.Token
	Function  Node
	Arguments []Node
	Awaited   bool
}

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

type CharacterLiteral struct {
	Token *token.Token
	Value rune
}

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 Comment

type Comment struct {
	Token *token.Token
	Value string
}

The Comment type represents a comment in the source code.

func (*Comment) String

func (cm *Comment) 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

type ExpressionStatement struct {
	Token      *token.Token
	Expression Node
}

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

type HashLiteral struct {
	Token *token.Token
	Pairs map[Node]Node
}

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

type Identifier struct {
	Token *token.Token
	Value string
}

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

type IndexExpression struct {
	Token *token.Token
	Left  Node
	Index Node
}

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

type InfixExpression struct {
	Token    *token.Token
	Left     Node
	Operator string
	Right    Node
}

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

type NumberLiteral struct {
	Token *token.Token
	Value float64
}

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

type PrefixExpression struct {
	Token    *token.Token
	Operator string
	Right    Node
}

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

type ReturnStatement struct {
	Token       *token.Token
	ReturnValue Node
}

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

type StringLiteral struct {
	Token *token.Token
	Value string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL