aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-12 13:26:36 +0100
committerAleksey Kladov <[email protected]>2020-08-12 13:28:32 +0100
commitf73a6419d43b21d07b7ee5d3804bdd586ee8036f (patch)
treec50a6d1bbb31debeaf9a0244f5dab4887b41c266 /crates/ra_parser/src
parent4b3d99f98f393d1c05b1041d3178cae45ebcd3ff (diff)
Allow default everywhere
closes #5681
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r--crates/ra_parser/src/grammar.rs2
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs2
-rw-r--r--crates/ra_parser/src/grammar/items.rs50
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs4
4 files changed, 22 insertions, 36 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index c2e1d701e..88468bc97 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -110,7 +110,7 @@ pub(crate) mod fragments {
110 } 110 }
111 111
112 pub(crate) fn item(p: &mut Parser) { 112 pub(crate) fn item(p: &mut Parser) {
113 items::item_or_macro(p, true, items::ItemFlavor::Mod) 113 items::item_or_macro(p, true)
114 } 114 }
115 115
116 pub(crate) fn macro_items(p: &mut Parser) { 116 pub(crate) fn macro_items(p: &mut Parser) {
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 51eaf7af6..3291e3f14 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -73,7 +73,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
73 73
74 // test block_items 74 // test block_items
75 // fn a() { fn b() {} } 75 // fn a() { fn b() {} }
76 let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { 76 let m = match items::maybe_item(p, m) {
77 Ok(()) => return, 77 Ok(()) => return,
78 Err(m) => m, 78 Err(m) => m,
79 }; 79 };
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index cca524cea..9b7623434 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -22,24 +22,19 @@ use super::*;
22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
23 attributes::inner_attributes(p); 23 attributes::inner_attributes(p);
24 while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) { 24 while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) {
25 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) 25 item_or_macro(p, stop_on_r_curly)
26 } 26 }
27} 27}
28 28
29pub(super) enum ItemFlavor {
30 Mod,
31 Trait,
32}
33
34pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ 29pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![
35 FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, 30 FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW,
36 CRATE_KW, USE_KW, MACRO_KW 31 CRATE_KW, USE_KW, MACRO_KW
37]; 32];
38 33
39pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { 34pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
40 let m = p.start(); 35 let m = p.start();
41 attributes::outer_attributes(p); 36 attributes::outer_attributes(p);
42 let m = match maybe_item(p, m, flavor) { 37 let m = match maybe_item(p, m) {
43 Ok(()) => { 38 Ok(()) => {
44 if p.at(T![;]) { 39 if p.at(T![;]) {
45 p.err_and_bump( 40 p.err_and_bump(
@@ -76,7 +71,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
76 } 71 }
77} 72}
78 73
79pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> { 74pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
80 // test_err pub_expr 75 // test_err pub_expr
81 // fn foo() { pub 92; } 76 // fn foo() { pub 92; }
82 let has_visibility = opt_visibility(p); 77 let has_visibility = opt_visibility(p);
@@ -114,38 +109,29 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
114 has_mods = true; 109 has_mods = true;
115 } 110 }
116 111
117 if p.at(IDENT) 112 // test default_item
118 && p.at_contextual_kw("default") 113 // default impl T for Foo {}
119 && (match p.nth(1) { 114 if p.at(IDENT) && p.at_contextual_kw("default") {
120 T![impl] => true, 115 match p.nth(1) {
116 T![fn] | T![type] | T![const] | T![impl] => {
117 p.bump_remap(T![default]);
118 has_mods = true;
119 }
121 T![unsafe] => { 120 T![unsafe] => {
122 // test default_unsafe_impl 121 // test default_unsafe_item
123 // default unsafe impl Foo {} 122 // default unsafe impl T for Foo {
124
125 // test default_unsafe_fn
126 // impl T for Foo {
127 // default unsafe fn foo() {} 123 // default unsafe fn foo() {}
128 // } 124 // }
129 if p.nth(2) == T![impl] || p.nth(2) == T![fn] { 125 if matches!(p.nth(2), T![impl] | T![fn]) {
130 p.bump_remap(T![default]); 126 p.bump_remap(T![default]);
131 p.bump(T![unsafe]); 127 p.bump(T![unsafe]);
132 has_mods = true; 128 has_mods = true;
133 } 129 }
134 false
135 }
136 T![fn] | T![type] | T![const] => {
137 if let ItemFlavor::Mod = flavor {
138 true
139 } else {
140 false
141 }
142 } 130 }
143 _ => false, 131 _ => (),
144 }) 132 }
145 {
146 p.bump_remap(T![default]);
147 has_mods = true;
148 } 133 }
134
149 if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { 135 if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] {
150 p.bump_remap(T![existential]); 136 p.bump_remap(T![existential]);
151 has_mods = true; 137 has_mods = true;
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index ef9c8ff5b..751ce65f2 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -47,7 +47,7 @@ pub(crate) fn trait_item_list(p: &mut Parser) {
47 error_block(p, "expected an item"); 47 error_block(p, "expected an item");
48 continue; 48 continue;
49 } 49 }
50 item_or_macro(p, true, ItemFlavor::Trait); 50 item_or_macro(p, true);
51 } 51 }
52 p.expect(T!['}']); 52 p.expect(T!['}']);
53 m.complete(p, ASSOC_ITEM_LIST); 53 m.complete(p, ASSOC_ITEM_LIST);
@@ -104,7 +104,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
104 error_block(p, "expected an item"); 104 error_block(p, "expected an item");
105 continue; 105 continue;
106 } 106 }
107 item_or_macro(p, true, ItemFlavor::Mod); 107 item_or_macro(p, true);
108 } 108 }
109 p.expect(T!['}']); 109 p.expect(T!['}']);
110 m.complete(p, ASSOC_ITEM_LIST); 110 m.complete(p, ASSOC_ITEM_LIST);