-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse subslice patterns #1509
Parse subslice patterns #1509
Conversation
@matklad you said the adjustment would need to be in In an example like It's unfortunate that subslice patterns can be parsed outside of slice patterns. I think I can fix that by adding a bool flag to |
atom_pat(p, recovery_set); | ||
m.complete(p, RANGE_PAT); | ||
if subslice_patterns && dots == T![..] && !p.at_ts(PATTERN_FIRST) { | ||
m.complete(p, SUBSLICE_PAT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think this is still not exactly what we want, as it'll match [1..]
, which is wrong: we need to enfroce that lhs is identifier.
I think the best solution would be to inline pat_list
into slice_pat
and handle a..
specially, simliar to ..
:
T![..] => p.bump(),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, special casing should happen around here: https://github.com/rust-analyzer/rust-analyzer/blob/5b19825e376b67aabbe8d5b163bf69b1acd92f04/crates/ra_parser/src/grammar/patterns.rs#L241
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, I see pat_list
is already inlined! So, we only need to pull haling of ..
out of pattern_with_subslice_patterns
into the while !p.at(EOF) && !p.at(T![']']) {
loop
0b873da
to
c4cbadf
Compare
OK, this commit copies from rustc does actually parse |
I think this won't parse macro patterns followed by |
Wow, looks like I don't really understand what this syntax means in the first place... I would expect that macros wouldn't be allowed to the left of |
Ok, so after reading through several RFC, it looks like Chasing unstable features is annoying :) |
The syntax |
UPDATE: The PR rust-lang/rust#62550 has been merged. |
closing due to inactivity! |
This attempt detects subslice patterns in the same place as range patterns;
when the right hand side of a
..
in a potential range definitely isn't a pattern,the parser stops and emits a
SUBSLICE_PAT
instead.cc #1479