Skip to content

Commit

Permalink
Print locations using line / col instead of offsets
Browse files Browse the repository at this point in the history
This commit changes printing of locations to use the format
(start_line,start_column)-(end_line,end_column) instead of using
offsets.
  • Loading branch information
jemmaissroff committed Sep 19, 2023
1 parent a3f5185 commit c078696
Show file tree
Hide file tree
Showing 912 changed files with 30,188 additions and 30,188 deletions.
8 changes: 4 additions & 4 deletions lib/yarp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def copy(**options)

# Returns a string representation of this location.
def inspect
"#<YARP::Location @start_offset=#{@start_offset} @length=#{@length}>"
"#<YARP::Location @start_offset=#{@start_offset} @length=#{@length} start_line=#{start_line}>"
end

# The source code that this location represents.
Expand Down Expand Up @@ -117,7 +117,7 @@ def deconstruct_keys(keys)
end

def pretty_print(q)
q.text("(#{start_offset}...#{end_offset})")
q.text("(#{start_line},#{start_column})-(#{end_line},#{end_column}))")
end

def ==(other)
Expand Down Expand Up @@ -330,7 +330,7 @@ def <<(line)
# for any given node.
def header(node)
output = +"@ #{node.class.name.split("::").last} ("
output << "location: (#{node.location.start_offset}...#{node.location.end_offset})"
output << "location: (#{node.location.start_line},#{node.location.start_column})-(#{node.location.end_line},#{node.location.end_column})"
output << ", newline: true" if node.newline?
output << ")\n"
output
Expand All @@ -354,7 +354,7 @@ def list(prefix, nodes)
# Generates a string that represents a location field on a node.
def location(value)
if value
"(#{value.start_offset}...#{value.end_offset}) = #{value.slice.inspect}"
"(#{value.start_line},#{value.start_column})-(#{value.end_line},#{value.end_column}) = #{value.slice.inspect}"
else
"∅"
end
Expand Down
188 changes: 94 additions & 94 deletions test/yarp/snapshots/alias.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c078696

Please sign in to comment.