#ast #parser #ast-graph #code-analysis #code-parser

codegraph-parser-api

Shared API and types for CodeGraph language parsers

3 unstable releases

0.2.0 Dec 15, 2025
0.1.1 Dec 10, 2025
0.1.0 Nov 6, 2025

#6 in #code-parser

48 downloads per month
Used in 18 crates (13 directly)

Apache-2.0

190KB
3.5K SLoC

CodeGraph Parser API

Shared trait and types for building CodeGraph language parsers.

This crate provides the foundation for implementing language parsers that work with the CodeGraph database. It defines:

  • CodeParser trait: The core interface all parsers must implement
  • Entity types: Language-agnostic representations of code elements (functions, classes, etc.)
  • Relationship types: Representations of code dependencies (calls, imports, etc.)
  • Configuration: Customizable parser behavior
  • Metrics: Performance and success tracking
  • Error handling: Comprehensive error types

Example

use codegraph_parser_api::{CodeParser, ParserConfig, ParserError, FileInfo};
use codegraph::CodeGraph;
use std::path::Path;

struct MyParser {
    config: ParserConfig,
}

impl CodeParser for MyParser {
    fn language(&self) -> &str {
        "mylang"
    }

    fn file_extensions(&self) -> &[&str] {
        &[".my"]
    }

    fn parse_file(&self, path: &Path, graph: &mut CodeGraph) -> Result<FileInfo, ParserError> {
        // Implementation here
        todo!()
    }

    fn parse_source(&self, source: &str, file_path: &Path, graph: &mut CodeGraph)
        -> Result<FileInfo, ParserError> {
        // Implementation here
        todo!()
    }

    fn config(&self) -> &ParserConfig {
        &self.config
    }

    fn metrics(&self) -> ParserMetrics {
        ParserMetrics::default()
    }

    fn reset_metrics(&mut self) {
        // Reset internal metrics
    }
}

Dependencies

~27MB
~560K SLoC