Commit 4ee42ae6 authored by Berk Onat's avatar Berk Onat

Added new replay settings to SmartParserCommon

parent 6002b92b
...@@ -988,16 +988,22 @@ class ParserBase(object): ...@@ -988,16 +988,22 @@ class ParserBase(object):
if "tableendsat" in parserOptions: if "tableendsat" in parserOptions:
tableEndRe = re.compile(parserOptions["tableendsat"]) tableEndRe = re.compile(parserOptions["tableendsat"])
stopOnMatch = False stopOnMatch = False
if stopOnMatchRe.findall(lastLine): if isinstance(stopOnMatchRe, str):
stopOnMatch = True pass
if parserDict["firstLine"] == 0: else:
if stopOnFirstLine: if stopOnMatchRe.findall(lastLine):
stopOnMatch = True
else:
stopOnMatch = False
if quitOnMatchRe is not None:
if quitOnMatchRe.findall(lastLine):
stopOnMatch = True stopOnMatch = True
if parserDict["firstLine"] == 0:
if stopOnFirstLine:
stopOnMatch = True
else:
stopOnMatch = False
if quitOnMatchRe is not None:
if isinstance(stopOnMatchRe, str):
pass
else:
if quitOnMatchRe.findall(lastLine):
stopOnMatch = True
if tableEndRe is not None: if tableEndRe is not None:
if tableEndRe.findall(lastLine): if tableEndRe.findall(lastLine):
stopOnMatch = True stopOnMatch = True
...@@ -1116,14 +1122,16 @@ class ParserBase(object): ...@@ -1116,14 +1122,16 @@ class ParserBase(object):
cName=cName.upper() cName=cName.upper()
hlist=[h.upper() for h in hlist] hlist=[h.upper() for h in hlist]
if cName in hlist: if cName in hlist:
v=vlist[hlist.index(cName)]
#print("PRINTING table_parser save:",cName,v) #print("PRINTING table_parser save:",cName,v)
if key in list(parser.lastMatch.keys()): hindex = hlist.index(cName)
parser.lastMatch[key]=v if hindex < len(vlist):
else: v=vlist[hlist.index(cName)]
mNameDict[key].value=v if key in list(parser.lastMatch.keys()):
mNameDict[key].activeInfo=True parser.lastMatch[key]=v
anythingmatched = True else:
mNameDict[key].value=v
mNameDict[key].activeInfo=True
anythingmatched = True
else: else:
if(header is not None and headersave is not None): if(header is not None and headersave is not None):
hlistc=0 hlistc=0
...@@ -1227,6 +1235,7 @@ class ParserBase(object): ...@@ -1227,6 +1235,7 @@ class ParserBase(object):
parsercntrlin = None parsercntrlin = None
lookupdict = None lookupdict = None
lookupvals = None lookupvals = None
maxLines = None
if "movetostopline" in parserOptions: if "movetostopline" in parserOptions:
updateLastLine = parserOptions["movetostopline"] updateLastLine = parserOptions["movetostopline"]
if "lookupdict" in parserOptions: if "lookupdict" in parserOptions:
...@@ -1243,6 +1252,9 @@ class ParserBase(object): ...@@ -1243,6 +1252,9 @@ class ParserBase(object):
parsercntrlin = getattr(self,parserOptions["parsercntrlin"]) parsercntrlin = getattr(self,parserOptions["parsercntrlin"])
else: else:
parsercntrlin = parserOptions["parsercntrlin"] parsercntrlin = parserOptions["parsercntrlin"]
if "maxtablelines" in parserOptions:
maxLines = parserOptions["maxtablelines"] if parserOptions[
"maxtablelines"]>0 else None
if(parsercntrlattr is not None and if(parsercntrlattr is not None and
parsercntrlin is not None): parsercntrlin is not None):
...@@ -1264,6 +1276,9 @@ class ParserBase(object): ...@@ -1264,6 +1276,9 @@ class ParserBase(object):
matchNameDict, updateMatchDict, matchNameDict, updateMatchDict,
onlyCaseSensitive, stopOnFirstLine, onlyCaseSensitive, stopOnFirstLine,
parserDict, parserOptions, globalDict, localDict) parserDict, parserOptions, globalDict, localDict)
if maxLines is not None:
if maxLines >= parserDict["numStoredLines"]:
rtn = True
if rtn is not True: if rtn is not True:
while True: while True:
if record and replayCount>0: if record and replayCount>0:
...@@ -1284,6 +1299,9 @@ class ParserBase(object): ...@@ -1284,6 +1299,9 @@ class ParserBase(object):
matchNameDict, updateMatchDict, matchNameDict, updateMatchDict,
onlyCaseSensitive, stopOnFirstLine, onlyCaseSensitive, stopOnFirstLine,
parserDict, parserOptions, globalDict, localDict) parserDict, parserOptions, globalDict, localDict)
if maxLines is not None:
if maxLines >= parserDict["numStoredLines"]:
rtn = True
if rtn: if rtn:
if updateLastLine: if updateLastLine:
# Playing from record? # Playing from record?
...@@ -2000,12 +2018,24 @@ class ParserBase(object): ...@@ -2000,12 +2018,24 @@ class ParserBase(object):
def check_subparsers(self, parser, lastLine, stopOnMatchRe, quitOnMatchRe, subParsers, def check_subparsers(self, parser, lastLine, stopOnMatchRe, quitOnMatchRe, subParsers,
ordered, parserDict, secDict, onStartRunFunction, onQuitRunFunction, ordered, parserDict, secDict, onStartRunFunction, onQuitRunFunction,
onlySubParsersReadLine, maxcycle=None, parent=None): onlySubParsersReadLine, maxcycle=None, parent=None):
record = None
replay = None
replayCount = None
if parserDict is not None:
record = parserDict["record"]
replay = parserDict["replay"]
replayCount = parserDict["replayCount"]
if record is None:
record = False
if replayCount is None:
replayCount = 0
if maxcycle is None: if maxcycle is None:
maxcycle=1000000 maxcycle=1000000
cyclenum = 0 cyclenum = 0
if parent is None: if parent is None:
parent = 0 parent = 0
rank = parent rank = parent
stopOnEOF = True
waitFirstCycle = False waitFirstCycle = False
if "waitFirstCycle" in parserDict: if "waitFirstCycle" in parserDict:
waitFirstCycle = parserDict["waitFirstCycle"] waitFirstCycle = parserDict["waitFirstCycle"]
...@@ -2151,6 +2181,15 @@ class ParserBase(object): ...@@ -2151,6 +2181,15 @@ class ParserBase(object):
# reached than quit loop # reached than quit loop
if cyclenum > maxcycle: if cyclenum > maxcycle:
break break
if stopOnEOF:
eofLine = None
if record and replayCount>0:
eofLine = self.peekrecord()
else:
eofLine = self.peekline(parser)
if not eofLine:
stopOnMatch = True
break
if stopOnMatch: if stopOnMatch:
return True, lastLine, parserDict, secDict return True, lastLine, parserDict, secDict
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment