changeset 72:72fb4eb79973 draft

Add better messages to State asserts
author Lewin Bormann <lbo@spheniscida.de>
date Sat, 25 May 2019 23:14:10 +0200
parents ae904cd0859e
children 28e317b97a64
files pcombinators/state.py
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pcombinators/state.py	Sat May 25 23:11:45 2019 +0200
+++ b/pcombinators/state.py	Sat May 25 23:14:10 2019 +0200
@@ -50,8 +50,8 @@
 
     def release(self, hold):
         """Release a hold. Generally called when a parser was successful."""
-        assert hold.total_index >= 0, 'double release'
-        assert self._holds[-1] == hold.total_index
+        assert hold.total_index >= 0, 'BUG: double reset/release'
+        assert self._holds[-1] == hold.total_index, 'BUG: releasing bad ordered hold'
         self._holds.pop()
         self._maybe_collect()
         hold.total_index = -1
@@ -61,8 +61,8 @@
         # Reset is only allowed when this hold is the latest hold or later.
         # It is possible that a caller accidentally released a hold that it
         # now wants to reset to.
-        assert hold.total_index >= 0, 'double reset'
-        assert self._holds[-1] == hold.total_index
+        assert hold.total_index >= 0, 'BUG: double reset/release'
+        assert self._holds[-1] == hold.total_index, 'BUG: reset/release in bad order'
         self._reset_index(hold.total_index)
         self._holds.pop()
         hold.total_index = -2