Method: Parser::Source::Buffer#decompose_position

Defined in:
lib/parser/source/buffer.rb

#decompose_position(position) ⇒ [Integer, Integer]

Convert a character index into the source to a [line, column] tuple.

Parameters:

  • position (Integer)

Returns:

  • ([Integer, Integer])

    [line, column]

[View source] [View on GitHub]

222
223
224
225
226
227
# File 'lib/parser/source/buffer.rb', line 222

def decompose_position(position)
  line_index = line_index_for_position(position)
  line_begin = line_begins[line_index]

  [ @first_line + line_index , position - line_begin ]
end