(self: P)
| 17 | # Decorator to wrap grammar methods. |
| 18 | # Resets position if `func` returns None. |
| 19 | def contextual_wrapper(self: P) -> N | None: |
| 20 | begin = self.getpos() |
| 21 | res = func(self) |
| 22 | if res is None: |
| 23 | self.setpos(begin) |
| 24 | return None |
| 25 | end = self.getpos() |
| 26 | res.context = Context(begin, end, self) |
| 27 | return res |
| 28 | |
| 29 | return contextual_wrapper |
| 30 |