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/ast/generated.rs | 6 ++++++ crates/libsyntax2/src/grammar.ron | 2 +- crates/libsyntax2/src/grammar/patterns.rs | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 2b400b847..999023e3d 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -893,6 +893,8 @@ pub enum ModuleItem<'a> { ImplItem(ImplItem<'a>), UseItem(UseItem<'a>), ExternCrateItem(ExternCrateItem<'a>), + ConstDef(ConstDef<'a>), + StaticDef(StaticDef<'a>), } impl<'a> AstNode<'a> for ModuleItem<'a> { @@ -905,6 +907,8 @@ impl<'a> AstNode<'a> for ModuleItem<'a> { IMPL_ITEM => Some(ModuleItem::ImplItem(ImplItem { syntax })), USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })), EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })), + CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })), + STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })), _ => None, } } @@ -917,6 +921,8 @@ impl<'a> AstNode<'a> for ModuleItem<'a> { ModuleItem::ImplItem(inner) => inner.syntax(), ModuleItem::UseItem(inner) => inner.syntax(), ModuleItem::ExternCrateItem(inner) => inner.syntax(), + ModuleItem::ConstDef(inner) => inner.syntax(), + ModuleItem::StaticDef(inner) => inner.syntax(), } } } diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index 8055a4687..f8fa7b694 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron @@ -334,7 +334,7 @@ Grammar( ), "ModuleItem": ( enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "ImplItem", - "UseItem", "ExternCrateItem" ] + "UseItem", "ExternCrateItem", "ConstDef", "StaticDef" ] ), "TupleExpr": (), 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