Track the current and nested state of the parser. This utility class is used to track the state of the `BlockParser` and support multiple levels if nesting. It's just a simple API wrapped around a list. Each time a state is set, that state is appended to the end of the list. Each t
| 39 | |
| 40 | |
| 41 | class State(list): |
| 42 | """ Track the current and nested state of the parser. |
| 43 | |
| 44 | This utility class is used to track the state of the `BlockParser` and |
| 45 | support multiple levels if nesting. It's just a simple API wrapped around |
| 46 | a list. Each time a state is set, that state is appended to the end of the |
| 47 | list. Each time a state is reset, that state is removed from the end of |
| 48 | the list. |
| 49 | |
| 50 | Therefore, each time a state is set for a nested block, that state must be |
| 51 | reset when we back out of that level of nesting or the state could be |
| 52 | corrupted. |
| 53 | |
| 54 | While all the methods of a list object are available, only the three |
| 55 | defined below need be used. |
| 56 | |
| 57 | """ |
| 58 | |
| 59 | def set(self, state: Any): |
| 60 | """ Set a new state. """ |
| 61 | self.append(state) |
| 62 | |
| 63 | def reset(self) -> None: |
| 64 | """ Step back one step in nested state. """ |
| 65 | self.pop() |
| 66 | |
| 67 | def isstate(self, state: Any) -> bool: |
| 68 | """ Test that top (current) level is of given state. """ |
| 69 | if len(self): |
| 70 | return self[-1] == state |
| 71 | else: |
| 72 | return False |
| 73 | |
| 74 | |
| 75 | class BlockParser: |