From 065e0d62985fffd604f6aa7e37311e00d62a104b Mon Sep 17 00:00:00 2001 From: Tilman Dannert Date: Tue, 14 Apr 2026 14:33:37 +0200 Subject: [PATCH] Separate treatment of intrinsic statements and control constructs --- fprettify/__init__.py | 31 +++++++++++++++++++++---------- fprettify/tests/unittests.py | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/fprettify/__init__.py b/fprettify/__init__.py index 5e1544b..7e1ddef 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -1573,21 +1573,22 @@ def format_single_fline( "multdiv": 5, # 5: arithm. operators multiply and divide "print": 6, # 6: print / read statements "type": 7, # 7: select type components - "intrinsics": 8, # 8: intrinsics + "intrinsics": 8, # 8: intrinsics (control-flow keywords: if, do while, case, …) "decl": 9, # 9: declarations "concat": 10, # 10: string concatenation + "intrinsic_stmts": 11, # 11: intrinsic statements (allocate, open, close, …) } if whitespace == 0: - spacey = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + spacey = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] elif whitespace == 1: - spacey = [1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0] + spacey = [1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1] elif whitespace == 2: - spacey = [1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0] + spacey = [1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1] elif whitespace == 3: - spacey = [1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0] + spacey = [1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1] elif whitespace == 4: - spacey = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + spacey = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] else: raise NotImplementedError("unknown value for whitespace") @@ -1711,11 +1712,12 @@ def add_whitespace_charwise(line, spacey, scope_parser, format_decl, filename, l or re.search( SOL_STR + r"(TYPE|CLASS)\s+IS\s*$", line[:pos], RE_FLAGS ) - or re.search( - r"(? spacing) + outstring_no_kw = "if(x) then\n allocate (a(10))\n open (unit=1, file='f')\n close (1)\nendif" + self.assert_fprettify_result( + ["--whitespace-intrinsics", "false"], instring, outstring_no_kw + ) + def test_indent(self): """simple test for indent options -i in [0, 3, 4]"""