code: def _escape(source, escape, state):
      # handle escape code in expression
      code = CATEGORIES.get(escape)
      if code:
          return code
      code = ESCAPES.get(escape)
      if code:
          return code
      try:
          c = escape[1:2]
          if c == "x":
              # hexadecimal escape
              escape += source.getwhile(2, HEXDIGITS)
              if len(escape) != 4:
                  raise source.error(
                      "incomplete escape %s" % escape, len(escape)
                  )
              return LITERAL, int(escape[2:], 16)
          elif c == "u" and source.istext:
              # unicode escape (exactly four digits)
              escape += source.getwhile(4, HEXDIGITS)
              if len(escape) != 6:
                  raise source.error(
                      "incomplete escape %s" % escape, len(escape)
                  )
              return LITERAL, int(escape[2:], 16)
          elif c == "U" and source.istext:
              # unicode escape (exactly eight digits)
              escape += source.getwhile(8, HEXDIGITS)
              if len(escape) != 10:
                  raise source.error(
                      "incomplete escape %s" % escape, len(escape)
                  )
              c = int(escape[2:], 16)
              chr(c)  # raise ValueError for invalid code
              return LITERAL, c
          elif c == "N" and source.istext:
              import unicodedata
  
              # named unicode escape e.g. \N{EM DASH}
              if not source.match("{"):
                  raise source.error("missing {")
              charname = source.getuntil("}", "character name")
              try:
                  c = ord(unicodedata.lookup(charname))
              except (KeyError, TypeError):
                  raise source.error(
                      "undefined character name %r" % charname,
                      len(charname) + len(r"\N{}"),
                  ) from None
              return LITERAL, c
          elif c == "0":
              # octal escape
              escape += source.getwhile(2, OCTDIGITS)
              return LITERAL, int(escape[1:], 8)
          elif c in DIGITS:
              # octal escape *or* decimal group reference (sigh)
              if source.next in DIGITS:
                  escape += source.get()
                  if (
                      escape[1] in OCTDIGITS
                      and escape[2] in OCTDIGITS
                      and source.next in OCTDIGITS
                  ):
                      # got three octal digits; this is an octal escape
                      escape += source.get()
                      c = int(escape[1:], 8)
                      if c > 0o377:
                          raise source.error(
                              "octal escape value %s outside of "
                              "range 0-0o377" % escape,
                              len(escape),
                          )
                      return LITERAL, c
              # not an octal escape, so this is a group reference
              group = int(escape[1:])
              if group < state.groups:
                  if not state.checkgroup(group):
                      raise source.error(
                          "cannot refer to an open group", len(escape)
                      )
                  state.checklookbehindgroup(group, source)
                  return GROUPREF, group
              raise source.error(
                  "invalid group reference %d" % group, len(escape) - 1
              )
          if len(escape) == 2:
              if c in ASCIILETTERS:
                  raise source.error(
                      "bad escape %s" % escape, len(escape)
                  )
              return LITERAL, ord(escape[1])
      except ValueError:
          pass
      raise source.error("bad escape %s" % escape, len(escape))
  
imports: from ._constants import *
label_desc: Use image node_id 2 for calling a global function with example usage: _escape(source, escape, state) and returns: code, code, LITERAL,  int, LITERAL,  ord, LITERAL,  int, LITERAL,  c, LITERAL,  c, LITERAL,  int, GROUPREF,  group, LITERAL,  c