Developers Guide#
This is a very rough outline of how FORD works internally.
Input arguments are parsed and normalised in
parse_arguments
. The dictionary of metadata created by markdown.extensions.meta is not usually in exactly the form we need, so we make sure all the arguments are the types we’re expecting, and relative paths are converted to absolute paths.We then create a
Project
: a collection of all the entities in a software project. There is a singleProject
for a given software project, but multiple projects can be linked together through the externalize and external options.The project instance iterates over all the source files in src_dir and opens any files with extensions extensions as
FortranSourceFile
, and any with extra_filetypes extensions asGenericSource
. Fortran files with fpp_extensions are preprocessed using preprocessor first.FortranSourceFile
: Represents a single Fortran source file. The raw source is first fed throughFortranReader
before being parsed into an Abstract Syntax Tree (AST) [1] withFortranContainer
.FortranReader
: Custom reader for Fortran files that converts them in a normalised form that makes parsing them easier.FortranContainer
: Represents some kind of Fortran entity that can contain other entities: so, things like programs, modules, procedures, and types. Variables are not represented byFortranContainer
, because they can’t contain other entities.This class also does the bulk of the parsing into the AST in its
__init__
constructor. The result is tree of objects, each with lists of the various entities they contain. For entities defined in the same file, these lists will be the actual objects representing those entities; for those defined in other files, they’ll just be strings for now.At the end of parsing a particular entity, its
_cleanup
method will be called, which will do things like, for example, collating all the public entities in a module.After each file has been parsed, the lists of entities are added to the
Project
’s lists of all the entities in the whole project.Entities defined in other files are now “correlated” with their concrete objects. This is done recursively from
Project.correlate
, first by finding which modules areuse
d by each entity, and then looking up names in the correspondingFortranModule
.After all the files have been parsed, the documentation comments are converted from Markdown to HTML, recursively down from the source files. At this point, metadata in the comments is also parsed. Several markdown extensions,
AliasPreprocessor
,FordLinkProcessor
,RelativeLinksTreeProcessor
, handle aliases, links, and absolute to relative link conversion respectively. TheMetaMarkdown
class just wraps constructing the markdown object.The static pages are processed with
get_page_tree
.Documentation
then processes the Jinja2 templates to create the actual HTML files.Lastly, if requested, the project is dumped to a JSON file using
external
. This is not a full dump of the project, but just the tree of entities and the paths to their respective documentation.
Footnotes