misra.py: Rewrote rule texts parser
This commit is contained in:
parent
ccc830870c
commit
146326bfaf
|
@ -2051,36 +2051,49 @@ class MisraChecker:
|
||||||
file_stream = open(filename, 'rt')
|
file_stream = open(filename, 'rt')
|
||||||
# Parse the rule texts
|
# Parse the rule texts
|
||||||
rule = None
|
rule = None
|
||||||
|
state = 0 # 0=Expect "Rule X.Y", 1=Expect "Advisory|Required|Mandatory", 2=Expect "Text..", 3=Expect "..more text"
|
||||||
for line in file_stream:
|
for line in file_stream:
|
||||||
line = line.replace('\r', '').replace('\n', '')
|
line = line.replace('\r', '').replace('\n', '')
|
||||||
if len(line) == 0:
|
|
||||||
if rule:
|
|
||||||
num1 = 0
|
|
||||||
num2 = 0
|
|
||||||
rule = None
|
|
||||||
continue
|
|
||||||
if not appendixA:
|
if not appendixA:
|
||||||
if line.find('Appendix A') >= 0 and line.find('Summary of guidelines') >= 10:
|
if line.find('Appendix A') >= 0 and line.find('Summary of guidelines') >= 10:
|
||||||
appendixA = True
|
appendixA = True
|
||||||
continue
|
continue
|
||||||
if line.find('Appendix B') >= 0:
|
if line.find('Appendix B') >= 0:
|
||||||
break
|
break
|
||||||
|
if len(line) == 0:
|
||||||
|
if state >= 3:
|
||||||
|
state = 0
|
||||||
|
continue
|
||||||
res = Rule_pattern.match(line)
|
res = Rule_pattern.match(line)
|
||||||
if res:
|
if res:
|
||||||
num1 = int(res.group(1))
|
num1 = int(res.group(1))
|
||||||
num2 = int(res.group(2))
|
num2 = int(res.group(2))
|
||||||
rule = Rule(num1, num2)
|
rule = Rule(num1, num2)
|
||||||
|
state = 1
|
||||||
continue
|
continue
|
||||||
if Choice_pattern.match(line):
|
if rule is None:
|
||||||
if rule:
|
continue
|
||||||
|
if state == 1: # Expect "Advisory|Required|Mandatory"
|
||||||
|
if Choice_pattern.match(line):
|
||||||
rule.severity = line
|
rule.severity = line
|
||||||
elif xA_Z_pattern.match(line):
|
state = 2
|
||||||
if rule:
|
else:
|
||||||
|
rule = None
|
||||||
|
state = 0
|
||||||
|
elif state == 2: # Expect "Text.."
|
||||||
|
if xA_Z_pattern.match(line):
|
||||||
|
state = 3
|
||||||
rule.text = line
|
rule.text = line
|
||||||
self.ruleTexts[rule.num] = rule
|
self.ruleTexts[rule.num] = rule
|
||||||
elif rule and a_z_pattern.match(line):
|
else:
|
||||||
self.ruleTexts[rule.num].text = self.ruleTexts[rule.num].text + ' ' + line
|
rule = None
|
||||||
continue
|
state = 0
|
||||||
|
elif state == 3: # Expect ".. more text"
|
||||||
|
if a_z_pattern.match(line):
|
||||||
|
self.ruleTexts[rule.num].text += ' ' + line
|
||||||
|
else:
|
||||||
|
rule = None
|
||||||
|
state = 0
|
||||||
|
|
||||||
def parseDump(self, dumpfile):
|
def parseDump(self, dumpfile):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue