Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow named select case #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions fortran_tests/after/example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions fortran_tests/before/example.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -212,7 +212,7 @@ program example_prog
enddo
case(2 )
l = i+ j + k
end select
end select case_label
enddo

! example 4.2
Expand Down
2 changes: 1 addition & 1 deletion fortran_tests/test_results/expected_results
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
example.f90 : f5b449553856f8e62b253402ed2189044554f53c9954aad045db44ff3c2d49b7
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
Expand Down
10 changes: 5 additions & 5 deletions fprettify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down