Parse const effect block

This commit is contained in:
Lukas Wirth 2020-12-23 02:15:30 +01:00
parent 03a9bbacf2
commit 2c94c4964a
4 changed files with 38 additions and 2 deletions

View file

@ -46,6 +46,7 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet =
T![continue],
T![async],
T![try],
T![const],
T![loop],
T![for],
LIFETIME_IDENT,
@ -115,6 +116,14 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
block_expr(p);
m.complete(p, EFFECT_EXPR)
}
// test const_block
// fn f() { const { } }
T![const] if la == T!['{'] => {
let m = p.start();
p.bump(T![const]);
block_expr(p);
m.complete(p, EFFECT_EXPR)
}
T!['{'] => {
// test for_range_from
// fn foo() {

View file

@ -96,7 +96,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
let mut has_mods = false;
// modifiers
has_mods |= p.eat(T![const]);
if p.at(T![const]) && p.nth(1) != T!['{'] {
p.eat(T![const]);
has_mods = true;
}
// test_err async_without_semicolon
// fn foo() { let _ = async {} }
@ -167,7 +170,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
m.complete(p, TRAIT);
}
T![const] => {
T![const] if p.nth(1) != T!['{'] => {
consts::konst(p, m);
}

View file

@ -0,0 +1,23 @@
SOURCE_FILE@0..21
FN@0..20
FN_KW@0..2 "fn"
WHITESPACE@2..3 " "
NAME@3..4
IDENT@3..4 "f"
PARAM_LIST@4..6
L_PAREN@4..5 "("
R_PAREN@5..6 ")"
WHITESPACE@6..7 " "
BLOCK_EXPR@7..20
L_CURLY@7..8 "{"
WHITESPACE@8..9 " "
EFFECT_EXPR@9..18
CONST_KW@9..14 "const"
WHITESPACE@14..15 " "
BLOCK_EXPR@15..18
L_CURLY@15..16 "{"
WHITESPACE@16..17 " "
R_CURLY@17..18 "}"
WHITESPACE@18..19 " "
R_CURLY@19..20 "}"
WHITESPACE@20..21 "\n"

View file

@ -0,0 +1 @@
fn f() { const { } }