Skip to content

Commit

Permalink
Merge pull request #21 from Demon000/improve-dts-string-prop-value-pa…
Browse files Browse the repository at this point in the history
…rsing

Improve dts string prop value parsing
  • Loading branch information
molejar authored Sep 18, 2024
2 parents d2f1d77 + 52b97c5 commit 6039b9b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions fdt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,30 @@ def parse_dts(text: str, root_dir: str = '') -> FDT:
raise NotImplementedError("Not implemented property value: /bits/")
else:
prop_obj = PropStrings(prop_name)
for prop in prop_value.split('",'):
prop = prop.replace('"', "")
prop = prop.strip()
if len(prop) > 0:
expect_open = True
in_prop = False
prop = ''
for c in prop_value:
if c == '"' and not in_prop and expect_open:
prop = ''
in_prop = True
elif c == '"' and in_prop:
if not len(prop) > 0:
raise ValueError('Empty string')
prop_obj.append(prop)
in_prop = False
expect_open = False
elif in_prop:
prop += c
elif c == ',' and not expect_open:
expect_open = True
elif c == ' ':
continue
else:
raise ValueError(f'Invalid char: {c}')

if expect_open:
raise ValueError('Expected string after ,')
if curnode is not None:
curnode.append(prop_obj)

Expand Down

0 comments on commit 6039b9b

Please sign in to comment.