ast

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: MIT Imports: 5 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

func TypeOf added in v0.17.8

func TypeOf(node Node) (*types.Type, error)

Types

type Argument

type Argument struct {
	Name string
	Type *types.Type
}

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

func (*Argument) String added in v0.17.8

func (arg *Argument) String() string

type Array

type Array struct {
	Kind     *types.Type
	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 for the `assert(BinaryExpr)` syntax.

func (*Assert) Position added in v0.13.1

func (node *Assert) Position() string

Position returns the position.

type AssertRaise added in v0.20.2

type AssertRaise struct {
	Call        *Call
	TypeOrValue Node
	Pos         string
}

AssertRaise is for the `assert(Call raise TypeOrValue)` syntax.

func (*AssertRaise) Position added in v0.20.2

func (node *AssertRaise) 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 {
	// Expr is the expression that returns the function to be called.
	Expr Node

	// 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 ErrorScope added in v0.15.0

type ErrorScope struct {
	// Statements is what will be run in this scope. It is allowed to be nil.
	Statements []Node

	// On can have zero or more elements.
	On []*On

	Pos string

	// Finally is optional. An empty finally block and no finally block are
	// treated the same way.
	Finally *Finally
}

ErrorScope represents the try/on error scope.

func (*ErrorScope) Position added in v0.15.0

func (node *ErrorScope) Position() string

Position returns the position.

type Finally added in v0.15.3

type Finally struct {
	// Index is the unique counter for each finally block in this function. It
	// is used to activate and deactivate finally blocks by the VM at runtime.
	Index int

	// Statement may be nil.
	Statements []Node

	Pos string
}

Finally will always be called on success or failure.

func (*Finally) Position added in v0.15.3

func (node *Finally) 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

	// All functions have a unique name assigned to them so they can be
	// referenced by the VM.
	UniqueName 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 []*types.Type

	// 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) Interface added in v0.17.8

func (f *Func) Interface() (map[string]*types.Type, error)

TODO(elliot): Deprecated. This shouldn't be part of the public API. Use

Type() instead.

func (*Func) IsConstructor added in v0.17.8

func (f *Func) IsConstructor() bool

func (*Func) Position added in v0.13.1

func (f *Func) Position() string

Position returns the position.

func (*Func) String added in v0.12.0

func (f *Func) String() string

String returns the signature, like:

func Foo(x number, y number) (string, string)

func (*Func) Type added in v0.17.8

func (f *Func) Type() *types.Type

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 {
	VariableName string
	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 {
	Value, Key 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 Interpolate added in v0.13.2

type Interpolate struct {
	// Parts will have at least one element. Each element will be one of
	// StringLiteral or Group. However, they can appear in any order.
	Parts []Node

	Pos string
}

Interpolate is a string literal that contains expressions.

func (*Interpolate) Position added in v0.13.2

func (node *Interpolate) 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. It is used for arrays, maps and objects.

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  *types.Type
	Value string

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

	// If the literal is a function Map will be the parent scope.
	Map map[string]*Literal

	Pos string

	// Used for file handles. Even though it is always a *os.File, we need to
	// keep it as a interface{} so that gob doesn't complain.
	File interface{}

	// We can only open one reader for a file handle as to not reset the
	// placement. This is always a *bufio.Reader, but we need to keep it an
	// interface{} for the same reason as File.
	Reader interface{}
}

Literal represents a literal of any type.

func (*Literal) Position added in v0.13.1

func (node *Literal) Position() string

Position returns the position.

func (*Literal) String added in v0.16.0

func (node *Literal) String() string

String is the human-readable representation of the value. To make it easier we just output everything as JSON.

type Map

type Map struct {
	Kind     *types.Type
	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 On added in v0.15.0

type On struct {
	// Type is the type name, like "MyError".
	Type *types.Type

	// Statement may be nil.
	Statements []Node

	Pos string
}

On a error handler for an ErrorScope.

func (*On) Position added in v0.15.0

func (node *On) Position() string

Position returns the position.

type Raise added in v0.15.0

type Raise struct {
	Err Node
	Pos string
}

Raise will raise an error to be handled. An error must be in the form of a constructor call, this is for simplicity right now.

func (*Raise) Position added in v0.15.0

func (node *Raise) Position() string

Position returns the position.

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