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 |
pub suberror ParseError {
Message(String, Int)
}pub struct Function {
name : String
kind : FunctionKind
params : Array[Param]
result : TypeExpr?
docs : String?
}pub enum FunctionKind {
Freestanding
Constructor(String)
Method(String)
Static(String)
}pub struct IncludeRename {
from : String
to : String
}pub struct PackageName {
ns : String
name : String
version : String?
}pub struct RFunction {
name : String
kind : RFunctionKind
params : Array[(String, RType)]
result : RType?
docs : String?
}pub enum RFunctionKind {
Freestanding
Constructor(Int)
Method(Int)
Static(Int)
}impl Eq for RFunctionKindimpl Show for RFunctionKindimpl ToJson for RFunctionKindpub enum RHandleKind {
Own(Int)
Borrow(Int)
}impl Eq for RHandleKindimpl Show for RHandleKindimpl ToJson for RHandleKindimpl Eq for RInterfaceimpl Show for RInterfaceimpl ToJson for RInterfacepub struct RInterfaceRef {
id : Int
}impl Eq for RInterfaceRefimpl Show for RInterfaceRefimpl ToJson for RInterfaceRefpub struct RPackageName {
ns : String
name : String
version : String?
}impl Eq for RPackageNameimpl Show for RPackageNameimpl ToJson for RPackageNameimpl Eq for RRecordFieldimpl Show for RRecordFieldimpl ToJson for RRecordFieldpub enum RType {
Bool
U8
U16
U32
U64
S8
S16
S32
S64
F32
F64
Char
String_
Id(Int)
}pub enum RTypeOwner {
Interface(Int)
World(Int)
None
}impl Eq for RTypeOwnerimpl Show for RTypeOwnerimpl ToJson for RTypeOwnerimpl Eq for RVariantCaseimpl Show for RVariantCaseimpl ToJson for RVariantCasepub struct RWorld {
name : String
docs : String?
imports : Map[String, RWorldItem]
exports : Map[String, RWorldItem]
pkg : Int?
}impl Eq for RWorldItemimpl Show for RWorldItemimpl ToJson for RWorldItemimpl Eq for ResolveInputimpl Show for ResolveInputimpl ToJson for ResolveInputpub struct ResolvedInterfaceInfo {
interface_id : Int
name : String?
docs : String?
package_name : RPackageName?
functions : Map[String, RFunction]
types : Map[String, ResolvedTypeInfo]
}impl Eq for ResolvedInterfaceInfoimpl 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?
}impl Eq for ResolvedTypeInfoimpl Show for ResolvedTypeInfopub enum TokenType {
Ident(String)
Keyword(String)
Symbol(String)
StringLit(String)
Number(String)
Doc(String)
Eof
}pub enum WorldItem {
Interface(UsePath)
Function(Function)
InlineInterface(InlineInterface)
Include(IncludeDecl)
}fn resolve_path_interface_infos(path : String, world? : String) -> Result[Array[ResolvedInterfaceInfo], ParseError]WIT parser and resolver in MoonBit
Dependencies