aboutsummaryrefslogtreecommitdiff
path: root/crates/parser/src/grammar/items/consts.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser/src/grammar/items/consts.rs')
-rw-r--r--crates/parser/src/grammar/items/consts.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs
new file mode 100644
index 000000000..eb7d1f828
--- /dev/null
+++ b/crates/parser/src/grammar/items/consts.rs
@@ -0,0 +1,33 @@
1//! FIXME: write short doc here
2
3use super::*;
4
5pub(super) fn static_(p: &mut Parser, m: Marker) {
6 const_or_static(p, m, T![static], STATIC)
7}
8
9pub(super) fn konst(p: &mut Parser, m: Marker) {
10 const_or_static(p, m, T![const], CONST)
11}
12
13fn 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}