wit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 3 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

This section is empty.

Types

type Enum

type Enum struct {
	Cases []string
}

Enum represents an enum type.

type Export

type Export struct {
	Name       string
	Type       ExportType
	Gate       Gate
	ExternalID string
}

Export represents an export statement.

type ExportFunc

type ExportFunc struct {
	Func Func
}

ExportFunc represents an exported function.

type ExportInterface

type ExportInterface struct {
	Items []InterfaceItem
}

ExportInterface represents an exported interface.

type ExportType

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

ExportType is a marker for export kinds.

type Flags

type Flags struct {
	Flags []string
}

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
}

Func represents a function definition or type.

type FuncParam

type FuncParam struct {
	Name string
	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"
}

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 {
	Name       string
	Type       ImportType
	Gate       Gate
	ExternalID string
}

Import represents an import statement.

type ImportFunc

type ImportFunc struct {
	Func Func
}

ImportFunc represents an imported function.

type ImportInterface

type ImportInterface struct {
	Items []InterfaceItem
}

ImportInterface represents an imported interface.

type ImportType

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

ImportType is a marker for import kinds.

type Include

type Include struct {
	Path       string
	Renames    map[string]string // original name -> alias
	Gate       Gate
	ExternalID string
}

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

type Interface

type Interface struct {
	Name       string
	Items      []InterfaceItem
	Gate       Gate
	ExternalID string
}

Interface represents a WIT interface definition.

type InterfaceFunc

type InterfaceFunc struct {
	Name       string
	Func       Func
	Gate       Gate
	ExternalID string
}

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 Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer tokenizes WIT source code.

func NewLexer

func NewLexer(input string) *Lexer

NewLexer creates a new lexer for the given source.

func (*Lexer) NextToken

func (lex *Lexer) NextToken() Token

NextToken returns the next token from the input.

type Package

type Package struct {
	// Name is the fully-qualified package name (e.g., "wasi:io@0.2.0").
	Name string

	// Items are the top-level declarations (interfaces, worlds, type definitions, use statements).
	Items []PackageItem
}

Package represents a WIT package definition.

func Parse

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

Parse parses WIT source code and returns a Package AST. name is used for error reporting.

type PackageItem

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

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

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses WIT source code into an AST.

type Record

type Record struct {
	Fields []RecordField
}

Record represents a record type.

type RecordField

type RecordField struct {
	Name string
	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
	IsStatic      bool
	IsConstructor bool
	Func          Func
	Gate          Gate
	ExternalID    string
}

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

type Token

type Token struct {
	Type   TokenType
	Text   string
	Line   int
	Column int
}

Token represents a lexical token.

func Tokenize

func Tokenize(source string) ([]Token, error)

Tokenize returns all tokens from the source.

type TokenType

type TokenType int

TokenType represents the kind of token.

const (
	TokenEOF TokenType = iota
	TokenError

	// Literals
	TokenIdent
	TokenString
	TokenVersion // semver

	// Keywords
	TokenPackage
	TokenInterface
	TokenWorld
	TokenKeywordType // "type" keyword
	TokenRecord
	TokenVariant
	TokenEnum
	TokenFlags
	TokenResource
	TokenFunc
	TokenUse
	TokenImport
	TokenExport
	TokenAs
	TokenAsync
	TokenConstructor
	TokenStatic

	// Primitive types
	TokenBool
	TokenS8
	TokenS16
	TokenS32
	TokenS64
	TokenU8
	TokenU16
	TokenU32
	TokenU64
	TokenF32
	TokenF64
	TokenChar
	TokenString_Keyword // "string" as a type keyword
	TokenList
	TokenOption
	TokenResult
	TokenTuple
	TokenMap
	TokenFuture
	TokenStream
	TokenOwn
	TokenBorrow
	TokenErrorContext // "error-context": the async ABI's terminal error-context type

	// Punctuation
	TokenLParen    // (
	TokenRParen    // )
	TokenLBrace    // {
	TokenRBrace    // }
	TokenLAngle    // <
	TokenRAngle    // >
	TokenColon     // :
	TokenSemicolon // ;
	TokenComma     // ,
	TokenDot       // .
	TokenEq        // =
	TokenArrow     // ->
	TokenSlash     // /
	TokenAt        // @
	TokenStar      // *

	// Feature gates
	TokenUnstable
	TokenSince
	TokenDeprecated
	TokenExternalID
	TokenFeature
	TokenVersion_Keyword
	TokenInclude
	TokenWith
)

func (TokenType) String

func (tt TokenType) String() string

TokenTypeString returns a string representation of a token type.

type TypeAlias

type TypeAlias struct {
	Target TypeRef
}

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

type TypeDef

type TypeDef struct {
	Name        string
	Type        TypeDefBody
	Docs        string
	Gate        Gate
	ExternalID  string
	Unsupported string // if unsupported construct is detected, name it here
}

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", "record", etc.
	Name        string     // for named types (user-defined or resource types)
	Inner       *TypeRef   // for list<T>, option<T>, own<T>, borrow<T>
	Inner2      *TypeRef   // for result<T,E>, map<K,V>, tuple element
	Tuple       []*TypeRef // for tuple<T1, T2, ...>
	Unsupported string     // if an unsupported construct is detected, name it here
}

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

func (*TypeRef) String

func (t *TypeRef) String() string

String returns a human-readable representation of the type.

type Use

type Use struct {
	Path       string            // e.g., "wasi:io/streams.{InputStream, OutputStream}"
	Names      map[string]string // local alias -> imported name
	Gate       Gate
	ExternalID string
}

Use represents a use statement.

type Variant

type Variant struct {
	Cases []VariantCase
}

Variant represents a variant type (discriminated union).

type VariantCase

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

VariantCase represents a case in a variant.

type World

type World struct {
	Name       string
	Items      []WorldItem
	Gate       Gate
	ExternalID string
}

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