code: def contextual(
      func: Callable[[P], N | None]
  ) -> Callable[[P], N | None]:
      # Decorator to wrap grammar methods.
      # Resets position if `func` returns None.
      def contextual_wrapper(self: P) -> N | None:
          begin = self.getpos()
          res = func(self)
          if res is None:
              self.setpos(begin)
              return None
          end = self.getpos()
          res.context = Context(begin, end, self)
          return res
  
      return contextual_wrapper
  
imports: from dataclasses import dataclass, field
  from typing import NamedTuple, Callable, TypeVar, Literal, cast
  import lexer
  from plexer import PLexer
label_desc: Use image node_id 1 for calling a global function with example usage: contextual(func) and returns: contextual_wrapper, res, None