diff --git a/common/python/nomadcore/simple_parser.py b/common/python/nomadcore/simple_parser.py index f23d1bc678eb6f3c0e383ec143c58d9549bfd7b4..8ab4885a343d301fb7dbd8b8dbaf5a0e544ce7e9 100644 --- a/common/python/nomadcore/simple_parser.py +++ b/common/python/nomadcore/simple_parser.py @@ -510,12 +510,20 @@ class CompiledMatcher(object): self.possibleNextsEnd = possibleNextsEnd self.possibleNextsRe = self.matchersToRe(possibleNexts) self.possibleNextsEndRe = self.matchersToRe(possibleNextsEnd) + strValueTransform = parserBuilder.strValueTransform + if strValueTransform is None: + strValueTransform = {} converters = {} + transformers = {} groups = extractGroupNames(matcher.startReStr) if matcher.endReStr: groups.extend(extractGroupNames(matcher.endReStr)) for gName, units in groups: metaInfo = parserBuilder.metaInfoEnv.infoKinds[gName] + if units in strValueTransform: + # override units by output units of string transform function + transformers[gName] = strValueTransform[units][0] + units = strValueTransform[units][1] if units: # By default use the unit given in metainfo target_unit = metaInfo.units @@ -535,6 +543,7 @@ class CompiledMatcher(object): converters[gName] = unit_conversion.convert_unit_function(units, target_unit) self.converters = converters + self.transformers = transformers def addStrValue(self, backend, metaNameWithUnits, strValue): """adds a string value with unit conversions (only for the groups in start and endRe)"""