Expand description
Structural Search Replace
Allows searching the AST for code that matches one or more patterns and then replacing that code based on a template.
Modulesยง
- errors ๐
- Code relating to errors produced by SSR.
- fragments ๐
- When specifying SSR rule, you generally want to map one kind of thing to the same kind of thing: path to path, expression to expression, type to type.
- from_
comment ๐ - This module allows building an SSR MatchFinder by parsing the SSR rule from a comment.
- matching ๐
- This module is responsible for matching a search pattern against a node in the AST. In the process of matching, placeholder values are recorded.
- nester ๐
- Converts a flat collection of matches into a nested form suitable for replacement. When there are multiple matches for a node, or that overlap, priority is given to the earlier rule. Nested matches are only permitted if the inner match is contained entirely within a placeholder of an outer match.
- parsing ๐
- This file contains code for parsing SSR rules, which look something like
foo($a) ==>> bar($b). We first split everything before and after the separator==>>. Next, both the search pattern and the replacement template get tokenized by the Rust tokenizer. Tokens are then searched for placeholders, which start with$. For replacement templates, this is the final form. For search patterns, we go further and parse the pattern as each kind of thing that we can match. e.g. expressions, type references etc. - replacing ๐
- Code for applying replacement templates for matches that have previously been found.
- resolving ๐
- This module is responsible for resolving paths within rules.
- search ๐
- Searching for matches.
Structsยง
- Match
- Information about a match that was found.
- Match
Debug Info - Match
Finder - Searches a crate for pattern matches and possibly replaces them with something else.
- SsrError
- SsrMatches
- SsrPattern
- SsrRule
Functionsยง
- ssr_
from_ comment - Attempts to build an SSR MatchFinder from a comment at the given file range. If successful, returns the MatchFinder and a TextRange covering comment.