Skip to content

Commit

Permalink
fixing member parsing for a definition without comment but with unit
Browse files Browse the repository at this point in the history
  • Loading branch information
hegner committed Aug 22, 2023
1 parent faca42c commit 42edf8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions python/podio/podio_config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class MemberParser:
member_re = re.compile(rf' *{type_str} +{name_str} *{def_val_str} *{unit_str} *{comment_str}')

# For cases where we don't require a description
bare_member_re = re.compile(rf' *{type_str} +{name_str} *{def_val_str}')
bare_array_re = re.compile(rf' *{array_str} +{name_str} *{def_val_str}')
bare_member_re = re.compile(rf' *{type_str} +{name_str} *{def_val_str} *{unit_str}')
bare_array_re = re.compile(rf' *{array_str} +{name_str} *{def_val_str} *{unit_str}')

@staticmethod
def _parse_with_regexps(string, regexps_callbacks):
Expand All @@ -60,7 +60,6 @@ def _parse_with_regexps(string, regexps_callbacks):
result = rgx.match(string)
if result:
return callback(result)

raise DefinitionError(f"'{string}' is not a valid member definition. Check syntax of the member definition.")

@staticmethod
Expand All @@ -79,14 +78,14 @@ def _full_member_conv(result):
@staticmethod
def _bare_array_conv(result):
"""MemberVariable construction for array members without docstring"""
typ, size, name, def_val = result.groups()
return MemberVariable(name=name, array_type=typ, array_size=size, default_val=def_val)
typ, size, name, def_val, unit = result.groups()
return MemberVariable(name=name, array_type=typ, array_size=size, unit=unit, default_val=def_val)

@staticmethod
def _bare_member_conv(result):
"""MemberVarible construction for members without docstring"""
klass, name, def_val = result.groups()
return MemberVariable(name=name, type=klass, default_val=def_val)
klass, name, def_val, unit = result.groups()
return MemberVariable(name=name, type=klass, unit=unit, default_val=def_val)

def parse(self, string, require_description=True):
"""Parse the passed string"""
Expand Down
8 changes: 4 additions & 4 deletions tests/datalayout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ options :
components :
SimpleStruct:
Members:
- int x
- int y
- int z
- std::array<int, 4> p
- int x [mm]
- int y [mm]
- int z [mm]
- std::array<int, 4> p [mm]
# can also add c'tors:
ExtraCode :
declaration: "
Expand Down

0 comments on commit 42edf8d

Please sign in to comment.