From 359e5a29c7c2a676e3343faea4673423d12d082e Mon Sep 17 00:00:00 2001 From: dbroemmel Date: Mon, 3 Jul 2023 16:13:40 +0200 Subject: [PATCH 1/2] allow named select case --- fortran_tests/after/example.f90 | 6 +++--- fortran_tests/before/example.f90 | 6 +++--- fortran_tests/test_results/expected_results | 2 +- fprettify/__init__.py | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fortran_tests/after/example.f90 b/fortran_tests/after/example.f90 index ed6c30b..05c4513 100644 --- a/fortran_tests/after/example.f90 +++ b/fortran_tests/after/example.f90 @@ -194,8 +194,8 @@ program example_prog ! example 4.1 l = 0 do r = 1, 10 - select case (r) - case (1) + case_label: select case(r) + case (1) case_label do i = 1, 100; if (i <= 2) then! comment do j = 1, 5 do k = 1, 3 @@ -211,7 +211,7 @@ program example_prog end do case (2) l = i + j + k - end select + end select case_label end do ! example 4.2 diff --git a/fortran_tests/before/example.f90 b/fortran_tests/before/example.f90 index d6b3ecb..aee6eb3 100644 --- a/fortran_tests/before/example.f90 +++ b/fortran_tests/before/example.f90 @@ -195,8 +195,8 @@ program example_prog ! example 4.1 l = 0 do r = 1, 10 - select case ( r ) - case( 1) + case_label : select case ( r ) + case( 1) case_label do i=1,100;if (i<=2) then! comment do j = 1,5 do k= 1, 3 @@ -212,7 +212,7 @@ program example_prog enddo case(2 ) l = i+ j + k - end select + end select case_label enddo ! example 4.2 diff --git a/fortran_tests/test_results/expected_results b/fortran_tests/test_results/expected_results index e109307..e74dbd4 100644 --- a/fortran_tests/test_results/expected_results +++ b/fortran_tests/test_results/expected_results @@ -1,4 +1,4 @@ -example.f90 : f5b449553856f8e62b253402ed2189044554f53c9954aad045db44ff3c2d49b7 +example.f90 : 1df5c1b38944d87eb73c561a9e13e4ea644ed5027c74367e3edbbf3903509dc4 RosettaCodeData/Task/100-doors/Fortran/100-doors-1.f : b44289edb55a75ca29407be3ca0d997119253d4c7adb5b3dfc1119944036ab0f RosettaCodeData/Task/100-doors/Fortran/100-doors-2.f : 263122b2af3e3637a7dab0bc0216dec27d76068b7352e9ab85e420de625408be RosettaCodeData/Task/24-game-Solve/Fortran/24-game-solve-1.f : 8927cfcfe15685f1513ed923b7ac38058358ec6586de83920679b537aa5b2d03 diff --git a/fprettify/__init__.py b/fprettify/__init__.py index d6450a3..f03232a 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -112,10 +112,10 @@ ENDDO_RE = re.compile(SOL_STR + r"END\s*DO(\s+\w+)?" + EOL_STR, RE_FLAGS) SELCASE_RE = re.compile( - SOL_STR + r"SELECT\s*(CASE|RANK|TYPE)\s*\(.*\)" + EOL_STR, RE_FLAGS) + SOL_STR + r"(\w+\s*:)?\s*SELECT\s*(CASE|RANK|TYPE)\s*\(.*\)" + EOL_STR, RE_FLAGS) CASE_RE = re.compile( - SOL_STR + r"((CASE|RANK|TYPE\s+IS|CLASS\s+IS)\s*(\(.*\)|DEFAULT)|CLASS\s+DEFAULT)" + EOL_STR, RE_FLAGS) -ENDSEL_RE = re.compile(SOL_STR + r"END\s*SELECT" + EOL_STR, RE_FLAGS) + SOL_STR + r"((CASE|RANK|TYPE\s+IS|CLASS\s+IS)\s*(\(.*\)|DEFAULT)|CLASS\s+DEFAULT)(\s+\w+)?" + EOL_STR, RE_FLAGS) +ENDSEL_RE = re.compile(SOL_STR + r"END\s*SELECT(\s+\w+)?" + EOL_STR, RE_FLAGS) ASSOCIATE_RE = re.compile(SOL_STR + r"ASSOCIATE\s*\(.*\)" + EOL_STR, RE_FLAGS) ENDASSOCIATE_RE = re.compile(SOL_STR + r"END\s*ASSOCIATE" + EOL_STR, RE_FLAGS) @@ -1308,7 +1308,7 @@ def add_whitespace_context(line, spacey): line = ''.join(line_parts) - for newre in [IF_RE, DO_RE, BLK_RE]: + for newre in [IF_RE, DO_RE, BLK_RE, SELCASE_RE]: if newre.search(line) and re.search(SOL_STR + r"\w+\s*:", line): line = ': '.join(_.strip() for _ in line.split(':', 1)) From b0ec7649cd57f80d7ce94c709294bf88da86f068 Mon Sep 17 00:00:00 2001 From: dbroemmel Date: Mon, 3 Jul 2023 16:38:21 +0200 Subject: [PATCH 2/2] fixing named case --- fortran_tests/after/example.f90 | 2 +- fortran_tests/test_results/expected_results | 2 +- fprettify/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fortran_tests/after/example.f90 b/fortran_tests/after/example.f90 index 05c4513..9b3ea4c 100644 --- a/fortran_tests/after/example.f90 +++ b/fortran_tests/after/example.f90 @@ -194,7 +194,7 @@ program example_prog ! example 4.1 l = 0 do r = 1, 10 - case_label: select case(r) + case_label: select case (r) case (1) case_label do i = 1, 100; if (i <= 2) then! comment do j = 1, 5 diff --git a/fortran_tests/test_results/expected_results b/fortran_tests/test_results/expected_results index e74dbd4..504bbf8 100644 --- a/fortran_tests/test_results/expected_results +++ b/fortran_tests/test_results/expected_results @@ -1,4 +1,4 @@ -example.f90 : 1df5c1b38944d87eb73c561a9e13e4ea644ed5027c74367e3edbbf3903509dc4 +example.f90 : e2554d901dea8f89bab644c02750ab2120e358680fb81b07188010a5d1f47fbd RosettaCodeData/Task/100-doors/Fortran/100-doors-1.f : b44289edb55a75ca29407be3ca0d997119253d4c7adb5b3dfc1119944036ab0f RosettaCodeData/Task/100-doors/Fortran/100-doors-2.f : 263122b2af3e3637a7dab0bc0216dec27d76068b7352e9ab85e420de625408be RosettaCodeData/Task/24-game-Solve/Fortran/24-game-solve-1.f : 8927cfcfe15685f1513ed923b7ac38058358ec6586de83920679b537aa5b2d03 diff --git a/fprettify/__init__.py b/fprettify/__init__.py index f03232a..1697298 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -1154,7 +1154,7 @@ def add_whitespace_charwise(line, spacey, scope_parser, format_decl, filename, l line[:pos], RE_FLAGS) or re.search(SOL_STR + r"(\w+\s*:)?\s*DO\s+WHILE\s*$", line[:pos], RE_FLAGS) or - re.search(SOL_STR + r"(SELECT)?\s*CASE\s*$", + re.search(SOL_STR + r"(\w+\s*:)?\s*(SELECT)?\s*CASE\s*$", line[:pos], RE_FLAGS) or re.search(SOL_STR + r"(SELECT)?\s*RANK\s*$", line[:pos], RE_FLAGS) or