1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::core::*;
use crate::kw;
use crate::parser::{Parse, Parser, Result};
use crate::token::{Id, NameAnnotation, Span};
#[derive(Debug)]
pub struct Global<'a> {
pub span: Span,
pub id: Option<Id<'a>>,
pub name: Option<NameAnnotation<'a>>,
pub exports: InlineExport<'a>,
pub ty: GlobalType<'a>,
pub kind: GlobalKind<'a>,
}
#[derive(Debug)]
pub enum GlobalKind<'a> {
Import(InlineImport<'a>),
Inline(Expression<'a>),
}
impl<'a> Parse<'a> for Global<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
let span = parser.parse::<kw::global>()?.0;
let id = parser.parse()?;
let name = parser.parse()?;
let exports = parser.parse()?;
let (ty, kind) = if let Some(import) = parser.parse()? {
(parser.parse()?, GlobalKind::Import(import))
} else {
(parser.parse()?, GlobalKind::Inline(parser.parse()?))
};
Ok(Global {
span,
id,
name,
exports,
ty,
kind,
})
}
}