strictdoc icon indicating copy to clipboard operation
strictdoc copied to clipboard

Feature: Parsing source code functions into requirements graph

Open stanislaw opened this issue 1 year ago • 0 comments

This issue outlines the proposed feature of parsing source code functions, building on the previous work that established connections between requirements and source code.

Current capabilities of StrictDoc

  • Users can define requirement relations using RELATION / TYPE: File, providing paths to relevant source files.
  • Users can annotate source files with @sdoc markers, such as @sdoc[REQ-1]. StrictDoc interprets these as Range Markers when a corresponding closing marker exists, or as Line Markers when the @sdoc(...) syntax is used.
  • StrictDoc constructs a traceability graph, linking requirements to source files.
  • The tool can generate an HTML output that allows navigation from a requirement to its associated source file, and vice versa.

Proposed enhancements

Building on the current functionality, StrictDoc could expand its capabilities to include parsing of programming languages to recognize functions and methods. In languages that support functions or methods, each function could be naturally mapped to one or more requirements. Similarly, a single requirement may map to multiple files or functions.

There are several libraries available for parsing popular programming languages. By leveraging such libraries, for example, to parse Python or C Abstract Syntax Trees (ASTs), StrictDoc could identify functions within the source code and parse the @sdoc markers associated with comments attached to these functions, such as the comment above a function in C and a """-comment in Python.

This feature would also contribute to project metrics by providing insights such as:

  • The total number of functions in a project.
  • The number of functions traced or untraced to requirements.
  • The number of requirements that are not traced to any file, function, or range (where a range in a source file is the smallest possible traceability target).
  • More useful metrics should be possible.

Implementation plan

The implementation would begin with support for Python, enabling StrictDoc to test traceability to functions within its own documentation. Subsequent language support would include C/C++ and potentially Rust.

  • [ ] Create another SourceFileReader that uses tree-sitter to parse an AST of a file. Start with tree-sitter-python.
  • [ ] SourceFileReader: Python: Recognize Python syntax, make all existing tests pass.
  • [ ] SourceFileReader: Python: Recognize function-level block comments.
  • [ ] SourceFileReader: C: Recognize C syntax, make all existing tests pass.
  • [ ] SourceFileReader: C: Recognize function-level block comments.
  • [ ] How to visualize functions on the Source Coverage Screen? Should the functions be simply presented as ranges?
  • [ ]

stanislaw avatar Oct 20 '24 18:10 stanislaw