minor: cleanup const parsing
This commit is contained in:
@@ -1,20 +1,20 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub(super) fn static_(p: &mut Parser, m: Marker) {
|
|
||||||
const_or_static(p, m, T![static], STATIC)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(super) fn konst(p: &mut Parser, m: Marker) {
|
pub(super) fn konst(p: &mut Parser, m: Marker) {
|
||||||
const_or_static(p, m, T![const], CONST)
|
p.bump(T![const]);
|
||||||
|
const_or_static(p, m, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
pub(super) fn static_(p: &mut Parser, m: Marker) {
|
||||||
assert!(p.at(kw));
|
p.bump(T![static]);
|
||||||
p.bump(kw);
|
const_or_static(p, m, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn const_or_static(p: &mut Parser, m: Marker, is_const: bool) {
|
||||||
p.eat(T![mut]);
|
p.eat(T![mut]);
|
||||||
|
|
||||||
// Allow `_` in place of an identifier in a `const`.
|
// Allow `_` in place of an identifier in a `const`.
|
||||||
let is_const_underscore = kw == T![const] && p.eat(T![_]);
|
let is_const_underscore = is_const && p.eat(T![_]);
|
||||||
if !is_const_underscore {
|
if !is_const_underscore {
|
||||||
name(p);
|
name(p);
|
||||||
}
|
}
|
||||||
@@ -30,5 +30,5 @@ fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
|
|||||||
expressions::expr(p);
|
expressions::expr(p);
|
||||||
}
|
}
|
||||||
p.expect(T![;]);
|
p.expect(T![;]);
|
||||||
m.complete(p, def);
|
m.complete(p, if is_const { CONST } else { STATIC });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user