diff options
author | Aleksey Kladov <[email protected]> | 2020-08-12 16:06:49 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-12 16:14:23 +0100 |
commit | 50a02eb3593591a02677e1b56f24d7ff0459b9d0 (patch) | |
tree | a17351b1e3addea0a719f38990fea9289b6ef65e /crates/parser/src/grammar/items/consts.rs | |
parent | 6dafc13f5f776980cd2560fb79d3d4790811c96d (diff) |
Rename ra_parser -> parser
Diffstat (limited to 'crates/parser/src/grammar/items/consts.rs')
-rw-r--r-- | crates/parser/src/grammar/items/consts.rs | 33 |
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..35ad766dc --- /dev/null +++ b/crates/parser/src/grammar/items/consts.rs | |||
@@ -0,0 +1,33 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use super::*; | ||
4 | |||
5 | pub(super) fn static_def(p: &mut Parser, m: Marker) { | ||
6 | const_or_static(p, m, T![static], STATIC) | ||
7 | } | ||
8 | |||
9 | pub(super) fn const_def(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 | } | ||