diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c1904f9..5bf57f07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ - Updated `setup.cfg` in preparation of submitting package to `conda-forge` - Added `Editor Integration` section in documentation +### Fixed + +- Fixed parsing of `defined` without by parenthesis surrounding the definition + ([#67](https://github.com/gnikit/fortls/pull/67)) + ## 2.2.4 ### Fixed diff --git a/fortls/regex_patterns.py b/fortls/regex_patterns.py index 31de5e12..ea28afee 100644 --- a/fortls/regex_patterns.py +++ b/fortls/regex_patterns.py @@ -110,7 +110,7 @@ class FortranRegularExpressions: FREE_OPENMP: Pattern = compile(r"[ ]*!\$OMP", I) FREE_FORMAT_TEST: Pattern = compile(r"[ ]{1,4}[a-z]", I) # Preprocessor matching rules - DEFINED: Pattern = compile(r"defined[ ]*\([ ]*([a-z_][a-z0-9_]*)[ ]*\)", I) + DEFINED: Pattern = compile(r"defined[ ]*\(?[ ]*([a-z_][a-z0-9_]*)[ ]*\)?", I) PP_REGEX: Pattern = compile(r"#(if |ifdef|ifndef|else|elif|endif)") PP_DEF: Pattern = compile(r"#(define|undef)[ ]*([\w]+)(\((\w+(,[ ]*)?)+\))?", I) PP_DEF_TEST: Pattern = compile(r"(![ ]*)?defined[ ]*\([ ]*([a-z0-9_]*)[ ]*\)$", I) diff --git a/test/test_preproc.py b/test/test_preproc.py index f1472b4b..35dce5af 100644 --- a/test/test_preproc.py +++ b/test/test_preproc.py @@ -27,6 +27,7 @@ def check_return(result_array, checks): string += hover_req(file_path, 7, 40) # multi-lin variable string += hover_req(file_path, 8, 7) # function with if conditional string += hover_req(file_path, 9, 7) # multiline function with if conditional + string += hover_req(file_path, 10, 15) # defined without () file_path = root_dir / "preproc_keywords.F90" string += hover_req(file_path, 6, 2) # ignores PP across Fortran line continuations config = str(root_dir / ".pp_conf.json") @@ -40,6 +41,7 @@ def check_return(result_array, checks): "#define varVar 55", "#define ewrite if (priority <= 3) write((priority), format)", "#define ewrite2 if (priority <= 3) write((priority), format)", + "#define SUCCESS .true.", "REAL, CONTIGUOUS, POINTER, DIMENSION(:)", ) assert len(ref_results) == len(results) - 1 diff --git a/test/test_source/pp/include/petscerror.h b/test/test_source/pp/include/petscerror.h index b1b500dd..bce29a4f 100644 --- a/test/test_source/pp/include/petscerror.h +++ b/test/test_source/pp/include/petscerror.h @@ -4,4 +4,9 @@ #define PETSC_ERR_MEM 55 #define PETSC_ERR_INT_OVERFLOW 84 #define PETSC_ERR_FLOP_COUNT 90 + +#if defined PETSC_ERR_MEM || defined PETSC_ERR_INT_OVERFLOW +#define SUCCESS .true. +#endif + #endif diff --git a/test/test_source/pp/preproc.F90 b/test/test_source/pp/preproc.F90 index 8da59d9c..5ed849c1 100644 --- a/test/test_source/pp/preproc.F90 +++ b/test/test_source/pp/preproc.F90 @@ -8,6 +8,7 @@ program preprocessor print*, PETSC_ERR_INT_OVERFLOW, varVar ewrite(1,*) 'Assemble EP P1 matrix and rhs sytem' ewrite2(1,*) 'Assemble EP P1 matrix and rhs sytem' + print*, SUCCESS #endif end program preprocessor \ No newline at end of file