class_docstr: Lexer that calls a pygments lexer.
  
  Example::
  
      from pygments.lexers.html import HtmlLexer
      lexer = PygmentsLexer(HtmlLexer)
  
  Note: Don't forget to also load a Pygments compatible style. E.g.::
  
      from prompt_toolkit.styles.from_pygments import style_from_pygments_cls
      from pygments.styles import get_style_by_name
      style = style_from_pygments_cls(get_style_by_name('monokai'))
  
  :param pygments_lexer_cls: A `Lexer` from Pygments.
  :param sync_from_start: Start lexing at the start of the document. This
      will always give the best results, but it will be slow for bigger
      documents. (When the last part of the document is display, then the
      whole document will be lexed by Pygments on every key stroke.) It is
      recommended to disable this for inputs that are expected to be more
      than 1,000 lines.
  :param syntax_sync: `SyntaxSync` object.
class_docstr_tok: ["Lexer","that","calls","a","pygments","lexer",".","Example",":",":","from","pygments.lexers.html","import","HtmlLexer","lexer","=","PygmentsLexer","(","HtmlLexer",")","Note",":","Do","n't","forget","to","also","load","a","Pygments","compatible","style",".","E.g",".",":",":","from","prompt_toolkit.styles.from_pygments","import","style_from_pygments_cls","from","pygments.styles","import","get_style_by_name","style","=","style_from_pygments_cls","(","get_style_by_name","(","'monokai","'",")",")",":","param","pygments_lexer_cls",":","A","`","Lexer","`","from","Pygments",".",":","param","sync_from_start",":","Start","lexing","at","the","start","of","the","document",".","This","will","always","give","the","best","results",",","but","it","will","be","slow","for","bigger","documents",".","(","When","the","last","part","of","the","document","is","display",",","then","the","whole","document","will","be","lexed","by","Pygments","on","every","key","stroke",".",")","It","is","recommended","to","disable","this","for","inputs","that","are","expected","to","be","more","than","1,000","lines",".",":","param","syntax_sync",":","`","SyntaxSync","`","object","."]
docstr: Create a lexer function that takes a line number and returns the list
  of (style_str, text) tuples as the Pygments lexer returns for that line.
docstr_tok: ["Create","a","lexer","function","that","takes","a","line","number","and","returns","the","list","of","(","style_str",",","text",")","tuples","as","the","Pygments","lexer","returns","for","that","line","."]
code: def lex_document(
      self, document: Document
  ) -> Callable[[int], StyleAndTextTuples]:
      """
      Create a lexer function that takes a line number and returns the list
      of (style_str, text) tuples as the Pygments lexer returns for that line.
      """
      LineGenerator = Generator[
          Tuple[int, StyleAndTextTuples], None, None
      ]
  
      # Cache of already lexed lines.
      cache: dict[int, StyleAndTextTuples] = {}
  
      # Pygments generators that are currently lexing.
      # Map lexer generator to the line number.
      line_generators: dict[LineGenerator, int] = {}
  
      def get_syntax_sync() -> SyntaxSync:
          "The Syntax synchronization object that we currently use."
          if self.sync_from_start():
              return SyncFromStart()
          else:
              return self.syntax_sync
  
      def find_closest_generator(i: int) -> LineGenerator | None:
          "Return a generator close to line 'i', or None if none was found."
          for generator, lineno in line_generators.items():
              if (
                  lineno < i
                  and i - lineno < self.REUSE_GENERATOR_MAX_DISTANCE
              ):
                  return generator
          return None
  
      def create_line_generator(
          start_lineno: int, column: int = 0
      ) -> LineGenerator:
          """
          Create a generator that yields the lexed lines.
          Each iteration it yields a (line_number, [(style_str, text), ...]) tuple.
          """
  
          def get_text_fragments() -> Iterable[tuple[str, str]]:
              text = "\n".join(document.lines[start_lineno:])[column:]
  
              # We call `get_text_fragments_unprocessed`, because `get_tokens` will
              # still replace \r\n and \r by \n.  (We don't want that,
              # Pygments should return exactly the same amount of text, as we
              # have given as input.)
              for _, t, v in self.pygments_lexer.get_tokens_unprocessed(
                  text
              ):
                  # Turn Pygments `Token` object into prompt_toolkit style
                  # strings.
                  yield _token_cache[t], v
  
          yield from enumerate(
              split_lines(list(get_text_fragments())), start_lineno
          )
  
      def get_generator(i: int) -> LineGenerator:
          """
          Find an already started generator that is close, or create a new one.
          """
          # Find closest line generator.
          generator = find_closest_generator(i)
          if generator:
              return generator
  
          # No generator found. Determine starting point for the syntax
          # synchronization first.
  
          # Go at least x lines back. (Make scrolling upwards more
          # efficient.)
          i = max(0, i - self.MIN_LINES_BACKWARDS)
  
          if i == 0:
              row = 0
              column = 0
          else:
              row, column = get_syntax_sync().get_sync_start_position(
                  document, i
              )
  
          # Find generator close to this point, or otherwise create a new one.
          generator = find_closest_generator(i)
          if generator:
              return generator
          else:
              generator = create_line_generator(row, column)
  
          # If the column is not 0, ignore the first line. (Which is
          # incomplete. This happens when the synchronization algorithm tells
          # us to start parsing in the middle of a line.)
          if column:
              next(generator)
              row += 1
  
          line_generators[generator] = row
          return generator
  
      def get_line(i: int) -> StyleAndTextTuples:
          "Return the tokens for a given line number."
          try:
              return cache[i]
          except KeyError:
              generator = get_generator(i)
  
              # Exhaust the generator, until we find the requested line.
              for num, line in generator:
                  cache[num] = line
                  if num == i:
                      line_generators[generator] = i
  
                      # Remove the next item from the cache.
                      # (It could happen that it's already there, because of
                      # another generator that started filling these lines,
                      # but we want to synchronize these lines with the
                      # current lexer's state.)
                      if num + 1 in cache:
                          del cache[num + 1]
  
                      return cache[num]
          return []
  
      return get_line
  
imports: from __future__ import annotations
  import re
  from abc import ABCMeta, abstractmethod
  from typing import TYPE_CHECKING, Callable, Dict, Generator, Iterable, Tuple
  from prompt_toolkit.document import Document
  from prompt_toolkit.filters import FilterOrBool, to_filter
  from prompt_toolkit.formatted_text.base import StyleAndTextTuples
  from prompt_toolkit.formatted_text.utils import split_lines
  from prompt_toolkit.styles.pygments import pygments_token_to_classname
  from .base import Lexer, SimpleLexer
label_desc: Use image node_id 3 for calling the PygmentsLexer obj's underlying member method code with example usage: obj.lex_document(document) and returns: get_line, None, generator, list, SyncFromStart, self, generator, generator, cache, generator, cache