Skip to content

Commit 8466034

Browse files
authored
Merge pull request #302 from albertziegenhagel/fix-form-detect
Ignore preprocessor lines when detecting fixed form fortran
2 parents 71d5f40 + f118412 commit 8466034

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
([#219](https://github.com/fortran-lang/fortls/issues/219))
2727
- Changed hover messages and signature help to use Markdown
2828
([#45](https://github.com/fortran-lang/fortls/issues/45))
29+
- Changed automatic detection of fixed/free-form of files to ignore
30+
preprocessor lines.
31+
([#302](https://github.com/fortran-lang/fortls/pull/302))
2932

3033
### Fixed
3134

fortls/helper_functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,31 @@ def detect_fixed_format(file_lines: list[str]) -> bool:
6868
Lines wih ampersands are not fixed format
6969
>>> detect_fixed_format(['trailing line & ! comment'])
7070
False
71+
72+
But preprocessor lines will be ignored
73+
>>> detect_fixed_format(
74+
... ['#if defined(A) && !defined(B)', 'C Fixed format', '#endif'])
75+
True
76+
77+
>>> detect_fixed_format(
78+
... ['#if defined(A) && !defined(B)', ' free format', '#endif'])
79+
False
80+
81+
And preprocessor line-continuation is taken into account
82+
>>> detect_fixed_format(
83+
... ['#if defined(A) \\\\ ', ' && !defined(B)', 'C Fixed format', '#endif'])
84+
True
85+
86+
>>> detect_fixed_format(
87+
... ['#if defined(A) \\\\', '&& \\\\', '!defined(B)', ' free format', '#endif'])
88+
False
7189
"""
90+
pp_continue = False
7291
for line in file_lines:
92+
# Ignore preprocessor lines
93+
if line.startswith("#") or pp_continue:
94+
pp_continue = line.rstrip().endswith("\\")
95+
continue
7396
if FRegex.FREE_FORMAT_TEST.match(line):
7497
return False
7598
tmp_match = FRegex.VAR.match(line)

0 commit comments

Comments
 (0)