aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/items/consts.rs
blob: 742a7e0562acf6b1483925b09906bd48e9990fc2 (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
32
33
//! FIXME: write short doc here

use super::*;

pub(super) fn static_def(p: &mut Parser, m: Marker) {
    const_or_static(p, m, T![static], STATIC_DEF)
}

pub(super) fn const_def(p: &mut Parser, m: Marker) {
    const_or_static(p, m, T![const], CONST_DEF)
}

fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
    assert!(p.at(kw));
    p.bump(kw);
    p.eat(T![mut]); // FIXME: validator to forbid const mut

    // Allow `_` in place of an identifier in a `const`.
    let is_const_underscore = kw == T![const] && p.eat(T![_]);
    if !is_const_underscore {
        name(p);
    }

    // test_err static_underscore
    // static _: i32 = 5;

    types::ascription(p);
    if p.eat(T![=]) {
        expressions::expr(p);
    }
    p.expect(T![;]);
    m.complete(p, def);
}