/rust/registry/src/index.crates.io-6f17d22bba15001f/wast-64.0.0/src/component/module.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::component::*; |
2 | | use crate::core; |
3 | | use crate::kw; |
4 | | use crate::parser::{Parse, Parser, Result}; |
5 | | use crate::token::{Id, NameAnnotation, Span}; |
6 | | |
7 | | /// A core WebAssembly module to be created as part of a component. |
8 | | /// |
9 | | /// This is a member of the core module section. |
10 | | #[derive(Debug)] |
11 | | pub struct CoreModule<'a> { |
12 | | /// Where this `core module` was defined. |
13 | | pub span: Span, |
14 | | /// An identifier that this module is resolved with (optionally) for name |
15 | | /// resolution. |
16 | | pub id: Option<Id<'a>>, |
17 | | /// An optional name for this module stored in the custom `name` section. |
18 | | pub name: Option<NameAnnotation<'a>>, |
19 | | /// If present, inline export annotations which indicate names this |
20 | | /// definition should be exported under. |
21 | | pub exports: InlineExport<'a>, |
22 | | /// What kind of module this is, be it an inline-defined or imported one. |
23 | | pub kind: CoreModuleKind<'a>, |
24 | | } |
25 | | |
26 | | /// Possible ways to define a core module in the text format. |
27 | | #[derive(Debug)] |
28 | | pub enum CoreModuleKind<'a> { |
29 | | /// A core module which is actually defined as an import |
30 | | Import { |
31 | | /// Where this core module is imported from |
32 | | import: InlineImport<'a>, |
33 | | /// The type that this core module will have. |
34 | | ty: CoreTypeUse<'a, ModuleType<'a>>, |
35 | | }, |
36 | | |
37 | | /// Modules that are defined inline. |
38 | | Inline { |
39 | | /// Fields in the core module. |
40 | | fields: Vec<core::ModuleField<'a>>, |
41 | | }, |
42 | | } |
43 | | |
44 | | impl<'a> Parse<'a> for CoreModule<'a> { |
45 | 0 | fn parse(parser: Parser<'a>) -> Result<Self> { |
46 | 0 | parser.depth_check()?; |
47 | | |
48 | 0 | let span = parser.parse::<kw::core>()?.0; |
49 | 0 | parser.parse::<kw::module>()?; |
50 | 0 | let id = parser.parse()?; |
51 | 0 | let name = parser.parse()?; |
52 | 0 | let exports = parser.parse()?; |
53 | | |
54 | 0 | let kind = if let Some(import) = parser.parse()? { |
55 | | CoreModuleKind::Import { |
56 | 0 | import, |
57 | 0 | ty: parser.parse()?, |
58 | | } |
59 | | } else { |
60 | 0 | let mut fields = Vec::new(); |
61 | 0 | while !parser.is_empty() { |
62 | 0 | fields.push(parser.parens(|p| p.parse())?); |
63 | | } |
64 | 0 | CoreModuleKind::Inline { fields } |
65 | | }; |
66 | | |
67 | 0 | Ok(Self { |
68 | 0 | span, |
69 | 0 | id, |
70 | 0 | name, |
71 | 0 | exports, |
72 | 0 | kind, |
73 | 0 | }) |
74 | 0 | } |
75 | | } |