Skip to content

Commit 7c4fa75

Browse files
committed
ignoring data statements when whitespacing '/'
1 parent 7499218 commit 7c4fa75

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fprettify/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@
206206

207207
# match namelist names
208208
NML_RE = re.compile(r"(/\w+/)", RE_FLAGS)
209+
# find namelists and data statements
210+
NML_STMT_RE = re.compile(SOL_STR + r"NAMELIST.*/.*/", RE_FLAGS)
211+
DATA_STMT_RE = re.compile(SOL_STR + r"DATA\s+\w", RE_FLAGS)
209212

210213
class F90Indenter(object):
211214
"""
@@ -779,7 +782,7 @@ def add_whitespace_context(line, spacey):
779782
line_parts.append(line[str_end + 1:])
780783

781784
# format namelists with spaces around /
782-
if re.match(r"namelist.*/.*/", line, RE_FLAGS):
785+
if NML_STMT_RE.match(line):
783786
for pos, part in enumerate(line_parts):
784787
# exclude comments, strings:
785788
if not re.match(r"['\"!]", part, RE_FLAGS):
@@ -791,8 +794,8 @@ def add_whitespace_context(line, spacey):
791794
for pos, part in enumerate(line_parts):
792795
# exclude comments, strings:
793796
if not re.search(r"^['\"!]", part, RE_FLAGS):
794-
# also exclude / if we see a namelist
795-
if not re.match(r"namelist.*/.*/", line, RE_FLAGS):
797+
# also exclude / if we see a namelist and data statement
798+
if not ( NML_STMT_RE.match(line) or DATA_STMT_RE.match(line) ):
796799
partsplit = lr_re.split(part)
797800
line_parts[pos] = (' ' * spacey[n_op + 2]).join(partsplit)
798801

0 commit comments

Comments
 (0)