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

54 lines
1016 B
Rust
Raw Normal View History

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
}
2021-04-17 14:31:52 +08:00
pub(super) fn meta(p: &mut Parser) {
2021-06-11 18:12:51 +02:00
let meta = p.start();
2021-04-17 14:31:52 +08:00
paths::use_path(p);
match p.current() {
T![=] => {
p.bump(T![=]);
if expressions::expr(p).0.is_none() {
p.error("expected expression");
}
}
T!['('] | T!['['] | T!['{'] => items::token_tree(p),
_ => {}
}
2021-06-11 18:12:51 +02:00
meta.complete(p, META);
2021-04-17 14:31:52 +08: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!['[']) {
2021-04-17 14:31:52 +08:00
meta(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
}