Change-Id: I89d3d01db51a78a0ff543650d95486208eb91d26
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
__author__ = "Philippe Proulx"
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
__author__ = "Philippe Proulx"
__all__ = [
"ByteOrder",
"parse",
__all__ = [
"ByteOrder",
"parse",
)
return int(m.group(0), 0)
)
return int(m.group(0), 0)
- # Tries to parse a repeatable item followed or not by a repetition,
- # returning an item on success.
- def _try_parse_item(self):
+ # Tries to parse an item, possibly followed by a repetition,
+ # returning `True` on success.
+ #
+ # Appends any parsed item to `items`.
+ def _try_append_item(self, items: List[_Item]):
self._skip_ws_and_comments()
# Parse a base item
self._skip_ws_and_comments()
# Parse a base item
if item is None:
# No item
if item is None:
# No item
# Parse repetition if the base item is repeatable
if isinstance(item, _RepableItem):
rep = self._try_parse_rep()
if rep == 0:
# Parse repetition if the base item is repeatable
if isinstance(item, _RepableItem):
rep = self._try_parse_rep()
if rep == 0:
+ # No item, but that's okay
+ return True
elif rep > 1:
# Convert to repetition item
item = _Rep(item, rep, self._text_loc)
elif rep > 1:
# Convert to repetition item
item = _Rep(item, rep, self._text_loc)
+ items.append(item)
+ return True
# Parses and returns items, skipping whitespaces, insignificant
# symbols, and comments when allowed, and stopping at the first
# Parses and returns items, skipping whitespaces, insignificant
# symbols, and comments when allowed, and stopping at the first
items = [] # type: List[_Item]
while self._isnt_done():
items = [] # type: List[_Item]
while self._isnt_done():
- # Try to parse item
- item = self._try_parse_item()
-
- if item is not None:
- # Append new item
- items.append(item)
- continue
-
- # Unknown at this point
- break
+ # Try to append item
+ if not self._try_append_item(items):
+ # Unknown at this point
+ break
[tool.poetry]
name = 'normand'
[tool.poetry]
name = 'normand'
description = 'Text-to-binary processor with its own language'
license = 'MIT'
authors = ['Philippe Proulx <eeppeliteloop@gmail.com>']
description = 'Text-to-binary processor with its own language'
license = 'MIT'
authors = ['Philippe Proulx <eeppeliteloop@gmail.com>']