From b30b3688208fd226862cd53d3dcb2bc6afdd6d71 Mon Sep 17 00:00:00 2001 From: Lerking Date: Sun, 10 Feb 2019 01:16:00 +0100 Subject: [PATCH] Updated lineanalyzer.py --- __pycache__/lineanalyzer.cpython-37.pyc | Bin 1323 -> 2236 bytes lineanalyzer.py | 87 ++++++++++++++++++++++-- parser.py | 1 + 3 files changed, 83 insertions(+), 5 deletions(-) diff --git a/__pycache__/lineanalyzer.cpython-37.pyc b/__pycache__/lineanalyzer.cpython-37.pyc index 20e6747086f1c58ee21cd789fb3bc65a8c3be3b7..5607597d2490c3e6f3e57a066a04a4eeb3a5d59b 100644 GIT binary patch literal 2236 zcmbVOTW=dh6rPz~uQ$FV4y1(wfr1gjmKswY5JFLuHgQl;L(%C)TsMIO#C5DiWs%js(VUB z3JYE+{h>=w%$fkRi5`Co;;}x5&B8MzKjVG#ko5~vNaF?TTVyZBBH4`5Cc81hc34%; zs@j5nd;j4N?X5?O<2IKFH5%!iE%f*^5XmRZVTTNqYbvAwZ)j>th8vBJzGJ6R$gD9? z^5U#K2nWIQ)C*v7X6F-`72Rkw^1=ivYA^tl8GFI-FQ&-NZ|=38L?f?tGzeRAkPKP} zDmwDqByK(V8aTG-w)`%&Hh!Mjj^l@Z;y6{(RtE~V@?U!Ul9g+-tu9$d&B(j9bQ_Zi zm;6}7HH_j|sFext!RnWgzv8E20&I^B)tm?|<(H(JT8jM*vy-ummv$N=Tgp{+a-+`$ zW95xi8Vi0`K3&Q?oY>6b%y~ z7HeN+{I@H}y(z5+ew+aH@y4fg4c%$6^!~MA&AhX=9z^aSh&RB@PV2BvMXQ+_t!DGl z>wnNv(QKtgv)S6ocoQlV;&I?7ifU2A)c#b<;4>bpTNtnCrj{W41U>!;gu$1K{Cz|$ zbu*_WUICx3-l*>NK5pX9n|z$`V@rKOfh_@Lqwqg*R}_=ins*xu_tF0Y^E?6GiaF9p z-N7~4dk5Y2L3e+v-Rtdlo$cK&3fAu9cJCt8>VvmwL-ErhZKkDxz`hCET&qr_M3p5R zj6BE5N{%y%ZcTv2*b z0f^~B$Ka09Brtp&xjP!dn$U8hn}$+TwGw z$=dJGW6Bu@k5I`@muK3}D>YtIlqG7F$j3woa#bgyAJIUc-+ulCrTsVPG5#`WWNo2H z)@j)Am?I;XJnK$B+kyX!B7Cz2Kk-x&ML|4$=tBs#EA-jxT$tJG)8N=3&2*TVFsLF{ I#Nxew0YpaFa{vGU delta 560 zcmXw0u}&L75Z&3myIo%l$i&8p10qq7%qe~LnTf_>0x}P`iV0=kyS2Ex4+X8t%oLM5ga<~k)`D@ zrR8}6t-792a5sy>Z)Dxmhx8FQFaQy@dT%M$<>Gt#rKi>LZ%HWDuDo9NpNmu8{L MEhDN@Rn9N{1828r9RL6T 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)