Class: Puppet::Pops::Parser::Locator::SubLocator
- Inherits:
-
Puppet::Pops::Parser::Locator
- Object
- Puppet::Pops::Parser::Locator
- Puppet::Pops::Parser::Locator::SubLocator
- Defined in:
- lib/puppet/pops/parser/locator.rb
Overview
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.
Instance Attribute Summary collapse
- #leading_line_count ⇒ Object readonly
- #leading_line_offset ⇒ Object readonly
- #leading_offset ⇒ Object readonly
- #locator ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#char_length(offset, end_offset) ⇒ Object
Given offsets are offsets in the subspace.
-
#char_offset(offset) ⇒ Object
Given offset is offset in the subspace.
- #file ⇒ Object
-
#initialize(locator, leading_line_count, leading_offset, leading_line_offset) ⇒ SubLocator
constructor
A new instance of SubLocator.
-
#line_for_offset(offset) ⇒ Object
Given offset is offset in the subspace.
-
#offset_on_line(offset) ⇒ Object
Given offset is offset in the subspace.
- #pos_on_line(offset) ⇒ Object
- #string ⇒ Object
Methods inherited from Puppet::Pops::Parser::Locator
#extract_text, #line_index, locator
Constructor Details
#initialize(locator, leading_line_count, leading_offset, leading_line_offset) ⇒ SubLocator
Returns a new instance of SubLocator.
89 90 91 92 93 94 |
# File 'lib/puppet/pops/parser/locator.rb', line 89 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 |
Instance Attribute Details
#leading_line_count ⇒ Object (readonly)
78 79 80 |
# File 'lib/puppet/pops/parser/locator.rb', line 78 def leading_line_count @leading_line_count end |
#leading_line_offset ⇒ Object (readonly)
80 81 82 |
# File 'lib/puppet/pops/parser/locator.rb', line 80 def leading_line_offset @leading_line_offset end |
#leading_offset ⇒ Object (readonly)
79 80 81 |
# File 'lib/puppet/pops/parser/locator.rb', line 79 def leading_offset @leading_offset end |
#locator ⇒ Object (readonly)
77 78 79 |
# File 'lib/puppet/pops/parser/locator.rb', line 77 def locator @locator end |
Class Method Details
.sub_locator(string, file, leading_line_count, leading_offset, leading_line_offset) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/puppet/pops/parser/locator.rb', line 82 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 |
Instance Method Details
#char_length(offset, end_offset) ⇒ Object
Given offsets are offsets in the subspace
121 122 123 124 |
# File 'lib/puppet/pops/parser/locator.rb', line 121 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 |
#char_offset(offset) ⇒ Object
Given offset is offset in the subspace
115 116 117 118 |
# File 'lib/puppet/pops/parser/locator.rb', line 115 def char_offset(offset) effective_line = @locator.line_for_offset(offset) locator.char_offset(offset) + (effective_line * @leading_line_offset) + @leading_offset end |
#file ⇒ Object
96 97 98 |
# File 'lib/puppet/pops/parser/locator.rb', line 96 def file @locator.file end |
#line_for_offset(offset) ⇒ Object
Given offset is offset in the subspace
105 106 107 |
# File 'lib/puppet/pops/parser/locator.rb', line 105 def line_for_offset(offset) @locator.line_for_offset(offset) + @leading_line_count end |
#offset_on_line(offset) ⇒ Object
Given offset is offset in the subspace
110 111 112 |
# File 'lib/puppet/pops/parser/locator.rb', line 110 def offset_on_line(offset) @locator.offset_on_line(offset) + @leading_line_offset end |
#pos_on_line(offset) ⇒ Object
126 127 128 |
# File 'lib/puppet/pops/parser/locator.rb', line 126 def pos_on_line(offset) offset_on_line(offset) +1 end |
#string ⇒ Object
100 101 102 |
# File 'lib/puppet/pops/parser/locator.rb', line 100 def string @locator.string end |