Skip to content

ssr: support regex-style backreferences to previously used expressions #16833

@nyurik

Description

@nyurik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ssrstructural search & replaceC-featureCategory: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions