]> git.lizzy.rs Git - rust.git/blob - crates/parser/src/grammar/attributes.rs
Update ungrammar
[rust.git] / crates / parser / src / grammar / attributes.rs
1 use super::*;
2
3 pub(super) fn inner_attrs(p: &mut Parser) {
4     while p.at(T![#]) && p.nth(1) == T![!] {
5         attr(p, true)
6     }
7 }
8
9 pub(super) fn outer_attrs(p: &mut Parser) {
10     while p.at(T![#]) {
11         attr(p, false)
12     }
13 }
14
15 pub(super) fn meta(p: &mut Parser) {
16     let meta = p.start();
17     paths::use_path(p);
18
19     match p.current() {
20         T![=] => {
21             p.bump(T![=]);
22             if expressions::expr(p).0.is_none() {
23                 p.error("expected expression");
24             }
25         }
26         T!['('] | T!['['] | T!['{'] => items::token_tree(p),
27         _ => {}
28     }
29
30     meta.complete(p, META);
31 }
32
33 fn attr(p: &mut Parser, inner: bool) {
34     let attr = p.start();
35     assert!(p.at(T![#]));
36     p.bump(T![#]);
37
38     if inner {
39         assert!(p.at(T![!]));
40         p.bump(T![!]);
41     }
42
43     if p.eat(T!['[']) {
44         meta(p);
45
46         if !p.eat(T![']']) {
47             p.error("expected `]`");
48         }
49     } else {
50         p.error("expected `[`");
51     }
52     attr.complete(p, ATTR);
53 }