Class: YARP::Location
- Inherits:
-
Object
- Object
- YARP::Location
- Defined in:
- lib/yarp.rb,
ext/yarp/extension.c
Overview
This represents a location in the source.
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
The length of this location in bytes.
-
#start_offset ⇒ Object
readonly
The byte offset from the beginning of the source where this location starts.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #deconstruct_keys(keys) ⇒ Object
-
#end_column ⇒ Object
The column number in bytes where this location ends from the start of the line.
-
#end_line ⇒ Object
The line number where this location ends.
-
#end_offset ⇒ Object
The byte offset from the beginning of the source where this location ends.
-
#initialize(source, start_offset, length) ⇒ Location
constructor
A new instance of Location.
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
-
#slice ⇒ Object
The source code that this location represents.
-
#start_column ⇒ Object
The column number in bytes where this location starts from the start of the line.
-
#start_line ⇒ Object
The line number where this location starts.
Constructor Details
#initialize(source, start_offset, length) ⇒ Location
Returns a new instance of Location.
49 50 51 52 53 |
# File 'lib/yarp.rb', line 49 def initialize(source, start_offset, length) @source = source @start_offset = start_offset @length = length end |
Instance Attribute Details
#length ⇒ Object (readonly)
The length of this location in bytes.
47 48 49 |
# File 'lib/yarp.rb', line 47 def length @length end |
#start_offset ⇒ Object (readonly)
The byte offset from the beginning of the source where this location starts.
44 45 46 |
# File 'lib/yarp.rb', line 44 def start_offset @start_offset end |
Class Method Details
.null ⇒ Object
105 106 107 |
# File 'lib/yarp.rb', line 105 def self.null new(0, 0) end |
Instance Method Details
#==(other) ⇒ Object
99 100 101 102 103 |
# File 'lib/yarp.rb', line 99 def ==(other) other.is_a?(Location) && other.start_offset == start_offset && other.end_offset == end_offset end |
#deconstruct_keys(keys) ⇒ Object
91 92 93 |
# File 'lib/yarp.rb', line 91 def deconstruct_keys(keys) { start_offset: start_offset, end_offset: end_offset } end |
#end_column ⇒ Object
The column number in bytes where this location ends from the start of the line.
87 88 89 |
# File 'lib/yarp.rb', line 87 def end_column source.column(end_offset - 1) end |
#end_line ⇒ Object
The line number where this location ends.
75 76 77 |
# File 'lib/yarp.rb', line 75 def end_line source.line(end_offset - 1) end |
#end_offset ⇒ Object
The byte offset from the beginning of the source where this location ends.
65 66 67 |
# File 'lib/yarp.rb', line 65 def end_offset start_offset + length end |
#inspect ⇒ Object
55 56 57 |
# File 'lib/yarp.rb', line 55 def inspect "#<YARP::Location @start_offset=#{@start_offset} @length=#{@length}>" end |
#pretty_print(q) ⇒ Object
95 96 97 |
# File 'lib/yarp.rb', line 95 def pretty_print(q) q.text("(#{start_offset}...#{end_offset})") end |
#slice ⇒ Object
The source code that this location represents.
60 61 62 |
# File 'lib/yarp.rb', line 60 def slice source.slice(start_offset, length) end |
#start_column ⇒ Object
The column number in bytes where this location starts from the start of the line.
81 82 83 |
# File 'lib/yarp.rb', line 81 def start_column source.column(start_offset) end |
#start_line ⇒ Object
The line number where this location starts.
70 71 72 |
# File 'lib/yarp.rb', line 70 def start_line source.line(start_offset) end |