Skip to content

Commit

Permalink
Fix regex for parsing records
Browse files Browse the repository at this point in the history
Now accepts records with these features:
- no quotes around the record name
- no whitespace between record() and { ... }

Also adds raise of RecordError if the record does not parse.
  • Loading branch information
gilesknap committed Feb 21, 2024
1 parent 0702019 commit c68696e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pvi/_convert/_template_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ def _parse_record(self, record_str: str) -> Tuple:
# info(autosaveFields, "VAL")

# https://regex101.com/r/MZz1oa
record_parser = re.compile(r'record\((\w+),\s*"([^"]+)"\)\s*{([^}]*)}')
return re.findall(record_parser, record_str)[0]
record_parser = re.compile(r'record\((\w+),\s*"?([^"]+)"?\)\s*{([^}]*)}')
matches = re.findall(record_parser, record_str)
if len(matches) != 1:
raise RecordError(f"Parse failed on record: {record_str}")
return matches[0]

def _extract_fields(self, fields_str: str) -> List[Tuple[str, str]]:
# extract two groups from a field e.g.
Expand Down

0 comments on commit c68696e

Please sign in to comment.