Skip to content

Commit b34363d

Browse files
phil-blaingnikit
authored andcommitted
Do not require parentheses for the 'defined' preprocessor operator
The regex that checks for preprocessor macros using the 'defined' operator assumes that the macro that follows the operator is between parenthesis. However, the syntax for the 'defined' operator does not require parenthesis, at least in GNU Cpp [1] and Intel fpp [2], arguably the two most commonly used Fortran preprocessors. Tweak the regex by allowing the opening and closing parenthesis zero or once. [1] https://gcc.gnu.org/onlinedocs/gcc-10.2.0/cpp/Defined.html#Defined [2] https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/optimization-and-programming-guide/fpp-preprocessing/using-fpp-preprocessor-directives.html
1 parent 085092c commit b34363d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fortls/regex_patterns.py

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)