From b64709f6a40e5ff86ae9da14e7df72c8d4532daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dirk=20Br=C3=B6mmel?= Date: Fri, 6 Oct 2023 15:59:46 +0200 Subject: [PATCH] Add modern Fortran comment style 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 --- AUTHORS.rst | 2 ++ CHANGELOG.md | 1 + src/reuse/comment.py | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 3f40894c..268addf2 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -66,6 +66,8 @@ Contributors - Shun Sakai +- Dirk Brömmel + Translators ----------- diff --git a/CHANGELOG.md b/CHANGELOG.md index 60fc8f64..e142f92f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/reuse/comment.py b/src/reuse/comment.py index 863e3932..dc5ddbf5 100644 --- a/src/reuse/comment.py +++ b/src/reuse/comment.py @@ -14,6 +14,7 @@ # SPDX-FileCopyrightText: 2023 Kevin Meagher # SPDX-FileCopyrightText: 2023 Mathias Dannesbo # SPDX-FileCopyrightText: 2023 Shun Sakai +# SPDX-FileCopyrightText: 2023 Juelich Supercomputing Centre, Forschungszentrum Juelich GmbH # # SPDX-License-Identifier: GPL-3.0-or-later @@ -341,7 +342,7 @@ def comment_at_first_character(cls, text: str) -> str: class FortranCommentStyle(CommentStyle): - """Fortran comment style.""" + """Fortran (fixed form) comment style.""" SHORTHAND = "f" @@ -349,6 +350,15 @@ class FortranCommentStyle(CommentStyle): 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.""" @@ -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,