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 complexity;
61pub mod config;
62pub mod entities;
63pub mod errors;
64pub mod ir;
65pub mod metrics;
66pub mod relationships;
67pub mod traits;
68
69// Re-export commonly used types
70pub use complexity::{ComplexityBuilder, ComplexityMetrics};
71pub use config::ParserConfig;
72pub use entities::{ClassEntity, Field, FunctionEntity, ModuleEntity, Parameter, TraitEntity};
73pub use errors::{ParserError, ParserResult};
74pub use ir::CodeIR;
75pub use metrics::ParserMetrics;
76pub use relationships::{
77 CallRelation, ImplementationRelation, ImportRelation, InheritanceRelation,
78};
79pub use traits::{CodeParser, FileInfo, ProjectInfo};
80
81#[cfg(test)]
82mod tests;