all2md.parsers.sourcecode
Source code to AST converter.
This module provides conversion from source code files to AST representation. It creates CodeBlock nodes with appropriate language identifiers.
- class all2md.parsers.sourcecode.SourceCodeToAstConverter
Bases:
BaseParserConvert source code files to AST representation.
This converter creates a CodeBlock node with the detected language.
- Parameters:
options (SourceCodeOptions or None) – Conversion options
Initialize the source code parser with options and progress callback.
- __init__(options: SourceCodeOptions | None = None, progress_callback: Callable[[ProgressEvent], None] | None = None)
Initialize the source code parser with options and progress callback.
- parse(input_data: str | Path | IO[bytes] | bytes) Document
Parse source code input into an AST Document.
- Parameters:
input_data (str, Path, IO[bytes], or bytes) – The input source code to parse
- Returns:
AST Document node with CodeBlock
- Return type:
- Raises:
ParsingError – If parsing fails
- convert_to_ast(content: str, filename: str | None = None, language: str | None = None) Document
Convert source code content to AST Document.
- Parameters:
content (str) – Source code content
filename (str | None) – Filename for language detection
language (str | None) – Override language identifier
- Returns:
AST document with CodeBlock node
- Return type:
- extract_metadata(document: Any) DocumentMetadata
Extract metadata from source code document.
- Parameters:
document (Any) – Source code document (not used)
- Returns:
Empty metadata (source code files don’t have standard metadata)
- Return type:
Notes
Source code files typically do not contain structured metadata. Information like language and filename is handled through the conversion options and file context, not as document metadata.