Class Parser::Source::Range
In: lib/parser/source/range.rb
Parent: Object

A range of characters in a particular source buffer.

The range is always exclusive, i.e. a range with `begin_pos` of 3 and `end_pos` of 5 will contain the following characters:

    example
       ^^

@!attribute [r] source_buffer

 @return [Parser::Diagnostic::Engine]

@!attribute [r] begin_pos

 @return [Integer] index of the first character in the range

@!attribute [r] end_pos

 @return [Integer] index of the character after the last character in the range

@api public

Methods

==   begin   column   column_range   disjoint?   empty?   end   first_line   inspect   intersect   is?   join   last_column   last_line   length   line   new   overlaps?   resize   size   source   source_line   to_a   to_s  

Attributes

begin_pos  [R] 
end_pos  [R] 
source_buffer  [R] 

Public Class methods

@param [Buffer] source_buffer @param [Integer] begin_pos @param [Integer] end_pos

Public Instance methods

Compares ranges. @return [Boolean]

@return [Range] a zero-length range located just before the beginning

  of this range.

@return [Integer] zero-based column number of the beginning of this range.

@return [::Range] a range of columns spanned by this range. @raise RangeError

@param [Range] other @return [Boolean] `true` if this range and `other` do not overlap

Checks if a range is empty; if it contains no characters @return [Boolean]

@return [Range] a zero-length range located just after the end

  of this range.
first_line()

Alias for line

@return [String] a human-readable representation of this range.

@param [Range] other @return [Range] overlapping region of this range and `other`, or `nil`

  if they do not overlap

`is?` provides a concise way to compare the source corresponding to this range. For example, `r.source == ’(’ || r.source == ‘begin’` is equivalent to `r.is?(’(’, ‘begin’)`.

@param [Range] other @return [Range] smallest possible range spanning both this range and `other`.

@return [Integer] zero-based column number of the end of this range.

@return [Integer] line number of the end of this range.

length()

Alias for size

Line number of the beginning of this range. By default, the first line of a buffer is 1; as such, line numbers are most commonly one-based.

@see Buffer @return [Integer] line number of the beginning of this range.

@param [Range] other @return [Boolean] `true` if this range and `other` overlap

@param [Integer] new_size @return [Range] a range beginning at the same point as this range and length `new_size`.

@return [Integer] amount of characters included in this range.

@return [String] all source code covered by this range.

@return [String] a line of source code containing the beginning of this range.

@return [Array(Integer)] a set of character indexes contained in this range.

Composes a GNU/Clang-style string representation of the beginning of this range.

For example, for the following range in file `foo.rb`,

    def foo
        ^^^

`to_s` will return `foo.rb:1:5`. Note that the column index is one-based.

@return [String]

[Validate]