Class: Steep::AST::Location
- Inherits:
-
Object
- Object
- Steep::AST::Location
- Defined in:
- lib/steep/ast/location.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#end_pos ⇒ Object
readonly
Returns the value of attribute end_pos.
-
#start_pos ⇒ Object
readonly
Returns the value of attribute start_pos.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #end_column ⇒ Object
- #end_line ⇒ Object
- #end_loc ⇒ Object
-
#initialize(buffer:, start_pos:, end_pos:) ⇒ Location
constructor
A new instance of Location.
- #inspect ⇒ Object
- #name ⇒ Object
- #pred?(loc) ⇒ Boolean
- #source ⇒ Object
- #start_column ⇒ Object
- #start_line ⇒ Object
- #start_loc ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(buffer:, start_pos:, end_pos:) ⇒ Location
Returns a new instance of Location.
8 9 10 11 12 |
# File 'lib/steep/ast/location.rb', line 8 def initialize(buffer:, start_pos:, end_pos:) @buffer = buffer @start_pos = start_pos @end_pos = end_pos end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
4 5 6 |
# File 'lib/steep/ast/location.rb', line 4 def buffer @buffer end |
#end_pos ⇒ Object (readonly)
Returns the value of attribute end_pos.
6 7 8 |
# File 'lib/steep/ast/location.rb', line 6 def end_pos @end_pos end |
#start_pos ⇒ Object (readonly)
Returns the value of attribute start_pos.
5 6 7 |
# File 'lib/steep/ast/location.rb', line 5 def start_pos @start_pos end |
Class Method Details
.concat(*locations) ⇒ Object
69 70 71 72 73 |
# File 'lib/steep/ast/location.rb', line 69 def self.concat(*locations) locations.inject {|l1, l2| l1 + l2 } end |
Instance Method Details
#+(other) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/steep/ast/location.rb', line 61 def +(other) raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer self.class.new(buffer: buffer, start_pos: start_pos, end_pos: other.end_pos) end |
#==(other) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/steep/ast/location.rb', line 54 def ==(other) other.is_a?(Location) && other.buffer == buffer && other.start_pos == start_pos && other.end_pos == end_pos end |
#end_column ⇒ Object
34 35 36 |
# File 'lib/steep/ast/location.rb', line 34 def end_column end_loc[1] end |
#end_line ⇒ Object
30 31 32 |
# File 'lib/steep/ast/location.rb', line 30 def end_line end_loc[0] end |
#end_loc ⇒ Object
42 43 44 |
# File 'lib/steep/ast/location.rb', line 42 def end_loc @end_loc ||= buffer.pos_to_loc(end_pos) end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/steep/ast/location.rb', line 14 def inspect "#<#{self.class}:#{self.__id__} @buffer=..., @start_pos=#{start_pos}, @end_pos=#{end_pos}, source='#{source.lines.first}', start_line=#{start_line}, start_column=#{start_column}>" end |
#name ⇒ Object
18 19 20 |
# File 'lib/steep/ast/location.rb', line 18 def name buffer.name end |
#pred?(loc) ⇒ Boolean
75 76 77 78 79 |
# File 'lib/steep/ast/location.rb', line 75 def pred?(loc) loc.is_a?(Location) && loc.name == name && loc.start_pos == end_pos end |
#source ⇒ Object
46 47 48 |
# File 'lib/steep/ast/location.rb', line 46 def source @source ||= buffer.source(start_pos...end_pos) end |
#start_column ⇒ Object
26 27 28 |
# File 'lib/steep/ast/location.rb', line 26 def start_column start_loc[1] end |
#start_line ⇒ Object
22 23 24 |
# File 'lib/steep/ast/location.rb', line 22 def start_line start_loc[0] end |
#start_loc ⇒ Object
38 39 40 |
# File 'lib/steep/ast/location.rb', line 38 def start_loc @start_loc ||= buffer.pos_to_loc(start_pos) end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/steep/ast/location.rb', line 50 def to_s "#{start_line}:#{start_column}...#{end_line}:#{end_column}" end |