aboutsummaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/src/grammar.rs12
-rw-r--r--crates/parser/src/grammar/items.rs2
-rw-r--r--crates/parser/src/grammar/items/traits.rs4
-rw-r--r--crates/parser/src/grammar/params.rs31
-rw-r--r--crates/parser/src/syntax_kind.rs3
-rw-r--r--crates/parser/src/syntax_kind/generated.rs1
6 files changed, 38 insertions, 15 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index bb9ffea8b..6913e9ec2 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -190,17 +190,25 @@ fn opt_visibility(p: &mut Parser) -> bool {
190 // test crate_visibility 190 // test crate_visibility
191 // pub(crate) struct S; 191 // pub(crate) struct S;
192 // pub(self) struct S; 192 // pub(self) struct S;
193 // pub(self) struct S; 193 // pub(super) struct S;
194 // pub(self) struct S;
195 194
196 // test pub_parens_typepath 195 // test pub_parens_typepath
197 // struct B(pub (super::A)); 196 // struct B(pub (super::A));
198 // struct B(pub (crate::A,)); 197 // struct B(pub (crate::A,));
199 T![crate] | T![self] | T![super] if p.nth(2) != T![:] => { 198 T![crate] | T![self] | T![super] if p.nth(2) != T![:] => {
200 p.bump_any(); 199 p.bump_any();
200 let path_m = p.start();
201 let path_segment_m = p.start();
202 let name_ref_m = p.start();
201 p.bump_any(); 203 p.bump_any();
204 name_ref_m.complete(p, NAME_REF);
205 path_segment_m.complete(p, PATH_SEGMENT);
206 path_m.complete(p, PATH);
202 p.expect(T![')']); 207 p.expect(T![')']);
203 } 208 }
209 // test crate_visibility_in
210 // pub(in super::A) struct S;
211 // pub(in crate) struct S;
204 T![in] => { 212 T![in] => {
205 p.bump_any(); 213 p.bump_any();
206 p.bump_any(); 214 p.bump_any();
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 2070ce163..1d894e907 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -270,7 +270,9 @@ fn extern_crate(p: &mut Parser, m: Marker) {
270 p.bump(T![crate]); 270 p.bump(T![crate]);
271 271
272 if p.at(T![self]) { 272 if p.at(T![self]) {
273 let m = p.start();
273 p.bump(T![self]); 274 p.bump(T![self]);
275 m.complete(p, NAME_REF);
274 } else { 276 } else {
275 name_ref(p); 277 name_ref(p);
276 } 278 }
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs
index d076974ed..d3327271c 100644
--- a/crates/parser/src/grammar/items/traits.rs
+++ b/crates/parser/src/grammar/items/traits.rs
@@ -40,6 +40,10 @@ pub(super) fn impl_(p: &mut Parser) {
40 type_params::opt_generic_param_list(p); 40 type_params::opt_generic_param_list(p);
41 } 41 }
42 42
43 // test impl_def_const
44 // impl const Send for X {}
45 p.eat(T![const]);
46
43 // FIXME: never type 47 // FIXME: never type
44 // impl ! {} 48 // impl ! {}
45 49
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs
index 2d006a1d5..6a98d7368 100644
--- a/crates/parser/src/grammar/params.rs
+++ b/crates/parser/src/grammar/params.rs
@@ -156,7 +156,7 @@ fn variadic_param(p: &mut Parser) -> bool {
156fn opt_self_param(p: &mut Parser, m: Marker) { 156fn opt_self_param(p: &mut Parser, m: Marker) {
157 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { 157 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] {
158 p.eat(T![mut]); 158 p.eat(T![mut]);
159 p.eat(T![self]); 159 self_as_name(p);
160 // test arb_self_types 160 // test arb_self_types
161 // impl S { 161 // impl S {
162 // fn a(self: &Self) {} 162 // fn a(self: &Self) {}
@@ -169,24 +169,29 @@ fn opt_self_param(p: &mut Parser, m: Marker) {
169 let la1 = p.nth(1); 169 let la1 = p.nth(1);
170 let la2 = p.nth(2); 170 let la2 = p.nth(2);
171 let la3 = p.nth(3); 171 let la3 = p.nth(3);
172 let mut n_toks = match (p.current(), la1, la2, la3) { 172 if !matches!((p.current(), la1, la2, la3),
173 (T![&], T![self], _, _) => 2, 173 (T![&], T![self], _, _)
174 (T![&], T![mut], T![self], _) => 3, 174 | (T![&], T![mut], T![self], _)
175 (T![&], LIFETIME_IDENT, T![self], _) => 3, 175 | (T![&], LIFETIME_IDENT, T![self], _)
176 (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, 176 | (T![&], LIFETIME_IDENT, T![mut], T![self])
177 _ => return m.abandon(p), 177 ) {
178 }; 178 return m.abandon(p);
179 p.bump_any(); 179 }
180 p.bump(T![&]);
180 if p.at(LIFETIME_IDENT) { 181 if p.at(LIFETIME_IDENT) {
181 lifetime(p); 182 lifetime(p);
182 n_toks -= 1;
183 }
184 for _ in 1..n_toks {
185 p.bump_any();
186 } 183 }
184 p.eat(T![mut]);
185 self_as_name(p);
187 } 186 }
188 m.complete(p, SELF_PARAM); 187 m.complete(p, SELF_PARAM);
189 if !p.at(T![')']) { 188 if !p.at(T![')']) {
190 p.expect(T![,]); 189 p.expect(T![,]);
191 } 190 }
192} 191}
192
193fn self_as_name(p: &mut Parser) {
194 let m = p.start();
195 p.bump(T![self]);
196 m.complete(p, NAME);
197}
diff --git a/crates/parser/src/syntax_kind.rs b/crates/parser/src/syntax_kind.rs
index 63204436c..9ea0e4f9b 100644
--- a/crates/parser/src/syntax_kind.rs
+++ b/crates/parser/src/syntax_kind.rs
@@ -6,6 +6,7 @@ mod generated;
6pub use self::generated::SyntaxKind; 6pub use self::generated::SyntaxKind;
7 7
8impl From<u16> for SyntaxKind { 8impl From<u16> for SyntaxKind {
9 #[inline]
9 fn from(d: u16) -> SyntaxKind { 10 fn from(d: u16) -> SyntaxKind {
10 assert!(d <= (SyntaxKind::__LAST as u16)); 11 assert!(d <= (SyntaxKind::__LAST as u16));
11 unsafe { std::mem::transmute::<u16, SyntaxKind>(d) } 12 unsafe { std::mem::transmute::<u16, SyntaxKind>(d) }
@@ -13,12 +14,14 @@ impl From<u16> for SyntaxKind {
13} 14}
14 15
15impl From<SyntaxKind> for u16 { 16impl From<SyntaxKind> for u16 {
17 #[inline]
16 fn from(k: SyntaxKind) -> u16 { 18 fn from(k: SyntaxKind) -> u16 {
17 k as u16 19 k as u16
18 } 20 }
19} 21}
20 22
21impl SyntaxKind { 23impl SyntaxKind {
24 #[inline]
22 pub fn is_trivia(self) -> bool { 25 pub fn is_trivia(self) -> bool {
23 matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT) 26 matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT)
24 } 27 }
diff --git a/crates/parser/src/syntax_kind/generated.rs b/crates/parser/src/syntax_kind/generated.rs
index 7d53cc4cd..bcefd183a 100644
--- a/crates/parser/src/syntax_kind/generated.rs
+++ b/crates/parser/src/syntax_kind/generated.rs
@@ -143,6 +143,7 @@ pub enum SyntaxKind {
143 MACRO_DEF, 143 MACRO_DEF,
144 PAREN_TYPE, 144 PAREN_TYPE,
145 TUPLE_TYPE, 145 TUPLE_TYPE,
146 MACRO_TYPE,
146 NEVER_TYPE, 147 NEVER_TYPE,
147 PATH_TYPE, 148 PATH_TYPE,
148 PTR_TYPE, 149 PTR_TYPE,