pyebnf/util.py
def get_line_and_char(newline_positions, position):
  """Given a list of newline positions, and an offset from the start of the source code
  that newline_positions was pulled from, return a 2-tuple of (line, char) coordinates.
  """
  if newline_positions:
    for line_no, nl_pos in enumerate(newline_positions):
      if nl_pos >= position:
        if line_no == 0:
          return (line_no, position)
        else:
          return (line_no, position - newline_positions[line_no - 1] - 1)
    return (line_no + 1, position - newline_positions[-1] - 1)
  else:
    return (0, position)
def get_line_and_char(newline_positions, position):
  """Given a list of newline positions, and an offset from the start of the source code
  that newline_positions was pulled from, return a 2-tuple of (line, char) coordinates.
  """
  if newline_positions:
    for line_no, nl_pos in enumerate(newline_positions):
      if nl_pos >= position:
        if line_no == 0:
          return (line_no, position)
        else:
          return (line_no, position - newline_positions[line_no - 1] - 1)
    return (line_no + 1, position - newline_positions[-1] - 1)
  else:
    return (0, position)
Given a list of newline positions, and an offset from the start of the source code
  that newline_positions was pulled from, return a 2-tuple of (line, char) coordinates.