549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
+
+
+
+
+
+
|
print(" options defined for: " + ", ".join([ t[0] for t in lOpt ]))
dOptions = { "lStructOpt": lStructOpt, "dOptLabel": dOptLabel }
dOptions.update({ "dOpt"+k: v for k, v in lOpt })
return dOptions, dOptPriority
def printBookmark (nLevel, sComment, nLine):
print(" {:>6}: {}".format(nLine, " " * nLevel + sComment))
def make (lRules, sLang, bJavaScript):
"compile rules, returns a dictionary of values"
# for clarity purpose, don’t create any file here
# removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines
print(" parsing rules...")
global dDEF
lLine = []
lRuleLine = []
lTest = []
lOpt = []
printBookmark(0, "PASS 0: PARAGRAPH BY PARAGRAPH", 0)
for i, sLine in enumerate(lRules, 1):
if sLine.startswith('#END'):
printBookmark(0, "BREAK BY #END", i)
break
elif sLine.startswith("#"):
pass
elif sLine.startswith("DEF:"):
m = re.match("DEF: +([a-zA-Z_][a-zA-Z_0-9]*) +(.+)$", sLine.strip())
|
581
582
583
584
585
586
587
588
589
590
|
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
+
+
+
+
+
+
|
pass
elif sLine.startswith(("OPTGROUP/", "OPTSOFTWARE:", "OPT/", "OPTLANG/", "OPTLABEL/", "OPTPRIORITY/")):
lOpt.append(sLine)
elif re.match("[ \t]*$", sLine):
pass
elif sLine.startswith("!!"):
if sLine[2:].strip():
printBookmark(1, sLine[2:].strip(), i)
elif sLine.startswith("[++]"):
printBookmark(0, "PASS 1: SENTENCE BY SENTENCE", i)
lRuleLine.append([i, "[++]"])
elif sLine.startswith((" ", "\t")):
lRuleLine[len(lRuleLine)-1][1] += " " + sLine.strip()
else:
lRuleLine.append([i, sLine.strip()])
|