code: def memoize(method: F) -> F:
      """Memoize a symbol method."""
      method_name = method.__name__
  
      def memoize_wrapper(self: "Parser", *args: object) -> Any:
          mark = self._mark()
          key = mark, method_name, args
          # Fast path: cache hit, and not verbose.
          if key in self._cache and not self._verbose:
              tree, endmark = self._cache[key]
              self._reset(endmark)
              return tree
          # Slow path: no cache hit, or verbose.
          verbose = self._verbose
          argsr = ",".join(repr(arg) for arg in args)
          fill = "  " * self._level
          if key not in self._cache:
              if verbose:
                  print(
                      f"{fill}{method_name}({argsr}) ... (looking at {self.showpeek()})"
                  )
              self._level += 1
              tree = method(self, *args)
              self._level -= 1
              if verbose:
                  print(
                      f"{fill}... {method_name}({argsr}) -> {tree!s:.200}"
                  )
              endmark = self._mark()
              self._cache[key] = tree, endmark
          else:
              tree, endmark = self._cache[key]
              if verbose:
                  print(
                      f"{fill}{method_name}({argsr}) -> {tree!s:.200}"
                  )
              self._reset(endmark)
          return tree
  
      memoize_wrapper.__wrapped__ = method  # type: ignore[attr-defined]
      return cast(F, memoize_wrapper)
  
imports: import argparse
  import sys
  import time
  import token
  import tokenize
  import traceback
  from abc import abstractmethod
  from typing import Any, Callable, ClassVar, Dict, Optional, Tuple, Type, TypeVar, cast
  from pegen.tokenizer import Mark, Tokenizer, exact_token_types
label_desc: Use image node_id 2 for calling a global function with example usage: memoize(method) and returns: cast, tree, tree