Skip to content

Commit

Permalink
Add modern Fortran comment style
Browse files Browse the repository at this point in the history
The current comment style for Fortran seems to target fixed form source code, where any character in col.1 would start a comment. The character usually is "c" or ''C".
Free form source code, on the other hand, requires an "!" to start comments. Adding comments with a leading "c" is not supported if I'm not mistaken, sources would no longer compile, `reuse` would thus break the code.

This PR adds an additional comment style for modern free form Fortran and adjusts the selection to commonly used file extensions. While the easiest fix would have been to replace
```python
    SINGLE_LINE = "c"
```
with
```python
    SINGLE_LINE = "!"
```
I think it is more customary to have 'c' with fixed form source code, hence the additional style block.

Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
  • Loading branch information
dbroemmel authored and carmenbianca committed Oct 24, 2023
1 parent 8a94f52 commit b64709f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Contributors

- Shun Sakai

- Dirk Brömmel

Translators
-----------

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CLI command and its behaviour. There are no guarantees of stability for the

- More file types are recognised:
- Julia (`.jl`) (#815)
- Modern Fortran (`.f90`) (#836)

### Changed

Expand Down
21 changes: 17 additions & 4 deletions src/reuse/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# SPDX-FileCopyrightText: 2023 Kevin Meagher
# SPDX-FileCopyrightText: 2023 Mathias Dannesbo <md@magenta.dk>
# SPDX-FileCopyrightText: 2023 Shun Sakai <sorairolake@protonmail.ch>
# SPDX-FileCopyrightText: 2023 Juelich Supercomputing Centre, Forschungszentrum Juelich GmbH
#
# SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -341,14 +342,23 @@ def comment_at_first_character(cls, text: str) -> str:


class FortranCommentStyle(CommentStyle):
"""Fortran comment style."""
"""Fortran (fixed form) comment style."""

SHORTHAND = "f"

SINGLE_LINE = "c"
INDENT_AFTER_SINGLE = " "


class ModernFortranCommentStyle(CommentStyle):
"""Fortran (free form) comment style."""

SHORTHAND = "f90"

SINGLE_LINE = "!"
INDENT_AFTER_SINGLE = " "


class FtlCommentStyle(CommentStyle):
"""FreeMarker Template Language comment style."""

Expand Down Expand Up @@ -562,15 +572,18 @@ class XQueryCommentStyle(CommentStyle):
".ex": PythonCommentStyle,
".exs": PythonCommentStyle,
".f": FortranCommentStyle,
".f03": FortranCommentStyle,
".f90": FortranCommentStyle,
".f95": FortranCommentStyle,
".f03": ModernFortranCommentStyle,
".f08": ModernFortranCommentStyle,
".f90": ModernFortranCommentStyle,
".f95": ModernFortranCommentStyle,
".fish": PythonCommentStyle,
".fnl": LispCommentStyle,
".fodp": UncommentableCommentStyle,
".fods": UncommentableCommentStyle,
".fodt": UncommentableCommentStyle,
".for": FortranCommentStyle,
".ftn": FortranCommentStyle,
".fpp": FortranCommentStyle,
".fs": CCommentStyle,
".ftl": FtlCommentStyle,
".gemspec": PythonCommentStyle,
Expand Down

0 comments on commit b64709f

Please sign in to comment.