aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/attributes.rs
blob: 20d58445f1513d8cdba8d7bbe9f22220ed18d9c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::*;

pub(super) fn inner_attributes(p: &mut Parser) {
    while p.current() == T![#] && p.nth(1) == T![!] {
        attribute(p, true)
    }
}

pub(super) fn outer_attributes(p: &mut Parser) {
    while p.at(T![#]) {
        attribute(p, false)
    }
}

fn attribute(p: &mut Parser, inner: bool) {
    let attr = p.start();
    assert!(p.at(T![#]));
    p.bump();

    if inner {
        assert!(p.at(T![!]));
        p.bump();
    }

    if p.at(T!['[']) {
        items::token_tree(p);
    } else {
        p.error("expected `[`");
    }
    attr.complete(p, ATTR);
}