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;
67
68// Re-export core parser functionality
69pub use core::{Parser, ParserError};
70
71// Re-export Language from language module (new location)
72// For backward compatibility, also keep it accessible from core
73pub use language::{detect_file_language, Language};
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78
79    #[test]
80    fn test_parser_creation() {
81        let parser = Parser::new();
82        // Parser should be created without errors
83        drop(parser);
84    }
85
86    #[test]
87    fn test_language_from_extension() {
88        assert_eq!(Language::from_extension("py"), Some(Language::Python));
89        assert_eq!(Language::from_extension("rs"), Some(Language::Rust));
90        assert_eq!(Language::from_extension("unknown"), None);
91    }
92}