1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! AST query system for semantic code search
//!
//! This module provides a query language for searching code by AST structure,
//! not just text patterns. It enables queries like:
//!
//! - `kind:function AND name~=^test_` - Find test functions
//! - `kind:method AND parent:class` - Find methods in classes
//! - `kind:function AND depth:>3` - Find deeply nested functions
//!
//! # Architecture
//!
//! The AST query system consists of three main components:
//!
//! - **types**: Core types (Context, ContextualMatch, ContextKind)
//! - **context**: Context extraction from ASTs (parent, ancestors, depth)
//! - **query**: Query parser and evaluator (predicate language + matching)
//!
//! # Examples
//!
//! ## Basic Query
//!
//! ```rust,no_run
//! use sqry_core::ast::{parse_query, ContextExtractor};
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Parse query
//! let query = parse_query("kind:function AND name~=test")?;
//!
//! // Extract context from file
//! let extractor = ContextExtractor::new();
//! let matches = extractor.extract_from_file(Path::new("src/lib.rs"))?;
//!
//! // Filter by query
//! let filtered: Vec<_> = matches.into_iter()
//! .filter(|m| query.matches(&m))
//! .collect();
//!
//! println!("Found {} test functions", filtered.len());
//! # Ok(())
//! # }
//! ```
//!
//! ## Complex Query with Multiple Predicates
//!
//! ```rust,no_run
//! use sqry_core::ast::{parse_query, ContextExtractor};
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Find methods inside classes, but not in test classes
//! let query = parse_query("kind:method AND parent:class AND NOT in:TestClass")?;
//!
//! let extractor = ContextExtractor::new();
//! let matches = extractor.extract_from_file(Path::new("src/lib.rs"))?;
//!
//! for ctx_match in matches.iter().filter(|m| query.matches(m)) {
//! println!("{} at {}:{}",
//! ctx_match.name,
//! ctx_match.file_path.display(),
//! ctx_match.start_line);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Depth-Based Filtering
//!
//! ```rust,no_run
//! use sqry_core::ast::{parse_query, ContextExtractor};
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Find deeply nested functions (more than 2 levels deep)
//! let query = parse_query("kind:function AND depth:>2")?;
//!
//! let extractor = ContextExtractor::new();
//! let matches = extractor.extract_from_file(Path::new("src/lib.rs"))?;
//!
//! for ctx_match in matches.iter().filter(|m| query.matches(m)) {
//! println!("{} depth={} path={}",
//! ctx_match.name,
//! ctx_match.context.depth(),
//! ctx_match.context.path());
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Directory Traversal
//!
//! ```rust,no_run
//! use sqry_core::ast::{parse_query, ContextExtractor};
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Find all public functions across entire codebase
//! let query = parse_query("kind:function")?;
//!
//! let extractor = ContextExtractor::new();
//! let matches = extractor.extract_from_directory(Path::new("src"))?;
//!
//! println!("Found {} functions across codebase",
//! matches.iter().filter(|m| query.matches(m)).count());
//! # Ok(())
//! # }
//! ```
//!
//! # Query Language
//!
//! The query language supports 7 predicate types:
//!
//! - `kind:TYPE` - Match symbol kind (function, method, class, struct, enum, etc.)
//! - `name~=REGEX` - Match symbol name with regex
//! - `parent:TYPE` - Match parent kind
//! - `in:NAME` - Match if inside ancestor with given name
//! - `depth:N` - Match nesting depth (supports >, <, >=, <=, =)
//! - `path:TEXT` - Match if symbol path contains text
//! - `lang:LANG` - Match language (rust, javascript, typescript, python, go)
//!
//! Boolean operators: `AND`, `OR`, `NOT` (case-insensitive) with parentheses for grouping.
//!
//! ## Example Queries
//!
//! - `kind:function` - All functions
//! - `kind:method AND parent:class` - Methods in classes
//! - `name~=^test_` - Names starting with "test_"
//! - `depth:>3` - Deeply nested symbols
//! - `lang:rust AND kind:struct` - Rust structs only
//! - `(kind:function OR kind:method) AND NOT name~=test` - Functions/methods excluding tests
//! - `in:MyClass AND depth:>=2` - Symbols inside MyClass at depth 2+
pub use ContextExtractor;
pub use AstQueryError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Type alias for Results in AST query module
pub type Result<T> = Result;