2018-01-07 21:46:10 +03:00
|
|
|
use super::*;
|
|
|
|
|
2018-01-11 23:01:12 +03:00
|
|
|
enum AttrKind {
|
|
|
|
Inner, Outer
|
|
|
|
}
|
|
|
|
|
2018-01-07 21:46:10 +03:00
|
|
|
pub(super) fn inner_attributes(p: &mut Parser) {
|
2018-01-11 23:01:12 +03:00
|
|
|
many(p, |p| attribute(p, AttrKind::Inner))
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 23:01:12 +03:00
|
|
|
pub(super) fn outer_attributes(p: &mut Parser) {
|
|
|
|
many(p, |p| attribute(p, AttrKind::Outer))
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-11 23:01:12 +03:00
|
|
|
fn attribute(p: &mut Parser, kind: AttrKind) -> bool {
|
2018-01-08 22:40:14 +03:00
|
|
|
fn attr_tail(p: &mut Parser) {
|
2018-01-07 21:46:10 +03:00
|
|
|
meta_item(p) && p.expect(R_BRACK);
|
2018-01-08 22:40:14 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 23:01:12 +03:00
|
|
|
match kind {
|
|
|
|
AttrKind::Inner => node_if(p, [POUND, EXCL, L_BRACK], ATTR, attr_tail),
|
|
|
|
AttrKind::Outer => node_if(p, [POUND, L_BRACK], ATTR, attr_tail),
|
2018-01-08 22:40:14 +03:00
|
|
|
}
|
2018-01-07 21:46:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn meta_item(p: &mut Parser) -> bool {
|
|
|
|
node_if(p, IDENT, META_ITEM, |p| {
|
|
|
|
if p.eat(EQ) {
|
|
|
|
if !expressions::literal(p) {
|
|
|
|
p.error()
|
|
|
|
.message("expected literal")
|
|
|
|
.emit();
|
|
|
|
}
|
|
|
|
} else if p.eat(L_PAREN) {
|
|
|
|
comma_list(p, R_PAREN, meta_item_inner);
|
|
|
|
p.expect(R_PAREN);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn meta_item_inner(p: &mut Parser) -> bool {
|
|
|
|
meta_item(p) || expressions::literal(p)
|
|
|
|
}
|
|
|
|
|