ops/:text
text-based matching for source code literals
clojure
(:text val)Where:
- val: text to match *
Behavior
- Matches against the exact text of a node (when used in bounded context) or finds all matching regions within a node's text (when used as free selector).
- Operates on raw source text rather than semantic structure - useful when TreeSitter doesn't expose specific syntax as named nodes.
Examples
Find Rust macro invocations that TreeSitter doesn't parse into structured nodes.
clojure
(:and (:text /Foo::A/) (:kind "token_tree"))Selects in lines { 2 } but not in { }:
typescript
macro_rules! m {
() => { Foo::A }
}
m!();Locate TODO comments in any language by matching comment text.
clojure
(:text /TODO:/)Selects in lines { 1, 1 } but not in { 2 }:
typescript
// TODO: fix this
// FIXME: refactor
/* TODO: add tests */Find specific string patterns that appear in code before extracting to constants.
clojure
(:text "https://api.example.com")Selects in lines { 1, 1 } but not in { }:
typescript
const url1 = 'https://api.example.com/users'
const url2 = 'https://api.other.com/users'
fetch('https://api.example.com/posts')Arguments
val
• String • Pattern • Identifier
Does NOT support: Composition — Free-form Selection — Refinement — Replacement