Skip to content

Commit 7a9e790

Browse files
committed
Support for missing Fortran 03/08 constructs.
Fixes #4.
1 parent b6c2916 commit 7a9e790

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

fprettify.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def any(iterable):
101101
ENDMOD_RE = re.compile(SOL_STR + r"END\s*MODULE(\s+\w+)?" + EOL_STR, RE_FLAGS)
102102

103103
TYPE_RE = re.compile(
104-
SOL_STR + r"TYPE(\s*,\s*BIND\s*\(\s*C\s*\))?(\s*::\s*|\s+)\w+" + EOL_STR,
104+
SOL_STR +
105+
r"TYPE(\s*,\s*(BIND\s*\(\s*C\s*\)|EXTENDS\s*\(.*\)))?(\s*::\s*|\s+)\w+" + EOL_STR,
105106
RE_FLAGS)
106107
ENDTYPE_RE = re.compile(SOL_STR + r"END\s*TYPE(\s+\w+)?" + EOL_STR, RE_FLAGS)
107108

@@ -116,6 +117,11 @@ def any(iterable):
116117

117118
CONTAINS_RE = re.compile(SOL_STR + r"CONTAINS" + EOL_STR, RE_FLAGS)
118119

120+
ENUM_RE = re.compile(
121+
SOL_STR + r"ENUM(\s*,\s*(BIND\s*\(\s*C\s*\)))?(\s*::\s*|\s+)\w+" + EOL_STR,
122+
RE_FLAGS)
123+
ENDENUM_RE = re.compile(SOL_STR + r"END\s*ENUM(\s+\w+)?" + EOL_STR, RE_FLAGS)
124+
119125
PUBLIC_RE = re.compile(SOL_STR + r"PUBLIC\s*::", RE_FLAGS)
120126

121127
# intrinsic statements with parenthesis notation that are not functions
@@ -152,11 +158,11 @@ def any(iterable):
152158

153159
# combine regex that define subunits
154160
NEW_SCOPE_RE = [IF_RE, DO_RE, SELCASE_RE, SUBR_RE,
155-
FCT_RE, MOD_RE, PROG_RE, INTERFACE_RE, TYPE_RE]
161+
FCT_RE, MOD_RE, PROG_RE, INTERFACE_RE, TYPE_RE, ENUM_RE]
156162
CONTINUE_SCOPE_RE = [ELSE_RE, None, CASE_RE, CONTAINS_RE,
157-
CONTAINS_RE, CONTAINS_RE, CONTAINS_RE, None, None]
163+
CONTAINS_RE, CONTAINS_RE, CONTAINS_RE, None, CONTAINS_RE, None]
158164
END_SCOPE_RE = [ENDIF_RE, ENDDO_RE, ENDSEL_RE, ENDSUBR_RE,
159-
ENDFCT_RE, ENDMOD_RE, ENDPROG_RE, ENDINTERFACE_RE, ENDTYPE_RE]
165+
ENDFCT_RE, ENDMOD_RE, ENDPROG_RE, ENDINTERFACE_RE, ENDTYPE_RE, ENDENUM_RE]
160166

161167

162168
class F90Indenter(object):
@@ -252,7 +258,8 @@ def process_lines_of_fline(self, f_line, lines, rel_ind, rel_ind_con,
252258

253259
elif is_con:
254260
if not valid_con:
255-
logger.debug('%s:%d invalid continue statement', filename, line_nr)
261+
logger.debug('%s:%d invalid continue statement',
262+
filename, line_nr)
256263
line_indents = [ind + indents[-2] for ind in line_indents]
257264

258265
elif is_end:
@@ -326,7 +333,8 @@ def process_lines_of_fline(self, f_line, lines, rel_ind, line_nr):
326333

327334
if len(self._br_indent_list) > 2 or self._level:
328335
logger = logging.getLogger('prettify-logger')
329-
logger.debug('%s:%d unpaired bracket delimiters', self._filename, self._line_nr)
336+
logger.debug('%s:%d unpaired bracket delimiters',
337+
self._filename, self._line_nr)
330338

331339
def get_lines_indent(self):
332340
"""
@@ -378,7 +386,8 @@ def __align_line_continuations(self, line, is_decl, indent_size, line_nr):
378386
level += -1
379387
indent_list.pop()
380388
else:
381-
logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr)
389+
logger.debug(
390+
'%s:%d unpaired bracket delimiters', filename, line_nr)
382391

383392
if pos_ldelim:
384393
pos_ldelim.pop()
@@ -391,7 +400,8 @@ def __align_line_continuations(self, line, is_decl, indent_size, line_nr):
391400
if what_del_open == r"[":
392401
valid = what_del_close == r"]"
393402
if not valid:
394-
logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr)
403+
logger.debug(
404+
'%s:%d unpaired bracket delimiters', filename, line_nr)
395405
else:
396406
pos_rdelim.append(pos)
397407
rdelim.append(what_del_close)
@@ -571,7 +581,8 @@ def format_single_fline(f_line, whitespace, linebreak_pos, ampersand_sep,
571581
if level > 0:
572582
level += -1 # close scope
573583
else:
574-
logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr)
584+
logger.debug(
585+
'%s:%d unpaired bracket delimiters', filename, line_nr)
575586
# add separating whitespace after closing delimiter
576587
# with some exceptions:
577588
if not re.search(r"^\s*(" + DEL_CLOSE_STR + r"|[,%:/\*])",

0 commit comments

Comments
 (0)