diff --git a/__pycache__/lineanalyzer.cpython-37.pyc b/__pycache__/lineanalyzer.cpython-37.pyc index 20e6747..5607597 100644 Binary files a/__pycache__/lineanalyzer.cpython-37.pyc and b/__pycache__/lineanalyzer.cpython-37.pyc differ diff --git a/lineanalyzer.py b/lineanalyzer.py index 8829136..1e66166 100644 --- a/lineanalyzer.py +++ b/lineanalyzer.py @@ -4,6 +4,8 @@ Contains class LINEANALYSER from contextlib import ContextDecorator from itertools import count +PREPROCESSOR_DIRECTIVES = ['#include','#define','#undef','#if','#ifdef','#ifndef','#error','#endif'] + class ANALYZEOBJECT: _passes = count(0) _analyzed = [] @@ -13,19 +15,94 @@ class ANALYZEOBJECT: self.analyzeline = [] self.analyzed = [] self.comment = False + self.typedef = False + self.members = False def analyze(self,l): - if l.startswith('/*') or l.startswith('/**'): + if self.typedef == True: + rv = self.analyze_typedef(l) + if rv != False: + return rv + if l == '' or l == '\n': + return l + rv = self.analyze_comment(l) + if rv != False: + return rv + rv = self.analyze_preproc(l) + if rv != False: + return rv + rv = self.analyze_typedef(l) + if rv != False: + return rv + return l + + def analyze_comment(self,l): + s = l.split() + w = [w for w in s] + if w[0] == '/*' or w[0] == '/**': self.comment = True - if l.endswith('*/') or l.endswith('**/'): + if w[-1] == '*/' or w[-1] == '**/': self.comment = False return l + if w[0] == '*/' or w[0] == '**/': + self.comment = False + return l if self.comment == True: - if l.startswith('*') or l.startswith('**'): - return l - if l.startswith(' *'): + if w[0] == '*': return l + return False + def analyze_preproc(self,l): + s = l.split() + w = [w for w in s] + if w[0] in PREPROCESSOR_DIRECTIVES: + return l + return False + + def analyze_typedef(self,l): + ts = '' + ts += l + s = l.split() + w = [w for w in s] + if w[0] == 'typedef': + if w[1] == 'struct': + if w[-1].endswith(';'): + self.typedef = False + return ts + else: + self.typedef = True + return 'next' + if w[1] == 'enum': + if w[-1].endswith(';'): + self.typedef = False + return ts + else: + self.typedef = True + return 'next' + return False + + def analyze_struct(self,l): + ts = '' + ts += l + s = l.split() + w = [w for w in s] + if w[0] == 'struct': + if w[-1].endswith(';'): + self.struct = False + return ts + else: + self.struct = True + return 'next' + if self.struct == True: + if w[0] == '{': + if w[-1].endswith(';'): + self.members = False + return ts + else: + self.members = True + return 'next' + return False + class ANALYZER(ANALYZEOBJECT): _ids = count(0) _passes = count(0) diff --git a/parser.py b/parser.py index b4a2ed4..28c58a1 100644 --- a/parser.py +++ b/parser.py @@ -123,6 +123,7 @@ class PARSEOBJECT: templine.append(rr) tempfile.append(templine) count += 1 + templine = [] self.inc_passes() for l in tempfile: analyzed_line = self.token_analyzer(l)