[ruby/prism] Tweak inspect representation of Prism::Location

This PR tweaks inspect representation of `Prism::Location`.

## Before

During debugging, the meaning of `@location=https://github.com/ruby/prism/commit/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=https://github.com/ruby/prism/commit/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.

https://github.com/ruby/prism/commit/e7421ce1c5
This commit is contained in:
Koichi ITO 2024-08-14 11:46:59 +09:00 committed by git
parent 264175dbb9
commit 88954a0e9a

View File

@ -711,5 +711,11 @@ module Prism
other.type == type &&
other.value == value
end
# Returns a string representation of this token.
def inspect
location
super
end
end
end