Skip to content

Commit e7421ce

Browse files
committed
Tweak inspect representation of Prism::Location
This PR tweaks inspect representation of `Prism::Location`. ## Before During debugging, the meaning of `@location=21474836481` was unclear: ```console $ ruby -Ilib -rprism -e 'p Prism.lex("puts :hi").value.map(&:first)[1]' #<Prism::Token:0x000000010cd74e40 @source=#<Prism::ASCIISource:0x000000010cb5f808 @source="puts :hi", @start_line=1, @offsets=[0]>, @type=:SYMBOL_BEGIN, @value=":", @location=21474836481> ``` ## After This PR clarifies the contents of the location object, aligning with what I think user expects: ```console $ ruby -Ilib -rprism -e 'p Prism.lex("puts :hi").value.map(&:first)[1]' #<Prism::Token:0x000000010e174d50 @source=#<Prism::ASCIISource:0x000000010df5efe8 @source="puts :hi", @start_line=1, @offsets=[0]>, @type=:SYMBOL_BEGIN, @value=":", @location=#<Prism::Location @start_offset=5 @Length=1 start_line=1>> ``` Although it is uncertain whether Prism will accept this change in the inspect representation, it is submitted here as a suggestion.
1 parent 50d79b7 commit e7421ce

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/prism/parse_result.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,5 +711,11 @@ def ==(other)
711711
other.type == type &&
712712
other.value == value
713713
end
714+
715+
# Returns a string representation of this token.
716+
def inspect
717+
location
718+
super
719+
end
714720
end
715721
end

0 commit comments

Comments
 (0)