aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/items/consts.rs
blob: 1f802246fef1a611171f063107a59ca610c8a430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use super::*;

pub(super) fn static_def(p: &mut Parser, m: Marker) {
    const_or_static(p, m, STATIC_KW, STATIC_DEF)
}

pub(super) fn const_def(p: &mut Parser, m: Marker) {
    const_or_static(p, m, CONST_KW, CONST_DEF)
}

fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
    assert!(p.at(kw));
    p.bump();
    p.eat(MUT_KW); // FIXME: validator to forbid const mut
    name(p);
    types::ascription(p);
    if p.eat(EQ) {
        expressions::expr(p);
    }
    p.expect(SEMI);
    m.complete(p, def);
}