Pipeline.Codebase.ASTParser (pipeline v0.0.1)
View SourceUnified AST parsing utilities for different programming languages.
Provides a consistent interface for parsing and analyzing code across multiple languages, extracting functions, classes, imports, and other code constructs.
⚠️ IMPORTANT WARNING ⚠️
This is a PROTOTYPE implementation using simplified regex-based parsing.
For production use, this module should be replaced with proper language parsers:
- JavaScript/TypeScript: Babylon, Acorn, or ESTree-based parsers
- Python: Built-in
ast
module orparso
library - Rust:
syn
crate orrustc_parse
- Go:
go/parser
andgo/ast
from Go standard library - Elixir: Enhanced AST traversal using
Code.string_to_quoted/2
The current regex patterns are fragile and will fail on complex code patterns.
Summary
Functions
Calculate cyclomatic complexity for a file.
Find class definitions in a file.
Find function definitions in a file.
Find import/require statements in a file.
Parse a file and extract code information.
Types
@type class_info() :: %{ name: String.t(), line: non_neg_integer(), end_line: non_neg_integer() | nil, methods: [function_info()], properties: [String.t()], inheritance: [String.t()] }
@type comment_info() :: %{ line: non_neg_integer(), type: String.t(), content: String.t() }
@type function_info() :: %{ name: String.t(), type: String.t(), line: non_neg_integer(), end_line: non_neg_integer() | nil, parameters: [String.t()], visibility: String.t(), signature: String.t() }
@type parse_result() :: %{ functions: [function_info()], classes: [class_info()], imports: [String.t()], exports: [String.t()], comments: [comment_info()], complexity: non_neg_integer() }
Functions
@spec calculate_complexity(String.t()) :: {:ok, non_neg_integer()} | {:error, String.t()}
Calculate cyclomatic complexity for a file.
@spec find_classes( String.t(), keyword() ) :: {:ok, [class_info()]} | {:error, String.t()}
Find class definitions in a file.
@spec find_functions( String.t(), keyword() ) :: {:ok, [function_info()]} | {:error, String.t()}
Find function definitions in a file.
Find import/require statements in a file.
@spec parse_file(String.t()) :: {:ok, parse_result()} | {:error, String.t()}
Parse a file and extract code information.
Returns structured information about functions, classes, imports, and other code constructs based on the file's language.