121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
+
+
|
sActionId = sRuleName + "__b" + str(iActionBlock) + "_a" + str(iAction) + "_" + str(len(lToken))
aAction = createAction(sActionId, sAction, nPriority, len(lToken), dPos)
if aAction:
dACTIONS[sActionId] = aAction
lResult = list(lToken)
lResult.extend(["##"+str(iLine), sActionId])
yield lResult
else:
print(" # Error on action at line:", iLine)
def changeReferenceToken (sText, dPos):
"change group reference in <sText> with values in <dPos>"
for i in range(len(dPos), 0, -1):
sText = sText.replace("\\"+str(i), "\\"+str(dPos[i]))
return sText
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
-
+
-
+
+
+
-
-
+
+
+
+
+
|
# Option
sOption = False
m = re.match("/(\\w+)/", sAction)
if m:
sOption = m.group(1)
sAction = sAction[m.end():].strip()
# valid action?
m = re.search(r"(?P<action>[-~=/>])(?P<start>\d+|)(?P<end>:\d+|)>>", sAction)
m = re.search(r"(?P<action>[-~=/>])(?P<start>\d+\.?|)(?P<end>:\.?\d+|)>>", sAction)
if not m:
print(" # Error. No action found at: ", sActionId)
print(" ==", sAction, "==")
return None
# Condition
sCondition = sAction[:m.start()].strip()
if sCondition:
sCondition = prepareFunction(sCondition)
sCondition = changeReferenceToken(sCondition, dPos)
dFUNCTIONS["_g_c_"+sActionId] = sCondition
sCondition = "_g_c_"+sActionId
else:
sCondition = ""
# Action
cAction = m.group("action")
sAction = sAction[m.end():].strip()
sAction = changeReferenceToken(sAction, dPos)
if not m.group("start"):
iStartAction = 1
iEndAction = 0
else:
if cAction != "-" and (m.group("start").endswith(".") or m.group("end").startswith(":.")):
print(" # Error. Wrong selection on tokens.", sActionId)
return None
iStartAction = int(m.group("start"))
iEndAction = int(m.group("end")[1:]) if m.group("end") else iStartAction
iStartAction = int(m.group("start")) if not m.group("start").endswith(".") else int("-"+m.group("start")[:-1])
if not m.group("end"):
iEndAction = iStartAction
else:
iEndAction = int(m.group("end")[1:]) if not m.group("end").startswith(":.") else int("-" + m.group("end")[2:])
if dPos and m.group("start"):
try:
iStartAction = dPos[iStartAction]
if iEndAction:
iEndAction = dPos[iEndAction]
except:
print("# Error. Wrong groups in: " + sActionId)
|
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
-
+
|
if "define" in sAction and not re.search(r"define\(\\\d+ *, *\[.*\] *\)", sAction):
print("# Error in action at line " + sActionId + ": second argument for <define> must be a list of strings")
sAction = prepareFunction(sAction)
dFUNCTIONS["_g_d_"+sActionId] = sAction
sAction = "_g_d_"+sActionId
return [sOption, sCondition, cAction, sAction]
else:
print("# Unknown action at line " + sActionId)
print(" # Unknown action.", sActionId)
return None
def make (lRule, dDef, sLang, bJavaScript):
"compile rules, returns a dictionary of values"
# for clarity purpose, don’t create any file here
|