Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
410 stars 134 forks source link

Python API for determining properties of a Fortran docstring #405

Open gnikit opened 2 years ago

gnikit commented 2 years ago

I was wondering if ford has a Python API that one can use to determine if

I suspect that internally it must have, but I was hoping to use said API to determine during parsing with fortls to what AST node should the docstring be attached. Currently the fortls documentation parsing is a bit flimsy.

ZedThree commented 2 years ago

Not exactly, no. The way it works is to first convert the source into a "normalised" form where any predocmarks are put after the entity, the *_alt forms are converted to non-alt forms, all preceding whitespace is stripped. Then during parsing, we can simply collect all consecutive lines that begin with docmark.

The normalisation is done via https://github.com/Fortran-FOSS-Programmers/ford/blob/e9775f9958969d99960a994ff2628f1e7994ed99/ford/reader.py#L78 which is essentially an iterator over the source file.

This is currently tied to opening a file and iterating over its contents, but I think could be easily modified to iterate over a StringIO so that you could pass in a snippet of text and convert it to the normalised form. Then you would know that all lines beginning with docmark would be annotating the previous line.

Maybe that is sufficient?

You can use ford.parse_arguments({}, "ford_docs.md") to get a dict of Ford options (plus the parsed"ford_docs.md" file, and the markdown object)