Class: Parser::Source::Range
- Inherits:
-
Object
- Object
- Parser::Source::Range
- Defined in:
- lib/parser/source/range.rb
Instance Attribute Summary collapse
-
#begin ⇒ Object
readonly
Returns the value of attribute begin.
-
#end ⇒ Object
readonly
Returns the value of attribute end.
-
#source_buffer ⇒ Object
readonly
Returns the value of attribute source_buffer.
Instance Method Summary collapse
- #begin_column ⇒ Object
- #column_range ⇒ Object
- #end_column ⇒ Object
-
#initialize(source_buffer, begin_, end_) ⇒ Range
constructor
A new instance of Range.
- #inspect ⇒ Object
- #join(other) ⇒ Object
- #line ⇒ Object
- #size ⇒ Object
- #source_line ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(source_buffer, begin_, end_) ⇒ 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_, end_) @source_buffer = source_buffer @begin, @end = begin_, end_ freeze end |
Instance Attribute Details
#begin ⇒ Object (readonly)
Returns the value of attribute begin.
6 7 8 |
# File 'lib/parser/source/range.rb', line 6 def begin @begin end |
#end ⇒ Object (readonly)
Returns the value of attribute end.
6 7 8 |
# File 'lib/parser/source/range.rb', line 6 def end @end 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
#begin_column ⇒ Object
25 26 27 28 29 |
# File 'lib/parser/source/range.rb', line 25 def begin_column _, column = @source_buffer.decompose_position(@begin) column end |
#column_range ⇒ Object
37 38 39 |
# File 'lib/parser/source/range.rb', line 37 def column_range begin_column..end_column end |
#end_column ⇒ Object
31 32 33 34 35 |
# File 'lib/parser/source/range.rb', line 31 def end_column _, column = @source_buffer.decompose_position(@end) column end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/parser/source/range.rb', line 60 def inspect "#<Source::Range #{@source_buffer.name} #{@begin}..#{@end}>" end |
#join(other) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/parser/source/range.rb', line 50 def join(other) if other.source_buffer == @source_buffer Range.new(@source_buffer, [@begin, other.begin].min, [@end, other.end].max) else raise ArgumentError, "Cannot join SourceRanges for different SourceFiles" end end |
#line ⇒ Object
19 20 21 22 23 |
# File 'lib/parser/source/range.rb', line 19 def line line, _ = @source_buffer.decompose_position(@begin) line end |
#size ⇒ Object
15 16 17 |
# File 'lib/parser/source/range.rb', line 15 def size @end - @begin + 1 end |
#source_line ⇒ Object
41 42 43 |
# File 'lib/parser/source/range.rb', line 41 def source_line @source_buffer.source_line(line) end |
#to_s ⇒ Object
45 46 47 48 |
# File 'lib/parser/source/range.rb', line 45 def to_s line, column = @source_buffer.decompose_position(@begin) [@source_buffer.name, line, column + 1].join(':') end |