Class: Parser::Source::Range
- Inherits:
-
Object
- Object
- Parser::Source::Range
- Defined in:
- lib/parser/source/range.rb
Instance Attribute Summary collapse
-
#begin_pos ⇒ Object
readonly
Returns the value of attribute begin_pos.
-
#end_pos ⇒ Object
readonly
Returns the value of attribute end_pos.
-
#source_buffer ⇒ Object
readonly
Returns the value of attribute source_buffer.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #begin ⇒ Object
- #column ⇒ Object
- #column_range ⇒ Object
- #end ⇒ Object
-
#initialize(source_buffer, begin_pos, end_pos) ⇒ Range
constructor
A new instance of Range.
- #inspect ⇒ Object
- #is?(*what) ⇒ Boolean
- #join(other) ⇒ Object
- #line ⇒ Object
- #size ⇒ Object (also: #length)
- #source_line ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #to_source ⇒ Object
Constructor Details
#initialize(source_buffer, begin_pos, end_pos) ⇒ Range
Returns a new instance of Range.
8 9 10 11 12 13 |
# File 'lib/parser/source/range.rb', line 8 def initialize(source_buffer, begin_pos, end_pos) @source_buffer = source_buffer @begin_pos, @end_pos = begin_pos, end_pos freeze end |
Instance Attribute Details
#begin_pos ⇒ Object (readonly)
Returns the value of attribute begin_pos.
6 7 8 |
# File 'lib/parser/source/range.rb', line 6 def begin_pos @begin_pos end |
#end_pos ⇒ Object (readonly)
Returns the value of attribute end_pos.
6 7 8 |
# File 'lib/parser/source/range.rb', line 6 def end_pos @end_pos end |
#source_buffer ⇒ Object (readonly)
Returns the value of attribute source_buffer.
5 6 7 |
# File 'lib/parser/source/range.rb', line 5 def source_buffer @source_buffer end |
Instance Method Details
#==(other) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/parser/source/range.rb', line 73 def ==(other) other.is_a?(Range) && @source_buffer == other.source_buffer && @begin_pos == other.begin_pos && @end_pos == other.end_pos end |
#begin ⇒ Object
15 16 17 |
# File 'lib/parser/source/range.rb', line 15 def begin Range.new(@source_buffer, @begin_pos, @begin_pos) end |
#column ⇒ Object
35 36 37 38 39 |
# File 'lib/parser/source/range.rb', line 35 def column _, column = @source_buffer.decompose_position(@begin_pos) column end |
#column_range ⇒ Object
41 42 43 |
# File 'lib/parser/source/range.rb', line 41 def column_range self.begin.column...self.end.column end |
#end ⇒ Object
19 20 21 |
# File 'lib/parser/source/range.rb', line 19 def end Range.new(@source_buffer, @end_pos, @end_pos) end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/parser/source/range.rb', line 80 def inspect "#<Source::Range #{@source_buffer.name} #{@begin_pos}...#{@end_pos}>" end |
#is?(*what) ⇒ Boolean
53 54 55 |
# File 'lib/parser/source/range.rb', line 53 def is?(*what) what.include?(to_source) end |
#join(other) ⇒ Object
67 68 69 70 71 |
# File 'lib/parser/source/range.rb', line 67 def join(other) Range.new(@source_buffer, [@begin_pos, other.begin_pos].min, [@end_pos, other.end_pos].max) end |
#line ⇒ Object
29 30 31 32 33 |
# File 'lib/parser/source/range.rb', line 29 def line line, _ = @source_buffer.decompose_position(@begin_pos) line end |
#size ⇒ Object Also known as: length
23 24 25 |
# File 'lib/parser/source/range.rb', line 23 def size @end_pos - @begin_pos end |
#source_line ⇒ Object
45 46 47 |
# File 'lib/parser/source/range.rb', line 45 def source_line @source_buffer.source_line(line) end |
#to_a ⇒ Object
57 58 59 |
# File 'lib/parser/source/range.rb', line 57 def to_a (@begin_pos...@end_pos).to_a end |
#to_s ⇒ Object
61 62 63 64 65 |
# File 'lib/parser/source/range.rb', line 61 def to_s line, column = @source_buffer.decompose_position(@begin_pos) [@source_buffer.name, line, column + 1].join(':') end |
#to_source ⇒ Object
49 50 51 |
# File 'lib/parser/source/range.rb', line 49 def to_source @source_buffer.source[self.begin_pos...self.end_pos] end |