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
use crate::{
ast::*,
parser::{combinator::*, expression::*, identifier::*},
};
pub fn attribute_decl(input: &str) -> ParseResult<AttributeDecl> {
alt((
redeclared_attribute,
attribute_id.map(AttributeDecl::Reference),
))
.parse(input)
}
pub fn referenced_attribute(input: &str) -> ParseResult<AttributeDecl> {
alt((
attribute_ref.map(AttributeDecl::Reference),
qualified_attribute,
))
.parse(input)
}
pub fn qualified_attribute(input: &str) -> ParseResult<AttributeDecl> {
tuple((tag("SELF"), group_qualifier, attribute_qualifier))
.map(|(_self, group, attribute)| AttributeDecl::Qualified {
group,
attribute,
rename: None,
})
.parse(input)
}
pub fn redeclared_attribute(input: &str) -> ParseResult<AttributeDecl> {
tuple((
qualified_attribute,
opt(tuple((tag("RENAMED"), attribute_id))),
))
.map(|(attr, opt)| match attr {
AttributeDecl::Qualified {
group,
attribute,
rename: _,
} => AttributeDecl::Qualified {
group,
attribute,
rename: opt.map(|(_renamed, name)| name),
},
_ => unreachable!(),
})
.parse(input)
}