Skip to content

Commit

Permalink
Merge pull request #67 from phil-blain/pp-defined-without-parens
Browse files Browse the repository at this point in the history
Do not require parentheses for the `defined` preprocessor operator
  • Loading branch information
gnikit authored Mar 6, 2022
2 parents 085092c + fe9d389 commit 65bfb20
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fortls/regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/test_preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/test_source/pp/include/petscerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/test_source/pp/preproc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 65bfb20

Please sign in to comment.