︙ | | |
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
+
-
+
|
import colorsys
import time
import compile_rules_js_convert as jsconv
import compile_rules_graph as crg
dDEFINITIONS = {}
dDEF = {}
dDECLENSIONS = {}
lFUNCTIONS = []
aRULESET = set() # set of rule-ids to check if there is several rules with the same id
nRULEWITHOUTNAME = 0
dJSREGEXES = {}
|
︙ | | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
-
+
|
return None
# quotes ?
if sRegex.startswith('"') and sRegex.endswith('"'):
sRegex = sRegex[1:-1]
## definitions
for sDef, sRepl in dDEF.items():
for sDef, sRepl in dDEFINITIONS.items():
sRegex = sRegex.replace(sDef, sRepl)
## count number of groups (must be done before modifying the regex)
nGroup = countGroupInRegex(sRegex)
if nGroup > 0:
if not tGroups:
print("# Warning: groups positioning code for JavaScript should be defined at line " + sLineId)
|
︙ | | |
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
|
-
+
+
+
+
+
+
+
+
+
|
elif sLine.startswith("#"):
# comment
pass
elif sLine.startswith("DEF:"):
# definition
m = re.match("DEF: +([a-zA-Z_][a-zA-Z_0-9]*) +(.+)$", sLine.strip())
if m:
dDEF["{"+m.group(1)+"}"] = m.group(2)
dDEFINITIONS["{"+m.group(1)+"}"] = m.group(2)
else:
print("Error in definition: ", end="")
print(sLine.strip())
elif sLine.startswith("DECL:"):
# declensions
m = re.match(r"DECL: +(\+\w+) (.+)$", sLine.strip())
if m:
dDECLENSIONS[m.group(1)] = m.group(2).strip().split()
else:
print("Error in declension list: ", end="")
print(sLine.strip())
elif sLine.startswith("TEST:"):
# test
lTest.append("{:<8}".format(i) + " " + sLine[5:].strip())
elif sLine.startswith("TODO:"):
# todo
pass
elif sLine.startswith(("OPTGROUP/", "OPTSOFTWARE:", "OPT/", \
|
︙ | | |
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
|
-
-
-
-
+
+
+
+
+
|
# Graph rules
elif sLine.startswith("@@@@GRAPH:"):
# rules graph call
m = re.match(r"@@@@GRAPH: *(\w+)", sLine.strip())
if m:
printBookmark(0, "GRAPH: " + m.group(1), i)
lRuleLine.append([i, "@@@@"+m.group(1)])
bGraph = True
lGraphRule.append([i, sLine])
bGraph = True
elif sLine.startswith("@@@@END_GRAPH"):
lGraphRule.append([i, sLine])
bGraph = True
else:
print("Graph error at line", i)
elif sLine.startswith(("@@@@END_GRAPH", "@@@@ENDGRAPH")):
#lGraphRule.append([i, sLine])
printBookmark(0, "ENDGRAPH", i)
bGraph = False
elif re.match("@@@@ *$", sLine):
pass
elif bGraph:
lGraphRule.append([i, sLine])
|
︙ | | |
629
630
631
632
633
634
635
636
637
638
639
640
641
|
639
640
641
642
643
644
645
646
647
648
649
650
651
|
-
+
|
"sentence_rules": mergeRulesByOption(lSentenceRules),
"paragraph_rules_JS": jsconv.writeRulesToJSArray(mergeRulesByOption(lParagraphRulesJS)),
"sentence_rules_JS": jsconv.writeRulesToJSArray(mergeRulesByOption(lSentenceRulesJS))
}
dVars.update(dOptions)
# compile graph rules
dVars2 = crg.make(lGraphRule, dDEF, sLang, dOptPriority)
dVars2 = crg.make(lGraphRule, sLang, dDEFINITIONS, dDECLENSIONS, dOptPriority)
dVars.update(dVars2)
with open("_build/data_cache.json", "w", encoding="utf-8") as hDst:
hDst.write(json.dumps(dVars, ensure_ascii=False))
return dVars
|