100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority, dOptPriority, dDef):
"generator: create rule as list"
# print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority)
for lToken in genTokenLines(sTokenLine, dDef):
# Calculate positions
dPos = {} # key: iGroup, value: iToken
iGroup = 0
#if iLine == 2211: # debug
# print(lToken)
for i, sToken in enumerate(lToken):
if sToken.startswith("(") and sToken.endswith(")"):
lToken[i] = sToken[1:-1]
iGroup += 1
dPos[iGroup] = i + 1 # we add 1, for we count tokens from 1 to n (not from 0)
|
|
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority, dOptPriority, dDef):
"generator: create rule as list"
# print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority)
for lToken in genTokenLines(sTokenLine, dDef):
# Calculate positions
dPos = {} # key: iGroup, value: iToken
iGroup = 0
#if iLine == 3971: # debug
# print(lToken)
for i, sToken in enumerate(lToken):
if sToken.startswith("(") and sToken.endswith(")"):
lToken[i] = sToken[1:-1]
iGroup += 1
dPos[iGroup] = i + 1 # we add 1, for we count tokens from 1 to n (not from 0)
|
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
199
200
201
202
203
204
205
206
207
|
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")) 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)
print(" iStartAction:", iStartAction, "iEndAction:", iEndAction)
print(" ", dPos)
if cAction == "-":
## error
iMsg = sAction.find(" # ")
if iMsg == -1:
sMsg = "# Error. Error message not found."
sURL = ""
|
>
>
>
>
>
|
>
>
|
|
|
>
>
>
>
|
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
sCondition = "_g_c_"+sActionId
else:
sCondition = ""
# Action
cAction = m.group("action")
sAction = sAction[m.end():].strip()
sAction = changeReferenceToken(sAction, dPos)
# target
cStartLimit = "<"
cEndLimit = ">"
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
if m.group("start").endswith("."):
cStartLimit = ">"
iStartAction = int(m.group("start").rstrip("."))
if not m.group("end"):
iEndAction = iStartAction
else:
if m.group("end").startswith(":."):
cEndLimit = "<"
iEndAction = int(m.group("end").lstrip(":."))
if dPos and m.group("start"):
try:
iStartAction = dPos.get(iStartAction, iStartAction)
if iEndAction:
iEndAction = dPos.get(iEndAction, iEndAction)
except:
print("# Error. Wrong groups in: " + sActionId)
print(" iStartAction:", iStartAction, "iEndAction:", iEndAction)
print(" ", dPos)
if iStartAction < 0:
iStartAction += 1
if iEndAction < 0:
iEndAction += 1
if cAction == "-":
## error
iMsg = sAction.find(" # ")
if iMsg == -1:
sMsg = "# Error. Error message not found."
sURL = ""
|
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
sAction = prepareFunction(sAction)
dFUNCTIONS["_g_s_"+sActionId] = sAction[1:]
sAction = "=_g_s_"+sActionId
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
if not sMsg:
print("# Error in action at line " + sActionId + ": The message is empty.")
return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, nPriority, sMsg, sURL]
elif cAction == "~":
## text processor
if sAction[0:1] == "=":
sAction = prepareFunction(sAction)
dFUNCTIONS["_g_p_"+sActionId] = sAction[1:]
sAction = "=_g_p_"+sActionId
elif sAction.startswith('"') and sAction.endswith('"'):
|
|
|
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
sAction = prepareFunction(sAction)
dFUNCTIONS["_g_s_"+sActionId] = sAction[1:]
sAction = "=_g_s_"+sActionId
elif sAction.startswith('"') and sAction.endswith('"'):
sAction = sAction[1:-1]
if not sMsg:
print("# Error in action at line " + sActionId + ": The message is empty.")
return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, cStartLimit, cEndLimit, nPriority, sMsg, sURL]
elif cAction == "~":
## text processor
if sAction[0:1] == "=":
sAction = prepareFunction(sAction)
dFUNCTIONS["_g_p_"+sActionId] = sAction[1:]
sAction = "=_g_p_"+sActionId
elif sAction.startswith('"') and sAction.endswith('"'):
|