]> git.lizzy.rs Git - rust.git/blob - crates/parser/src/grammar/items/consts.rs
Align parser names with grammar
[rust.git] / crates / parser / src / grammar / items / consts.rs
1 //! FIXME: write short doc here
2
3 use super::*;
4
5 pub(super) fn static_(p: &mut Parser, m: Marker) {
6     const_or_static(p, m, T![static], STATIC)
7 }
8
9 pub(super) fn konst(p: &mut Parser, m: Marker) {
10     const_or_static(p, m, T![const], CONST)
11 }
12
13 fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
14     assert!(p.at(kw));
15     p.bump(kw);
16     p.eat(T![mut]); // FIXME: validator to forbid const mut
17
18     // Allow `_` in place of an identifier in a `const`.
19     let is_const_underscore = kw == T![const] && p.eat(T![_]);
20     if !is_const_underscore {
21         name(p);
22     }
23
24     // test_err static_underscore
25     // static _: i32 = 5;
26
27     types::ascription(p);
28     if p.eat(T![=]) {
29         expressions::expr(p);
30     }
31     p.expect(T![;]);
32     m.complete(p, def);
33 }