Files
rust/crates/parser/src/grammar/attributes.rs

49 lines
1004 B
Rust
Raw Normal View History

//! FIXME: write short doc here
2018-01-07 21:46:10 +03:00
use super::*;
pub(super) fn inner_attributes(p: &mut Parser) {
2019-09-09 13:23:37 +03:00
while p.at(T![#]) && p.nth(1) == T![!] {
2018-01-21 00:31:29 +03:00
attribute(p, true)
}
2018-01-07 21:46:10 +03:00
}
2018-01-11 23:01:12 +03:00
pub(super) fn outer_attributes(p: &mut Parser) {
2019-05-15 15:35:47 +03:00
while p.at(T![#]) {
2018-01-21 00:31:29 +03:00
attribute(p, false)
}
2018-01-07 21:46:10 +03:00
}
2018-01-27 18:31:23 -05:00
fn attribute(p: &mut Parser, inner: bool) {
2018-01-21 00:31:29 +03:00
let attr = p.start();
2019-05-15 15:35:47 +03:00
assert!(p.at(T![#]));
2019-09-19 15:51:46 -04:00
p.bump(T![#]);
2018-01-21 00:31:29 +03:00
if inner {
2019-05-15 15:35:47 +03:00
assert!(p.at(T![!]));
2019-09-19 15:51:46 -04:00
p.bump(T![!]);
2018-01-08 22:40:14 +03:00
}
2018-01-21 00:31:29 +03:00
2019-09-30 04:44:33 +08:00
if p.eat(T!['[']) {
paths::use_path(p);
2019-09-30 16:09:02 +08:00
match p.current() {
T![=] => {
p.bump(T![=]);
if expressions::literal(p).is_none() {
p.error("expected literal");
}
2019-09-30 04:44:33 +08:00
}
2019-09-30 16:09:02 +08:00
T!['('] | T!['['] | T!['{'] => items::token_tree(p),
_ => {}
2019-09-30 04:44:33 +08:00
}
if !p.eat(T![']']) {
p.error("expected `]`");
}
2018-01-20 21:49:58 +03:00
} else {
2018-08-16 12:51:40 +03:00
p.error("expected `[`");
2018-01-21 00:31:29 +03:00
}
2018-08-16 12:51:40 +03:00
attr.complete(p, ATTR);
2018-01-21 00:31:29 +03:00
}