ast

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: MIT Imports: 1 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
	Pos      string
}

Array is zero or more elements.

func (*Array) Position added in v0.13.1

func (node *Array) Position() string

Position returns the position.

type Assert

type Assert struct {
	Expr *Binary
	Pos  string
}

Assert is used in tests.

func (*Assert) Position added in v0.13.1

func (node *Assert) Position() string

Position returns the position.

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 "=".

func (*Assign) Position added in v0.13.1

func (node *Assign) Position() string

Position returns the position.

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 (*Binary) Position added in v0.13.1

func (node *Binary) Position() string

Position returns the position.

type Break

type Break struct {
	Pos string
}

Break represents a "break" statement.

func (*Break) Position added in v0.13.1

func (node *Break) Position() string

Position returns the position.

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

	Pos string
}

Call represents a function call with zero or more arguments.

func (*Call) Position added in v0.13.1

func (node *Call) Position() string

Position returns the position.

type Case

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

	// Statements may be nil.
	Statements []Node

	Pos string
}

Case represents a switch case statement.

func (*Case) Position added in v0.13.1

func (node *Case) Position() string

Position returns the position.

type Comment

type Comment struct {
	Comment string

	// Func will be the name of the function this comment is attached to;
	// otherwise it will be empty.
	Func string

	Pos string
}

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

func (*Comment) Position added in v0.13.1

func (c *Comment) Position() string

Position returns the position.

func (*Comment) String added in v0.12.0

func (c *Comment) String() string

String returns the cleaner presentation version of the comment.

type Continue

type Continue struct {
	Pos string
}

Continue represents a "continue" statement.

func (*Continue) Position added in v0.13.1

func (node *Continue) Position() string

Position returns the position.

type For

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

	// Statements may be nil.
	Statements []Node

	Pos string
}

For represents a for loop.

func (*For) Position added in v0.13.1

func (node *For) Position() string

Position returns the position.

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

	Pos string
}

Func represents the definition of a function.

func (*Func) Position added in v0.13.1

func (f *Func) Position() string

Position returns the position.

func (*Func) Signature added in v0.12.0

func (f *Func) Signature() string

Signature returns the signature, like `Foo(x number, y number)`.

func (*Func) String added in v0.12.0

func (f *Func) String() string

String returns the signature, like `func Foo(x number, y number)`.

type Group

type Group struct {
	Expr Node
	Pos  string
}

Group is an expression wrapped in "()".

func (*Group) Position added in v0.13.1

func (node *Group) Position() string

Position returns the position.

type Identifier

type Identifier struct {
	Name string
	Pos  string
}

Identifier could refer to a variable, function, etc.

func (*Identifier) Position added in v0.13.1

func (node *Identifier) Position() string

Position returns the position.

type If

type If struct {
	Condition Node

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

	Pos string
}

If represents an if/else combination.

func (*If) Position added in v0.13.1

func (node *If) Position() string

Position returns the position.

type Import

type Import struct {
	PackageName string
	Pos         string
}

Import is used to include packages.

func (*Import) Position added in v0.13.1

func (node *Import) Position() string

Position returns the position.

type In

type In struct {
	Key, Value string
	Expr       Node
	Pos        string
}

In represents an "in" expression in for loops.

func (*In) Position added in v0.13.1

func (node *In) Position() string

Position returns the position.

type Key

type Key struct {
	Expr Node
	Key  Node
	Pos  string
}

Key returns the value based on the index.

func (*Key) Position added in v0.13.1

func (node *Key) Position() string

Position returns the position.

type KeyValue

type KeyValue struct {
	Key, Value Node
}

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

func (*KeyValue) Position added in v0.13.1

func (node *KeyValue) Position() string

Position returns the position.

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

	Pos string
}

Literal represents a literal of any type.

func (*Literal) Position added in v0.13.1

func (node *Literal) Position() string

Position returns the position.

type Map

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

Map is zero or more elements.

func (*Map) Position added in v0.13.1

func (node *Map) Position() string

Position returns the position.

type Node

type Node interface {
	Position() string
}

Node is the interface for all ast structures.

type Return

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

Return is a statement to return values.

func (*Return) Position added in v0.13.1

func (node *Return) Position() string

Position returns the position.

type Switch

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

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

	// Else may be nil.
	Else []Node

	Pos string
}

Switch represents a switch statement.

func (*Switch) Position added in v0.13.1

func (node *Switch) Position() string

Position returns the position.

type Test

type Test struct {
	Name       string
	Statements []Node
	Pos        string
}

Test is a named test.

func (*Test) Position added in v0.13.1

func (node *Test) Position() string

Position returns the position.

type Unary

type Unary struct {
	// Op is TokenMinus, TokenNot, TokenIncrement or TokenDecrement.
	Op   string
	Expr Node
	Pos  string
}

Unary is an unary operator operation.

func (*Unary) Position added in v0.13.1

func (node *Unary) Position() string

Position returns the position.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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