ast

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package ast provides structures for representing parsed source code.

The structures in this package will be initialized from the parser package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Type string
}

Argument is used to define a name and type for a function argument.

type Array

type Array struct {
	Kind     string
	Elements []Node
}

Array is zero or more elements.

func NewArrayNumbers

func NewArrayNumbers(values []string) *Array

NewArrayNumbers creates an Array with some number literal values.

type Assert

type Assert struct {
	Expr *Binary
}

Assert is used in tests.

type Assign

type Assign struct {
	// There will always be at least one Lefts element.
	Lefts []Node

	// There may be one Right element, or the same number of elements as Lefts.
	Rights []Node
}

Assign is a specific case of Binary, just for "=".

type Binary

type Binary struct {
	// Op is TokenPlus, TokenMinusAssign, etc. It will never be TokenAssign,
	// this special case is handled in an Assign operation.
	Op string

	Left, Right Node
}

Binary is an binary operator operation.

func NewBinary

func NewBinary(left Node, op string, right Node) *Binary

NewBinary creates a binary operation.

type Break

type Break struct{}

Break represents a "break" statement.

type Call

type Call struct {
	// FunctionName is the name of the function being invoked.
	FunctionName string

	// Arguments contains zero or more elements that represent each of the
	// arguments respectively.
	Arguments []Node
}

Call represents a function call with zero or more arguments.

func NewCall

func NewCall(functionName string, arguments ...Node) *Call

NewCall produces a new call to functionName with any number of arguments.

type Case

type Case struct {
	// Conditions will always contain at least one element.
	Conditions []Node

	// Statements may be nil.
	Statements []Node
}

Case represents a switch case statement.

type Comment

type Comment struct {
	Comment string
}

Comment represents a single line comment. All characters immediately following `//` are part of the comment (even the proceeding space) upto but not including the new line.

type Continue

type Continue struct{}

Continue represents a "continue" statement.

type For

type For struct {
	// All of Init, Condition and Next may be nil.
	Init, Condition, Next Node

	// Statements may be nil.
	Statements []Node
}

For represents a for loop.

type Func

type Func struct {
	// Name is the name of the function being declared.
	Name string

	// Arguments may contain zero or more elements. They will always be in the
	// order in which their are declared.
	Arguments []*Argument

	// Returns may contain zero or more types. They will always be in the order
	// in which they are declared.
	Returns []string

	// Statements can have zero or more elements for each of the ordered
	// discreet statements in the function.
	Statements []Node
}

Func represents the definition of a function.

type Group

type Group struct {
	Expr Node
}

Group is an expression wrapped in "()".

type Identifier

type Identifier struct {
	Name string
}

Identifier could refer to a variable, function, etc.

type If

type If struct {
	Condition Node

	// Either or both is allowed to be nil.
	True, False []Node
}

If represents an if/else combination.

type Import

type Import struct {
	PackageName string
}

Import is used to include packages.

type In

type In struct {
	Key, Value string
	Expr       Node
}

In represents an "in" expression in for loops.

type Key

type Key struct {
	Expr Node
	Key  Node
}

Key returns the value based on the index.

type KeyValue

type KeyValue struct {
	Key, Value Node
}

KeyValue represents a key-value pair used in maps and object initialization.

type Literal

type Literal struct {
	Kind  string
	Value string

	// Array is also used to hold the keys of the map. This is required for
	// iteration.
	Array []*Literal

	Map map[string]*Literal
}

Literal represents a literal of any type.

func NewLiteralBool

func NewLiteralBool(b bool) *Literal

NewLiteralBool create a new literal representing a boolean value.

func NewLiteralChar

func NewLiteralChar(c rune) *Literal

NewLiteralChar create a new literal representing a character value.

func NewLiteralData

func NewLiteralData(data []byte) *Literal

NewLiteralData create a new literal representing a data value.

func NewLiteralNumber

func NewLiteralNumber(number string) *Literal

NewLiteralNumber create a new literal representing a number value.

func NewLiteralString

func NewLiteralString(str string) *Literal

NewLiteralString create a new literal representing a string value.

type Map

type Map struct {
	Kind     string
	Elements []*KeyValue
}

Map is zero or more elements.

func NewMapNumbers

func NewMapNumbers(values map[string]string) *Map

NewMapNumbers creates a Map with some number literal values. This function is for convenience and should not be used for general production code.

type Node

type Node interface{}

Node is the interface for all ast structures.

type Return

type Return struct {
	// Exprs can be zero or more elements.
	Exprs []Node
}

Return is a statement to return values.

type Switch

type Switch struct {
	// Expr may be nil.
	Expr Node

	// Cases may be nil.
	Cases []*Case

	// Else may be nil.
	Else []Node
}

Switch represents a switch statement.

type Test

type Test struct {
	Name       string
	Statements []Node
}

Test is a named test.

type Unary

type Unary struct {
	// Op is TokenMinus, TokenNot, TokenIncrement or TokenDecrement.
	Op string

	Expr Node
}

Unary is an unary operator operation.

Jump to

Keyboard shortcuts

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