aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/libeditor/src/scope/mod_scope.rs2
-rw-r--r--crates/libsyntax2/src/ast/generated.rs6
-rw-r--r--crates/libsyntax2/src/grammar.ron2
-rw-r--r--crates/libsyntax2/src/grammar/patterns.rs6
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0019_let_recover.rs8
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0019_let_recover.txt76
6 files changed, 92 insertions, 8 deletions
diff --git a/crates/libeditor/src/scope/mod_scope.rs b/crates/libeditor/src/scope/mod_scope.rs
index 0e51108d9..aa8dd93a7 100644
--- a/crates/libeditor/src/scope/mod_scope.rs
+++ b/crates/libeditor/src/scope/mod_scope.rs
@@ -13,6 +13,8 @@ impl ModuleScope {
13 ast::ModuleItem::StructDef(item) => Entry::new(item), 13 ast::ModuleItem::StructDef(item) => Entry::new(item),
14 ast::ModuleItem::EnumDef(item) => Entry::new(item), 14 ast::ModuleItem::EnumDef(item) => Entry::new(item),
15 ast::ModuleItem::FnDef(item) => Entry::new(item), 15 ast::ModuleItem::FnDef(item) => Entry::new(item),
16 ast::ModuleItem::ConstDef(item) => Entry::new(item),
17 ast::ModuleItem::StaticDef(item) => Entry::new(item),
16 ast::ModuleItem::TraitDef(item) => Entry::new(item), 18 ast::ModuleItem::TraitDef(item) => Entry::new(item),
17 ast::ModuleItem::ExternCrateItem(_) | 19 ast::ModuleItem::ExternCrateItem(_) |
18 ast::ModuleItem::ImplItem(_) | 20 ast::ModuleItem::ImplItem(_) |
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> {
893 ImplItem(ImplItem<'a>), 893 ImplItem(ImplItem<'a>),
894 UseItem(UseItem<'a>), 894 UseItem(UseItem<'a>),
895 ExternCrateItem(ExternCrateItem<'a>), 895 ExternCrateItem(ExternCrateItem<'a>),
896 ConstDef(ConstDef<'a>),
897 StaticDef(StaticDef<'a>),
896} 898}
897 899
898impl<'a> AstNode<'a> for ModuleItem<'a> { 900impl<'a> AstNode<'a> for ModuleItem<'a> {
@@ -905,6 +907,8 @@ impl<'a> AstNode<'a> for ModuleItem<'a> {
905 IMPL_ITEM => Some(ModuleItem::ImplItem(ImplItem { syntax })), 907 IMPL_ITEM => Some(ModuleItem::ImplItem(ImplItem { syntax })),
906 USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })), 908 USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })),
907 EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })), 909 EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })),
910 CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })),
911 STATIC_DEF => Some(ModuleItem::StaticDef(StaticDef { syntax })),
908 _ => None, 912 _ => None,
909 } 913 }
910 } 914 }
@@ -917,6 +921,8 @@ impl<'a> AstNode<'a> for ModuleItem<'a> {
917 ModuleItem::ImplItem(inner) => inner.syntax(), 921 ModuleItem::ImplItem(inner) => inner.syntax(),
918 ModuleItem::UseItem(inner) => inner.syntax(), 922 ModuleItem::UseItem(inner) => inner.syntax(),
919 ModuleItem::ExternCrateItem(inner) => inner.syntax(), 923 ModuleItem::ExternCrateItem(inner) => inner.syntax(),
924 ModuleItem::ConstDef(inner) => inner.syntax(),
925 ModuleItem::StaticDef(inner) => inner.syntax(),
920 } 926 }
921 } 927 }
922} 928}
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(
334 ), 334 ),
335 "ModuleItem": ( 335 "ModuleItem": (
336 enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "ImplItem", 336 enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "ImplItem",
337 "UseItem", "ExternCrateItem" ] 337 "UseItem", "ExternCrateItem", "ConstDef", "StaticDef" ]
338 ), 338 ),
339 339
340 "TupleExpr": (), 340 "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) {
22 } 22 }
23} 23}
24 24
25const PAT_RECOVERY_SET: TokenSet =
26 token_set![LET_KW, IF_KW, WHILE_KW, LOOP_KW, MATCH_KW];
27
28
25fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> { 29fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> {
26 let la0 = p.nth(0); 30 let la0 = p.nth(0);
27 let la1 = p.nth(1); 31 let la1 = p.nth(1);
@@ -52,7 +56,7 @@ fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> {
52 L_PAREN => tuple_pat(p), 56 L_PAREN => tuple_pat(p),
53 L_BRACK => slice_pat(p), 57 L_BRACK => slice_pat(p),
54 _ => { 58 _ => {
55 p.err_and_bump("expected pattern"); 59 p.err_recover("expected pattern", PAT_RECOVERY_SET);
56 return None; 60 return None;
57 } 61 }
58 }; 62 };
diff --git a/crates/libsyntax2/tests/data/parser/err/0019_let_recover.rs b/crates/libsyntax2/tests/data/parser/err/0019_let_recover.rs
index 52bddd494..48bf3d68b 100644
--- a/crates/libsyntax2/tests/data/parser/err/0019_let_recover.rs
+++ b/crates/libsyntax2/tests/data/parser/err/0019_let_recover.rs
@@ -1,4 +1,12 @@
1fn foo() { 1fn foo() {
2 let foo = 2 let foo =
3 let bar = 1; 3 let bar = 1;
4 let
5 let baz = 92;
6 let
7 if true {}
8 let
9 while true {}
10 let
11 loop {}
4} 12}
diff --git a/crates/libsyntax2/tests/data/parser/err/0019_let_recover.txt b/crates/libsyntax2/tests/data/parser/err/0019_let_recover.txt
index 9ffa9d781..6e74771f1 100644
--- a/crates/libsyntax2/tests/data/parser/err/0019_let_recover.txt
+++ b/crates/libsyntax2/tests/data/parser/err/0019_let_recover.txt
@@ -1,5 +1,5 @@
1ROOT@[0; 44) 1ROOT@[0; 139)
2 FN_DEF@[0; 43) 2 FN_DEF@[0; 138)
3 FN_KW@[0; 2) 3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3) 4 WHITESPACE@[2; 3)
5 NAME@[3; 6) 5 NAME@[3; 6)
@@ -8,7 +8,7 @@ ROOT@[0; 44)
8 L_PAREN@[6; 7) 8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8) 9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9) 10 WHITESPACE@[8; 9)
11 BLOCK@[9; 43) 11 BLOCK@[9; 138)
12 L_CURLY@[9; 10) 12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 15) 13 WHITESPACE@[10; 15)
14 LET_STMT@[15; 24) 14 LET_STMT@[15; 24)
@@ -34,6 +34,70 @@ ROOT@[0; 44)
34 LITERAL@[39; 40) 34 LITERAL@[39; 40)
35 INT_NUMBER@[39; 40) "1" 35 INT_NUMBER@[39; 40) "1"
36 SEMI@[40; 41) 36 SEMI@[40; 41)
37 WHITESPACE@[41; 42) 37 WHITESPACE@[41; 46)
38 R_CURLY@[42; 43) 38 LET_STMT@[46; 49)
39 WHITESPACE@[43; 44) 39 LET_KW@[46; 49)
40 err: `expected pattern`
41 err: `expected SEMI`
42 WHITESPACE@[49; 54)
43 LET_STMT@[54; 67)
44 LET_KW@[54; 57)
45 WHITESPACE@[57; 58)
46 BIND_PAT@[58; 61)
47 NAME@[58; 61)
48 IDENT@[58; 61) "baz"
49 WHITESPACE@[61; 62)
50 EQ@[62; 63)
51 WHITESPACE@[63; 64)
52 LITERAL@[64; 66)
53 INT_NUMBER@[64; 66) "92"
54 SEMI@[66; 67)
55 WHITESPACE@[67; 72)
56 LET_STMT@[72; 75)
57 LET_KW@[72; 75)
58 err: `expected pattern`
59 err: `expected SEMI`
60 WHITESPACE@[75; 80)
61 EXPR_STMT@[80; 90)
62 IF_EXPR@[80; 90)
63 IF_KW@[80; 82)
64 WHITESPACE@[82; 83)
65 CONDITION@[83; 87)
66 LITERAL@[83; 87)
67 TRUE_KW@[83; 87)
68 WHITESPACE@[87; 88)
69 BLOCK@[88; 90)
70 L_CURLY@[88; 89)
71 R_CURLY@[89; 90)
72 WHITESPACE@[90; 95)
73 LET_STMT@[95; 98)
74 LET_KW@[95; 98)
75 err: `expected pattern`
76 err: `expected SEMI`
77 WHITESPACE@[98; 103)
78 EXPR_STMT@[103; 116)
79 WHILE_EXPR@[103; 116)
80 WHILE_KW@[103; 108)
81 WHITESPACE@[108; 109)
82 CONDITION@[109; 113)
83 LITERAL@[109; 113)
84 TRUE_KW@[109; 113)
85 WHITESPACE@[113; 114)
86 BLOCK@[114; 116)
87 L_CURLY@[114; 115)
88 R_CURLY@[115; 116)
89 WHITESPACE@[116; 121)
90 LET_STMT@[121; 124)
91 LET_KW@[121; 124)
92 err: `expected pattern`
93 err: `expected SEMI`
94 WHITESPACE@[124; 129)
95 LOOP_EXPR@[129; 136)
96 LOOP_KW@[129; 133)
97 WHITESPACE@[133; 134)
98 BLOCK@[134; 136)
99 L_CURLY@[134; 135)
100 R_CURLY@[135; 136)
101 WHITESPACE@[136; 137)
102 R_CURLY@[137; 138)
103 WHITESPACE@[138; 139)