Skip to content
Snippets Groups Projects
Commit 8a183ab7 authored by Henning Glawe's avatar Henning Glawe
Browse files

setup CompiledMatcher.transformers from parserBuilder.strValueTransform

transformers assign custom strValueTransform functions to named groups
in SimpleMatcher regular expressions.
Implemented analogously to the existing 'converters' mechanism
for unit conversion.
parent 03b120f8
Branches
Tags
No related merge requests found
...@@ -510,12 +510,20 @@ class CompiledMatcher(object): ...@@ -510,12 +510,20 @@ class CompiledMatcher(object):
self.possibleNextsEnd = possibleNextsEnd self.possibleNextsEnd = possibleNextsEnd
self.possibleNextsRe = self.matchersToRe(possibleNexts) self.possibleNextsRe = self.matchersToRe(possibleNexts)
self.possibleNextsEndRe = self.matchersToRe(possibleNextsEnd) self.possibleNextsEndRe = self.matchersToRe(possibleNextsEnd)
strValueTransform = parserBuilder.strValueTransform
if strValueTransform is None:
strValueTransform = {}
converters = {} converters = {}
transformers = {}
groups = extractGroupNames(matcher.startReStr) groups = extractGroupNames(matcher.startReStr)
if matcher.endReStr: if matcher.endReStr:
groups.extend(extractGroupNames(matcher.endReStr)) groups.extend(extractGroupNames(matcher.endReStr))
for gName, units in groups: for gName, units in groups:
metaInfo = parserBuilder.metaInfoEnv.infoKinds[gName] 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: if units:
# By default use the unit given in metainfo # By default use the unit given in metainfo
target_unit = metaInfo.units target_unit = metaInfo.units
...@@ -535,6 +543,7 @@ class CompiledMatcher(object): ...@@ -535,6 +543,7 @@ class CompiledMatcher(object):
converters[gName] = unit_conversion.convert_unit_function(units, target_unit) converters[gName] = unit_conversion.convert_unit_function(units, target_unit)
self.converters = converters self.converters = converters
self.transformers = transformers
def addStrValue(self, backend, metaNameWithUnits, strValue): def addStrValue(self, backend, metaNameWithUnits, strValue):
"""adds a string value with unit conversions (only for the groups in start and endRe)""" """adds a string value with unit conversions (only for the groups in start and endRe)"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment