WIT parser and resolver in MoonBit
Dependencies
moon add mizchi/witlet source = "package local:hello;\n\ninterface greet {\n greet: func(name: string) -> string;\n}\n\nworld hello {\n export greet;\n}\n"
inspect(parse(source))let source = "package local:hello;\n\ninterface greet {\n greet: func(name: string) -> string;\n}\n\nworld hello {\n export greet;\n}\n"
inspect(resolve(source))| Function | Description |
|---|---|
| parse(String) -> Result[WitFile, ParseError] | Parse a WIT source string into an AST |
| parse_path(String) -> Result[WitFile, ParseError] | Parse a WIT file from a file path |
| resolve(String) -> Result[Resolve, ParseError] | Parse and resolve a WIT source string |
| resolve_path(String, world? : String) -> Result[ResolveInput, ParseError] | Resolve WIT from a directory path with optional world selection |
| tokenize(String) -> Result[Array[Token], ParseError] | Tokenize a WIT source string |
impl Show for ParseErrorimpl Show for IncludeRenamepub struct InlineInterface {
name : String
docs : String?
items : Array[InterfaceItem]
} derive(Eq, Debug)impl Show for InlineInterfaceimpl Show for InterfaceItemimpl Show for PackageNamepub struct RPackage {
name : RPackageName
interfaces : Map[String, Int]
worlds : Map[String, Int]
} derive(Eq, Debug)pub struct RTypeDef {
name : String?
kind : RTypeKind
owner : RTypeOwner
docs : String?
} derive(Eq, Debug)pub struct RWorld {
name : String
docs : String?
imports : Map[String, RWorldItem]
exports : Map[String, RWorldItem]
pkg : Int?
} derive(Eq, Debug)pub struct ResolvedInterfaceInfo {
interface_id : Int
name : String?
docs : String?
package_name : RPackageName?
functions : Map[String, RFunction]
types : Map[String, ResolvedTypeInfo]
} derive(Eq, Debug)impl Show for ResolvedInterfaceInfopub struct ResolvedTypeInfo {
local_name : String
type_id : Int
type_name : String?
type_kind : RTypeKind
owner : RTypeOwner
owner_package : RPackageName?
owner_interface : String?
owner_world : String?
} derive(Eq, Debug)impl Show for ResolvedTypeInfoimpl Show for VariantCasepub enum WorldItem {
Interface(UsePath)
Function(Function)
InlineInterface(InlineInterface)
Include(IncludeDecl)
} derive(Eq, Debug)fn resolve_path_interface_infos(path : String, world? : String) -> Result[Array[ResolvedInterfaceInfo], ParseError]WIT parser and resolver in MoonBit
Dependencies