Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fortls/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class FortranRegularExpressions:
I,
)
PP_DEF_TEST: Pattern = compile(r"(![ ]*)?defined[ ]*\([ ]*(\w*)[ ]*\)$", I)
PP_INCLUDE: Pattern = compile(r"[ ]*#[ ]*include[ ]*([\"\w\.]*)", I)
PP_INCLUDE: Pattern = compile(r"[ ]*#[ ]*include[ ]*([\"\w\./\\]*)", I)
PP_ANY: Pattern = compile(r"^[ ]*#:?[ ]*(\w+)")
# Context matching rules
CALL: Pattern = compile(r"[ ]*CALL[ ]+[\w%]*$", I)
Expand Down
18 changes: 18 additions & 0 deletions test/test_regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ def test_src_file_exts(
regex = create_src_file_exts_regex(input_exts)
results = [bool(regex.search(file)) for file in input_files]
assert results == matches


def test_issue_481_include_with_slashes():
"""Test that preprocessor includes correctly capture directory slashes."""
# Import the class instead of the standalone variable
from fortls.regex_patterns import FortranRegularExpressions

# The exact string that was failing for the user
test_string = '#include "petsc/finclude/petscvec.h"'

# Call the regex pattern through the class
match = FortranRegularExpressions.PP_INCLUDE.match(test_string)

# Assert that it found a match
assert match is not None

# Assert that the captured group contains the full path with slashes
assert match.group(1) == '"petsc/finclude/petscvec.h"'
Loading