Skip to content

Commit 25650c5

Browse files
author
H_Leusmann
committed
Added #ifdefnot which is a short for
#ifdef #else but also allows: #ifdefnot …. #else … #endif which means #ifdef #else …. #endif #ifdef …. #endif
1 parent 87aea3c commit 25650c5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pypreprocessor/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ def lexer(self, line):
100100
else:
101101
self.__excludeblock = False
102102
return False, True
103+
# handle #ifnotdef directives (is the same as: #ifdef X #else)
104+
elif line[:9] == self.escapeChar + 'ifdefnot':
105+
if len(line.split()) != 2:
106+
self.exit_error(self.escapeChar + 'ifdefnot')
107+
else:
108+
self.__ifblocks.append(not(self.search_defines(line.split()[1])))
109+
self.__ifconditions.append(line.split()[1])
110+
return False, True
103111
# handle #ifdef directives
104112
elif line[:6] == self.escapeChar + 'ifdef':
105113
if len(line.split()) != 2:
@@ -114,7 +122,7 @@ def lexer(self, line):
114122
if len(line.split()) != 2:
115123
self.exit_error(self.escapeChar + 'elseif')
116124
else:
117-
self.__ifblocks[-1]=not(self.search_defines(self.__ifconditions[-1]))
125+
self.__ifblocks[-1]=not(self.__ifblocks[-1])#self.search_defines(self.__ifconditions[-1]))
118126
self.__ifblocks.append(self.search_defines(line.split()[1]))
119127
self.__ifconditions.append(line.split()[1])
120128
return False, True
@@ -123,7 +131,7 @@ def lexer(self, line):
123131
if len(line.split()) != 1:
124132
self.exit_error(self.escapeChar + 'else')
125133
else:
126-
self.__ifblocks[-1]=not(self.search_defines(self.__ifconditions[-1]))
134+
self.__ifblocks[-1]=not(self.__ifblocks[-1])#self.search_defines(self.__ifconditions[-1]))
127135
return False, True
128136
# handle #endif..
129137
# handle #endifall directives

test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
tests += ['#define: failed']
1919
#endif
2020

21+
#ifdefnot testdefine
22+
tests += ['#definenot: failed']
23+
#else
24+
tests += ['#definenot: passed']
25+
#endif
26+
27+
2128
# #not define test
2229
#ifdef testdefine2
2330
tests += ['#not define: failed']

0 commit comments

Comments
 (0)