misra.py: updated parsing of misra-rules.txt

This commit is contained in:
Daniel Marjamäki 2018-03-14 23:00:17 +01:00
parent c74b0934e9
commit 1110cd0c57
1 changed files with 20 additions and 7 deletions

View File

@ -1069,8 +1069,15 @@ def loadRuleTexts(filename):
num1 = 0 num1 = 0
num2 = 0 num2 = 0
appendixA = False appendixA = False
ruleText = False
for line in open(filename, 'rt'): for line in open(filename, 'rt'):
line = line.replace('\r', '').replace('\n', '') line = line.replace('\r', '').replace('\n', '')
if len(line) == 0:
if ruleText:
num1 = 0
num2 = 0
ruleText = False
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
@ -1081,15 +1088,21 @@ def loadRuleTexts(filename):
if res: if res:
num1 = int(res.group(1)) num1 = int(res.group(1))
num2 = int(res.group(2)) num2 = int(res.group(2))
ruleText = False
continue continue
res = re.match(r'^[ ]*(Advisory|Required|Mandatory)$', line) if re.match(r'^[ ]*(Advisory|Required|Mandatory)$', line):
if res: ruleText = False
continue elif re.match(r'^[#A-Z].*', line):
res = re.match(r'^[ ]*([#A-Z].*)', line) if ruleText:
if res: num2 = num2 + 1
num = num1 * 100 + num2
global ruleTexts global ruleTexts
ruleTexts[num1*100+num2] = res.group(1) ruleTexts[num] = line
num2 = num2 + 1 ruleText = True
elif ruleText and re.match(r'^[a-z].*', line):
global ruleTexts
num = num1 * 100 + num2
ruleTexts[num] = ruleTexts[num] + ' ' + line
continue continue
def loadRuleTextsFromPdf(filename): def loadRuleTextsFromPdf(filename):