improve parsing of property values; fixes #138
This commit is contained in:
parent
555831380d
commit
52e9667ec4
@ -115,6 +115,7 @@ class GraceEditor:
|
||||
return s
|
||||
|
||||
def parse(self, filename: str | pathlib.Path):
|
||||
self.clear()
|
||||
self.file = pathlib.Path(filename)
|
||||
|
||||
# we start always with the header
|
||||
@ -354,8 +355,8 @@ class GraceHeader(list):
|
||||
class GraceProperties(list):
|
||||
_RE_ENTRY = re.compile(r'(?!.*(on|off)$)' # ignore lines that end with on or off
|
||||
r'@\s*(?P<graph>[gs]\d+)?\s*' # @ maybe followed by g0 or s12
|
||||
r'(?P<key>[\w\s]*)\s+' # key: stops at last space unless comma-separated values
|
||||
r'(?P<val>(?:\s*[\d\w.+-]+\s*,)*\s*[\\{}\"\w.+\- ]+)', # one value, maybe more with commas
|
||||
r'(?P<key>[\w\s]*\w)*\s+' # key: stops at last space unless comma-separated values
|
||||
r'(?P<val>(?<!^)(?:\s*[\d\w.+-]+\s*,)*\s*[\S ]+)', # one value, maybe more with commas
|
||||
re.IGNORECASE | re.VERBOSE)
|
||||
_RE_ONOFF = re.compile(r'@\s(?P<graph>[gs]\d+)*\s*(?P<val>[\w\s]*)\s+(on|off)')
|
||||
|
||||
@ -730,7 +731,11 @@ class GraceRegion(list):
|
||||
|
||||
|
||||
def _convert_to_value(parse_string):
|
||||
tuples = parse_string.split(',')
|
||||
if re.match(r'\".*\"', parse_string):
|
||||
tuples = [parse_string]
|
||||
else:
|
||||
tuples = parse_string.split(',')
|
||||
|
||||
for i, v in enumerate(tuples):
|
||||
v = v.strip()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user