Skip to main content

oak_wit/ast/
mod.rs

1/// WIT 根节点
2#[derive(Clone, Debug)]
3pub struct WitRoot {
4    pub items: Vec<WitItem>,
5}
6
7/// WIT 项目
8#[derive(Clone, Debug)]
9pub enum WitItem {
10    Package(WitPackage),
11    World(WitWorld),
12    Interface(WitInterface),
13}
14
15/// WIT 包
16#[derive(Clone, Debug)]
17pub struct WitPackage {
18    pub name: String,
19}
20
21/// WIT World
22#[derive(Clone, Debug)]
23pub struct WitWorld {
24    pub name: String,
25    pub items: Vec<WitWorldItem>,
26}
27
28/// WIT World 项目
29#[derive(Clone, Debug)]
30pub enum WitWorldItem {
31    Import(WitImport),
32    Export(WitExport),
33    Include(WitInclude),
34}
35
36/// WIT 接口
37#[derive(Clone, Debug)]
38pub struct WitInterface {
39    pub name: String,
40    pub items: Vec<WitInterfaceItem>,
41}
42
43/// WIT 接口项目
44#[derive(Clone, Debug)]
45pub enum WitInterfaceItem {
46    Type(WitType),
47    Func(WitFunc),
48}
49
50/// WIT 函数
51#[derive(Clone, Debug)]
52pub struct WitFunc {
53    pub name: String,
54    pub params: Vec<WitParam>,
55    pub result: Option<WitTypeKind>,
56}
57
58/// WIT 参数
59#[derive(Clone, Debug)]
60pub struct WitParam {
61    pub name: String,
62    pub ty: WitTypeKind,
63}
64
65/// WIT 类型
66#[derive(Clone, Debug)]
67pub struct WitType {
68    pub name: String,
69    pub kind: WitTypeKind,
70}
71
72/// WIT 类型种类
73#[derive(Clone, Debug)]
74pub enum WitTypeKind {
75    Bool,
76    U32,
77    String,
78    // ...
79}
80
81/// WIT 导入
82#[derive(Clone, Debug)]
83pub struct WitImport {
84    pub name: String,
85}
86
87/// WIT 导出
88#[derive(Clone, Debug)]
89pub struct WitExport {
90    pub name: String,
91}
92
93/// WIT 包含
94#[derive(Clone, Debug)]
95pub struct WitInclude {
96    pub name: String,
97}