Skip to content

Commit 65bfb20

Browse files
authored
Merge pull request #67 from phil-blain/pp-defined-without-parens
Do not require parentheses for the `defined` preprocessor operator
2 parents 085092c + fe9d389 commit 65bfb20

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
- Updated `setup.cfg` in preparation of submitting package to `conda-forge`
88
- Added `Editor Integration` section in documentation
99

10+
### Fixed
11+
12+
- Fixed parsing of `defined` without by parenthesis surrounding the definition
13+
([#67](https://github.com/gnikit/fortls/pull/67))
14+
1015
## 2.2.4
1116

1217
### Fixed

fortls/regex_patterns.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class FortranRegularExpressions:
110110
FREE_OPENMP: Pattern = compile(r"[ ]*!\$OMP", I)
111111
FREE_FORMAT_TEST: Pattern = compile(r"[ ]{1,4}[a-z]", I)
112112
# Preprocessor matching rules
113-
DEFINED: Pattern = compile(r"defined[ ]*\([ ]*([a-z_][a-z0-9_]*)[ ]*\)", I)
113+
DEFINED: Pattern = compile(r"defined[ ]*\(?[ ]*([a-z_][a-z0-9_]*)[ ]*\)?", I)
114114
PP_REGEX: Pattern = compile(r"#(if |ifdef|ifndef|else|elif|endif)")
115115
PP_DEF: Pattern = compile(r"#(define|undef)[ ]*([\w]+)(\((\w+(,[ ]*)?)+\))?", I)
116116
PP_DEF_TEST: Pattern = compile(r"(![ ]*)?defined[ ]*\([ ]*([a-z0-9_]*)[ ]*\)$", I)

test/test_preproc.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def check_return(result_array, checks):
2727
string += hover_req(file_path, 7, 40) # multi-lin variable
2828
string += hover_req(file_path, 8, 7) # function with if conditional
2929
string += hover_req(file_path, 9, 7) # multiline function with if conditional
30+
string += hover_req(file_path, 10, 15) # defined without ()
3031
file_path = root_dir / "preproc_keywords.F90"
3132
string += hover_req(file_path, 6, 2) # ignores PP across Fortran line continuations
3233
config = str(root_dir / ".pp_conf.json")
@@ -40,6 +41,7 @@ def check_return(result_array, checks):
4041
"#define varVar 55",
4142
"#define ewrite if (priority <= 3) write((priority), format)",
4243
"#define ewrite2 if (priority <= 3) write((priority), format)",
44+
"#define SUCCESS .true.",
4345
"REAL, CONTIGUOUS, POINTER, DIMENSION(:)",
4446
)
4547
assert len(ref_results) == len(results) - 1

test/test_source/pp/include/petscerror.h

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
#define PETSC_ERR_MEM 55
55
#define PETSC_ERR_INT_OVERFLOW 84
66
#define PETSC_ERR_FLOP_COUNT 90
7+
8+
#if defined PETSC_ERR_MEM || defined PETSC_ERR_INT_OVERFLOW
9+
#define SUCCESS .true.
10+
#endif
11+
712
#endif

test/test_source/pp/preproc.F90

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ program preprocessor
88
print*, PETSC_ERR_INT_OVERFLOW, varVar
99
ewrite(1,*) 'Assemble EP P1 matrix and rhs sytem'
1010
ewrite2(1,*) 'Assemble EP P1 matrix and rhs sytem'
11+
print*, SUCCESS
1112

1213
#endif
1314
end program preprocessor

0 commit comments

Comments
 (0)