ast

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(node Node, visit func(Node) bool)

Inspect walks the syntax under node depth first, calling visit for node and then for each of its children; when visit returns false the children of that node are skipped. A nil node is not visited.

func Walk

func Walk(node Node, visit func(Node) bool)

Walk traverses an AST in depth-first order. It calls visit for each non-nil node; if visit returns false, Walk does not descend into that node's children.

Types

type ArrayLiteral

type ArrayLiteral struct {
	diag.Pos
	Elements []Node
	End      diag.Pos // the closing ']'
}

ArrayLiteral is an array literal, `[a, b, c]`

func (ArrayLiteral) String

func (node ArrayLiteral) String() string

String returns the literal as Evie source

type Assign

type Assign struct {
	diag.Pos
	Lhs   Node
	Value Node
}

Assign is `Lhs = Value`, where Lhs is a name, a field or an index

type Await

type Await struct {
	diag.Pos
	Task Node
}

Await is `await task`, which waits for the task and gives back its result

type AwaitAll

type AwaitAll struct {
	diag.Pos
	Tasks []Node
}

AwaitAll is `await.all(...)`, which waits for every task

type AwaitAny

type AwaitAny struct {
	diag.Pos
	Tasks []Node
}

AwaitAny is `await.any(...)`, which waits for the first task to succeed

type AwaitRace

type AwaitRace struct {
	diag.Pos
	Tasks []Node
}

AwaitRace is `await.race(...)`, which waits for the first task to finish

type AwaitTimeout

type AwaitTimeout struct {
	diag.Pos
	Task    Node
	Timeout Node
}

AwaitTimeout is `await.timeout(task, ms)`, which waits for the task for at most Timeout milliseconds

type BinOp

type BinOp struct {
	diag.Pos // [required]
	Operator // [required]

	Lhs Node // [required]
	Rhs Node // [required]
}

BinOp is a binary expression such as `a + b` or `a < b`

func (BinOp) IsLike

func (bop BinOp) IsLike(ops ...Operator) bool

IsLike reports whether the expression's operator is one of ops

func (BinOp) String

func (node BinOp) String() string

String returns the expression as Evie source

type Block

type Block struct {
	diag.Pos
	Code []Node
	End  diag.Pos
}

Block is code between braces; Pos is its '{' and End its '}'

func (Block) String

func (block Block) String() string

String returns the block as Evie source

type Break

type Break struct {
	diag.Pos
}

Break is a break statement

func (Break) String

func (node Break) String() string

String returns "break"

type Call

type Call struct {
	diag.Pos
	Fn   Node
	Args []Node
}

Call is a call of Fn with Args

func (Call) String

func (call Call) String() string

String returns the call as Evie source

type Catch

type Catch struct {
	diag.Pos
	Action Node // [required]
}

Catch is `catch(expr)` or `catch { ... }`: it gives back the value of Action, or the error raised while running it

type ClassDefinition

type ClassDefinition struct {
	diag.Pos
	Name      string
	NamePos   diag.Pos // where the name is written; unknown for an unnamed class
	Parent    string
	ParentPos diag.Pos // where the parent's name is written, when there is one
	Args      []string
	ArgPos    []diag.Pos // where each of Args is written
	Action    Node
}

ClassDefinition is a class declaration or expression: its constructor parameters, its optional parent and the body that declares its fields and methods

func (ClassDefinition) String

func (node ClassDefinition) String() string

String returns "class"

type Conditional

type Conditional struct {
	diag.Pos
	Condition Node // [required]
	Action    Node // [required]
	Otherwise Node // [optional]
}

Conditional is an if statement, with an optional else branch in Otherwise

func (Conditional) String

func (node Conditional) String() string

String returns the statement as Evie source

type Continue

type Continue struct {
	diag.Pos
}

Continue is a continue statement

func (Continue) String

func (node Continue) String() string

String returns "continue"

type Decl

type Decl struct {
	diag.Pos
	Name     string
	Value    Node
	IsStatic bool
}

Decl declares a binding: `x := v` and `const x := v` are static (immutable), `var x := v` is not

func (Decl) String

func (node Decl) String() string

String returns the declaration as Evie source

type Echo

type Echo struct {
	diag.Pos
	Value Node
}

Echo is `echo value`, which prints the value to the engine's standard output

func (Echo) String

func (echo Echo) String() string

String returns the statement as Evie source

type Exists

type Exists struct {
	diag.Pos
	Value Node
}

Exists is `value?`, which reports whether a field or index is present

func (Exists) String

func (node Exists) String() string

String returns the check as Evie source

type FieldAccess

type FieldAccess struct {
	diag.Pos
	Lhs    Node
	Rhs    string
	RhsPos diag.Pos // where the member's name is written
}

FieldAccess is `Lhs.Rhs`, reading a field, method or package member by name

func (FieldAccess) String

func (fa FieldAccess) String() string

String returns the access as written, such as "user.name"

type Fn

type Fn struct {
	diag.Pos
	Name       string
	NamePos    diag.Pos // where the name is written; unknown for an unnamed fn
	Args       []string
	ArgPos     []diag.Pos // where each of Args is written
	IsVariadic bool
	Action     Node
	UsedAsExpr bool // if true then create and return, else declare
}

Fn is a function declaration, or a function expression when UsedAsExpr is set; with IsVariadic the last of Args collects any further arguments

func (Fn) String

func (fn Fn) String() string

String returns the function as Evie source

type For

type For struct {
	diag.Pos
	IndexVar   string   // optional, "" if none
	IndexPos   diag.Pos // where IndexVar is written, when there is one
	ItemVar    string   // [required]
	ItemPos    diag.Pos // where ItemVar is written
	Collection Node     // [required]
	Action     Node     // [required]
}

For is `for item in collection` or `for index, item in collection`

func (For) String

func (node For) String() string

String returns the loop as Evie source

type Go

type Go struct {
	diag.Pos
	Fn Node
}

Go is `go call(...)`, which runs the call on a new fiber and gives back its task

type Ident

type Ident struct {
	diag.Pos
	Name string
}

Ident is a name used as a value

func (Ident) String

func (node Ident) String() string

String returns the name

type ImportSpec

type ImportSpec struct {
	diag.Pos
	Path     string
	Alias    string   // empty when not explicitly aliased
	AliasPos diag.Pos // where the alias is written, when there is one
}

ImportSpec is one entry in `imports("path")` or `imports("path" as alias)`.

type Input

type Input[T Literal] struct {
	diag.Pos
	Value T
}

Input is a literal in the source: a number, string, bool or nil

func (Input[T]) String

func (node Input[T]) String() string

String returns the literal as Evie source

type IsInstanceOf

type IsInstanceOf struct {
	diag.Pos
	Lhs Node
	Rhs Node
}

IsInstanceOf is `Lhs is Rhs`, true when Lhs is of the type or class Rhs names

type Literal

type Literal interface {
	bool | float64 | string | struct{}
}

Literal lists the Go types an Input can hold; struct{} stands for nil

type MutableBinOp

type MutableBinOp struct {
	diag.Pos // [required]
	Operator // [required]

	Lhs Node // [required] can be e.g. Ident
	Rhs Node // [required] can be e.g. Input[float64]
}

MutableBinOp is a compound assignment such as `x += 1`

func (MutableBinOp) String

func (node MutableBinOp) String() string

String returns the assignment as Evie source

type Neg

type Neg struct {
	diag.Pos      // [required]
	Value    Node // [required]
}

Neg is unary `-value`

type Node

type Node interface {
	Where() diag.Pos
}

Node is any piece of syntax; Where reports its span in the source

type Not

type Not struct {
	diag.Pos      // [required]
	Value    Node // [required]
}

Not is `!value`

func (Not) String

func (node Not) String() string

String returns the expression as Evie source

type Object

type Object struct {
	diag.Pos
	Fields []ObjectField
	End    diag.Pos // the closing '}'
}

Object is an object literal, `{ key: value, ... }`

func (Object) String

func (node Object) String() string

String returns the literal as Evie source

type ObjectField

type ObjectField struct {
	Key    string
	KeyPos diag.Pos // where the key is written
	Value  Node
}

ObjectField is one `key: value` entry of an Object literal

func (ObjectField) String

func (node ObjectField) String() string

String returns the entry as Evie source

type Operator

type Operator int

Operator is a binary operator

const (
	// the vm relies on + - * / coming first, in this order
	AddOp Operator = iota + 1
	SubOp
	MulOp
	DivOp
	ModOp

	EqOp
	NotEqOp
	LtOp
	GtOp
	LtEqOp
	GtEqOp

	OrOp
	AndOp
)

The binary operators: arithmetic, then comparison, then logical

func (Operator) String

func (op Operator) String() string

String returns the operator as written, such as "+" or "&&"

type Package

type Package struct {
	diag.Pos
	Name    string
	NamePos diag.Pos // where the package name is written
	Imports []ImportSpec
	Code    []Node
}

Package is a parsed file: its package clause, its imports and its top-level code

func (Package) String

func (pkg Package) String() string

String returns the package clause, its imports and its code as Evie source

type Plus

type Plus struct {
	diag.Pos      // [required]
	Value    Node // [required]
}

Plus is unary `+value`

type Return

type Return struct {
	diag.Pos
	Value Node
}

Return is a return statement; a bare `return` returns nil

func (Return) String

func (ret Return) String() string

String returns the statement as Evie source

type Slice

type Slice struct {
	diag.Pos
	Lhs   Node
	Start Node
	End   Node
}

Slice is `Lhs[Start:End]`; either bound may be nil

func (Slice) String

func (node Slice) String() string

String returns the slice expression as Evie source

type StringTemplate

type StringTemplate struct {
	diag.Pos
	Parts []string // the literal text around the interpolations; one more than Args
	Args  []Node
}

StringTemplate is a backtick string with `{expr}` interpolations

func (StringTemplate) String

func (node StringTemplate) String() string

String returns the template's text with each interpolation in braces

type Subscript

type Subscript struct {
	diag.Pos
	Lhs Node
	Key Node
}

Subscript is `Lhs[Key]`, indexing an array, string, buffer or object

func (Subscript) String

func (node Subscript) String() string

String returns the index expression as Evie source

type Switch

type Switch struct {
	diag.Pos
	Value   Node         // [optional] value to match against; nil for tagless switch
	Cases   []SwitchCase // list of case branches
	Default Node         // [optional] default action (ast.Block), nil if none
	End     diag.Pos     // the closing '}'
}

Switch is a switch statement, matching Value against each case in order, or testing each case as a condition when Value is nil

func (Switch) String

func (node Switch) String() string

String returns the switch's head, with its cases elided

type SwitchCase

type SwitchCase struct {
	diag.Pos
	Values []Node // multiple case expressions e.g. case 1, 2, 3:
	Action Node   // body of the case (ast.Block)
}

SwitchCase is one `case a, b:` branch of a Switch

type Throw

type Throw struct {
	diag.Pos
	Value Node
}

Throw is a throw statement; a bare `throw` throws the string "error"

func (Throw) String

func (node Throw) String() string

String returns the statement as Evie source

type While

type While struct {
	diag.Pos
	Condition Node // [required]
	Action    Node // [required]
}

While is a while loop

func (While) String

func (node While) String() string

String returns the loop as Evie source

Jump to

Keyboard shortcuts

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