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
60
use crate::ast::{self, kw};
use crate::parser::{Parse, Parser, Result};
#[derive(Debug)]
pub struct Alias<'a> {
pub span: ast::Span,
pub id: Option<ast::Id<'a>>,
pub name: Option<ast::NameAnnotation<'a>>,
pub source: AliasSource<'a>,
pub kind: ast::ExportKind,
}
#[derive(Debug)]
#[allow(missing_docs)]
pub enum AliasSource<'a> {
InstanceExport {
instance: ast::ItemRef<'a, kw::instance>,
export: &'a str,
},
Outer {
module: ast::Index<'a>,
index: ast::Index<'a>,
},
}
impl<'a> Parse<'a> for Alias<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
let span = parser.parse::<kw::alias>()?.0;
let source = if parser.parse::<Option<kw::outer>>()?.is_some() {
AliasSource::Outer {
module: parser.parse()?,
index: parser.parse()?,
}
} else {
AliasSource::InstanceExport {
instance: parser.parse::<ast::IndexOrRef<_>>()?.0,
export: parser.parse()?,
}
};
let (kind, id, name) = parser.parens(|p| Ok((p.parse()?, p.parse()?, p.parse()?)))?;
Ok(Alias {
span,
id,
name,
kind,
source,
})
}
}