wit

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 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 LastSegment added in v0.6.0

func LastSegment(path string) string

LastSegment is the item name in a use path: "c" in "c" or "a:b/c@1.0.0".

Types

type Accessor added in v0.6.0

type Accessor int

Accessor says whether a func is a property getter ("name: get() -> T") or setter ("name: set(value: T)").

const (
	NoAccessor Accessor = iota
	Getter
	Setter
)

type Attrs added in v0.6.0

type Attrs struct {
	Gate       Gate
	ExternalID []Pos
}

Attrs are the attributes written before an item: its gate, and the position of each "@external-id(...)", in order.

type Enum

type Enum struct {
	Cases []string
	Pos   []Pos // of each case
}

Enum represents an enum type.

type Error added in v0.6.0

type Error struct {
	Pos Pos
	Msg string
}

Error is a WIT error at a place in a source.

func (*Error) Error added in v0.6.0

func (e *Error) Error() string

type Export

type Export struct {
	Extern
}

Export represents an export statement.

type Extern added in v0.6.0

type Extern struct {
	Name string
	Pos  Pos
	Kind ExternKind
	Attrs
}

Extern is what an import or export names. Name is the func's, inline interface's or label's name -- or, for an interface named by path alone, the path.

type ExternFunc added in v0.6.0

type ExternFunc struct{ Func Func }

ExternFunc is "name: func(...)".

type ExternInterface added in v0.6.0

type ExternInterface struct{ Items []InterfaceItem }

ExternInterface is "name: interface { ... }".

type ExternKind added in v0.6.0

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

ExternKind is the shape of an import or export.

type ExternNamedPath added in v0.6.0

type ExternNamedPath struct {
	Path    string
	PathPos Pos
}

ExternNamedPath is "label: path;": an import or export under a name of its own that implements the interface at Path.

type ExternPath added in v0.6.0

type ExternPath struct{}

ExternPath is an interface named by path alone: "iface;" or "ns:pkg/iface@ver;". Its Extern.Name is the path.

type Flags

type Flags struct {
	Flags []string
	Pos   []Pos // of each flag
}

Flags represents a flags (bitset) type.

type Func

type Func struct {
	Params   []FuncParam
	Result   *TypeRef // nil if no return type, or points to the result type
	Async    bool
	Accessor Accessor
	Pos      Pos // the `func`, `get`, `set` or `constructor` keyword
}

Func represents a function definition or type.

type FuncParam

type FuncParam struct {
	Name string
	Pos  Pos
	Type TypeRef
}

FuncParam represents a function parameter.

type Gate

type Gate []GateItem

Gate is zero or more feature-gate attributes stacked immediately before an item (e.g. "@since(version = 0.2.0) @deprecated(version = 0.2.2)").

type GateItem

type GateItem struct {
	Kind    string // "since", "unstable", or "deprecated"
	Version string // semver value, set for "since" and "deprecated"
	Feature string // feature name, set for "unstable"
	Pos     Pos
}

GateItem is a single feature-gate attribute attached to a WIT item: "@since(version = X)", "@unstable(feature = X)", or "@deprecated(version = X)".

type Import

type Import struct {
	Extern
}

Import represents an import statement.

type Include

type Include struct {
	Path    string
	PathPos Pos
	Renames []IncludeName
	Attrs
}

Include represents an "include world;" or "include world with { a as a1, b as b1 }" statement.

type IncludeName added in v0.6.0

type IncludeName struct {
	Name, As string
	Pos      Pos
}

IncludeName is one "a as b" of an include's with-list.

type Interface

type Interface struct {
	Name  string
	Pos   Pos
	Items []InterfaceItem
	Attrs
}

Interface represents a WIT interface definition.

type InterfaceFunc

type InterfaceFunc struct {
	Name string
	Pos  Pos
	Func Func
	Attrs
}

InterfaceFunc represents a named function item directly inside an interface, e.g. "read: func(len: u64) -> result<list<u8>, stream-error>;".

type InterfaceItem

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

InterfaceItem is a marker interface for items within an interface.

type Package

type Package struct {
	// Name is the package name ("wasi:io@0.2.0"), or "" without a header.
	Name    string
	NamePos Pos
	// Docs says whether comments precede a file's header, which
	// wit-parser takes as the package's docs.
	Docs bool
	// Items are *Interface, *World and *ToplevelUse.
	Items  []PackageItem
	Nested []*Package
}

Package is one parsed WIT file: an optional "package ns:name@ver;" header, the items at its top level, and any nested "package ns:name { ... }" blocks, each a package of its own.

func Parse

func Parse(filename, src string) (*Package, error)

Parse parses one WIT file. filename is used for positions.

type PackageItem

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

PackageItem is a marker interface for top-level package items.

type Pos added in v0.6.0

type Pos struct {
	File      string
	Line, Col int
}

Pos is where an item is written: a file, and a 1-based line and byte column, as wit-parser reports them.

func (Pos) String added in v0.6.0

func (p Pos) String() string

type Record

type Record struct {
	Fields []RecordField
}

Record represents a record type.

type RecordField

type RecordField struct {
	Name string
	Pos  Pos
	Type TypeRef
}

RecordField represents a field in a record.

type Resource

type Resource struct {
	Methods []ResourceMethod
}

Resource represents a resource type.

type ResourceMethod

type ResourceMethod struct {
	Name          string
	Pos           Pos
	IsStatic      bool
	IsConstructor bool
	Func          Func
	Attrs
}

ResourceMethod represents a method, static function, or constructor on a resource: "name: func(...)", "name: static func(...)", or "constructor(...)".

type ToplevelUse added in v0.6.0

type ToplevelUse struct {
	Path    string
	PathPos Pos
	As      string // "" for none
	AsPos   Pos
	Pos     Pos // the `use` keyword
	Attrs
}

ToplevelUse is "use path;" or "use path as name;" at a file's top level: it names an interface or world for the rest of that file.

func (*ToplevelUse) Local added in v0.6.0

func (u *ToplevelUse) Local() (string, Pos)

Local is the name a ToplevelUse is known by in its file.

type TypeAlias

type TypeAlias struct {
	Target TypeRef
}

TypeAlias represents a type alias (e.g., "type foo = u32;").

type TypeDef

type TypeDef struct {
	Name string
	Pos  Pos
	Type TypeDefBody
	Attrs
}

TypeDef represents a type definition.

type TypeDefBody

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

TypeDefBody represents the body of a type definition.

type TypeRef

type TypeRef struct {
	Kind   string     // "u32", "string", "list", "option", "result", "named", etc.
	Name   string     // for named types and own/borrow handles
	Inner  *TypeRef   // list<T>, option<T>, result<T, _>, map<K, _>, future<T>, stream<T>
	Inner2 *TypeRef   // result<_, E>, map<_, V>
	Tuple  []*TypeRef // tuple<T1, T2, ...>
	Fixed  bool       // list<T, N>: a fixed-length list
	Length uint32     // list<T, N>: N
	Pos    Pos
}

TypeRef represents a type reference (including primitive types and compound types).

func (*TypeRef) String

func (t *TypeRef) String() string

String returns the type as WIT writes it.

type Use

type Use struct {
	Path    string // "iface" or "ns:pkg/iface@ver"
	PathPos Pos
	Names   []UseName
	Attrs
}

Use represents "use path.{a, b as c};" in an interface or world.

type UseName added in v0.6.0

type UseName struct {
	Name  string
	Pos   Pos
	As    string
	AsPos Pos
}

UseName is one name a Use brings in: Name, under As if that is set.

func (UseName) Local added in v0.6.0

func (n UseName) Local() (string, Pos)

Local is the name a UseName is known by in the using scope.

type Variant

type Variant struct {
	Cases []VariantCase
}

Variant represents a variant type (discriminated union).

type VariantCase

type VariantCase struct {
	Name string
	Pos  Pos
	Type *TypeRef // nil if no associated data
}

VariantCase represents a case in a variant.

type World

type World struct {
	Name  string
	Pos   Pos
	Items []WorldItem
	Attrs
}

World represents a WIT world definition.

type WorldItem

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

WorldItem is a marker interface for items within a world.

Jump to

Keyboard shortcuts

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