Sha256: 8fe6e466fe6f7ec908552ffd08f81252e6bc806a042eb3b33eae02ca6d84001d
Contents?: true
Size: 989 Bytes
Versions: 57
Compression:
Stored size: 989 Bytes
Contents
# Adapted from https://github.com/whitequark/parser/blob/master/lib/parser/source/buffer.rb module CC module Analyzer class SourceBuffer attr_reader :name attr_reader :source def initialize(name, source) @name = name @source = source end def decompose_position(position) line_no, line_begin = line_for(position) [ 1 + line_no, position - line_begin ] end def line_count @source.lines.count end private def line_for(position) line_begins.bsearch do |line, line_begin| line_begin <= position end end def line_begins unless @line_begins @line_begins, index = [ [ 0, 0 ] ], 1 @source.each_char do |char| if char == "\n" @line_begins.unshift [ @line_begins.length, index ] end index += 1 end end @line_begins end end end end
Version data entries
57 entries across 57 versions & 1 rubygems