Expand description
§ADA_Standards
A library for parsing and analyzing Ada source code to enforce coding standards and identify potential issues.
This library provides a way to programmatically inspect the structure and content of Ada files, allowing for the creation of custom rules to verify specific coding conventions.
§Overview
The ADA_Standards library uses regular expressions to perform a lightweight parsing of Ada code
and builds an Abstract Syntax Tree (AST) represented by the indextree crate. This AST can then
be traversed to analyze the code based on user-defined rules.
§Modules
text_format: Provides constants for ANSI escape codes to format output in the console.
§Enums
The library defines several enums to represent different elements of Ada expressions:
Unaries: Represents unary operators likenot.Memberships: Represents membership operators likeinandnot in.Binaries: Represents binary operators likeand,or,and then,or else, etc.
§Structs
Key data structures used by the library:
NodeData: Stores information about a node in the AST, including its name, type, line numbers, and specific data related to the Ada construct it represents (e.g., conditions for anifstatement, arguments for a procedure).UnaryExpression,BinaryExpression,MembershipExpression,ConditionExpr: Represent different types of expressions in Ada code.ArgumentData: Stores information about procedure or function arguments.ReturnKeywordData: Stores information about the return type of a function.AST: Represents the Abstract Syntax Tree of the Ada code. It provides methods to build the tree from a list ofNodeDataand traverse it.
§Usage
To use the ADA_Standards library, you would typically:
- Read the content of an Ada file as a string.
- Use the library’s functions (like
extract_packages,extract_procedures_functions, etc.) to parse the code and create aVec<NodeData>. - Create an
ASTinstance from theVec<NodeData>. - Define your own analysis rules as functions that take an
&AST - Process the list of nodes and various informations in the AST to try to check if your coding standards are respected
Structs§
- AST
- Represents the Abstract Syntax Tree (AST) for Ada source code.
- Argument
Data - Binary
Expression - Condition
Expr - EndStatement
- Membership
Expression - Node
Data - Creates a new
NodeDatainstance with specified attributes. - Return
Keyword Data - Unary
Expression
Enums§
- ASTError
- Represents errors that can occur during AST construction or analysis.
- Binaries
- Expression
- Memberships
- Unaries