class_docstr: Synchronize by starting at a line that matches the given regex pattern.
class_docstr_tok: ["Synchronize","by","starting","at","a","line","that","matches","the","given","regex","pattern","."]
docstr: Scan backwards, and find a possible position to start.
docstr_tok: ["Scan","backwards",",","and","find","a","possible","position","to","start","."]
code: def get_sync_start_position(
      self, document: Document, lineno: int
  ) -> tuple[int, int]:
      """
      Scan backwards, and find a possible position to start.
      """
      pattern = self._compiled_pattern
      lines = document.lines
  
      # Scan upwards, until we find a point where we can start the syntax
      # synchronization.
      for i in range(lineno, max(-1, lineno - self.MAX_BACKWARDS), -1):
          match = pattern.match(lines[i])
          if match:
              return i, match.start()
  
      # No synchronization point found. If we aren't that far from the
      # beginning, start at the very beginning, otherwise, just try to start
      # at the current line.
      if lineno < self.FROM_START_IF_NO_SYNC_POS_FOUND:
          return 0, 0
      else:
          return lineno, 0
  
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 2 for calling the RegexSync obj's underlying member method code with example usage: obj.get_sync_start_position(document, lineno) and returns: int,  int, lineno,  int, i,  match