127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
+
|
if aAction:
dACTIONS[sActionId] = aAction
lResult = list(lToken)
lResult.extend(["##"+str(iLine), sActionId])
yield lResult
else:
print(" # Error on action at line:", iLine)
print(sTokenLine, "\n", sActions)
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
|
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
-
-
+
+
-
+
+
+
+
+
+
-
+
|
if m:
sRuleName = m.group(1)
iActionBlock = 1
nPriority = int(m.group(2)[1:]) if m.group(2) else -1
else:
print("Syntax error in rule group: ", sLine, " -- line:", i)
exit()
elif re.search("^ +<<- ", sLine) or sLine.startswith(" ") \
or re.search("^ +#", sLine) or re.search(r"^ [-~=>/](?:\d\.?(?::\.?\d+|)|)>> ", sLine) :
elif re.search("^ +<<- ", sLine) or (sLine.startswith(" ") and not sLine.startswith(" ||")) \
or re.search("^ +#", sLine) or re.search(r"[-~=>/%](?:-?\d\.?(?::\.?-?\d+|)|)>> ", sLine) :
# actions
sActions += " " + sLine.strip()
elif re.match("[ ]*$", sLine):
# empty line to end merging
if not lTokenLine:
continue
if not sActions:
print("Error. No action found at line:", i)
exit()
if not sGraphName:
print("Error. All rules must belong to a named graph. Line: ", i)
exit()
for j, sTokenLine in lTokenLine:
dAllGraph[sGraphName].append((j, sRuleName, sTokenLine, iActionBlock, sActions, nPriority))
lTokenLine.clear()
sActions = ""
iActionBlock += 1
elif sLine.startswith((" ")):
elif sLine.startswith(" "):
# tokens
sLine = sLine.strip()
if sLine.startswith("||"):
iPrevLine, sPrevLine = lTokenLine[-1]
lTokenLine[-1] = [iPrevLine, sPrevLine + " " + sLine[2:]]
else:
lTokenLine.append([i, sLine.strip()])
lTokenLine.append([i, sLine])
else:
print("Unknown line:")
print(sLine)
# processing rules
print(" preparing rules...")
for sGraphName, lRuleLine in dAllGraph.items():
|