AST pattern matching with captures.
Patterns are valid Elixir syntax where:
- Bare variables (
name,expr) capture the matched AST node _and_nameare wildcards (match anything, don't capture)- Structs and maps match partially (only specified keys must be present)
- Pipes are normalized (
data |> Enum.map(f)matchesEnum.map(data, f)) - Multi-statement patterns match contiguous sequences in blocks
Repeated variable names require the same value at every position.
Summary
Functions
Matches a Sourceror AST node against a pattern string.
Matches a Sourceror AST node against an already-parsed pattern AST.
Finds all contiguous subsequences of nodes matching pattern_asts.
Returns true if the pattern string contains multiple statements
(separated by ; or newlines), enabling sequential matching.
Returns the individual pattern ASTs from a multi-node pattern string.
Substitutes captured values into a replacement template AST.
Types
Functions
Matches a Sourceror AST node against a pattern string.
Returns {:ok, captures} on match, :error otherwise.
Matches a Sourceror AST node against an already-parsed pattern AST.
Finds all contiguous subsequences of nodes matching pattern_asts.
Returns a list of {captures, start_index..end_index} tuples.
Captures are accumulated across all matched nodes and must be consistent.
Returns true if the pattern string contains multiple statements
(separated by ; or newlines), enabling sequential matching.
Returns the individual pattern ASTs from a multi-node pattern string.
Substitutes captured values into a replacement template AST.
Variables in the template that match capture names are replaced with the captured AST nodes.