Class: Puppet::Pops::Parser::Locator

Inherits:
Object
  • Object
show all
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

AbstractLocator, SubLocator

Defined Under Namespace

Classes: AbstractLocator, Locator19, LocatorForChars, SubLocator

Class Method Summary collapse

Instance Method Summary collapse

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.



7
8
9
10
11
12
13
# File 'lib/puppet/pops/parser/locator.rb', line 7

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 reported offset



41
42
# File 'lib/puppet/pops/parser/locator.rb', line 41

def char_length(offset, end_offset)
end

#char_offset(byte_offset) ⇒ Object

Returns the character offset for a given reported offset



37
38
# File 'lib/puppet/pops/parser/locator.rb', line 37

def char_offset(byte_offset)
end

#fileObject

Returns the file name associated with the string content



16
17
# File 'lib/puppet/pops/parser/locator.rb', line 16

def file
end

#line_for_offset(offset) ⇒ Object

Returns the line number (first line is 1) for the given offset



28
29
# File 'lib/puppet/pops/parser/locator.rb', line 28

def line_for_offset(offset)
end

#line_indexObject

Returns the line index - an array of line offsets for the start position of each line, starting at 0 for the first line.



47
48
# File 'lib/puppet/pops/parser/locator.rb', line 47

def line_index()
end

#offset_on_line(offset) ⇒ Object

Returns the offset on line (first offset on a line is 0).



33
34
# File 'lib/puppet/pops/parser/locator.rb', line 33

def offset_on_line(offset)
end

#pos_on_line(offset) ⇒ Object

Returns the position on line (first position on a line is 1)



24
25
# File 'lib/puppet/pops/parser/locator.rb', line 24

def pos_on_line(offset)
end

#stringObject

Returns the string content



20
21
# File 'lib/puppet/pops/parser/locator.rb', line 20

def string
end