60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
nGroup += 1
dPos[nGroup] = i
# Parse actions
for nAction, sAction in enumerate(sActions.split(" <<- ")):
if sAction.strip():
sActionId = sRuleName + "_a" + str(nAction)
sCondition, tAction = createAction(sActionId, sAction, nGroup, nPriority, dPos)
if tAction:
dACTIONS[sActionId] = tAction
lResult = list(lToken)
lResult.extend(["##"+str(iLine), sRuleName, sCondition, sActionId])
yield lResult
def createAction (sIdAction, sAction, nGroup, nPriority, dPos):
m = re.search("([-~=])(\\d+|)(:\\d+|)>> ", sAction)
if not m:
print(" # Error. No action found at: ", sIdAction)
print(" ==", sAction, "==")
return None, None
# Condition
sCondition = sAction[:m.start()].strip()
if sCondition:
sCondition = prepareFunction(sCondition)
sCondition = changeReferenceToken(sCondition, dPos)
lFUNCTIONS.append(("gc_"+sIdAction, sCondition))
sCondition = "gc_"+sIdAction
|
|
|
|
|
|
|
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
nGroup += 1
dPos[nGroup] = i
# Parse actions
for nAction, sAction in enumerate(sActions.split(" <<- ")):
if sAction.strip():
sActionId = sRuleName + "_a" + str(nAction)
aAction = createAction(sActionId, sAction, nGroup, nPriority, dPos)
if aAction:
dACTIONS[sActionId] = aAction
lResult = list(lToken)
lResult.extend(["##"+str(iLine), sActionId])
yield lResult
def createAction (sIdAction, sAction, nGroup, nPriority, dPos):
m = re.search("([-~=])(\\d+|)(:\\d+|)>> ", sAction)
if not m:
print(" # Error. No action found at: ", sIdAction)
print(" ==", sAction, "==")
return None
# Condition
sCondition = sAction[:m.start()].strip()
if sCondition:
sCondition = prepareFunction(sCondition)
sCondition = changeReferenceToken(sCondition, dPos)
lFUNCTIONS.append(("gc_"+sIdAction, sCondition))
sCondition = "gc_"+sIdAction
|
147
148
149
150
151
152
153
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
|
if sAction[0:1] == "=":
lFUNCTIONS.append(("gs_"+sIdAction, sAction[1:]))
sAction = "=gs_"+sIdAction
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
if not sMsg:
print("# Error in action at line " + sIdAction + ": The message is empty.")
return [sCondition, (cAction, sAction, iStartAction, iEndAction, nPriority, sMsg, sURL)]
elif cAction == "~":
## text processor
if not sAction:
print("# Error in action at line " + sIdAction + ": This action is empty.")
if sAction[0:1] == "=":
lFUNCTIONS.append(("gp_"+sIdAction, sAction[1:]))
sAction = "=gp_"+sIdAction
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
return [sCondition, (cAction, sAction, iStartAction, iEndAction)]
elif cAction == "=":
## disambiguator
if sAction[0:1] == "=":
sAction = sAction[1:]
if not sAction:
print("# Error in action at line " + sIdAction + ": This action is empty.")
lFUNCTIONS.append(("gd_"+sIdAction, sAction))
sAction = "gd_"+sIdAction
return [sCondition, (cAction, sAction)]
elif cAction == ">":
## no action, break loop if condition is False
return [sCondition, (cAction, "")]
else:
print("# Unknown action at line " + sIdAction)
return None
def make (spLang, sLang, bJavaScript):
"compile rules, returns a dictionary of values"
|
|
|
|
|
|
147
148
149
150
151
152
153
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
|
if sAction[0:1] == "=":
lFUNCTIONS.append(("gs_"+sIdAction, sAction[1:]))
sAction = "=gs_"+sIdAction
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
if not sMsg:
print("# Error in action at line " + sIdAction + ": The message is empty.")
return [sCondition, cAction, sAction, iStartAction, iEndAction, nPriority, sMsg, sURL]
elif cAction == "~":
## text processor
if not sAction:
print("# Error in action at line " + sIdAction + ": This action is empty.")
if sAction[0:1] == "=":
lFUNCTIONS.append(("gp_"+sIdAction, sAction[1:]))
sAction = "=gp_"+sIdAction
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
return [sCondition, cAction, sAction, iStartAction, iEndAction]
elif cAction == "=":
## disambiguator
if sAction[0:1] == "=":
sAction = sAction[1:]
if not sAction:
print("# Error in action at line " + sIdAction + ": This action is empty.")
lFUNCTIONS.append(("gd_"+sIdAction, sAction))
sAction = "gd_"+sIdAction
return [sCondition, cAction, sAction]
elif cAction == ">":
## no action, break loop if condition is False
return [sCondition, cAction, ""]
else:
print("# Unknown action at line " + sIdAction)
return None
def make (spLang, sLang, bJavaScript):
"compile rules, returns a dictionary of values"
|