pub fn parse<'input>(input: &'input Buffer<'_>) -> Result<Interfaces<'input>>
Expand description

Parse a WIT definition in its textual format, and produces an AST with the Interfaces structure upon succesful.

Examples

use wasmer_interface_types::{
    ast::{Adapter, Export, Implementation, Import, Interfaces, Type},
    decoders::wat::{parse, Buffer},
    interpreter::Instruction,
    types::IType,
};

let input = Buffer::new(
    r#"(@interface type (func (param i32) (result s8)))

(@interface import "ns" "foo" (func (type 0)))

(@interface func (type 0) arg.get 42)

(@interface export "bar" (func 0))

(@interface implement (func 0) (func 1))"#,
)
.unwrap();
let output = Interfaces {
    types: vec![Type::Function {
        inputs: vec![IType::I32],
        outputs: vec![IType::S8],
    }],
    imports: vec![Import {
        namespace: "ns",
        name: "foo",
        function_type: 0,
    }],
    adapters: vec![Adapter {
        function_type: 0,
        instructions: vec![Instruction::ArgumentGet { index: 42 }],
    }],
    exports: vec![Export {
        name: "bar",
        function_type: 0,
    }],
    implementations: vec![Implementation {
        core_function_type: 0,
        adapter_function_type: 1,
    }],
};

assert_eq!(parse(&input).unwrap(), output);