Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/grammar/items/consts.rs')
| -rw-r--r-- | crates/parser/src/grammar/items/consts.rs | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs index 1b317dd84a..93ba7d05fe 100644 --- a/crates/parser/src/grammar/items/consts.rs +++ b/crates/parser/src/grammar/items/consts.rs @@ -1,26 +1,29 @@ use super::*; -pub(super) fn static_(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![static], STATIC) +// test const_item +// const C: u32 = 92; +pub(super) fn konst(p: &mut Parser, m: Marker) { + p.bump(T![const]); + const_or_static(p, m, true) } -pub(super) fn konst(p: &mut Parser, m: Marker) { - const_or_static(p, m, T![const], CONST) +pub(super) fn static_(p: &mut Parser, m: Marker) { + p.bump(T![static]); + const_or_static(p, m, false) } -fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { - assert!(p.at(kw)); - p.bump(kw); +fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) { p.eat(T![mut]); - // Allow `_` in place of an identifier in a `const`. - let is_const_underscore = kw == T![const] && p.eat(T![_]); - if !is_const_underscore { + if is_const && p.eat(T![_]) { + // test anonymous_const + // const _: u32 = 0; + } else { + // test_err anonymous_static + // static _: i32 = 5; name(p); } - // test_err static_underscore - // static _: i32 = 5; if p.at(T![:]) { types::ascription(p); } else { @@ -30,5 +33,5 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { expressions::expr(p); } p.expect(T![;]); - m.complete(p, def); + m.complete(p, if is_const { CONST } else { STATIC }); } |