SQL-like query API for AST search.
This module builds on ExAST.Selector with names that read like query
predicates:
import ExAST.Query
from("def _ do ... end")
|> where(contains("Repo.transaction(_)"))
|> where(not contains("IO.inspect(_)"))where/2 also supports capture guards using ^ to pin captured values,
similar to Ecto's parameter syntax:
from("Enum.take(_, count)")
|> where(match?({:-, _, [_]}, ^count))
from("left == right")
|> where(^left == ^right)The resulting query can be passed to ExAST.search/3 or
ExAST.Patcher.find_all/3 anywhere a selector is accepted.
Summary
Functions
Matches when all nested predicates match.
Matches when any nested predicate matches.
Matches comments associated with the selected node.
Matches comments immediately after the selected node.
Matches comments immediately before the selected node.
Matches inline comments on the selected node start line.
Matches comments inside the selected node range.
Matches when the selected node contains a descendant matching pattern.
Builds an exact comment matcher.
Finds matching descendants of the current selection.
Finds matching direct children of the current selection.
Matches the first semantic child in its parent.
Matches when a previous sibling matches pattern.
Starts a query from one pattern or a list of alternative patterns.
Matches when the selected node has a direct child matching pattern.
Matches when the immediately previous sibling matches pattern.
Matches when the immediately following sibling matches pattern.
Matches when the selected node is inside an ancestor matching pattern.
Matches the last semantic child in its parent.
Matches the nth semantic child in its parent, using 1-based indexing.
Matches when the selected node has a direct parent matching pattern.
Matches when a following sibling matches pattern.
Builds a comment prefix matcher.
Builds a comment suffix matcher.
Builds a substring comment matcher.
Adds a predicate filter without changing the selected node.
Types
@type t() :: ExAST.Selector.t()
Functions
Matches when all nested predicates match.
Matches when any nested predicate matches.
Matches comments associated with the selected node.
Matches comments immediately after the selected node.
Matches comments immediately before the selected node.
Matches inline comments on the selected node start line.
Matches comments inside the selected node range.
Matches when the selected node contains a descendant matching pattern.
Builds an exact comment matcher.
Finds matching descendants of the current selection.
Finds matching direct children of the current selection.
Matches the first semantic child in its parent.
Matches when a previous sibling matches pattern.
Starts a query from one pattern or a list of alternative patterns.
Matches when the selected node has a direct child matching pattern.
Matches when the immediately previous sibling matches pattern.
Matches when the immediately following sibling matches pattern.
Matches when the selected node is inside an ancestor matching pattern.
Matches the last semantic child in its parent.
Matches the nth semantic child in its parent, using 1-based indexing.
Matches when the selected node has a direct parent matching pattern.
Matches when a following sibling matches pattern.
Builds a comment prefix matcher.
Builds a comment suffix matcher.
Builds a substring comment matcher.
Adds a predicate filter without changing the selected node.
Accepts structural predicates (contains/1, inside/1, etc.),
boolean expressions (not, and, or), and capture guards.
Capture guards
Use ^name to reference a captured value from the pattern. The expression
is evaluated against the captures map at match time:
from("Enum.take(_, count)")
|> where(match?({:-, _, [_]}, ^count))
from("def handle_event(event, _, _) do ... end")
|> where(^event == :click or ^event == :keydown)
from("left == right")
|> where(^left == ^right)