Expand description
§ADA_Standards
A comprehensive library for parsing and analyzing Ada source code to enforce coding standards and identify potential issues through Abstract Syntax Tree (AST) analysis.
§Overview
The ADA_Standards library provides a lightweight, regex-based approach to parsing Ada code.
It extracts language constructs (packages, procedures, types, control flow, etc.) and builds
a hierarchical tree structure that can be traversed and analyzed programmatically.
§Key Components
- NodeData: Represents individual Ada constructs with metadata (location, type, parameters, etc.)
- AST: The main Abstract Syntax Tree structure with methods for building and querying
- Expression Types: Unary, Binary, Membership, and Condition expressions for parsing logic
- ArgumentData: Structured representation of procedure/function parameters
§Workflow
- Clean Code: Remove comments and normalize strings while preserving structure
- Extract Nodes: Use regex patterns to identify all Ada constructs
- Build Tree: Establish parent-child relationships based on code structure
- Post-Process: Populate derived data like case alternatives and loop conditions
- Analyze: Traverse the tree to enforce standards or generate metrics
§Example
use ADA_Standards::{AST, ASTError};
use std::fs;
let code = fs::read_to_string("blop.ada")?;
let cleaned = AST::clean_code(&code);
let nodes = AST::extract_all_nodes(&cleaned)?;
let mut ast = AST::new(nodes);
ast.build(&cleaned)?;
ast.populate_cases(&cleaned)?;
// Find and analyze a specific procedure
if let Some(proc_id) = ast.find_node_by_name_and_type("Main", "ProcedureNode") {
let proc = ast.arena().get(proc_id).unwrap().get();
println!("Found procedure at line {}", proc.start_line.unwrap());
}Structs§
- AST
- Represents the Abstract Syntax Tree (AST) for Ada source code.
- Argument
Data - Represents a single procedure, function, or entry parameter.
- Binary
Expression - Represents a binary operation in an expression tree.
- Condition
Expr - Represents a parsed conditional expression.
- EndStatement
- Internal structure representing a found
endstatement. - Membership
Expression - Represents a membership test expression.
- Node
Data - The core data structure representing an Ada construct in the AST.
- Return
Keyword Data - Represents the return type of a function.
- Unary
Expression - Represents a unary operation in an expression tree.
Enums§
- ASTError
- Represents errors that can occur during AST construction or analysis.
- Binaries
- Represents Ada binary operators in conditional expressions.
- Expression
- Represents different types of expressions in Ada conditional logic.
- Memberships
- Represents Ada membership test operators.
- Unaries
- Represents Ada unary operators in conditional expressions.