From 5d5bafb1686caf14b6d4e442c5289a0c34ba7cc8 Mon Sep 17 00:00:00 2001
From: Lauri Himanen <lauri.himanen@aalto.fi>
Date: Mon, 19 Sep 2016 13:27:04 +0300
Subject: [PATCH] Fixed bug with caused clash in handling starReTransform and
 fixedStartValues on the same SimpleMatcher.

---
 common/python/nomadcore/simple_parser.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py
index 5e81cb1..e7133b4 100644
--- a/common/python/nomadcore/simple_parser.py
+++ b/common/python/nomadcore/simple_parser.py
@@ -636,25 +636,30 @@ class CompiledMatcher(object):
         result_dict = {}
 
         # If a separate transform function was defined in the matcher, call it
-        # and do nothing else.
+        # and ignore any named groups.
         if self.matcher.startReTransform is not None:
             self.matcher.startReTransform(parser.backend, m.groups())
         else:
-
             for k,v in sorted(m.groupdict().items()):
                 if v is None:
                     # a group may be optional (subexpression of ? or | in regex)
                     continue
                 k_converted, v_converted = self.addStrValue(parser.backend, k, v)
                 result_dict[k_converted] = v_converted
-            if self.matcher.fixedStartValues:
-                for k,v in sorted(self.matcher.fixedStartValues.items()):
-                    if k not in result_dict:
-                        v_converted = self.addValue(parser.backend, k, v)
-                        result_dict[k] = v_converted
+
+        # Emit fixed start values
+        if self.matcher.fixedStartValues:
+            for k,v in sorted(self.matcher.fixedStartValues.items()):
+                if k not in result_dict:
+                    v_converted = self.addValue(parser.backend, k, v)
+                    result_dict[k] = v_converted
+
+        # If the match needs to be forwarded, push the read line back into the
+        # file stream
         if self.matcher.forwardMatch:
             logger.debug("handleStartMatch of %s on (%s) pushing back line", self.matcher.desc(),line)
             parser.fIn.pushbackLine(line)
+
         return result_dict
 
     def handleEndMatch(self, parser):
-- 
GitLab