Skip to content
Snippets Groups Projects
Commit 25f63cfb authored by Ihrig, Arvid Conrad (ari)'s avatar Ihrig, Arvid Conrad (ari)
Browse files

reversed execution order of the free callbacks in the previous commit

-onOpen now executes the callback associated with key None AFTER all
 sections have been opened and section-bound callbacks are executed
-onClose now executes the callback associated with key None BEFORE all
 sections have been closed and section-bound callbacks are executed
parent 068c8172
Branches
No related tags found
No related merge requests found
...@@ -1132,12 +1132,6 @@ class SimpleParser(object): ...@@ -1132,12 +1132,6 @@ class SimpleParser(object):
compiledMatcher = self.parserBuilder.compiledMatchers[stateIndex] compiledMatcher = self.parserBuilder.compiledMatchers[stateIndex]
sects = OrderedDict() sects = OrderedDict()
# call the not section-bound onOpen function of the specific matcher
if compiledMatcher.matcher.onOpen:
callback = compiledMatcher.matcher.onOpen.get(None)
if callback:
callback(self.backend, None, None)
for s in compiledMatcher.matcher.sections: for s in compiledMatcher.matcher.sections:
gIndex = self.backend.openSection(s) gIndex = self.backend.openSection(s)
sects[s] = gIndex sects[s] = gIndex
...@@ -1150,11 +1144,23 @@ class SimpleParser(object): ...@@ -1150,11 +1144,23 @@ class SimpleParser(object):
section = section_manager.openSections[gIndex] section = section_manager.openSections[gIndex]
callback(self.backend, gIndex, section) callback(self.backend, gIndex, section)
# call the not section-bound onOpen function of the specific matcher
if compiledMatcher.matcher.onOpen:
callback = compiledMatcher.matcher.onOpen.get(None)
if callback:
callback(self.backend, None, None)
self.context.append(ParsingContext(stateIndex, sects, compiledMatcher, ParsingContext.Start)) self.context.append(ParsingContext(stateIndex, sects, compiledMatcher, ParsingContext.Start))
def contextClose(self, cNow): def contextClose(self, cNow):
if cNow.startEnd == ParsingContext.Start: if cNow.startEnd == ParsingContext.Start:
# call the not section-bound onClose function of the specific matcher
if cNow.compiledMatcher.matcher.onClose:
callback = cNow.compiledMatcher.matcher.onClose.get(None)
if callback:
callback(self.backend, None, None)
for s, gIndex in reversed(list(cNow.sections.items())): for s, gIndex in reversed(list(cNow.sections.items())):
# Call the matcher specific onClose callbacks # Call the matcher specific onClose callbacks
...@@ -1168,12 +1174,6 @@ class SimpleParser(object): ...@@ -1168,12 +1174,6 @@ class SimpleParser(object):
# Call the global onClose callbacks # Call the global onClose callbacks
self.backend.closeSection(s, gIndex) self.backend.closeSection(s, gIndex)
# call the not section-bound onClose function of the specific matcher
if cNow.compiledMatcher.matcher.onClose:
callback = cNow.compiledMatcher.matcher.onClose.get(None)
if callback:
callback(self.backend, None, None)
cNow.startEnd = ParsingContext.End cNow.startEnd = ParsingContext.End
return True return True
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment