From dea6ed73fac6f3f4daf38b1cb6df4c8fb68872b7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Aug 2018 19:35:09 +0300 Subject: better pattern recovery --- crates/libsyntax2/src/grammar/patterns.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/libsyntax2/src/grammar') diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs index 114964651..065570b99 100644 --- a/crates/libsyntax2/src/grammar/patterns.rs +++ b/crates/libsyntax2/src/grammar/patterns.rs @@ -22,6 +22,10 @@ pub(super) fn pattern(p: &mut Parser) { } } +const PAT_RECOVERY_SET: TokenSet = + token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW]; + + fn atom_pat(p: &mut Parser) -> Option { let la0 = p.nth(0); let la1 = p.nth(1); @@ -52,7 +56,7 @@ fn atom_pat(p: &mut Parser) -> Option { L_PAREN => tuple_pat(p), L_BRACK => slice_pat(p), _ => { - p.err_and_bump("expected pattern"); + p.err_recover("expected pattern", PAT_RECOVERY_SET); return None; } }; -- cgit v1.2.3