infiniloom_engine/parser/mod.rs
1//! Tree-sitter based code parser for extracting symbols from source files
2//!
3//! This module provides a unified interface for parsing source code across
4//! multiple programming languages and extracting symbols (functions, classes,
5//! methods, structs, enums, etc.) with their metadata.
6//!
7//! # Module Structure
8//!
9//! - [`core`] - Main Parser struct and symbol extraction logic
10//! - [`language`] - Language enum and support utilities
11//! - [`queries`] - Tree-sitter query strings for all languages
12//!
13//! # Supported Languages
14//!
15//! Full symbol extraction support (with tree-sitter queries):
16//! - Python
17//! - JavaScript
18//! - TypeScript
19//! - Rust
20//! - Go
21//! - Java
22//! - C
23//! - C++
24//! - C#
25//! - Ruby
26//! - Bash
27//! - PHP
28//! - Kotlin
29//! - Swift
30//! - Scala
31//! - Haskell
32//! - Elixir
33//! - Clojure
34//! - OCaml
35//! - Lua
36//! - R
37//!
38//! Note: F# is recognized by file extension but tree-sitter parser support
39//! is not yet implemented.
40//!
41//! # Example
42//!
43//! ```rust,ignore
44//! use infiniloom_engine::parser::{Parser, Language};
45//!
46//! let parser = Parser::new();
47//! let source_code = std::fs::read_to_string("example.py")?;
48//! let symbols = parser.parse(&source_code, Language::Python)?;
49//!
50//! for symbol in symbols {
51//! println!("{}: {} (lines {}-{})",
52//! symbol.kind.name(),
53//! symbol.name,
54//! symbol.start_line,
55//! symbol.end_line
56//! );
57//! }
58//! ```
59
60// Sub-modules
61mod core;
62pub mod extraction;
63pub mod init;
64pub mod language;
65pub mod queries;
66pub mod query_builder;
67pub mod thread_local;
68
69// Re-export core parser functionality
70pub use core::{Parser, ParserError};
71
72// Re-export Language from language module (new location)
73// For backward compatibility, also keep it accessible from core
74pub use language::{detect_file_language, Language};
75
76// Re-export optimized thread-local parser API
77pub use thread_local::{parse_file_symbols, parse_with_language};
78
79#[cfg(test)]
80mod tests {
81 use super::*;
82
83 #[test]
84 fn test_parser_creation() {
85 let parser = Parser::new();
86 // Parser should be created without errors
87 drop(parser);
88 }
89
90 #[test]
91 fn test_language_from_extension() {
92 assert_eq!(Language::from_extension("py"), Some(Language::Python));
93 assert_eq!(Language::from_extension("rs"), Some(Language::Rust));
94 assert_eq!(Language::from_extension("unknown"), None);
95 }
96}