Skip to content

Commit

Permalink
feat: better metavar detection
Browse files Browse the repository at this point in the history
BREAKING CHANGE: metavar in pattern is more intuitive now.
Previously we only treat leaf node and error node as metavar.
This commit will detect metavar as long as the text in the node
matches metavar regex pattern. This results in a more intuitive
pattern syntax. However, this introduces 5% perf overhead and
is a breaking change. Breaking change is ok since the matching
is better now.
  • Loading branch information
HerringtonDarkholme committed Dec 13, 2023
1 parent 489aff3 commit e1ab18a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/core/src/match_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ fn match_leaf_meta_var<'tree, D: Doc>(
fn is_node_eligible_for_meta_var(goal: &Node<impl Doc>, is_leaf: bool) -> bool {
// allow Error as meta_var
// see https://github.com/ast-grep/ast-grep/issues/526
is_leaf || goal.is_error()
extract_var_from_node(goal).is_some()
// is_leaf || goal.is_error()
}

fn try_get_ellipsis_mode(node: &Node<impl Doc>) -> Result<Option<String>, ()> {
Expand Down

0 comments on commit e1ab18a

Please sign in to comment.