diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index 3c46500463c8b46362aa582b80b6792b2186ed68..4d116dc787b2623fc313855cc29051b436ce625e 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -1132,12 +1132,6 @@ class SimpleParser(object): compiledMatcher = self.parserBuilder.compiledMatchers[stateIndex] 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: gIndex = self.backend.openSection(s) sects[s] = gIndex @@ -1150,11 +1144,23 @@ class SimpleParser(object): section = section_manager.openSections[gIndex] 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)) def contextClose(self, cNow): 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())): # Call the matcher specific onClose callbacks @@ -1168,12 +1174,6 @@ class SimpleParser(object): # Call the global onClose callbacks 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 return True else: