Skip to content

Commit ff6d62c

Browse files
committed
fix(parser): preproc operator mixed with line cont
The logical operator `&&` present in the preprocessor expressions interfered with the line continuation operator `&` thus resulting into invalid syntax Fixed #398
1 parent a5fc5ed commit ff6d62c

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

fortls/parsers/internal/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,9 @@ def get_code_line(
11041104
elif next_line != "":
11051105
post_lines[-1] = next_line[:iAmper]
11061106
next_line = self.get_line(line_ind, pp_content)
1107+
if next_line is None:
1108+
break
1109+
11071110
line_ind += 1
11081111
# Skip any preprocessor statements when seeking the next line
11091112
if FRegex.PP_ANY.match(next_line):

test/test_parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ def test_end_scopes_semicolon():
4848
ast = file.parse()
4949
assert err_str is None
5050
assert not ast.end_errors
51+
52+
53+
def test_weird_parser_bug():
54+
file_path = test_dir / "parse" / "mixed" / "preproc_and_normal_syntax.F90"
55+
file = FortranFile(str(file_path))
56+
err_str, _ = file.load_from_disk()
57+
ast = file.parse()
58+
assert err_str is None
59+
assert not ast.end_errors

test/test_source/.fortls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"docs",
1111
"rename",
1212
"parse",
13+
"parse/mixed/**",
1314
"vis"
1415
]
1516

test/test_source/parse/.fortls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"excl_paths": [
3+
"mixed"
4+
]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
USE base_hooks
3+
#if VAR < 8 || VAR == 8 && VAR2 < 3
4+
#define OMP_DEFAULT_NONE_WITH_OOP NONE
5+
#endif

0 commit comments

Comments
 (0)