codegraph_parser_api/
lib.rs

1//! CodeGraph Parser API
2//!
3//! Shared trait and types for building CodeGraph language parsers.
4//!
5//! This crate provides the foundation for implementing language parsers that work
6//! with the CodeGraph database. It defines:
7//!
8//! - **CodeParser trait**: The core interface all parsers must implement
9//! - **Entity types**: Language-agnostic representations of code elements (functions, classes, etc.)
10//! - **Relationship types**: Representations of code dependencies (calls, imports, etc.)
11//! - **Configuration**: Customizable parser behavior
12//! - **Metrics**: Performance and success tracking
13//! - **Error handling**: Comprehensive error types
14//!
15//! # Example
16//!
17//! ```rust,ignore
18//! use codegraph_parser_api::{CodeParser, ParserConfig, ParserError, FileInfo};
19//! use codegraph::CodeGraph;
20//! use std::path::Path;
21//!
22//! struct MyParser {
23//!     config: ParserConfig,
24//! }
25//!
26//! impl CodeParser for MyParser {
27//!     fn language(&self) -> &str {
28//!         "mylang"
29//!     }
30//!
31//!     fn file_extensions(&self) -> &[&str] {
32//!         &[".my"]
33//!     }
34//!
35//!     fn parse_file(&self, path: &Path, graph: &mut CodeGraph) -> Result<FileInfo, ParserError> {
36//!         // Implementation here
37//!         todo!()
38//!     }
39//!
40//!     fn parse_source(&self, source: &str, file_path: &Path, graph: &mut CodeGraph)
41//!         -> Result<FileInfo, ParserError> {
42//!         // Implementation here
43//!         todo!()
44//!     }
45//!
46//!     fn config(&self) -> &ParserConfig {
47//!         &self.config
48//!     }
49//!
50//!     fn metrics(&self) -> ParserMetrics {
51//!         ParserMetrics::default()
52//!     }
53//!
54//!     fn reset_metrics(&mut self) {
55//!         // Reset internal metrics
56//!     }
57//! }
58//! ```
59
60pub mod config;
61pub mod entities;
62pub mod errors;
63pub mod ir;
64pub mod metrics;
65pub mod relationships;
66pub mod traits;
67
68// Re-export commonly used types
69pub use config::ParserConfig;
70pub use entities::{ClassEntity, Field, FunctionEntity, ModuleEntity, Parameter, TraitEntity};
71pub use errors::{ParserError, ParserResult};
72pub use ir::CodeIR;
73pub use metrics::ParserMetrics;
74pub use relationships::{
75    CallRelation, ImplementationRelation, ImportRelation, InheritanceRelation,
76};
77pub use traits::{CodeParser, FileInfo, ProjectInfo};
78
79#[cfg(test)]
80mod tests;