32 lines
775 B
Rust
Raw Normal View History

2018-02-03 12:05:25 +03:00
use super::*;
pub(super) fn static_def(p: &mut Parser, m: Marker) {
2019-05-15 15:35:47 +03:00
const_or_static(p, m, T![static], STATIC_DEF)
2018-02-03 12:05:25 +03:00
}
pub(super) fn const_def(p: &mut Parser, m: Marker) {
2019-05-15 15:35:47 +03:00
const_or_static(p, m, T![const], CONST_DEF)
2018-02-03 12:05:25 +03:00
}
fn const_or_static(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) {
2018-02-03 12:05:25 +03:00
assert!(p.at(kw));
2019-09-10 00:59:29 +03:00
p.bump_any();
2019-05-15 15:35:47 +03:00
p.eat(T![mut]); // FIXME: validator to forbid const mut
// Allow `_` in place of an identifier in a `const`.
let is_const_underscore = kw == T![const] && p.eat(T![_]);
if !is_const_underscore {
name(p);
}
// test_err static_underscore
// static _: i32 = 5;
2018-07-31 15:35:59 +03:00
types::ascription(p);
2019-05-15 15:35:47 +03:00
if p.eat(T![=]) {
2018-08-08 00:53:03 +03:00
expressions::expr(p);
}
2019-05-15 15:35:47 +03:00
p.expect(T![;]);
m.complete(p, def);
2018-02-03 12:05:25 +03:00
}