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

49 lines
981 B
Rust
Raw Normal View History

//! FIXME: write short doc here
2018-01-07 21:46:10 +03:00
use super::*;
2020-08-13 17:58:35 +02:00
pub(super) fn inner_attrs(p: &mut Parser) {
2019-09-09 13:23:37 +03:00
while p.at(T![#]) && p.nth(1) == T![!] {
2020-08-13 17:58:35 +02:00
attr(p, true)
2018-01-21 00:31:29 +03:00
}
2018-01-07 21:46:10 +03:00
}
2020-08-13 17:58:35 +02:00
pub(super) fn outer_attrs(p: &mut Parser) {
2019-05-15 15:35:47 +03:00
while p.at(T![#]) {
2020-08-13 17:58:35 +02:00
attr(p, false)
2018-01-21 00:31:29 +03:00
}
2018-01-07 21:46:10 +03:00
}
2020-08-13 17:58:35 +02:00
fn attr(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![=]);
2021-03-18 22:25:10 +01:00
if expressions::expr(p).0.is_none() {
p.error("expected expression");
2019-09-30 16:09:02 +08:00
}
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
}