Skip to content
Snippets Groups Projects
Commit d11d3efe authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added some convenience functions to CachingBackend/CachingSectionManager,...

Added some convenience functions to CachingBackend/CachingSectionManager, added new 'endAction' argument for SimpleMatchers.
parent 40e42f75
Branches
Tags
No related merge requests found
......@@ -272,7 +272,7 @@ class RegexService(object):
Stores basic regex definitions that can be reused on multiple parsers.
"""
def __init__(self):
self.float = "-?\d+\.\d+(?:E(?:\+|-)\d+)?" # Regex for a floating point value
self.float = "-?\d+\.\d+(?:[ED](?:\+|-)\d+)?" # Regex for a floating point value
self.int = "-?\d+" # Regex for an integer
self.word = "[\S]+" # Regex for a single word. Can contain anything else but whitespace
self.letter = "[^\W\d_]" # Regex for a single alphabetical letter
......
......@@ -178,6 +178,12 @@ class CachingSectionManager(object):
def setSectionInfo(self, gIndex, references):
self.openSections[gIndex].references = [reference[x] for x in self.parentSectionNames]
def get_latest_section(self):
"""Returns the latest opened section if it is still open.
"""
section = self.openSections.get(self.lastSectionGIndex)
return section
def openSection(self, backend):
newGIndex = self.lastSectionGIndex + 1
self.openSectionWithGIndex(backend, newGIndex)
......@@ -317,6 +323,14 @@ class ActiveBackend(object):
def appendOnClose(self, sectionName, onClose):
self.sectionManagers.onClose.append(onClose)
def get_latest_section(self, metaname):
"""Returns the latest opened section with the given metaname if it has
not been closed.
"""
manager = self.sectionManagers.get(metaname)
if manager:
return manager.get_latest_section()
def appendOnOpen(self, sectionName, onOpen):
self.sectionManagers.onOpen.append(onOpen)
......
......@@ -74,6 +74,7 @@ class SimpleMatcher(object):
defLine=0,
defFile='',
coverageIgnore=False, # mark line as ignored in coverage analysis
endAction = None,
):
self.index = -1
self.startReStr = startReStr
......@@ -118,6 +119,7 @@ class SimpleMatcher(object):
"and is marked as coverageIgnore", name)
self.coverageIgnore = coverageIgnore
self.endAction = endAction
caller=inspect.currentframe()
if (defFile == '') and (defLine == 0):
if (caller is not None) and (caller.f_back is not None):
......@@ -679,8 +681,10 @@ class CompiledMatcher(object):
parser.skipped += 1
def findNextMatch(self, parser):
nextI = None
if self.matcher.adHoc:
nextI = self.matcher.adHoc(parser)
if nextI is not None:
return nextI
return self.findNextWithRe(self.possibleNextsRe, self.possibleNexts, parser)
......@@ -1088,6 +1092,11 @@ class SimpleParser(object):
self.context.append(ParsingContext(stateIndex, sects, compiledMatcher, ParsingContext.Start))
def contextClose(self, cNow):
# Handle end action before closing sections
# Call the end action
if cNow.compiledMatcher.matcher.endAction:
cNow.compiledMatcher.matcher.endAction()
if cNow.startEnd == ParsingContext.Start:
for s,gIndex in reversed(list(cNow.sections.items())):
self.backend.closeSection(s, gIndex)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment