diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index d22bf5415c3ce46fcb1b12e16d627ed1e77416e2..ffe0e680d0486ca95021623f86f940c4478c0a2b 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -1,6 +1,5 @@ from __future__ import division from future import standard_library -from future.utils import raise_from standard_library.install_aliases() from builtins import str from builtins import range @@ -1061,37 +1060,33 @@ class SimpleParser(object): def parseStep(self): if not self.context: return False - try: - currentContext = self.context[len(self.context) - 1] - if logger.isEnabledFor(logging.DEBUG): - logger.debug("lineNr: %d context: %s", self.fIn.lineNr,self.contextDesc()) - if currentContext.startEnd == ParsingContext.Start: - nextI = currentContext.compiledMatcher.findNextMatch(self) - else: - nextI = currentContext.compiledMatcher.findNextMatchEnd(self) - logger.debug("lineNr: %d nextI: %d", self.fIn.lineNr, nextI) - - if nextI < 0: - cNames = self.contextDesc() - while self.context: - self.contextPop() - if nextI != -1 and nextI != -3: - raise Exception("finished with error with parsing context %s" % (cNames)) + currentContext = self.context[len(self.context) - 1] + if logger.isEnabledFor(logging.DEBUG): + logger.debug("lineNr: %d context: %s", self.fIn.lineNr,self.contextDesc()) + if currentContext.startEnd == ParsingContext.Start: + nextI = currentContext.compiledMatcher.findNextMatch(self) + else: + nextI = currentContext.compiledMatcher.findNextMatchEnd(self) + logger.debug("lineNr: %d nextI: %d", self.fIn.lineNr, nextI) + + if nextI < 0: + cNames = self.contextDesc() + while self.context: + self.contextPop() + if nextI != -1 and nextI != -3: + raise Exception("finished with error with parsing context %s" % (cNames)) + else: + index = nextI // 2 + startEnd = nextI % 2 + matcherNew = self.parserBuilder.flatIndex[index] + self.goToMatcher(matcherNew, startEnd) + logger.debug("new context: %s\n", self.contextDesc()) + currentCtx = self.context[len(self.context) - 1] + if startEnd == ParsingContext.End: + self.lastMatch = currentCtx.compiledMatcher.handleEndMatch(self) + self.contextClose(currentCtx) else: - index = nextI // 2 - startEnd = nextI % 2 - matcherNew = self.parserBuilder.flatIndex[index] - self.goToMatcher(matcherNew, startEnd) - logger.debug("new context: %s\n", self.contextDesc()) - currentCtx = self.context[len(self.context) - 1] - if startEnd == ParsingContext.End: - self.lastMatch = currentCtx.compiledMatcher.handleEndMatch(self) - self.contextClose(currentCtx) - else: - self.lastMatch = currentCtx.compiledMatcher.handleStartMatch(self) - except Exception as e: - origin = traceback.format_exc() - raise_from(Exception("Failure, context %s, line %d coming from %s"%(self.contextDesc(), self.fIn.lineNr, origin)), e) + self.lastMatch = currentCtx.compiledMatcher.handleStartMatch(self) return len(self.context) > 0 def parse(self):