Skip to content
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 #1500

Closed
wants to merge 1 commit into from

Conversation

tomjakubowski
Copy link

cc #1479

@tomjakubowski
Copy link
Author

tomjakubowski commented Jul 7, 2019

This adds a new SyntaxKind for "subslice patterns", to match the b.. in something like if let [a, b..] = foo {}. atom_pat() gets a new branch to look for these. By the way, the syntax for those is due to change: rust-lang/rust#62254

I'm not sure what to do with the text in crates/ra_syntax/tests/data/parser/inline/ok/0024_slice_pat.txt, which is causing the test failure. Should I just replace the contents with the debug dump for the new test with a subslice pattern? Or should I just put it into a new test?

@tomjakubowski
Copy link
Author

cargo run --bin ra_cli parse < crates/ra_syntax/tests/data/parser/inline/ok/0024_slice_pat.rs > crates/ra_syntax/tests/data/parser/inline/ok/0024_slice_pat.txt

That wasn't too bad!

@tomjakubowski tomjakubowski changed the title WIP: issue 1479 subslice patterns Parse subslice patterns Jul 7, 2019
@matklad
Copy link
Member

matklad commented Jul 7, 2019

Should I just replace the contents with the debug dump for the new test with a subslice pattern?

There's also REWRITE constant in the tests which you can set to true to update them

@@ -58,6 +58,12 @@ const PAT_RECOVERY_SET: TokenSet =
fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
let la0 = p.nth(0);
let la1 = p.nth(1);
if la0 == IDENT && la1 == T![..] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think this would allow x.. anywhere where patterns are allowed, and not only inside slices. I think we need to adjust slice_pat instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh you're right of course. I inlined pat_list() to slice_pat() and made the adjustment there. Seeing as pat_list() now only had one caller, I inlined it there and deleted it.

@tomjakubowski
Copy link
Author

This was a valuable learning exercise! I'll update the issue and take another crack at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants