@@ -4353,9 +4353,8 @@ def loadRuleTexts(self, filename):
4353
4353
num1 = 0
4354
4354
num2 = 0
4355
4355
appendixA = False
4356
- expect_more = False
4357
4356
4358
- Rule_pattern = re .compile (r'^Rule ([0-9]+).([0-9]+)' )
4357
+ Rule_pattern = re .compile (r'^Rule ([0-9]+)\ .([0-9]+)' )
4359
4358
severity_pattern = re .compile (r'.*[ ]*(Advisory|Required|Mandatory)$' )
4360
4359
xA_Z_pattern = re .compile (r'^[#A-Z].*' )
4361
4360
a_z_pattern = re .compile (r'^[a-z].*' )
@@ -4383,70 +4382,63 @@ def loadRuleTexts(self, filename):
4383
4382
file_stream = open (filename , 'rt' )
4384
4383
4385
4384
rule = None
4386
- have_severity = False
4387
- severity_loc = 0
4385
+ rule_line_number = 0
4388
4386
4389
4387
for line in file_stream :
4390
4388
4391
- line = line .replace ('\r ' , '' ).replace ('\n ' , '' )
4389
+ line = line .strip ()
4390
+ if len (line ) == 0 :
4391
+ expect_more = False
4392
+ continue
4392
4393
4393
4394
if not appendixA :
4394
4395
if line .find ('Appendix A' ) >= 0 and line .find ('Summary of guidelines' ) >= 10 :
4395
4396
appendixA = True
4396
4397
continue
4397
4398
if line .find ('Appendix B' ) >= 0 :
4398
4399
break
4399
- if len (line ) == 0 :
4400
- continue
4401
4400
4402
4401
# Parse rule declaration.
4403
4402
res = Rule_pattern .match (line )
4404
4403
4405
4404
if res :
4406
- have_severity = False
4407
- expect_more = False
4408
- severity_loc = 0
4405
+ rule_line_number = 0
4409
4406
num1 = int (res .group (1 ))
4410
4407
num2 = int (res .group (2 ))
4411
4408
rule = Rule (num1 , num2 )
4412
4409
4413
- if not have_severity and rule is not None :
4414
4410
res = severity_pattern .match (line )
4415
-
4416
4411
if res :
4417
4412
rule .misra_severity = res .group (1 )
4418
- have_severity = True
4419
- else :
4420
- severity_loc += 1
4413
+ rule_line_number = 1
4414
+ continue
4415
+
4416
+ if rule is None :
4417
+ continue
4421
4418
4422
- # Only look for severity on the Rule line
4423
- # or the next non-blank line after
4424
- # If it's not in either of those locations then
4425
- # assume a severity was not provided.
4419
+ rule_line_number += 1
4426
4420
4427
- if severity_loc < 2 :
4421
+ if rule_line_number == 1 :
4422
+ res = severity_pattern .match (line )
4423
+
4424
+ if res :
4425
+ rule .misra_severity = res .group (1 )
4428
4426
continue
4429
4427
4430
- rule .misra_severity = ''
4431
- have_severity = True
4428
+ rule_line_number = 2
4432
4429
4433
- if rule is None :
4430
+ # Parse beginning of rule text.
4431
+ if not rule .text and xA_Z_pattern .match (line ):
4432
+ rule .text = line .strip ()
4433
+ self .ruleTexts [rule .num ] = rule
4434
4434
continue
4435
4435
4436
4436
# Parse continuing of rule text.
4437
- if expect_more :
4438
- if a_z_pattern .match (line ):
4439
- self .ruleTexts [rule .num ].text += ' ' + line
4440
- continue
4441
-
4442
- expect_more = False
4437
+ if a_z_pattern .match (line ):
4438
+ self .ruleTexts [rule .num ].text += ' ' + line .strip ()
4443
4439
continue
4444
4440
4445
- # Parse beginning of rule text.
4446
- if xA_Z_pattern .match (line ):
4447
- rule .text = line
4448
- self .ruleTexts [rule .num ] = rule
4449
- expect_more = True
4441
+ rule = None
4450
4442
4451
4443
file_stream .close ()
4452
4444
0 commit comments