From 7a9e7908aa59575996dad0a41923165b6443b599 Mon Sep 17 00:00:00 2001 From: Patrick Seewald Date: Thu, 1 Sep 2016 22:01:16 +0200 Subject: [PATCH] Support for missing Fortran 03/08 constructs. Fixes #4. --- fprettify.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/fprettify.py b/fprettify.py index 1f328a9..ec5e8c6 100755 --- a/fprettify.py +++ b/fprettify.py @@ -101,7 +101,8 @@ def any(iterable): ENDMOD_RE = re.compile(SOL_STR + r"END\s*MODULE(\s+\w+)?" + EOL_STR, RE_FLAGS) TYPE_RE = re.compile( - SOL_STR + r"TYPE(\s*,\s*BIND\s*\(\s*C\s*\))?(\s*::\s*|\s+)\w+" + EOL_STR, + SOL_STR + + r"TYPE(\s*,\s*(BIND\s*\(\s*C\s*\)|EXTENDS\s*\(.*\)))?(\s*::\s*|\s+)\w+" + EOL_STR, RE_FLAGS) ENDTYPE_RE = re.compile(SOL_STR + r"END\s*TYPE(\s+\w+)?" + EOL_STR, RE_FLAGS) @@ -116,6 +117,11 @@ def any(iterable): CONTAINS_RE = re.compile(SOL_STR + r"CONTAINS" + EOL_STR, RE_FLAGS) +ENUM_RE = re.compile( + SOL_STR + r"ENUM(\s*,\s*(BIND\s*\(\s*C\s*\)))?(\s*::\s*|\s+)\w+" + EOL_STR, + RE_FLAGS) +ENDENUM_RE = re.compile(SOL_STR + r"END\s*ENUM(\s+\w+)?" + EOL_STR, RE_FLAGS) + PUBLIC_RE = re.compile(SOL_STR + r"PUBLIC\s*::", RE_FLAGS) # intrinsic statements with parenthesis notation that are not functions @@ -152,11 +158,11 @@ def any(iterable): # combine regex that define subunits NEW_SCOPE_RE = [IF_RE, DO_RE, SELCASE_RE, SUBR_RE, - FCT_RE, MOD_RE, PROG_RE, INTERFACE_RE, TYPE_RE] + FCT_RE, MOD_RE, PROG_RE, INTERFACE_RE, TYPE_RE, ENUM_RE] CONTINUE_SCOPE_RE = [ELSE_RE, None, CASE_RE, CONTAINS_RE, - CONTAINS_RE, CONTAINS_RE, CONTAINS_RE, None, None] + CONTAINS_RE, CONTAINS_RE, CONTAINS_RE, None, CONTAINS_RE, None] END_SCOPE_RE = [ENDIF_RE, ENDDO_RE, ENDSEL_RE, ENDSUBR_RE, - ENDFCT_RE, ENDMOD_RE, ENDPROG_RE, ENDINTERFACE_RE, ENDTYPE_RE] + ENDFCT_RE, ENDMOD_RE, ENDPROG_RE, ENDINTERFACE_RE, ENDTYPE_RE, ENDENUM_RE] class F90Indenter(object): @@ -252,7 +258,8 @@ def process_lines_of_fline(self, f_line, lines, rel_ind, rel_ind_con, elif is_con: if not valid_con: - logger.debug('%s:%d invalid continue statement', filename, line_nr) + logger.debug('%s:%d invalid continue statement', + filename, line_nr) line_indents = [ind + indents[-2] for ind in line_indents] elif is_end: @@ -326,7 +333,8 @@ def process_lines_of_fline(self, f_line, lines, rel_ind, line_nr): if len(self._br_indent_list) > 2 or self._level: logger = logging.getLogger('prettify-logger') - logger.debug('%s:%d unpaired bracket delimiters', self._filename, self._line_nr) + logger.debug('%s:%d unpaired bracket delimiters', + self._filename, self._line_nr) def get_lines_indent(self): """ @@ -378,7 +386,8 @@ def __align_line_continuations(self, line, is_decl, indent_size, line_nr): level += -1 indent_list.pop() else: - logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr) + logger.debug( + '%s:%d unpaired bracket delimiters', filename, line_nr) if pos_ldelim: pos_ldelim.pop() @@ -391,7 +400,8 @@ def __align_line_continuations(self, line, is_decl, indent_size, line_nr): if what_del_open == r"[": valid = what_del_close == r"]" if not valid: - logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr) + logger.debug( + '%s:%d unpaired bracket delimiters', filename, line_nr) else: pos_rdelim.append(pos) rdelim.append(what_del_close) @@ -571,7 +581,8 @@ def format_single_fline(f_line, whitespace, linebreak_pos, ampersand_sep, if level > 0: level += -1 # close scope else: - logger.debug('%s:%d unpaired bracket delimiters', filename, line_nr) + logger.debug( + '%s:%d unpaired bracket delimiters', filename, line_nr) # add separating whitespace after closing delimiter # with some exceptions: if not re.search(r"^\s*(" + DEL_CLOSE_STR + r"|[,%:/\*])",