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, Locator18, Locator19, SubLocator
Constant Summary collapse
- RUBY_1_9_3 =
(1 << 16 | 9 << 8 | 3)
- RUBY_2_0_0 =
(2 << 16 | 0 << 8 | 0)
- RUBYVER_ARRAY =
RUBY_VERSION.split(".").collect {|s| s.to_i }
- RUBYVER =
(RUBYVER_ARRAY[0] << 16 | RUBYVER_ARRAY[1] << 8 | RUBYVER_ARRAY[2])
- LOCATOR_VERSION =
locator_version
- MULTIBYTE =
Constant set to true if multibyte is supported (includes multibyte extended regular expressions)
!!(LOCATOR_VERSION == :ruby19 || LOCATOR_VERSION == :ruby20)
Class Method Summary collapse
-
.locator(string, file, index = nil) ⇒ Object
Creates, or recreates a Locator.
-
.locator_version ⇒ Object
Computes a symbol representing which ruby runtime this is running on This implementation will fail if there are more than 255 minor or micro versions of ruby.
Instance Method Summary collapse
-
#char_length(offset, end_offset) ⇒ Object
Returns the length measured in number of characters from the given start and end reported offset.
-
#char_offset(byte_offset) ⇒ Object
Returns the character offset for a given reported 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) ⇒ 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.
30 31 32 33 34 35 36 37 |
# File 'lib/puppet/pops/parser/locator.rb', line 30 def self.locator(string, file, index = nil) case LOCATOR_VERSION when :ruby20, :ruby19 Locator19.new(string, file, index) else Locator18.new(string, file, index) end end |
.locator_version ⇒ Object
Computes a symbol representing which ruby runtime this is running on This implementation will fail if there are more than 255 minor or micro versions of ruby
13 14 15 16 17 18 19 20 21 |
# File 'lib/puppet/pops/parser/locator.rb', line 13 def self.locator_version if RUBYVER >= RUBY_2_0_0 :ruby20 elsif RUBYVER >= RUBY_1_9_3 :ruby19 else :ruby18 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
65 66 |
# File 'lib/puppet/pops/parser/locator.rb', line 65 def char_length(offset, end_offset) end |
#char_offset(byte_offset) ⇒ Object
Returns the character offset for a given reported offset
61 62 |
# File 'lib/puppet/pops/parser/locator.rb', line 61 def char_offset(byte_offset) end |
#file ⇒ Object
Returns the file name associated with the string content
40 41 |
# File 'lib/puppet/pops/parser/locator.rb', line 40 def file end |
#line_for_offset(offset) ⇒ Object
Returns the line number (first line is 1) for the given offset
52 53 |
# File 'lib/puppet/pops/parser/locator.rb', line 52 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.
71 72 |
# File 'lib/puppet/pops/parser/locator.rb', line 71 def line_index() end |
#offset_on_line(offset) ⇒ Object
Returns the offset on line (first offset on a line is 0).
57 58 |
# File 'lib/puppet/pops/parser/locator.rb', line 57 def offset_on_line(offset) end |
#pos_on_line(offset) ⇒ Object
Returns the position on line (first position on a line is 1)
48 49 |
# File 'lib/puppet/pops/parser/locator.rb', line 48 def pos_on_line(offset) end |
#string ⇒ Object
Returns the string content
44 45 |
# File 'lib/puppet/pops/parser/locator.rb', line 44 def string end |