Class: Puppet::Pops::Parser::Locator
- Defined in:
- lib/puppet/pops/parser/locator.rb
Overview
Helper class that keeps track of where line breaks are located and can answer questions about positions.
Direct Known Subclasses
Defined Under Namespace
Classes: AbstractLocator, Locator19, LocatorForChars, SubLocator
Class Method Summary collapse
-
.locator(string, file, index = nil, char_offsets = false) ⇒ Object
Creates, or recreates a Locator.
Instance Method Summary collapse
-
#char_length(offset, end_offset) ⇒ Object
Returns the length measured in number of characters from the given start and end byte offseta.
-
#char_offset(byte_offset) ⇒ Object
Returns the character offset for a given reported offset.
-
#extract_text(offset, length) ⇒ Object
Extracts the text from offset with given length (measured in what the locator uses for offset).
-
#file ⇒ Object
Returns the file name associated with the string content.
-
#line_for_offset(offset) ⇒ Object
Returns the line number (first line is 1) for the given offset.
-
#line_index ⇒ Object
Returns the line index - an array of line offsets for the start position of each line, starting at 0 for the first line.
-
#offset_on_line(offset) ⇒ Object
Returns the offset on line (first offset on a line is 0).
-
#pos_on_line(offset) ⇒ Object
Returns the position on line (first position on a line is 1).
-
#string ⇒ Object
Returns the string content.
Class Method Details
.locator(string, file, index = nil, char_offsets = false) ⇒ Object
Creates, or recreates a Locator. A Locator is created if index is not given (a scan is then performed of the given source string.
9 10 11 12 13 14 15 |
# File 'lib/puppet/pops/parser/locator.rb', line 9 def self.locator(string, file, index = nil, char_offsets = false) if char_offsets LocatorForChars.new(string, file, index) else Locator19.new(string, file, index) end end |
Instance Method Details
#char_length(offset, end_offset) ⇒ Object
Returns the length measured in number of characters from the given start and end byte offseta
43 44 |
# File 'lib/puppet/pops/parser/locator.rb', line 43 def char_length(offset, end_offset) end |
#char_offset(byte_offset) ⇒ Object
Returns the character offset for a given reported offset
39 40 |
# File 'lib/puppet/pops/parser/locator.rb', line 39 def char_offset(byte_offset) end |
#extract_text(offset, length) ⇒ Object
Extracts the text from offset with given length (measured in what the locator uses for offset)
52 53 |
# File 'lib/puppet/pops/parser/locator.rb', line 52 def extract_text(offset, length) end |
#file ⇒ Object
Returns the file name associated with the string content
18 19 |
# File 'lib/puppet/pops/parser/locator.rb', line 18 def file end |
#line_for_offset(offset) ⇒ Object
Returns the line number (first line is 1) for the given offset
30 31 |
# File 'lib/puppet/pops/parser/locator.rb', line 30 def line_for_offset(offset) end |
#line_index ⇒ Object
Returns the line index - an array of line offsets for the start position of each line, starting at 0 for the first line.
58 59 |
# File 'lib/puppet/pops/parser/locator.rb', line 58 def line_index() end |
#offset_on_line(offset) ⇒ Object
Returns the offset on line (first offset on a line is 0).
35 36 |
# File 'lib/puppet/pops/parser/locator.rb', line 35 def offset_on_line(offset) end |
#pos_on_line(offset) ⇒ Object
Returns the position on line (first position on a line is 1)
26 27 |
# File 'lib/puppet/pops/parser/locator.rb', line 26 def pos_on_line(offset) end |
#string ⇒ Object
Returns the string content
22 23 |
# File 'lib/puppet/pops/parser/locator.rb', line 22 def string end |