Crate ADA_Standards

Crate ADA_Standards 

Source
Expand description

§ADA_Standards

crates.io docs.rs

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

  1. Clean Code: Remove comments and normalize strings while preserving structure
  2. Extract Nodes: Use regex patterns to identify all Ada constructs
  3. Build Tree: Establish parent-child relationships based on code structure
  4. Post-Process: Populate derived data like case alternatives and loop conditions
  5. 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.
ArgumentData
Represents a single procedure, function, or entry parameter.
BinaryExpression
Represents a binary operation in an expression tree.
ConditionExpr
Represents a parsed conditional expression.
EndStatement
Internal structure representing a found end statement.
MembershipExpression
Represents a membership test expression.
NodeData
The core data structure representing an Ada construct in the AST.
ReturnKeywordData
Represents the return type of a function.
UnaryExpression
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.