ast

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT 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

Overview

Package ast declares the syntax tree of an Ant module, as the parser builds it and the resolver annotates it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(n Node, p Pos) bool

Contains reports whether p lies in the span of n, from its Start inclusive to its EndPosition exclusive.

func Inspect

func Inspect(n Node, f func(Node) bool)

Inspect walks the tree under n in source order, calling f for each node, children included when f returns true. Besides the expressions, statements, types, and targets, it visits the parts a node is made of that carry a position: imports' names, type and value parameters, the fields of a record type or destructuring, the entries of literals, call arguments, string parts, select clauses, and the nodes, elements, and attributes of markup.

func Sprint

func Sprint(n Node) string

Sprint renders a node as an S-expression, for tests and debugging.

Types

type Arg

type Arg struct {
	Pos   Pos
	End   Pos
	Name  string
	Value Expr
}

Arg is a call argument, named when Name is set.

func (*Arg) EndPosition

func (n *Arg) EndPosition() Pos

func (*Arg) Position

func (n *Arg) Position() Pos

type ArrayElem

type ArrayElem struct {
	Value  Expr
	Spread bool
}

ArrayElem is an element of an array literal, or a spread.

type ArrayLit

type ArrayLit struct {
	Pos   Pos
	End   Pos
	Elems []ArrayElem
	// Off is the byte offset of the [, and SpreadComma reports a comma after a final
	// spread, for the parser when the literal turns out to be a destructuring assignment.
	Off         int
	SpreadComma bool
}

ArrayLit is [ elements ].

func (*ArrayLit) EndPosition

func (n *ArrayLit) EndPosition() Pos

func (*ArrayLit) Position

func (n *ArrayLit) Position() Pos

type ArrayTarget

type ArrayTarget struct {
	Pos   Pos
	End   Pos
	Elems []Target
	Rest  *NameTarget // nil without a rest
}

ArrayTarget is an array destructuring [a, b, ...rest].

func (*ArrayTarget) EndPosition

func (n *ArrayTarget) EndPosition() Pos

func (*ArrayTarget) Position

func (n *ArrayTarget) Position() Pos

type Assert

type Assert struct {
	// Cond is the argument that would fill cond, the first positional one or the one named
	// cond, or nil when there is none.
	Cond Expr
	// Text is the condition's source.
	Text string
	// Op is the condition's outermost operator when it is a comparison or is, and "" otherwise;
	// X and Y index its operands in Parts, Y being -1 for is.
	Op   string
	X, Y int
	// Parts are the subexpressions whose values are recorded as the condition evaluates, and
	// Index finds each one's place in Parts.
	Parts []AssertPart
	Index map[Expr]int
}

Assert is what a call of assert needs to report a failure (section 8, assert): its condition, and the subexpressions of the condition whose values the report shows, with the source text of each. The arguments are matched to cond and message as any call's are.

type AssertPart

type AssertPart struct {
	Expr Expr
	Text string
	// Shown marks a part listed on a line of its own; the comparison's operands are not.
	Shown bool
	// Receiver marks the x of a call x.f(…), recorded only when x is passed to f as its first
	// argument: not when it is a namespace, as Array is, or a record whose field f is called.
	Receiver bool
}

AssertPart is a subexpression of an assert's condition.

type Assign

type Assign struct {
	Pos    Pos
	End    Pos
	Op     string
	Target Node
	Value  Expr
}

Assign is target op value. Target is an Ident, Field, Index, or ArrayTarget.

func (*Assign) EndPosition

func (n *Assign) EndPosition() Pos

func (*Assign) Position

func (n *Assign) Position() Pos

type AssignArray

type AssignArray struct {
	Pos   Pos
	End   Pos
	Elems []Node // Ident, Field, Index, or *AssignArray
	Rest  Expr   // Ident, Field, or Index; nil without a rest
}

AssignArray is the array destructuring target of an assignment: places and nested targets, with an optional rest place.

func (*AssignArray) EndPosition

func (n *AssignArray) EndPosition() Pos

func (*AssignArray) Position

func (n *AssignArray) Position() Pos

type BadExpr

type BadExpr struct{ Pos, End Pos }

BadExpr, BadStmt, and BadType stand for source that did not parse, in a tree the parser built past a syntax error (parser.ParseRecover). They have no meaning: the checker gives a BadExpr the type Invalid and reports nothing about it.

func (*BadExpr) EndPosition

func (n *BadExpr) EndPosition() Pos

func (*BadExpr) Position

func (n *BadExpr) Position() Pos

type BadStmt

type BadStmt struct{ Pos, End Pos }

func (*BadStmt) EndPosition

func (n *BadStmt) EndPosition() Pos

func (*BadStmt) Position

func (n *BadStmt) Position() Pos

type BadType

type BadType struct{ Pos, End Pos }

func (*BadType) EndPosition

func (n *BadType) EndPosition() Pos

func (*BadType) Position

func (n *BadType) Position() Pos

type Binary

type Binary struct {
	Pos  Pos
	End  Pos
	Op   string
	X, Y Expr
}

Binary is an arithmetic, comparison, equality, logical, or ?? operation.

func (*Binary) EndPosition

func (n *Binary) EndPosition() Pos

func (*Binary) Position

func (n *Binary) Position() Pos

type Block

type Block struct {
	Pos      Pos
	End      Pos
	Stmts    []Stmt
	HasDefer bool        // a defer statement registers directly with this block
	Types    []*TypeDecl // the types declared directly in the block, bound when it starts
	Scope    *BlockScope // filled by the resolver; nil when the block declares nothing
}

Block is { statements }.

func (*Block) EndPosition

func (n *Block) EndPosition() Pos

func (*Block) Position

func (n *Block) Position() Pos

type BlockScope

type BlockScope struct {
	Plain  int // number of plain slots
	Shared int // number of shared slots
	// Names lists the bindings that have a slot, in declaration order, for a debugger to show.
	Names []SlotName
}

BlockScope describes the environment a block, loop iteration, or function allocates.

type BoolLit

type BoolLit struct {
	Pos   Pos
	End   Pos
	Value bool
}

func (*BoolLit) EndPosition

func (n *BoolLit) EndPosition() Pos

func (*BoolLit) Position

func (n *BoolLit) Position() Pos

type Break

type Break struct{ Pos, End Pos }

func (*Break) EndPosition

func (n *Break) EndPosition() Pos

func (*Break) Position

func (n *Break) Position() Pos

type Call

type Call struct {
	Pos      Pos
	End      Pos
	Fn       Expr
	Args     []Arg
	Optional bool
	Pipe     bool
	Grouped  bool
	// Bar is the position of a pipe's |, and Stage is set on each pipe of a pipeline of two
	// or more, where a debugger stops before the stage (dap.md section 4).
	Bar   Pos
	Stage bool
	// Assert is set on a call of assert, which the parser recognizes by its name, since no
	// declaration may shadow a prelude name.
	Assert *Assert
}

Call is f(args) or f?.(args). A pipe a | f(b) is a Call with Pipe set and a as the first argument; it evaluates that argument before f. Grouped as for Field.

func (*Call) EndPosition

func (n *Call) EndPosition() Pos

func (*Call) Position

func (n *Call) Position() Pos

type Continue

type Continue struct{ Pos, End Pos }

func (*Continue) EndPosition

func (n *Continue) EndPosition() Pos

func (*Continue) Position

func (n *Continue) Position() Pos

type Decl

type Decl interface {
	Node

	Exported() bool
	// contains filtered or unexported methods
}

Decl is a top-level declaration.

type Defer

type Defer struct {
	Pos   Pos
	End   Pos
	Body  *Block
	Scope *FuncScope
}

func (*Defer) EndPosition

func (n *Defer) EndPosition() Pos

func (*Defer) Position

func (n *Defer) Position() Pos

type DurationLit added in v0.2.0

type DurationLit struct {
	Pos   Pos
	End   Pos
	Text  string
	Value temporal.Duration
}

DurationLit is a duration literal (section 2), as 2h30m. Text is the literal as written, and Value the Time.Duration it evaluates to.

func (*DurationLit) EndPosition added in v0.2.0

func (n *DurationLit) EndPosition() Pos

func (*DurationLit) Position added in v0.2.0

func (n *DurationLit) Position() Pos

type Expr

type Expr interface {
	Stmt
	// contains filtered or unexported methods
}

Expr is an expression. Every construct of section 5 is an expression, including if, loops, go, defer, return, break, continue, and assignment.

type Field

type Field struct {
	Pos      Pos // the . or ?.
	End      Pos
	X        Expr
	Name     string
	NamePos  Pos
	Optional bool
	Grouped  bool
}

Field is a.name or a?.name. Grouped marks one written in parentheses, which ends its postfix chain: a ?. inside skips nothing outside (section 12).

func (*Field) EndPosition

func (n *Field) EndPosition() Pos

func (*Field) Position

func (n *Field) Position() Pos

type FieldType

type FieldType struct {
	Pos     Pos
	End     Pos
	Name    string
	Type    Type
	Default Expr
}

FieldType is one field of a record type. Default is the expression a literal that leaves the field out evaluates, or nil; only the body of a type declaration has defaults (section 4).

func (*FieldType) EndPosition

func (n *FieldType) EndPosition() Pos

func (*FieldType) Position

func (n *FieldType) Position() Pos

type File

type File struct {
	Path    string
	Doc     string // the module doc, from the //! lines before the first import (section 2), or ""
	Imports []*Import
	Decls   []Decl
	// Stmts holds the top-level var declarations and statements in source order: a script's
	// body (section 10), or a session input's or a spec example's statements.
	Stmts []Stmt
	// Script is set for a program module with a statement at the top level; FirstStmt is where
	// the first one starts.
	Script    bool
	FirstStmt Pos
	// Tests holds a test file's top-level tests in source order (section 10, Tests).
	Tests []*Test
	// Declarations is set for a declaration file (section 10, Declaration files), parsed in
	// the parser's Declarations mode: its funcs have no bodies and its names join the prelude.
	Declarations bool
	// NamespaceDocs holds the section labels of a declaration file, keyed by namespace name.
	NamespaceDocs map[string]string
	// End is the position after the last token of the file.
	End Pos
	// Scope is filled by the resolver: the module record's fields.
	Scope *ModuleScope
}

File is a parsed module.

func (*File) EndPosition

func (n *File) EndPosition() Pos

func (*File) Position

func (n *File) Position() Pos

type Fixed

type Fixed uint8

Fixed says whether a binding can be reassigned, and if not, why (section 3).

const (
	Assignable Fixed = iota // a var, or _
	FixedLet                // declared with let
	FixedParam              // a parameter of a function or anonymous function
	FixedX                  // the implicit parameter x of a lambda
	FixedFor                // a name a for binds
)

func (Fixed) What

func (f Fixed) What() string

What names the kind of a fixed binding for a message: "a let", "a parameter".

type FloatLit

type FloatLit struct {
	Pos   Pos
	End   Pos
	Value float64
}

func (*FloatLit) EndPosition

func (n *FloatLit) EndPosition() Pos

func (*FloatLit) Position

func (n *FloatLit) Position() Pos

type For

type For struct {
	Pos      Pos
	End      Pos
	Target   Target
	Iter     Expr
	Body     *Block
	Scope    *BlockScope // the per-iteration scope, filled by the resolver
	Assigned []string    // the locals declared outside the loop that its body assigns, filled by the resolver
}

func (*For) EndPosition

func (n *For) EndPosition() Pos

func (*For) Position

func (n *For) Position() Pos

type FuncDecl

type FuncDecl struct {
	Pos        Pos
	End        Pos
	Export     bool
	Owner      string // the type for func Type.name, or ""
	OwnerPos   Pos    // where Owner is written, or zero
	Name       string
	NamePos    Pos
	TypeParams []TypeParam
	Params     []Param
	Return     Type   // nil when inferred
	Body       *Block // nil only in declarations mode
	Doc        string // the doc comment (section 2), or ""
	Sig        string // the source from func through the result type, as written
	// Scope is filled by the resolver.
	Scope *FuncScope
}

FuncDecl is a named function, or a function declared on a type when Owner is set.

func (*FuncDecl) EndPosition

func (n *FuncDecl) EndPosition() Pos

func (*FuncDecl) Exported

func (n *FuncDecl) Exported() bool

func (*FuncDecl) Position

func (n *FuncDecl) Position() Pos

type FuncLit

type FuncLit struct {
	Pos    Pos
	End    Pos
	Params []Param
	Return Type
	Body   *Block
	Scope  *FuncScope
}

FuncLit is an anonymous func.

func (*FuncLit) EndPosition

func (n *FuncLit) EndPosition() Pos

func (*FuncLit) Position

func (n *FuncLit) Position() Pos

type FuncScope

type FuncScope struct {
	BlockScope
	// X is the slot of the implicit lambda parameter.
	X Slot
}

FuncScope describes a function body, lambda, go block, or defer block.

type FuncType

type FuncType struct {
	Pos    Pos
	End    Pos
	Params []FuncTypeParam
	Return Type
}

FuncType is a function type func(T, U): R.

func (*FuncType) EndPosition

func (n *FuncType) EndPosition() Pos

func (*FuncType) Position

func (n *FuncType) Position() Pos

type FuncTypeParam

type FuncTypeParam struct {
	Name string
	Type Type
}

FuncTypeParam is one parameter of a function type, with an optional documenting name.

type Go

type Go struct {
	Pos   Pos
	End   Pos
	Body  *Block
	Scope *FuncScope
}

func (*Go) EndPosition

func (n *Go) EndPosition() Pos

func (*Go) Position

func (n *Go) Position() Pos

type Html

type Html struct {
	Pos     Pos
	End     Pos
	Content []HtmlNode
	Close   Pos // the </> of a fragment, or zero for an element
}

Html is an HTML expression (section 5): an element, or a fragment, as its content.

func (*Html) EndPosition

func (n *Html) EndPosition() Pos

func (*Html) Position

func (n *Html) Position() Pos

type HtmlAttr

type HtmlAttr struct {
	Pos    Pos
	End    Pos
	Name   string
	Text   string
	Expr   Expr
	Spread bool
}

HtmlAttr is an attribute: literal Text when Expr is nil, a value when Expr is set, and every entry of a map when Spread is set, in which case Name is empty.

func (*HtmlAttr) EndPosition

func (n *HtmlAttr) EndPosition() Pos

func (*HtmlAttr) Position

func (n *HtmlAttr) Position() Pos

type HtmlElement

type HtmlElement struct {
	Pos      Pos // the <
	End      Pos
	Name     string
	NamePos  Pos
	Attrs    []HtmlAttr
	Content  []HtmlNode
	Close    Pos
	TextOnly bool
}

HtmlElement is an element as written. TextOnly marks a <title> or <textarea> outside <svg> and <math>, whose content may not hold Html. Close is where its end tag starts, or zero when it is written self-closing.

func (*HtmlElement) EndPosition

func (n *HtmlElement) EndPosition() Pos

func (*HtmlElement) Position

func (n *HtmlElement) Position() Pos

type HtmlNode

type HtmlNode struct {
	Pos     Pos
	End     Pos
	Text    string
	Expr    Expr
	Element *HtmlElement
}

HtmlNode is an item of an HTML expression's content: decoded text, an interpolated Expr, or an Element.

func (*HtmlNode) EndPosition

func (n *HtmlNode) EndPosition() Pos

func (*HtmlNode) Position

func (n *HtmlNode) Position() Pos

type Ident

type Ident struct {
	Pos  Pos
	End  Pos
	Name string
	Ref  Ref
}

Ident is a variable reference. Ref is filled by the resolver.

func (*Ident) EndPosition

func (n *Ident) EndPosition() Pos

func (*Ident) Position

func (n *Ident) Position() Pos

type If

type If struct {
	Pos  Pos
	End  Pos
	Cond Expr
	Then *Block
	Else Node // *If, *Block, or nil
}

func (*If) EndPosition

func (n *If) EndPosition() Pos

func (*If) Position

func (n *If) Position() Pos

type Import

type Import struct {
	Pos          Pos
	End          Pos
	Path         string
	PathPos      Pos // the path string, from its opening quote
	PathEnd      Pos
	Namespace    string       // the bare name that binds the whole module, or ""
	NamespacePos Pos          // where Namespace is written, or zero
	Names        []ImportName // the destructured names, when Namespace is ""
	// Module is filled by the loader: the index of the imported module in the program, or -1
	// when the module could not be loaded and the loader went on (Config.Recover).
	Module int
}

Import is one import declaration.

func (*Import) EndPosition

func (n *Import) EndPosition() Pos

func (*Import) Position

func (n *Import) Position() Pos

type ImportName

type ImportName struct {
	Pos      Pos
	End      Pos
	Name     string
	Alias    string // the local name; equals Name when not renamed
	AliasPos Pos    // where the alias is written, or zero when not renamed
}

ImportName is one entry of an import list: the export, and the local name it binds.

func (*ImportName) EndPosition

func (n *ImportName) EndPosition() Pos

func (*ImportName) Position

func (n *ImportName) Position() Pos

type Index

type Index struct {
	Pos      Pos
	End      Pos
	X        Expr
	Index    Expr
	Optional bool
	Grouped  bool
}

Index is a[i] or a?.[i]; Grouped as for Field.

func (*Index) EndPosition

func (n *Index) EndPosition() Pos

func (*Index) Position

func (n *Index) Position() Pos

type IntLit

type IntLit struct {
	Pos   Pos
	End   Pos
	Value int64
}

func (*IntLit) EndPosition

func (n *IntLit) EndPosition() Pos

func (*IntLit) Position

func (n *IntLit) Position() Pos

type InterfaceDecl

type InterfaceDecl struct {
	Pos        Pos
	End        Pos
	Export     bool
	Name       string
	NamePos    Pos
	TypeParams []TypeParam
	Funcs      []InterfaceFunc
	Doc        string // the doc comment (section 2), or ""
	Sig        string // the source from interface through the type parameters, as written
}

InterfaceDecl is an interface declaration (section 4, Interfaces): a named set of function signatures, each taking the satisfying type, Self, first. The checker reads it, and the interpreter discards it, so the name binds nothing at run time.

func (*InterfaceDecl) EndPosition

func (n *InterfaceDecl) EndPosition() Pos

func (*InterfaceDecl) Exported

func (n *InterfaceDecl) Exported() bool

func (*InterfaceDecl) Position

func (n *InterfaceDecl) Position() Pos

type InterfaceFunc

type InterfaceFunc struct {
	Pos     Pos
	End     Pos
	Name    string
	NamePos Pos
	Params  []Param
	Return  Type
	Doc     string // the doc comment (section 2), or ""
	Sig     string // the signature as written
}

InterfaceFunc is one signature of an interface: its name, its parameters, the first of which has the type Self, and its return type.

func (*InterfaceFunc) EndPosition

func (n *InterfaceFunc) EndPosition() Pos

func (*InterfaceFunc) Position

func (n *InterfaceFunc) Position() Pos

type Is

type Is struct {
	Pos     Pos // the is
	End     Pos
	X       Expr
	Kind    string
	KindPos Pos // where Kind is written, or zero
	Path    Expr
}

Is is x is T. Kind is set for a kind test (null, void, bool, string, func, Array, Map, and the numeric names); otherwise Path is the type's expression.

func (*Is) EndPosition

func (n *Is) EndPosition() Pos

func (*Is) Position

func (n *Is) Position() Pos

type Lambda

type Lambda struct {
	Pos   Pos
	End   Pos
	Body  *Block
	Scope *FuncScope
}

Lambda is a bare block with the implicit parameter x.

func (*Lambda) EndPosition

func (n *Lambda) EndPosition() Pos

func (*Lambda) Position

func (n *Lambda) Position() Pos

type MapEntry

type MapEntry struct {
	Pos   Pos
	End   Pos
	Key   Expr
	Value Expr
}

MapEntry is one key and value of a map literal.

func (*MapEntry) EndPosition

func (n *MapEntry) EndPosition() Pos

func (*MapEntry) Position

func (n *MapEntry) Position() Pos

type MapLit

type MapLit struct {
	Pos     Pos
	End     Pos
	Entries []MapEntry
}

MapLit is Map{ entries }.

func (*MapLit) EndPosition

func (n *MapLit) EndPosition() Pos

func (*MapLit) Position

func (n *MapLit) Position() Pos

type ModuleScope

type ModuleScope struct {
	Fields []string
	Index  map[string]int
	// Let holds the fields bound by a top-level let, which no assignment may change.
	Let map[string]bool
	// PendingLet holds, in a session, the names the input being run declares with let: each
	// joins Let once its declaration has bound it, so a let whose initializer fails can be
	// declared again (section 10, Scripts).
	PendingLet map[string]bool
	// Types holds, in a session, the type declared by each field that names one, so a later
	// input can declare functions on it.
	Types map[string]*TypeDecl
}

ModuleScope lists the fields of the module record in declaration order.

type NameTarget

type NameTarget struct {
	Pos  Pos
	End  Pos
	Name string
	// Slot is filled by the resolver.
	Slot Slot
}

NameTarget binds a name; "_" binds nothing.

func (*NameTarget) EndPosition

func (n *NameTarget) EndPosition() Pos

func (*NameTarget) Position

func (n *NameTarget) Position() Pos

type Node

type Node interface {
	Position() Pos
	EndPosition() Pos
}

Node is any syntax node. Position is where it starts, as messages report it, and EndPosition is just after its last token, so the two span the node; Start is where it begins on the page, which for a postfix chain or an operator is its first operand.

func Path

func Path(f *File, p Pos) []Node

Path returns the nodes that contain p, outermost first: the file, and then each node whose span holds p, down to the innermost. A node whose span is empty is never on the path.

type NullLit

type NullLit struct{ Pos, End Pos }

func (*NullLit) EndPosition

func (n *NullLit) EndPosition() Pos

func (*NullLit) Position

func (n *NullLit) Position() Pos

type Param

type Param struct {
	Pos     Pos
	End     Pos
	Name    string
	Type    Type
	Default Expr
	// Slot is filled by the resolver.
	Slot Slot
}

Param is a function parameter.

func (*Param) EndPosition

func (n *Param) EndPosition() Pos

func (*Param) Position

func (n *Param) Position() Pos

type Placeholder

type Placeholder struct{ Pos, End Pos }

Placeholder is the "..." of spec mode.

func (*Placeholder) EndPosition

func (n *Placeholder) EndPosition() Pos

func (*Placeholder) Position

func (n *Placeholder) Position() Pos

type Pos

type Pos struct {
	Line, Col int
}

Pos is a position in the module's source: 1-based line and 1-based byte column.

func Start

func Start(n Node) Pos

Start is where n begins on the page: its Position, except for a postfix link, an operator, an is test, an assignment, or a pipe, whose Position is the operator and whose first operand comes before it.

func (Pos) Before

func (a Pos) Before(b Pos) bool

Before reports whether a comes before b.

type RecordEntry

type RecordEntry struct {
	Pos    Pos
	End    Pos
	Name   string
	Value  Expr
	Spread Expr
}

RecordEntry is a field of a record literal, or a spread.

func (*RecordEntry) EndPosition

func (n *RecordEntry) EndPosition() Pos

func (*RecordEntry) Position

func (n *RecordEntry) Position() Pos

type RecordLit

type RecordLit struct {
	Pos     Pos
	End     Pos
	Head    Expr
	Entries []RecordEntry
}

RecordLit is Head{ entries }, where Head is an identifier path.

func (*RecordLit) EndPosition

func (n *RecordLit) EndPosition() Pos

func (*RecordLit) Position

func (n *RecordLit) Position() Pos

type RecordTarget

type RecordTarget struct {
	Pos    Pos
	End    Pos
	Fields []RecordTargetField
}

RecordTarget is a record destructuring { x, y: py, ... }.

func (*RecordTarget) EndPosition

func (n *RecordTarget) EndPosition() Pos

func (*RecordTarget) Position

func (n *RecordTarget) Position() Pos

type RecordTargetField

type RecordTargetField struct {
	Pos    Pos
	End    Pos
	Name   string
	Target Target
}

RecordTargetField is one entry of a record destructuring: the field, and the target it binds (a NameTarget with the field's name for the shorthand).

func (*RecordTargetField) EndPosition

func (n *RecordTargetField) EndPosition() Pos

func (*RecordTargetField) Position

func (n *RecordTargetField) Position() Pos

type RecordType

type RecordType struct {
	Pos    Pos
	End    Pos
	Fields []FieldType
}

RecordType is an anonymous record type { name: T, ... }.

func (*RecordType) EndPosition

func (n *RecordType) EndPosition() Pos

func (*RecordType) Position

func (n *RecordType) Position() Pos

type Ref

type Ref struct {
	Kind   RefKind
	Depth  int  // RefLocal: environments to walk up
	Index  int  // RefLocal: slot index; RefModule: field index; RefImport: import index
	Shared bool // RefLocal: the slot is shared (captured by a nested body)
	// Fixed, for RefLocal and RefModule, says why the binding cannot be assigned.
	Fixed Fixed
	Name  string
}

Ref is where an identifier resolves to.

type RefKind

type RefKind int

RefKind says what an identifier refers to.

const (
	RefUnresolved RefKind = iota
	RefLocal              // a slot Depth environments up
	RefModule             // a field of this module's record
	RefImport             // a field of an imported module's record
	RefPrelude            // a prelude name
	RefUnbound            // no scope binds the name: a panic when evaluated
	RefDiscard            // the write-only _: a panic when read
)

type RegexLit

type RegexLit struct {
	Pos     Pos
	End     Pos
	Source  string // normalized
	Flags   string // sorted
	Pattern *value.Regex
}

RegexLit is a regular expression literal (section 2). Pattern is the value it evaluates to, built once when the literal is parsed.

func (*RegexLit) EndPosition

func (n *RegexLit) EndPosition() Pos

func (*RegexLit) Position

func (n *RegexLit) Position() Pos

type Return

type Return struct {
	Pos   Pos
	End   Pos
	Value Expr // nil for a bare return
}

func (*Return) EndPosition

func (n *Return) EndPosition() Pos

func (*Return) Position

func (n *Return) Position() Pos

type Select

type Select struct {
	Pos     Pos
	End     Pos
	Clauses []*SelectClause
}

Select is a select expression (section 5): clauses with a head each, and at most one else, last.

func (*Select) EndPosition

func (n *Select) EndPosition() Pos

func (*Select) Position

func (n *Select) Position() Pos

type SelectClause

type SelectClause struct {
	Pos    Pos
	End    Pos
	Let    bool // the binding is written let rather than var
	Target *NameTarget
	Head   *Call
	Body   *Block
	Scope  *BlockScope
}

SelectClause is one clause of a select. Head is the call that names the wait, one of Channel.receive, Channel.send, Context.wait, WaitGroup.wait and Time.sleep, which the parser checks, and nil for else. Target binds the head's result when the clause has var x =. Scope is the body's scope with that binding, filled by the resolver, nil when it declares nothing.

func (*SelectClause) EndPosition

func (n *SelectClause) EndPosition() Pos

func (*SelectClause) Keyword

func (c *SelectClause) Keyword() string

Keyword is the keyword that binds the clause's result: var or let.

func (*SelectClause) Position

func (n *SelectClause) Position() Pos

type Slot

type Slot struct {
	Index  int
	Shared bool
	Module bool // a module field rather than a local slot
	// AssignedNested is set when the binding is assigned inside a nested body (section 7).
	AssignedNested bool
	// Discard is set for _, which binds nothing: a value stored there is dropped.
	Discard bool
	// Fixed says why the binding cannot be reassigned, or is Assignable.
	Fixed Fixed
}

Slot is where a binding lives in its environment, with the facts narrowing needs.

type SlotName

type SlotName struct {
	Name   string
	Index  int
	Shared bool
	Type   bool  // a type declared in the block, which a debugger leaves out
	Fixed  Fixed // why the binding cannot be reassigned, or Assignable
}

SlotName names one slot of a BlockScope.

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt is a statement in a block: an expression or a var declaration.

type StringLit

type StringLit struct {
	Pos   Pos
	End   Pos
	Value string
}

func (*StringLit) EndPosition

func (n *StringLit) EndPosition() Pos

func (*StringLit) Position

func (n *StringLit) Position() Pos

type Target

type Target interface {
	Node
	// contains filtered or unexported methods
}

Target is the left side of a var declaration or a for: a name or a destructuring.

type Template

type Template struct {
	Pos   Pos
	End   Pos
	Parts []TemplatePart
}

Template is a string with interpolations; each part is literal text or an interpolated expression.

func (*Template) EndPosition

func (n *Template) EndPosition() Pos

func (*Template) Position

func (n *Template) Position() Pos

type TemplatePart

type TemplatePart struct {
	Pos  Pos
	End  Pos
	Text string
	Expr Expr
}

TemplatePart is literal text or an interpolated expression; an interpolation spans from its $ to its closing brace.

func (*TemplatePart) EndPosition

func (n *TemplatePart) EndPosition() Pos

func (*TemplatePart) Position

func (n *TemplatePart) Position() Pos

type Test

type Test struct {
	Pos   Pos
	End   Pos
	Name  Expr
	Body  *Block
	Scope *FuncScope
	Doc   string // the doc comment (section 2) of a top-level test, or ""
}

Test is a test declaration at the top level of a test file, or the statement that runs a subtest inside a test's body (section 10, Tests). Name is a *StringLit for a top-level test, and a *StringLit or a *Template for a subtest.

func (*Test) EndPosition

func (n *Test) EndPosition() Pos

func (*Test) Position

func (n *Test) Position() Pos

type Type

type Type interface {
	Node
	// contains filtered or unexported methods
}

Type is a type expression, read by the checker and discarded by the interpreter except for the field names of a record type.

type TypeDecl

type TypeDecl struct {
	Pos        Pos
	End        Pos
	Export     bool
	Owner      string
	OwnerPos   Pos // where Owner is written, or zero
	Name       string
	NamePos    Pos
	TypeParams []TypeParam
	Body       Type
	Doc        string // the doc comment (section 2), or ""
	Sig        string // the whole declaration from type on, as written
	// Slot is filled by the resolver for a type declared in a block.
	Slot Slot
}

TypeDecl is a type declaration. In declarations mode Owner may name the namespace the type belongs to, as in type Json.Value, and Body may be nil for an opaque type such as Mutex.

func (*TypeDecl) EndPosition

func (n *TypeDecl) EndPosition() Pos

func (*TypeDecl) Exported

func (n *TypeDecl) Exported() bool

func (*TypeDecl) Position

func (n *TypeDecl) Position() Pos

type TypeExpr

type TypeExpr struct {
	Pos  Pos
	End  Pos
	Type Type
}

TypeExpr is a type expression type(T): the type T as a value (section 4, Types as values). Pos is the type keyword.

func (*TypeExpr) EndPosition

func (n *TypeExpr) EndPosition() Pos

func (*TypeExpr) Position

func (n *TypeExpr) Position() Pos

type TypeName

type TypeName struct {
	Pos     Pos
	End     Pos
	Path    []string
	PathPos []Pos // where each part of Path is written
	Args    []Type
	// Head, filled by the resolver for a type the interpreter resolves (section 4, Types as
	// values), is the identifier that evaluates the first part of Path; nil for a built-in
	// name or a type parameter.
	Head *Ident
}

TypeName is a named type with optional type arguments: int, Array[T], Geometry.Point, and also null and void.

func (*TypeName) EndPosition

func (n *TypeName) EndPosition() Pos

func (*TypeName) Position

func (n *TypeName) Position() Pos

type TypeParam

type TypeParam struct {
	Pos   Pos
	End   Pos
	Name  string
	Bound Type
}

TypeParam is a type parameter with an optional bound.

func (*TypeParam) EndPosition

func (n *TypeParam) EndPosition() Pos

func (*TypeParam) Position

func (n *TypeParam) Position() Pos

type Unary

type Unary struct {
	Pos Pos
	End Pos
	Op  string
	X   Expr
}

Unary is -a, !a, or try a.

func (*Unary) EndPosition

func (n *Unary) EndPosition() Pos

func (*Unary) Position

func (n *Unary) Position() Pos

type UnionType

type UnionType struct {
	Pos     Pos
	End     Pos
	Members []Type
}

UnionType is A | B.

func (*UnionType) EndPosition

func (n *UnionType) EndPosition() Pos

func (*UnionType) Position

func (n *UnionType) Position() Pos

type VarDecl

type VarDecl struct {
	Pos      Pos
	End      Pos
	Export   bool
	Let      bool   // declared with let, so its names cannot be reassigned (section 3)
	Owner    string // the namespace of a declaration file's constant, let Owner.NAME: T, or ""
	OwnerPos Pos    // where Owner is written, or zero
	Target   Target
	Type     Type // nil when inferred; only with a NameTarget
	Init     Expr
	Doc      string // the doc comment (section 2) of a top-level var, or ""
	Sig      string // the source from var or let through the type, as written, without the initializer
}

VarDecl is a var or let declaration, at the top level or in a block. In declarations mode a constant such as let Math.PI: float64 has an Owner and no Init.

func (*VarDecl) EndPosition

func (n *VarDecl) EndPosition() Pos

func (*VarDecl) Exported

func (n *VarDecl) Exported() bool

func (*VarDecl) Keyword

func (d *VarDecl) Keyword() string

Keyword is the keyword that declares d: var or let.

func (*VarDecl) Position

func (n *VarDecl) Position() Pos

type VoidLit

type VoidLit struct{ Pos, End Pos }

func (*VoidLit) EndPosition

func (n *VoidLit) EndPosition() Pos

func (*VoidLit) Position

func (n *VoidLit) Position() Pos

type While

type While struct {
	Pos      Pos
	End      Pos
	Cond     Expr
	Body     *Block
	Assigned []string // the locals declared outside the loop that its body assigns, filled by the resolver
}

func (*While) EndPosition

func (n *While) EndPosition() Pos

func (*While) Position

func (n *While) Position() Pos

Jump to

Keyboard shortcuts

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