Help us shape the future of Go! Take the 2026 Go Developer Survey

syntax

package
v0.0.91 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package syntax contains bork's lexer, syntax tree, and parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Keywords added in v0.0.4

func Keywords() []string

Keywords returns the reserved words recognized by the lexer.

func Lex

func Lex(file string, src []byte, diags *diag.List) ([]Token, []Comment)

Lex splits src into tokens. Like Go, a newline ends a statement when the line's last token could end one (an identifier, a literal, `return`, `)`, or `}`); the lexer then emits a Semi token. Comments are returned separately.

func LexCompiler

func LexCompiler(file string, src []byte, diags *diag.List) ([]Token, []Comment)

LexCompiler permits reserved names in compiler-owned sources and formatting.

Types

type AmbientDecl

type AmbientDecl struct {
	Pos  diag.Pos
	Name string
	Type *TypeExpr
	// Logged is the position of the logged marker, if present.
	Logged *diag.Pos
	// Propagated is the propagated marker, if present.
	Propagated *Propagated
}

AmbientDecl declares an ambient value: `ambient traceId: String`, optionally marked `logged` (its value is added to every log line written while a with binds it) or `propagated("header")` (sent across process boundaries under that name).

type Argument

type Argument struct {
	Name              string
	Pos, NameEnd, End diag.Pos
	ValueStart        diag.Pos
	// RemovalStart includes the preceding comma, when no comment would
	// be removed with it. Zero for the first argument or commented spans.
	RemovalStart diag.Pos
}

Argument describes a call argument as written; Name is empty for a positional argument. End is after its expression, NameEnd after its label.

type Arm

type Arm struct {
	Pattern Pattern
	Body    Expr
}

type Binary

type Binary struct {
	Pos  diag.Pos // position of the operator
	Op   Kind
	X, Y Expr
}

func (*Binary) Position

func (e *Binary) Position() diag.Pos

type Binding

type Binding struct {
	// Package values use process-lifetime memo cells, including without lazy.
	Package    bool
	AsyncScope Expr
	AsyncPos   diag.Pos
	Lazy       bool
	LazyPos    diag.Pos
	Pos        diag.Pos
	Name       string
	Type       *TypeExpr // nil if not written
	Value      Expr
}

Binding is `name = value`, or `name: Type = value`. Bindings are immutable.

type Block

type Block struct {
	Pos   diag.Pos
	Stmts []Stmt
	Tail  Expr
	End   diag.Pos // position of the closing '}'
}

Block is `{ stmts; tail }`. Tail is the block's value; nil means the block's value is Ok (or Never, if it ends by returning).

func (*Block) Position

func (e *Block) Position() diag.Pos

type BoolLit

type BoolLit struct {
	Pos   diag.Pos
	Value bool
}

func (*BoolLit) Position

func (e *BoolLit) Position() diag.Pos

type Bundle

type Bundle struct {
	Pos   diag.Pos
	Name  string
	Items []*Use // instances, bundles, and pkg.* of imported packages
}

Bundle names a set of instances, which `use` brings into scope at once: `instances Json { ItemDecode, ItemEncode, money.* }`. A package suggests instances to its importers with one.

type Call

type Call struct {
	Start  diag.Pos // start of the callee, including grouping parentheses
	Pos    diag.Pos // position of '('
	End    diag.Pos // position after the closing ')'
	Fun    Expr
	FunEnd diag.Pos // position after the callee, before type arguments
	Args   []Expr
	// Arguments retains labels and source ranges, parallel to Args. A
	// synthesized pipeline input has no label.
	Arguments []Argument
	// TypeArgs are explicit type arguments: `empty[Int]()`.
	TypeArgs []*TypeExpr
	// Pipe retains the source of a desugared pipeline for diagnostics.
	Pipe               diag.Pos
	PipeStart, PipeEnd diag.Pos // range of the receiver expression
	PipeTargetEnd      diag.Pos // end of the original pipeline target
	PipeWrap           bool     // receiver needs parentheses before a selector
	PipeBare           bool     // target was written without call parentheses
}

func (*Call) Position

func (e *Call) Position() diag.Pos

type ClassDecl

type ClassDecl struct {
	Pos        diag.Pos
	Name       string
	TypeParams []*TypeParam
	Methods    []*FuncDecl
}

ClassDecl is a type class: `class Show[T] { fn show(x: T): String }`. Its methods are signatures, without bodies.

type Comment

type Comment struct {
	Text string
	Pos  diag.Pos
	End  diag.Pos // position immediately after the token
}

Comment is a source comment, kept for future tooling (formatter, editor support). The parser does not use comments.

type Comptime

type Comptime struct {
	Pos  diag.Pos
	Body *Block
}

Comptime is an explicit build-time value computation.

func (*Comptime) Position

func (e *Comptime) Position() diag.Pos

type ContextName

type ContextName struct {
	Pos, End diag.Pos
	NamePos  diag.Pos
	Name     string
}

ContextName omits a constructor's owner: .{ ... } or .Variant. Name is empty for a record, and End is after the dot or variant name.

func (*ContextName) Position

func (e *ContextName) Position() diag.Pos

type Copy

type Copy struct {
	Pos     diag.Pos // position of 'copy'
	X       Expr
	Updates []*CopyUpdate
}

Copy is `x.copy(age: 37, address.city: "Oslo")`: a new record equal to x except for the given (possibly nested) fields.

func (*Copy) Position

func (e *Copy) Position() diag.Pos

type CopyUpdate

type CopyUpdate struct {
	PathEnd              diag.Pos
	ValueStart, ValueEnd diag.Pos
	Pos                  diag.Pos
	Path                 []string
	Value                Expr
}

type DeriveDecl added in v0.0.65

type DeriveDecl struct {
	Pos, End diag.Pos
	ClassPos diag.Pos
	Class    string
	Type     *TypeExpr
}

DeriveDecl requests one instance independently of a type declaration.

type Effect

type Effect struct {
	Pos  diag.Pos
	Name string
}

Effect is one effect named in a `uses` declaration.

type Expr

type Expr interface {
	Position() diag.Pos
	// contains filtered or unexported methods
}

Expr is an expression. Everything that produces a value is an expression, including if, blocks, and return.

type ExprStmt

type ExprStmt struct {
	X Expr
}

type ExpressionSpan added in v0.0.17

type ExpressionSpan struct {
	Expr Expr
	SourceSpan
}

type FieldDecl

type FieldDecl struct {
	Lazy    bool
	LazyPos diag.Pos
	GoTags  []GoTag
	Default Expr
	Doc     string
	Pos     diag.Pos
	Name    string
	Type    *TypeExpr
}

type FieldInit

type FieldInit struct {
	Pos   diag.Pos
	Name  string
	Value Expr
}

type FieldPat

type FieldPat struct {
	Pos     diag.Pos
	Field   string
	Pattern Pattern // nil for the `{ radius }` shorthand
}

FieldPat is one field of a destructuring pattern: `{ radius }` binds the field to its own name, and `{ radius: p }` matches it against the pattern p (a name to bind, a literal, a nested pattern, ...).

type File

type File struct {
	// PatternTestOperators includes contextual is positions, including unfinished edits.
	PatternTestOperators []diag.Pos
	// ExpressionSpans retains parser ranges, including grouping, for compiler
	// source queries and refactorings. One node can have several grouped spans.
	ExpressionSpans []ExpressionSpan
	// Script marks a single executable file with an implicit main.
	Script bool
	Path   string
	// Source retains the original text for compile-time debug probes.
	Source string
	// Package is the import path of the file's package (set by the
	// driver), and Imports what the file imports.
	Package string
	Imports []*Import
	Uses    []*Use
	Bundles []*Bundle
	Rules   []*RuleDecl
	// Classes and Instances; the instances' methods are also in Funcs.
	Classes       []*ClassDecl
	Instances     []*InstanceDecl
	Derives       []*DeriveDecl
	Templates     []*InstanceDecl
	DeriveHelpers []*FuncDecl
	// Prelude is set for the compiler's built-in prelude.
	Prelude  bool
	Types    []*TypeDecl
	Ambients []*AmbientDecl
	Funcs    []*FuncDecl
	// Bindings contains immutable package values.
	Bindings []*Binding
	Tests    []*TestDecl
	Comments []Comment
}

File is one parsed .bork source file.

func Parse

func Parse(path string, src []byte, diags *diag.List) *File

Parse parses one source file. Syntax errors are added to diags; the returned file holds whatever could be parsed.

func ParseEmbedded

func ParseEmbedded(path string, src []byte, diags *diag.List) *File

ParseEmbedded reuses the immutable tokens of embedded prelude/standard sources. Every call builds a fresh syntax tree: the checker expands calls in that tree. User files use Parse, so edits do not grow this bounded compiler-source cache.

func ParseFiles

func ParseFiles(paths []string, srcs [][]byte, embedded bool, diags *diag.List) []*File

ParseFiles parses independent sources concurrently when there is enough work to amortize worker setup. Files and diagnostics retain the input order.

func ParseScript

func ParseScript(path string, src []byte, diags *diag.List) *File

ParseScript parses top-level statements as the body of an implicit main.

type FloatLit

type FloatLit struct {
	Pos  diag.Pos
	Text string
}

FloatLit is a floating-point literal: `1.5`, `2e10`.

func (*FloatLit) Position

func (e *FloatLit) Position() diag.Pos

type For

type For struct {
	Comptime      bool
	Comprehension bool
	Pos           diag.Pos
	Name          string
	NamePos       diag.Pos
	Items         Expr
	Body          *Block

	Cond    Expr
	Clauses bool
	Init    []*Binding
	Post    []*Binding
}

For is a loop (see docs/design/loops.md). With Items it is `for (x in xs)`. Otherwise it is `for { }` (no header), `for (cond)` (Cond alone), or `for (init; cond; post)` (Clauses), whose Init binds the loop's header names and whose Post rebinds them for the next iteration; Cond may then be nil.

func (*For) Form added in v0.0.85

func (f *For) Form() ForForm

func (*For) Position

func (e *For) Position() diag.Pos

type ForForm added in v0.0.85

type ForForm int

ForForm says which form of loop f is.

const (
	ForIn       ForForm = iota // for (x in xs)
	ForInfinite                // for { }
	ForWhile                   // for (cond)
	ForClauses                 // for (init; cond; post)
)

type FuncDecl

type FuncDecl struct {
	// ScriptMain is the synthetic entrypoint of a script.
	ScriptMain bool
	// Derivation marks a compile-time helper, available only to derive templates.
	Derivation bool
	// Constructor names the owning record in `fn New = Config.new`.
	Constructor *TypeExpr
	Pos         diag.Pos
	End         diag.Pos // just after the complete declaration, including a body when present
	Name        string
	// IsPred is set for `pred name(x: T, ...) { ... }`: a function
	// returning Bool that can be used in `where` clauses.
	IsPred bool
	// TypeParams lists the type parameters of a generic function:
	// `fn map[A, B](...)`.
	TypeParams []*TypeParam
	Params     []*Param
	// ParamsEnd is the position of the ')' that ends the parameters.
	ParamsEnd diag.Pos
	// Requires relates function inputs; result constraints remain on Result.
	Requires Expr
	// Uses lists the effects the function may have, `uses io + net`,
	// or is nil when it declares none.
	Uses *Uses
	// Needs lists the ambient values it reads, `needs traceId +
	// locale?`, or is nil when it reads none.
	Needs  *Needs
	Result *TypeExpr
	Body   *Block
	GoBody *GoCode
	// GoBind is set instead of a body for a binding to a Go function:
	// `fn Getenv(key: String): String unsafe go "os.Getenv"`.
	GoBind *GoBind
	// Instance is set for a method of an instance declaration.
	Instance *InstanceDecl
	// IsMethod is set for a method, `fn (xs: List[T]) first[T](): T`:
	// its receiver is its first parameter.
	IsMethod bool
}

FuncDecl is `fn name(params): Result { body }`. Result is nil when the function returns Ok. A function implemented in Go has GoBody instead of Body.

func (*FuncDecl) IsGo

func (fd *FuncDecl) IsGo() bool

IsGo reports whether the function is implemented in Go, by an `unsafe go` body or a binding: bork trusts its signature.

type FuncTypeExpr

type FuncTypeExpr struct {
	Params []*TypeExpr
	Uses   *Uses
	Result *TypeExpr
}

FuncTypeExpr is a function type: `(A, B) => C`, or with effects, `(A) uses io => C`.

type Generate

type Generate struct {
	Pos  diag.Pos
	Elem *TypeExpr
	Body *Block
}

func (*Generate) Position

func (e *Generate) Position() diag.Pos

type GoBind

type GoBind struct {
	Pos  diag.Pos // position of the string
	Name string
}

GoBind names the Go function a binding calls, with its import path: "os.Getenv", "crypto/sha256.Sum256".

type GoCode

type GoCode struct {
	Pos     diag.Pos // position of '{'
	Imports []string
	// ImportAliases contains explicit aliases by path.
	ImportAliases map[string]string
	// Body is the text between the braces, with the import lines
	// blanked out, so its lines still match the source.
	Body string
}

GoCode is the body of `unsafe go { ... }`: Go statements, preceded by optional `import [alias] "path"` lines.

type GoTag

type GoTag struct {
	Pos         diag.Pos
	Name, Value string
}

GoTag is an ordered Go struct tag on a generated field.

type Ident

type Ident struct {
	Pos  diag.Pos
	Name string
}

func (*Ident) Position

func (e *Ident) Position() diag.Pos

type If

type If struct {
	Comptime bool
	Pos      diag.Pos
	Cond     Expr
	Then     *Block
	Else     Expr
}

If is `if (cond) { ... } else { ... }`. Else is nil, a *Block, or an *If (for `else if`).

func (*If) Position

func (e *If) Position() diag.Pos

type Import

type Import struct {
	Pos  diag.Pos
	End  diag.Pos // after the quoted import path
	Name string   // what the file calls the package
	Path string
}

Import is `import "example.com/shop/money"` or, with a name to use instead of the path's last element, `import cash "example.com/shop/money"`.

The parser reads a use of an imported name, `money.add` or `money.Amount`, as one qualified name: an Ident (or type, predicate, or pattern name) "money.add".

type InstanceDecl

type InstanceDecl struct {
	// Derivation marks a template rather than a selectable instance.
	Derivation bool
	Pos        diag.Pos
	Name       string
	TypeParams []*TypeParam
	Class      string // possibly qualified: fmt.Show
	ClassPos   diag.Pos
	Type       *TypeExpr
	Methods    []*FuncDecl
	Metadata   []*InstanceMetadata
}

InstanceDecl is a named instance of a class for a type: `instance showInt: Show[Int] { fn show(x: Int): String { ... } }`, or generic: `instance showList[T: Show]: Show[List[T]] { ... }`.

type InstanceMetadata added in v0.0.90

type InstanceMetadata struct {
	Pos   diag.Pos
	Type  *TypeExpr
	Value Expr
}

InstanceMetadata associates a checked expression with its resolved type key. Metadata is contextual instance syntax, not a reserved word.

type IntLit

type IntLit struct {
	Pos  diag.Pos
	Text string
}

func (*IntLit) Position

func (e *IntLit) Position() diag.Pos

type Interp

type Interp struct {
	Prefix    Expr     // nil for the built-in s prefix
	PrefixEnd diag.Pos // opening quote position for a named prefix
	Pos       diag.Pos
	Parts     []string
	Exprs     []Expr
}

Interp is an interpolated string: s"Hello $name, ${age + 1}". Parts holds the (unquoted) text around the expressions, so it has one more element than Exprs.

func (*Interp) Position

func (e *Interp) Position() diag.Pos

type Is added in v0.0.61

type Is struct {
	Pos     diag.Pos // contextual is operator
	End     diag.Pos
	X       Expr
	Pattern Pattern
}

Is tests a value against a pattern without introducing source bindings.

func (*Is) Position added in v0.0.61

func (x *Is) Position() diag.Pos

type Kind

type Kind int

Kind is the kind of a token.

const (
	EOF Kind = iota
	Illegal
	Semi // explicit ';' or a newline that ends a statement

	TIdent
	TInt
	TFloat
	TRune
	TString
	TInterp // s"...": the text from the opening quote to the closing one
	TGoCode // the raw Go inside `unsafe go { ... }`

	// Keywords
	KwFn
	KwIf
	KwElse
	KwReturn
	KwTrue
	KwFalse
	KwType
	KwSealed
	KwMatch
	KwUnsafe
	KwPred
	KwWhere
	KwAnd
	KwTrust
	KwRule
	KwOr
	KwGenerate
	KwYield
	KwFor
	KwBreak
	KwContinue

	// Delimiters
	LParen
	RParen
	LBrace
	RBrace
	LBrack
	RBrack
	Comma
	Colon
	Dot
	Ellipsis   // ... in a list pattern
	Underscore // the wildcard pattern _

	// Operators
	Assign // =
	Plus   // +
	Minus  // -
	Star   // *
	Slash  // /
	Pct    // %
	Amp    // &
	Caret  // ^ (binary XOR or unary complement)
	Shl    // <<
	Shr    // >>
	Not    // !
	AndAnd // &&
	OrOr   // ||
	Eq     // ==
	NotEq  // !=
	Lt     // <
	LtEq   // <=
	Gt     // >
	GtEq   // >=
	Pipe   // |
	PipeGt // |>
	Arrow  // =>
	Quest  // ?
)

func (Kind) String

func (k Kind) String() string

type Lambda

type Lambda struct {
	Pos    diag.Pos
	Params []*Param
	Body   Expr
}

Lambda is a function value: `x => x + 1`, `(a, b) => a + b`, or `(x: Int) => { ... }`.

func (*Lambda) Position

func (e *Lambda) Position() diag.Pos

type ListLit

type ListLit struct {
	Pos   diag.Pos
	Elems []Expr
}

ListLit is a list literal: `[1, 2, 3]`.

func (*ListLit) Position

func (e *ListLit) Position() diag.Pos

type ListPat

type ListPat struct {
	Pos     diag.Pos
	Elems   []Pattern
	HasRest bool
	Rest    string // "" when ignored
	RestPos diag.Pos
}

VariantPat is a name pattern: a variant (`Shape.Circle { radius }`, `Option.None`), a type (`NotFound`), a record destructure (`User { name }`), or, for a single name that is not a type, a binding of the whole value (`n`). ListPat matches a list: `[]`, `[a, b]`, or `[first, ...rest]` (Rest binds the remaining elements; `[first, ...]` ignores them).

func (*ListPat) Position

func (p *ListPat) Position() diag.Pos

type LitPat

type LitPat struct {
	Pos   diag.Pos
	Value Expr
}

LitPat is a literal pattern: a number, String, or Bool literal.

func (*LitPat) Position

func (p *LitPat) Position() diag.Pos

type LoopControl

type LoopControl struct {
	Pos      diag.Pos
	Continue bool
}

func (*LoopControl) Position

func (e *LoopControl) Position() diag.Pos

type MapLit

type MapLit struct {
	Pos    diag.Pos
	Keys   []Expr
	Values []Expr
}

MapLit is a map literal: `{"a": 1, "b": 2}`, or `{:}` for the empty map.

func (*MapLit) Position

func (e *MapLit) Position() diag.Pos

type Match

type Match struct {
	Comptime          bool
	Pos               diag.Pos
	Close             diag.Pos // the closing brace, before which new arms can be inserted
	TrailingSeparator bool     // the final arm already has a comma or newline
	X                 Expr
	Arms              []*Arm
}

Match is `match (x) { pattern => value, ... }`.

func (*Match) Position

func (e *Match) Position() diag.Pos

type MockStmt

type MockStmt struct {
	Pos     diag.Pos // the binding's name, or 'mock'
	Name    string   // the handle's name, or ""
	MockPos diag.Pos // 'mock'
	Target  Expr
	Params  []*Param
	// ParamsStart and ParamsEnd are the positions of the '(' and ')'
	// around the parameters.
	ParamsStart, ParamsEnd diag.Pos
	// Requires relates function inputs; result constraints remain on Result.
	Requires Expr
	Body     *Block
}

MockStmt is `mock target(a, b) { ... }`, or `m = mock target(...) { ... }` with a handle m that records the calls: in a test, it replaces the function target until the end of the enclosing block. Target is an *Ident (`fetch`, `payments.Charge`) or a *Selector naming a method (`Store.save`, `model.Point.Value`). Params holds the parameters' names only (no types); `_` ignores one.

type Need

type Need struct {
	Pos      diag.Pos
	Name     string // as written: traceId, or trace.Id
	Optional bool
}

Need is one ambient value named in a `needs` declaration; Optional is set for `locale?`, which is read as an Option.

type Needs

type Needs struct {
	Pos   diag.Pos
	End   diag.Pos // just after the last need
	Items []*Need
}

Needs is a declaration of the ambient values a function reads: `needs traceId + locale?`.

type Param

type Param struct {
	Pos  diag.Pos
	Name string
	Type *TypeExpr
	// Default is the value of a function parameter that a call may
	// leave out (`attrs: Map[String, Int] = {:}`), or nil.
	Default Expr
	// In names the parameter (a Scope or an OwnedScope) whose scope this
	// one belongs to, in `conn: Conn in prev`; "" if none.
	In    string
	InPos diag.Pos
}

Param is a function's or a lambda's parameter. A lambda's parameter may leave out its type (Type is nil).

type Pattern

type Pattern interface {
	Position() diag.Pos
	// contains filtered or unexported methods
}

Pattern is a match pattern.

type PredRef

type PredRef struct {
	Pos  diag.Pos
	Name string
	Args []Expr
	Or   []*PredRef
}

PredRef is one predicate in a where clause: `positive`, or `between(1, 65535)`, whose arguments are constants or parameter names. The constrained value itself is the predicate's first argument and is not written. A clause with alternatives, `p or q`, has the first in Name and Args and the rest in Or.

type Propagated

type Propagated struct {
	Pos       diag.Pos
	Header    string
	HeaderPos diag.Pos
}

Propagated is the `propagated("traceparent")` marker of an ambient declaration: the name of the header (or message metadata) that carries the value.

type RecordLit

type RecordLit struct {
	Positional bool // synthetic ordered payload literal of a variant call
	Type       Expr // *Ident, *TypeHead, *Selector or *ContextName
	Fields     []*FieldInit
	End        diag.Pos
}

RecordLit is `User { name: "Ada", age: 36 }` or `Shape.Circle { radius: 3 }`.

func (*RecordLit) Position

func (e *RecordLit) Position() diag.Pos

type Return

type Return struct {
	Pos   diag.Pos
	Value Expr
}

Return is `return` or `return value`. Its own type is Never.

func (*Return) Position

func (e *Return) Position() diag.Pos

type RuleDecl

type RuleDecl struct {
	Pos         diag.Pos
	Name        string
	Params      []*Param
	Premises    []Expr
	Conclusions []Expr
}

RuleDecl is an inference rule:

rule weaken(x: Int, a: Int, b: Int) {
  atLeast(x, a) and a >= b => atLeast(x, b)
}

Premises are predicate calls (facts to find) or other Bool expressions (conditions, computed when their variables are constants). Conclusions are predicate calls.

type RuneLit

type RuneLit struct {
	Pos  diag.Pos
	Text string
}

RuneLit is a rune (Unicode code point) literal: 'a', '\n'.

func (*RuneLit) Position

func (e *RuneLit) Position() diag.Pos

type ScopeExpr

type ScopeExpr struct {
	Pos  diag.Pos
	Name string
	// Policies are those of `scope s with taskTimeout(100),
	// cleanupTimeout(500) { ... }`; none for the defaults.
	Policies []Expr
	Body     *Block
}

ScopeExpr is `scope s { ... }`: a block with a scope named s, which closes (running its finalizers) when the block ends.

func (*ScopeExpr) Position

func (e *ScopeExpr) Position() diag.Pos

type Select added in v0.0.85

type Select struct {
	Pos   diag.Pos
	Close diag.Pos // the closing brace
	Arms  []*SelectArm
}

Select is `select { n = ch.receive(s) => value, ... }`: it waits until one of its arms' channel operations can complete, completes only that one, and gives the value of its arm.

func (*Select) Position added in v0.0.85

func (e *Select) Position() diag.Pos

type SelectArm added in v0.0.85

type SelectArm struct {
	Pos     diag.Pos
	Name    string // the binding of the operation's result, or ""
	NamePos diag.Pos
	Op      Expr
	Body    Expr
}

SelectArm is one arm of a select: `[name =] op => body`, where op is a channel's receive or send call, or `_ => body` (Op nil), which runs when no operation is ready, so the select does not wait.

type Selector

type Selector struct {
	Pos  diag.Pos // position of the name
	X    Expr
	Name string
}

Selector is `x.name`: a field access, or a qualified variant (`Shape.Empty`).

func (*Selector) Position

func (e *Selector) Position() diag.Pos

type SourceSpan added in v0.0.17

type SourceSpan struct{ Start, End diag.Pos }

type StaticPartsLit

type StaticPartsLit struct {
	Pos   diag.Pos
	Parts []string
}

StaticPartsLit is created only by the checker for a named interpolation. It has no source syntax: runtime Strings cannot acquire literal provenance.

func (*StaticPartsLit) Position

func (e *StaticPartsLit) Position() diag.Pos

type Stmt

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

Stmt is a statement inside a block.

type StringLit

type StringLit struct {
	Pos   diag.Pos
	Value string // unquoted
}

func (*StringLit) Position

func (e *StringLit) Position() diag.Pos

type TestDecl

type TestDecl struct {
	Pos    diag.Pos
	Name   string
	Params []*Param
	Body   *Block
}

TestDecl is a test: `test "adds numbers" { assert(add(1, 2) == 3) }`. Tests run with `bork test`, and are left out of programs. A test with parameters is a property test, run on generated values of them: `test "doubles" (n: Int where small) { assert(double(n) > n) }`.

type Token

type Token struct {
	Kind Kind
	Text string
	Pos  diag.Pos
	End  diag.Pos // position immediately after the token
}

Token is a lexed token. Text holds the source text for identifiers and literals.

type TrustStmt

type TrustStmt struct {
	Pos  diag.Pos
	Call *Call
}

TrustStmt is `trust p(x, ...)`: from here on, p(x, ...) is taken as a fact without proof.

type Try

type Try struct {
	Pos diag.Pos // position of '?'
	X   Expr
}

Try is `x?`: keep the leftmost member of x's type, and return every other member from the enclosing function.

func (*Try) Position

func (e *Try) Position() diag.Pos

type TupleBinding added in v0.0.60

type TupleBinding struct {
	Pos     diag.Pos
	Pattern *TuplePat
	Value   Expr
}

ExprStmt is an expression evaluated for its effect.

type TupleLit added in v0.0.60

type TupleLit struct {
	Pos, End diag.Pos
	Elems    []Expr
}

func (*TupleLit) Position added in v0.0.60

func (e *TupleLit) Position() diag.Pos

type TuplePat added in v0.0.60

type TuplePat struct {
	Pos, End diag.Pos
	Elems    []Pattern
}

func (*TuplePat) Position added in v0.0.60

func (p *TuplePat) Position() diag.Pos

type TypeDecl

type TypeDecl struct {
	Pos  diag.Pos
	Name string
	// TypeParams lists a generic type's parameters: `type Pair[A, B]`.
	TypeParams []*TypeParam
	GoName     *GoBind
	Kind       TypeKind
	Private    bool           // record construction belongs to its package
	Fields     []*FieldDecl   // RecordType
	Variants   []*VariantDecl // SealedType
	Alias      *TypeExpr      // AliasType
	Where      []*PredRef     // whole-value invariants on records and sealed types
	// Derive lists the classes to derive instances of:
	// `type User = { ... } derive (Decode, Encode)`.
	Derive    []string
	DerivePos diag.Pos
}

TypeDecl is `type Name = ...`.

type TypeExpr

type TypeExpr struct {
	Uses *Uses // latent effects on Seq[T]

	Pos   diag.Pos
	Name  string
	Args  []*TypeExpr
	Tuple []*TypeExpr // non-nil for a positional tuple type
	Union []*TypeExpr // non-nil for a union; Name and Args are then unused
	// Func is set for a function type `(A, B) => C`; Name and Args are
	// then unused.
	Func *FuncTypeExpr
	// Where lists the clauses of `T where p and (q(1) or r)`, all of
	// which must hold.
	Where []*PredRef
}

TypeExpr is a written type: a name with optional type arguments (`Option[Int]`), or a union of types (`User | NotFound`).

type TypeHead

type TypeHead struct {
	Type *TypeExpr
	End  diag.Pos
}

TypeHead specializes a constructor owner, as in Box[Int] or Option[Int].None.

func (*TypeHead) Position

func (e *TypeHead) Position() diag.Pos

type TypeKind

type TypeKind int

TypeKind says what a type declaration declares.

const (
	RecordType   TypeKind = iota // type User = { name: String }
	SealedType                   // type Shape = sealed { Circle { radius: Int }, Empty }
	AliasType                    // type Result = User | NotFound
	ResourceType                 // type File = resource
	GoType                       // type Request = go "*net/http.Request"
)

type TypeParam

type TypeParam struct {
	Pos  diag.Pos
	Name string
	// Bounds lists the classes the type must have instances of:
	// `T: Show + Eq`.
	Bounds []string
}

TypeParam is a declared type parameter.

type TypePat

type TypePat struct {
	Pos  diag.Pos
	Name string
	Type *TypeExpr
}

TypePat is `name: Type`; it matches values of that type and binds them.

func (*TypePat) Position

func (p *TypePat) Position() diag.Pos

type Unary

type Unary struct {
	Pos diag.Pos
	Op  Kind
	X   Expr
}

func (*Unary) Position

func (e *Unary) Position() diag.Pos

type Use

type Use struct {
	Pos  diag.Pos
	Name string // "money.showAmount" or "money.*"
}

Use brings instances of another package into scope: `use money.showAmount`, or every exported one: `use money.*`.

type Uses

type Uses struct {
	Pos     diag.Pos
	End     diag.Pos // just after the last effect (or nothing)
	Effects []Effect
}

Uses is a declaration of effects: `uses io + net`, or `uses nothing` (Effects is then empty).

func (*Uses) TailRec added in v0.0.85

func (u *Uses) TailRec() (diag.Pos, bool)

TailRec is the position of the tailrec marker among the effects, if the list has one: `uses io + tailrec`. It is not an effect (see docs/design/loops.md).

type VariantDecl

type VariantDecl struct {
	Positional bool
	Slots      []*TypeExpr
	Pos        diag.Pos
	Name       string
	Fields     []*FieldDecl
	Where      []*PredRef
}

type VariantPat

type VariantPat struct {
	PayloadPos diag.Pos
	PayloadEnd diag.Pos
	Owner      *TypeExpr // explicit specialized owner, when written
	Positional bool
	Elems      []Pattern
	Pos        diag.Pos
	NamePos    diag.Pos // written context variant identifier, after whitespace/comments
	End        diag.Pos // end of a context variant name, for diagnostics and fixes
	Context    bool     // owner omitted with .Variant
	Path       []string
	Fields     []*FieldPat
	Braces     bool // written with { ... }, possibly empty
}

func (*VariantPat) Position

func (p *VariantPat) Position() diag.Pos

type WildcardPat

type WildcardPat struct{ Pos diag.Pos }

WildcardPat is `_`.

func (*WildcardPat) Position

func (p *WildcardPat) Position() diag.Pos

type WithBinding

type WithBinding struct {
	Pos   diag.Pos
	Name  string // as written: traceId, or trace.Id
	Value Expr
}

WithBinding is one `name: value` of a with.

type WithExpr

type WithExpr struct {
	Pos      diag.Pos
	Bindings []*WithBinding
	Body     *Block
}

WithExpr binds ambient values for a block: `with (traceId: id, principal: p) { ... }`.

func (*WithExpr) Position

func (e *WithExpr) Position() diag.Pos

type Yield

type Yield struct {
	Pos   diag.Pos
	Value Expr
}

func (*Yield) Position

func (e *Yield) Position() diag.Pos

Jump to

Keyboard shortcuts

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