diff --git a/fortls/regex_patterns.py b/fortls/regex_patterns.py index 55536976..da808111 100644 --- a/fortls/regex_patterns.py +++ b/fortls/regex_patterns.py @@ -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) diff --git a/test/test_regex_patterns.py b/test/test_regex_patterns.py index f0095660..470fa124 100644 --- a/test/test_regex_patterns.py +++ b/test/test_regex_patterns.py @@ -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"'