rust-lang / rust-lang/rust-analyzer
ssr: support regex-style backreferences to previously used expressions
Open
Nobody has claimed this yet.
A-ssr
C-feature
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
In some cases, just like in regex, it is needed to reference an expression previously declared:
rust-analyzer ssr \
'while $i < $end { $block; $i = $i.wrapping_add(1); } ==>> for $i in 0..$end { $block; }'
To match this type of code:
while counter < 100 {
// ...
counter = counter.wrapping_add(1);
}
to transform it into
for counter in 0..100 {
// ...
}
Currently I get an error:
can't parse `rule`, Parse error: Placeholder `$i` repeats more than once
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the rust-analyzer SSR command, reproducing the shown rule and its “Placeholder $i repeats more than once” error. Trace how SSR rules are parsed and how placeholders are matched; done means the example rule accepts the repeated expression and transforms the shown while loop into the for loop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100