From 98718e0544f42e55642d2838b00d6a7bef1e2414 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 15 Jan 2021 21:07:38 +0100 Subject: Wrap remaining self/super/crate in Name{Ref} --- crates/parser/src/grammar.rs | 12 ++++++++++-- crates/parser/src/grammar/items.rs | 2 ++ crates/parser/src/grammar/params.rs | 31 ++++++++++++++++++------------- 3 files changed, 30 insertions(+), 15 deletions(-) (limited to 'crates/parser') 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 { // test crate_visibility // pub(crate) struct S; // pub(self) struct S; - // pub(self) struct S; - // pub(self) struct S; + // pub(super) struct S; // test pub_parens_typepath // struct B(pub (super::A)); // struct B(pub (crate::A,)); T![crate] | T![self] | T![super] if p.nth(2) != T![:] => { p.bump_any(); + let path_m = p.start(); + let path_segment_m = p.start(); + let name_ref_m = p.start(); p.bump_any(); + name_ref_m.complete(p, NAME_REF); + path_segment_m.complete(p, PATH_SEGMENT); + path_m.complete(p, PATH); p.expect(T![')']); } + // test crate_visibility_in + // pub(in super::A) struct S; + // pub(in crate) struct S; T![in] => { p.bump_any(); 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) { p.bump(T![crate]); if p.at(T![self]) { + let m = p.start(); p.bump(T![self]); + m.complete(p, NAME_REF); } else { name_ref(p); } 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 { fn opt_self_param(p: &mut Parser, m: Marker) { if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { p.eat(T![mut]); - p.eat(T![self]); + self_as_name(p); // test arb_self_types // impl S { // fn a(self: &Self) {} @@ -169,24 +169,29 @@ fn opt_self_param(p: &mut Parser, m: Marker) { let la1 = p.nth(1); let la2 = p.nth(2); let la3 = p.nth(3); - let mut n_toks = match (p.current(), la1, la2, la3) { - (T![&], T![self], _, _) => 2, - (T![&], T![mut], T![self], _) => 3, - (T![&], LIFETIME_IDENT, T![self], _) => 3, - (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, - _ => return m.abandon(p), - }; - p.bump_any(); + if !matches!((p.current(), la1, la2, la3), + (T![&], T![self], _, _) + | (T![&], T![mut], T![self], _) + | (T![&], LIFETIME_IDENT, T![self], _) + | (T![&], LIFETIME_IDENT, T![mut], T![self]) + ) { + return m.abandon(p); + } + p.bump(T![&]); if p.at(LIFETIME_IDENT) { lifetime(p); - n_toks -= 1; - } - for _ in 1..n_toks { - p.bump_any(); } + p.eat(T![mut]); + self_as_name(p); } m.complete(p, SELF_PARAM); if !p.at(T![')']) { p.expect(T![,]); } } + +fn self_as_name(p: &mut Parser) { + let m = p.start(); + p.bump(T![self]); + m.complete(p, NAME); +} -- cgit v1.2.3