From 40b43f90223a90bcc80054ec824e8fc3664ac933 Mon Sep 17 00:00:00 2001 From: tcumby Date: Wed, 7 Mar 2018 14:30:55 -0700 Subject: [PATCH 1/2] Stipped leading whitespace characters in lexer() Stripped any and all whitespace characters from the line in lexer(line) before we try to find preprocessor directives. --- pypreprocessor/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pypreprocessor/__init__.py b/pypreprocessor/__init__.py index b0b2a07..b35c5ef 100644 --- a/pypreprocessor/__init__.py +++ b/pypreprocessor/__init__.py @@ -107,6 +107,8 @@ def lexer(self, line): #this block only for faster processing (not necessary) elif line[:len(self.escape)] != self.escape: return False, False + # strip any and all leading whitespace characters + line = line.lstrip() # handle #define directives if line[:len(self.escape) + 6] == self.escape + 'define': if len(line.split()) != 2: From 958698383844fb8bbe8ba743063f42aa41f651ac Mon Sep 17 00:00:00 2001 From: tcumby Date: Fri, 9 Mar 2018 16:40:44 -0700 Subject: [PATCH 2/2] Improved reliability of lstrip()'d lines Moved the lstrip() call to the start of lexer() to improve reliability. --- pypreprocessor/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pypreprocessor/__init__.py b/pypreprocessor/__init__.py index b35c5ef..8a02639 100644 --- a/pypreprocessor/__init__.py +++ b/pypreprocessor/__init__.py @@ -100,15 +100,15 @@ def __if(self): # evaluate def lexer(self, line): - # return values are (squelch, metadata) + # strip any and all leading whitespace characters + line = line.lstrip() + # return values are (squelch, metadata) if not (self.__ifblocks or self.__excludeblock): if 'pypreprocessor.parse()' in line: return True, True #this block only for faster processing (not necessary) elif line[:len(self.escape)] != self.escape: return False, False - # strip any and all leading whitespace characters - line = line.lstrip() # handle #define directives if line[:len(self.escape) + 6] == self.escape + 'define': if len(line.split()) != 2: