From d29ff8d811b284cf370c860abe07e5036165c41f Mon Sep 17 00:00:00 2001
From: Henning Glawe <glaweh@debian.org>
Date: Mon, 18 Jul 2016 10:12:47 +0200
Subject: [PATCH] store dict-result of handleStartMatch / handleEndMatch in
 SimpleParser.lastMatch

this way, adHoc(parser) hooks can access the information extracted by
startReStr via parser.lastMatch

startReStr=r"(?P<something>\d+)" as parser.lastMatch['something']
---
 common/python/nomadcore/simple_parser.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py
index 45a3f3a..7762fa4 100644
--- a/common/python/nomadcore/simple_parser.py
+++ b/common/python/nomadcore/simple_parser.py
@@ -989,6 +989,7 @@ class SimpleParser(object):
         self.superContext = superContext
         self.annotateFile = None
         self.matchHighlighter = MatchHighlighter(highlightmode)
+        self.lastMatch = {}
         if annotate:
             annofilename=fIn.fIn.name + ".annotate"
             logger.info("writing annotated input to " + annofilename)
@@ -1080,10 +1081,10 @@ class SimpleParser(object):
                 logger.debug("new context: %s\n", self.contextDesc())
                 currentCtx = self.context[len(self.context) - 1]
                 if startEnd == ParsingContext.End:
-                    currentCtx.compiledMatcher.handleEndMatch(self)
+                    self.lastMatch = currentCtx.compiledMatcher.handleEndMatch(self)
                     self.contextClose(currentCtx)
                 else:
-                    currentCtx.compiledMatcher.handleStartMatch(self)
+                    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)
-- 
GitLab