133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
def writeRulesToJSArray (lRules):
"create rules as a string of arrays (to be bundled in a JSON string)"
sArray = "[\n"
for sOption, aRuleGroup in lRules:
if sOption != "@@@@":
sArray += ' ["' + sOption + '", [\n' if sOption else " [false, [\n"
for sRegex, bCaseInsensitive, sLineId, sRuleId, nPriority, lActions, aGroups, aNegLookBehindRegex in aRuleGroup:
sArray += ' [' + sRegex + ", "
sArray += "true, " if bCaseInsensitive else "false, "
sArray += '"' + sLineId + '", '
sArray += '"' + sRuleId + '", '
sArray += str(nPriority) + ", "
sArray += json.dumps(lActions, ensure_ascii=False) + ", "
sArray += json.dumps(aGroups, ensure_ascii=False) + ", "
sArray += json.dumps(aNegLookBehindRegex, ensure_ascii=False) + "],\n"
sArray += " ]],\n"
else:
sArray += ' ["' + sOption + '", [\n'
for sGraphName, sLineId in aRuleGroup:
sArray += ' ["' + sGraphName + '", "' + sLineId + '"],\n'
sArray += " ]],\n"
sArray += "]"
return sArray
def groupsPositioningCodeToList (sGroupsPositioningCode):
"convert <sGroupsPositioningCode> to a list of codes (numbers or strings)"
|
>
|
<
|
<
<
<
|
|
|
>
|
|
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
def writeRulesToJSArray (lRules):
"create rules as a string of arrays (to be bundled in a JSON string)"
sArray = "[\n"
for sOption, aRuleGroup in lRules:
if sOption != "@@@@":
sOption = "false" if not sOption else f'"{sOption}"'
sArray += f' [{sOption}, [\n'
for sRegex, bCaseInsensitive, sLineId, sRuleId, nPriority, lActions, aGroups, aNegLookBehindRegex in aRuleGroup:
sCaseSensitive = "true" if bCaseInsensitive else "false"
sActions = json.dumps(lActions, ensure_ascii=False)
sGroups = json.dumps(aGroups, ensure_ascii=False)
sNLBRegex = json.dumps(aNegLookBehindRegex, ensure_ascii=False)
sArray += f' [{sRegex}, {sCaseSensitive}, "{sLineId}", "{sRuleId}", {nPriority}, {sActions}, {sGroups}, {sNLBRegex}],\n'
sArray += " ]],\n"
else:
sArray += f' ["{sOption}", [\n'
for sGraphName, sLineId in aRuleGroup:
sArray += f' ["{sGraphName}", "{sLineId}"],\n'
sArray += " ]],\n"
sArray += "]"
return sArray
def groupsPositioningCodeToList (sGroupsPositioningCode):
"convert <sGroupsPositioningCode> to a list of codes (numbers or strings)"
|