AST

Struct AST 

Source
pub struct AST { /* private fields */ }
Expand description

Represents the Abstract Syntax Tree (AST) for Ada source code.

Manages a collection of NodeData instances in an indextree::Arena, with a root node anchoring the tree. Provides methods to extract nodes, build the tree, and analyze Ada code for coding standard enforcement.

§Fields

  • arena: The indextree arena holding all nodes.
  • root_id: The ID of the synthetic root node.
  • nodes_data: Temporary storage for extracted nodes before building.

§Examples

use ADA_Standards::{AST, NodeData};
let nodes = vec![NodeData::new("Root".to_string(), "RootNode".to_string(), None, None, false)];
let ast = AST::new(nodes);

Implementations§

Source§

impl AST

Source

pub fn new(nodes_data: Vec<NodeData>) -> Self

Source

pub fn associate_end_lines(&mut self, code_text: &str) -> Result<(), ASTError>

Source

pub fn build(&mut self, code_text: &str) -> Result<(), ASTError>

Source

pub fn print_tree(&self)

Source

pub fn output_tree(&self) -> String

Source

pub fn print_nodes_info(&self) -> Result<(), ASTError>

Source

pub fn get_end_keyword(node_type: &str) -> Option<&'static str>

Source

pub fn extract_end_statements( code_text: &str, ) -> Result<Vec<EndStatement>, ASTError>

Source

pub fn extract_packages(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_procedures_functions( code_text: &str, ) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_type_declarations( code_text: &str, ) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_declare_blocks( code_text: &str, ) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_control_flow_nodes( code_text: &str, nodes: &mut Vec<NodeData>, ) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_simple_loops(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_while_loops(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Extracts while loops from Ada source code.

Parses the provided source code to identify while loops, capturing their loop condition, start position, and other metadata. Creates NodeData instances for each while loop, setting the node_type to “WhileLoop” and populating fields like conditions, start_line, start_index, and body_start. Fields like end_line and end_index are set to None, to be resolved later by associate_end_lines. This function is part of the node extraction phase, enabling analysis of while loops for Ada coding standards, such as ensuring termination conditions or limiting loop complexity.

§Parameters
  • code_text: The Ada source code to parse, as a string slice.
§Returns
  • Ok(Vec<NodeData>): A vector of NodeData instances, each representing a while loop.
  • Err(ASTError): If the regular expression for parsing fails to compile or another error occurs.
§Errors
  • ASTError::RegexError: If the regex pattern for while loops cannot be compiled.
§Notes
  • Captures the condition after while up to loop, storing it in conditions.list.
  • Sets body_start to the index after loop, marking the start of the loop body.
  • Ignores comments and nested constructs during initial extraction.
  • Use with build and associate_end_lines to complete node metadata.
Source

pub fn extract_for_loops(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_statement_nodes( code_text: &str, nodes: &mut Vec<NodeData>, ) -> Result<Vec<NodeData>, ASTError>

Source

pub fn extract_if_statements(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Extracts if statements from Ada source code.

Parses the provided source code to identify if statements, capturing their conditions, start position, and other metadata. Creates NodeData instances for each if statement, setting the node_type to “IfStatement” and populating fields like conditions, start_line, start_index, and body_start. Fields like end_line and end_index are set to None, to be resolved later by associate_end_lines. This function is part of the node extraction phase, enabling analysis of if statements for Ada coding standards, such as condition complexity or proper nesting.

§Parameters
  • code_text: The Ada source code to parse, as a string slice.
§Returns
  • Ok(Vec<NodeData>): A vector of NodeData instances, each representing an if statement.
  • Err(ASTError): If the regular expression for parsing fails to compile or another error occurs.
§Errors
  • ASTError::RegexError: If the regex pattern for if statements cannot be compiled.
§Notes
  • Captures the condition after if up to then, storing it in conditions.list.
  • Sets body_start to the index after then, marking the start of the if body.
  • Ignores comments and nested constructs during initial extraction.
  • Use with build and associate_end_lines to complete node metadata.
Source

pub fn extract_case_statements( code_text: &str, ) -> Result<Vec<NodeData>, ASTError>

Extracts case statements from Ada source code.

Identifies case statements using a regex pattern, capturing their switch expression and body start position. Creates NodeData instances for each case statement, setting cases to None for later population by populate_cases.

§Parameters
  • code_text: The Ada source code to parse.
§Returns
  • Ok(Vec<NodeData>): A vector of NodeData instances for case statements.
  • Err(ASTError): If the regex pattern fails to compile.
Source

pub fn populate_cases(&mut self, code_text: &str) -> Result<(), ASTError>

Populates the cases field for all CaseStatement nodes in the AST.

This method traverses the AST, identifies nodes with node_type “CaseStatement”, and extracts the list of case alternatives (e.g., “when X =>”) from their body text, defined by body_start and end_index. It is called after build to ensure all nodes have valid start and end positions. The extracted cases are stored in the cases field, enabling analysis like checking for complete coverage or duplicate cases in Ada code.

§Parameters
  • code_text: The full Ada source code from which to extract case bodies.
§Returns
  • Ok(()) if cases are populated successfully.
  • Err(ASTError) if a node lacks required positions (body_start or end_index) or if parsing fails.
§Errors
  • ASTError::NodeNotInArena if a node ID is invalid.
  • ASTError::InvalidNodeData if body_start or end_index is missing.
§Notes
  • Must be called after build to ensure end_index is set.
  • Handles nested case statements by checking indentation, if implemented.
  • Performance depends on the number of case statements and body text size.
Source

pub fn extract_cases_from_body(body_text: &str) -> Vec<String>

Extracts case alternatives from the body text of a case statement.

Parses the body text to identify “when” clauses (e.g., “when X =>”) and returns their conditions as a vector of strings. This is a helper function for populate_cases.

§Parameters
  • body_text: The body text of the case statement (from body_start to end_index).
§Returns

A vector of case conditions (e.g., [“1”, “2”, “others”]).

Source

pub fn parse_condition_expression(condition_str: &str) -> ConditionExpr

Source

pub fn recursive_function( keyword_str: &str, condstring: String, index: usize, lst: &mut Vec<Expression>, ) -> Expression

Source

pub fn supersplitter( condstring_in: String, lst: &mut Vec<Expression>, ) -> Expression

Source

pub fn flag_setter( char: char, string_flag: i32, number_of_open_parenthesis: i32, number_of_closed_parenthesis: i32, ) -> (i32, i32, i32)

Source

pub fn flags_check( number_of_open_parenthesis: i32, number_of_closed_parenthesis: i32, string_flag: i32, ) -> bool

Source

pub fn is_parenthesis_exterior(expression: &str) -> bool

Source

pub fn is_expression_a_parenthesis(expression: &str) -> bool

Source

pub fn clean_code(raw_code: &str) -> String

Source

pub fn extract_all_nodes(code_text: &str) -> Result<Vec<NodeData>, ASTError>

Source

pub fn leggitree(nodo: &Expression, level: u32, prefix: &str)

Auto Trait Implementations§

§

impl Freeze for AST

§

impl RefUnwindSafe for AST

§

impl Send for AST

§

impl Sync for AST

§

impl Unpin for AST

§

impl UnwindSafe for AST

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.