From 375de571caba5a9776ade5b1ca72c16abba3ceec Mon Sep 17 00:00:00 2001 From: dhruvch12 Date: Sun, 29 Mar 2026 15:07:33 +0530 Subject: [PATCH 1/2] Fix: Support directory slashes in preprocessor include regex (#481) --- fortls/regex_patterns.py | 2 +- test/test_regex_patterns.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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..4ca72756 100644 --- a/test/test_regex_patterns.py +++ b/test/test_regex_patterns.py @@ -44,3 +44,22 @@ 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"' \ No newline at end of file From 32da697ccfd61b00e7a23d77b01594e57cb57836 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 29 Mar 2026 09:44:18 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- test/test_regex_patterns.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/test_regex_patterns.py b/test/test_regex_patterns.py index 4ca72756..470fa124 100644 --- a/test/test_regex_patterns.py +++ b/test/test_regex_patterns.py @@ -46,20 +46,19 @@ def test_src_file_exts( 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"' \ No newline at end of file + assert match.group(1) == '"petsc/finclude/petscvec.h"'