This represents a location in the source.
Methods
- #
-
- C
-
- D
-
- E
-
- I
-
- J
-
- N
-
- P
-
- S
-
Attributes
[R]
|
comments |
The list of comments attached to this location |
[R]
|
length |
The length of this location in bytes. |
[R]
|
start_offset |
The byte offset from the beginning of the source where this location starts. |
Class Public methods
new(source, start_offset, length)
Link
Create a new location object with the given source, start byte offset, and byte length.
Source:
show
| on GitHub
def initialize(source, start_offset, length)
@source = source
@start_offset = start_offset
@length = length
@comments = []
end
Returns a null location that does not correspond to a source and points to the beginning of the file. Useful for when you want a location object but do not care where it points.
Instance Public methods
==(other)
Link
Returns true if the given other location is equal to this location.
Source:
show
| on GitHub
def ==(other)
other.is_a?(Location) &&
other.start_offset == start_offset &&
other.end_offset == end_offset
end
copy(**options)
Link
Create a new location object with the given options.
Source:
show
| on GitHub
def copy(**options)
Location.new(
options.fetch(:source) { source },
options.fetch(:start_offset) { start_offset },
options.fetch(:length) { length }
)
end
deconstruct_keys(keys)
Link
Implement the hash pattern matching interface for Location
.
Source:
show
| on GitHub
def deconstruct_keys(keys)
{ start_offset: start_offset, end_offset: end_offset }
end
end_character_column()
Link
The column number in characters where this location ends from the start of the line.
Source:
show
| on GitHub
def end_character_column
source.character_column(end_offset)
end
end_character_offset()
Link
The character offset from the beginning of the source where this location ends.
Source:
show
| on GitHub
def end_character_offset
source.character_offset(end_offset)
end
end_column()
Link
The column number in bytes where this location ends from the start of the line.
Source:
show
| on GitHub
def end_column
source.column(end_offset)
end
end_line()
Link
The line number where this location ends.
Source:
show
| on GitHub
def end_line
source.line(end_offset)
end
end_offset()
Link
The byte offset from the beginning of the source where this location ends.
Source:
show
| on GitHub
def end_offset
start_offset + length
end
inspect()
Link
Returns a string representation of this location.
Source:
show
| on GitHub
def inspect
"#<Prism::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
end
join(other)
Link
Returns a new location that stretches from this location to the given other location. Raises an error if this location is not before the other location or if they don’t share the same source.
Source:
show
| on GitHub
def join(other)
raise "Incompatible sources" if source != other.source
raise "Incompatible locations" if start_offset > other.start_offset
Location.new(source, start_offset, other.end_offset - start_offset)
end
pretty_print(q)
Link
Implement the pretty print interface for Location
.
Source:
show
| on GitHub
def pretty_print(q)
q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column})")
end
The source code that this location represents.
Source:
show
| on GitHub
def slice
source.slice(start_offset, length)
end
start_character_column()
Link
The column number in characters where this location ends from the start of the line.
Source:
show
| on GitHub
def start_character_column
source.character_column(start_offset)
end
start_character_offset()
Link
The character offset from the beginning of the source where this location starts.
Source:
show
| on GitHub
def start_character_offset
source.character_offset(start_offset)
end
start_column()
Link
The column number in bytes where this location starts from the start of the line.
Source:
show
| on GitHub
def start_column
source.column(start_offset)
end
start_line()
Link
The line number where this location starts.
Source:
show
| on GitHub
def start_line
source.line(start_offset)
end
start_line_slice()
Link
The content of the line where this location starts before this location.
Source:
show
| on GitHub
def start_line_slice
offset = source.line_start(start_offset)
source.slice(offset, start_offset - offset)
end