Skip to content

Commit

Permalink
chore!: Adjust IGNORE pattern
Browse files Browse the repository at this point in the history
The new pattern is stricter, and will reduce naming collisions
  • Loading branch information
alexpovel committed Jun 8, 2024
1 parent b30afe9 commit 96d4d4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,11 @@ Let's assume there's a node type for matching *entire* macros (`macro_invocation
one to match macro *names* (`((macro_invocation macro: (identifier) @name))`), but
*none* to match macro *contents* (this is wrong, tree-sitter offers this in the form of
`token_tree`, but let's imagine...). To match just `"This went error"`, the entire macro
would need to be matched, with the name part ignored. Any capture name containing
`IGNORE` will provide just that:
would need to be matched, with the name part ignored. Any capture name starting with
`_SRGN_IGNORE` will provide just that:

```bash
cat wrong.rs | srgn --rust-query '((macro_invocation macro: (identifier) @IGNORE_name) @macro)' 'error' 'wrong'
cat wrong.rs | srgn --rust-query '((macro_invocation macro: (identifier) @_SRGN_IGNORE_name) @macro)' 'error' 'wrong'
```

```rust output-wrong.rs
Expand Down
4 changes: 2 additions & 2 deletions src/scoping/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
///
/// Useful for queries where tree-sitter doesn't natively support a fitting node type,
/// and a result is instead obtained by ignoring unwanted parts of bigger captures.
pub(super) const IGNORE: &str = "IGNORE";
pub(super) const IGNORE: &str = "_SRGN_IGNORE";

/// A scoper for a language.
///
Expand Down Expand Up @@ -132,7 +132,7 @@ pub trait LanguageScoper: Scoper {

let ranges = run(query);

let is_ignored = |name: &str| name.contains(IGNORE);
let is_ignored = |name: &str| name.starts_with(IGNORE);
let has_ignored_captures = query.capture_names().iter().any(|name| is_ignored(name));

if has_ignored_captures {
Expand Down

0 comments on commit 96d4d4c

Please sign in to comment.