Fortran-FOSS-Programmers / ford

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

Wrong parsing of @end* at end of file #578

Closed mcocdawc closed 10 months ago

mcocdawc commented 10 months ago

If a @end* (@end* referring to @endnote, @endbug, or @endtodo) appears at the end of a markdown file parsed by Ford, then this happens:

Traceback (most recent call last):
  File "/home/mcocdawc/.local/bin/ford", line 8, in <module>
    sys.exit(run())
  File "/home/mcocdawc/code/ford/ford/__init__.py", line 491, in run
    main(proj_data, proj_docs)
  File "/home/mcocdawc/code/ford/ford/__init__.py", line 445, in main
    proj_docs = md.reset().convert(proj_docs)
  File "/home/mcocdawc/code/ford/ford/_markdown.py", line 119, in convert
    return super().convert(source)
  File "/home/mcocdawc/.local/lib/python3.8/site-packages/markdown/core.py", line 261, in convert
    self.lines = prep.run(self.lines)
  File "/home/mcocdawc/code/ford/ford/md_admonition.py", line 149, in run
    return self._process_admonitions(admonitions, lines)
  File "/home/mcocdawc/code/ford/ford/md_admonition.py", line 230, in _process_admonitions
    if lines[idx] != "":
IndexError: list index out of range

It is easily fixed by adding an empty line afterwards.

The same is true for such constructs at the end of a docstring, i.e.

real elemental function add(x, y)
    !! Adds two real numbers `x` and `y`.
    !!
    !! @note
    !!  Because of machine precision floating point numbers, this operation is not always associative.
    !! @endnote
    real, intent(in) :: x, y
    add = x + y
end function

Leads to an error, while

[...]
    !! @note
    !!  Because of machine precision floating point numbers, this operation is not always associative.
    !! @endnote
    !!
[...]

works.

Can be easily reproduced in the example of the repository.

ZedThree commented 10 months ago

Thanks for the bug report @mcocdawc, I've got a fix for it in #579

mcocdawc commented 10 months ago

Thank you for the quick fix.