mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Yielded structures now include the indentation level.
This commit is contained in:
parent
780fd4e614
commit
651f0d05db
@ -32,7 +32,7 @@ DEFINITION_SYNTAX = re.compile(r"""^
|
|||||||
""", re.VERBOSE)
|
""", re.VERBOSE)
|
||||||
|
|
||||||
Definition = namedtuple("Definition", ("var_assign", "address", "length", "eval", "description", "type", "expects", "asserts"))
|
Definition = namedtuple("Definition", ("var_assign", "address", "length", "eval", "description", "type", "expects", "asserts"))
|
||||||
Structure = namedtuple("Structure", ("description", "value", "unexpected"))
|
Structure = namedtuple("Structure", ("level", "description", "value", "unexpected"))
|
||||||
|
|
||||||
class StructParser:
|
class StructParser:
|
||||||
def __init__(self, struct_defs):
|
def __init__(self, struct_defs):
|
||||||
@ -56,7 +56,8 @@ class StructParser:
|
|||||||
Yields:
|
Yields:
|
||||||
Named structure tuples,
|
Named structure tuples,
|
||||||
attributes:
|
attributes:
|
||||||
description: The description from the structure definition used.
|
level: The indentation level from the structure definition.
|
||||||
|
description: The description from the structure definition.
|
||||||
value: Parsed value of this structure occurrence in the binary data. The type of this is specified by the type specified in the structure definition.
|
value: Parsed value of this structure occurrence in the binary data. The type of this is specified by the type specified in the structure definition.
|
||||||
unexpected: None if no expects defined, True if any expects are False, False if all expects are True.
|
unexpected: None if no expects defined, True if any expects are False, False if all expects are True.
|
||||||
Raises:
|
Raises:
|
||||||
@ -207,7 +208,7 @@ class StructParser:
|
|||||||
|
|
||||||
if def_.var_assign is not None:
|
if def_.var_assign is not None:
|
||||||
self._variables[def_.var_assign] = value
|
self._variables[def_.var_assign] = value
|
||||||
yield Structure(def_.description, value, unexpected)
|
yield Structure(stack_level, def_.description, value, unexpected)
|
||||||
|
|
||||||
if children:
|
if children:
|
||||||
yield from self._parse_struct_occurrences(stream, children, stack_level+1, value)
|
yield from self._parse_struct_occurrences(stream, children, stack_level+1, value)
|
||||||
|
Loading…
Reference in New Issue
Block a user