Fix: parse a 0-item repetition v0.1.1
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 27 Sep 2023 17:59:58 +0000 (13:59 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 27 Sep 2023 18:01:18 +0000 (14:01 -0400)
Change-Id: I89d3d01db51a78a0ff543650d95486208eb91d26
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
normand/normand.py
pyproject.toml

index 31c3aff5f134b285db979ebaa08a55b1279d69af..fd308eda4fe02ca3fb0f9ec8b3121ccc9539390e 100644 (file)
@@ -22,7 +22,7 @@
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 __author__ = "Philippe Proulx"
-__version__ = "0.1.0"
+__version__ = "0.1.1"
 __all__ = [
     "ByteOrder",
     "parse",
@@ -863,9 +863,11 @@ class _Parser:
         )
         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
@@ -873,20 +875,21 @@ class _Parser:
 
         if item is None:
             # No item
-            return
+            return False
 
         # Parse repetition if the base item is repeatable
         if isinstance(item, _RepableItem):
             rep = self._try_parse_rep()
 
             if rep == 0:
-                # No item
-                return
+                # No item, but that's okay
+                return True
             elif rep > 1:
                 # Convert to repetition item
                 item = _Rep(item, rep, self._text_loc)
 
-        return item
+        items.append(item)
+        return True
 
     # Parses and returns items, skipping whitespaces, insignificant
     # symbols, and comments when allowed, and stopping at the first
@@ -895,16 +898,10 @@ class _Parser:
         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
 
         return items
 
index ae8c1b35894df659241fb418fa1d63d8a4747dcc..bab57d82717ea5e258294fff78fe01cfdf94cb7a 100644 (file)
@@ -23,7 +23,7 @@
 
 [tool.poetry]
 name = 'normand'
-version = '0.1.0'
+version = '0.1.1'
 description = 'Text-to-binary processor with its own language'
 license = 'MIT'
 authors = ['Philippe Proulx <eeppeliteloop@gmail.com>']
This page took 0.025303 seconds and 4 git commands to generate.