Skip to content

Commit

Permalink
fix(parser): preproc operator mixed with line cont
Browse files Browse the repository at this point in the history
The logical operator `&&` present in the preprocessor
expressions interfered with the line continuation operator
`&` thus resulting into invalid syntax

Fixed #398
  • Loading branch information
gnikit committed May 18, 2024
1 parent a5fc5ed commit ff6d62c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fortls/parsers/internal/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ def get_code_line(
elif next_line != "":
post_lines[-1] = next_line[:iAmper]
next_line = self.get_line(line_ind, pp_content)
if next_line is None:
break

line_ind += 1
# Skip any preprocessor statements when seeking the next line
if FRegex.PP_ANY.match(next_line):
Expand Down
9 changes: 9 additions & 0 deletions test/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,12 @@ def test_end_scopes_semicolon():
ast = file.parse()
assert err_str is None
assert not ast.end_errors


def test_weird_parser_bug():
file_path = test_dir / "parse" / "mixed" / "preproc_and_normal_syntax.F90"
file = FortranFile(str(file_path))
err_str, _ = file.load_from_disk()
ast = file.parse()
assert err_str is None
assert not ast.end_errors
1 change: 1 addition & 0 deletions test/test_source/.fortls
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"docs",
"rename",
"parse",
"parse/mixed/**",
"vis"
]

Expand Down
5 changes: 5 additions & 0 deletions test/test_source/parse/.fortls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"excl_paths": [
"mixed"
]
}
5 changes: 5 additions & 0 deletions test/test_source/parse/mixed/preproc_and_normal_syntax.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

USE base_hooks
#if VAR < 8 || VAR == 8 && VAR2 < 3
#define OMP_DEFAULT_NONE_WITH_OOP NONE
#endif

0 comments on commit ff6d62c

Please sign in to comment.