class_docstr: Compiles a grammar. This will take the parse tree of a regular expression
  and compile the grammar.
  
  :param root_node: :class~`.regex_parser.Node` instance.
  :param escape_funcs: `dict` mapping variable names to escape callables.
  :param unescape_funcs: `dict` mapping variable names to unescape callables.
class_docstr_tok: ["Compiles","a","grammar",".","This","will","take","the","parse","tree","of","a","regular","expression","and","compile","the","grammar",".",":","param","root_node",":",":","class~","`",".regex_parser.Node","`","instance",".",":","param","escape_funcs",":","`","dict","`","mapping","variable","names","to","escape","callables",".",":","param","unescape_funcs",":","`","dict","`","mapping","variable","names","to","unescape","callables","."]
code: def __init__(
      self,
      root_node: Node,
      escape_funcs: EscapeFuncDict | None = None,
      unescape_funcs: EscapeFuncDict | None = None,
  ) -> None:
      self.root_node = root_node
      self.escape_funcs = escape_funcs or {}
      self.unescape_funcs = unescape_funcs or {}
  
      #: Dictionary that will map the regex names to Node instances.
      self._group_names_to_nodes: dict[
          str, str
      ] = {}  # Maps regex group names to varnames.
      counter = [0]
  
      def create_group_func(node: Variable) -> str:
          name = "n%s" % counter[0]
          self._group_names_to_nodes[name] = node.varname
          counter[0] += 1
          return name
  
      # Compile regex strings.
      self._re_pattern = "^%s$" % self._transform(
          root_node, create_group_func
      )
      self._re_prefix_patterns = list(
          self._transform_prefix(root_node, create_group_func)
      )
  
      # Compile the regex itself.
      flags = (
          re.DOTALL
      )  # Note that we don't need re.MULTILINE! (^ and $
      # still represent the start and end of input text.)
      self._re = re.compile(self._re_pattern, flags)
      self._re_prefix = [
          re.compile(t, flags) for t in self._re_prefix_patterns
      ]
  
      # We compile one more set of regexes, similar to `_re_prefix`, but accept any trailing
      # input. This will ensure that we can still highlight the input correctly, even when the
      # input contains some additional characters at the end that don't match the grammar.)
      self._re_prefix_with_trailing_input = [
          re.compile(
              r"(?:{})(?P<{}>.*?)$".format(
                  t.rstrip("$"), _INVALID_TRAILING_INPUT
              ),
              flags,
          )
          for t in self._re_prefix_patterns
      ]
  
imports: from __future__ import annotations
  import re
  from typing import Callable, Dict, Iterable, Iterator, Pattern
  from typing import Match
  from .regex_parser import AnyNode, Lookahead, Node, NodeSequence, Regex, Repeat, Variable, parse_regex, tokenize_regex
label_desc: Use image node_id 1 to create a new _CompiledGrammar object  with example: obj = _CompiledGrammar(root_node, escape_funcs, unescape_funcs)