A Sublocator locates a concrete locator (subspace) in a virtual space. The `#leading_line_count` is the (virtual) number of lines preceding the first line in the concrete locator. The `#leading_offset` is the (virtual) byte offset of the first byte in the concrete locator. The `#leading_line_offset` is the (virtual) offset / margin in characters for each line.
This illustrates characters in the sublocator (`.`) inside the subspace (`X`):
1:XXXXXXXX 2:XXXX.... .. ... .. 3:XXXX. . .... .. 4:XXXX............
This sublocator would be configured with #leading_line_count = 1, #leading_offset=8, and #leading_line_offset=4
Note that #leading_offset must be the same for all lines and measured in characters.
Given offsets are offsets in the subspace
# File lib/puppet/pops/parser/locator.rb, line 136 def char_length(offset, end_offset) effective_line = @locator.line_for_offset(end_offset) - @locator.line_for_offset(offset) locator.char_length(offset, end_offset) + (effective_line * @leading_line_offset) end
Given offset is offset in the subspace
# File lib/puppet/pops/parser/locator.rb, line 130 def char_offset(offset) effective_line = @locator.line_for_offset(offset) locator.char_offset(offset) + (effective_line * @leading_line_offset) + @leading_offset end
# File lib/puppet/pops/parser/locator.rb, line 111 def file @locator.file end
Given offset is offset in the subspace
# File lib/puppet/pops/parser/locator.rb, line 120 def line_for_offset(offset) @locator.line_for_offset(offset) + @leading_line_count end
Given offset is offset in the subspace
# File lib/puppet/pops/parser/locator.rb, line 125 def offset_on_line(offset) @locator.offset_on_line(offset) + @leading_line_offset end
# File lib/puppet/pops/parser/locator.rb, line 141 def pos_on_line(offset) offset_on_line(offset) +1 end
# File lib/puppet/pops/parser/locator.rb, line 115 def string @locator.string end
# File lib/puppet/pops/parser/locator.rb, line 104 def initialize(locator, leading_line_count, leading_offset, leading_line_offset) @locator = locator @leading_line_count = leading_line_count @leading_offset = leading_offset @leading_line_offset = leading_line_offset end
# File lib/puppet/pops/parser/locator.rb, line 97 def self.sub_locator(string, file, leading_line_count, leading_offset, leading_line_offset) self.new(Puppet::Pops::Parser::Locator.locator(string, file), leading_line_count, leading_offset, leading_line_offset) end