From 88954a0e9a199156aadc472c4795133e5ac7651b Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 14 Aug 2024 11:46:59 +0900 Subject: [PATCH] [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]' #, @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]' #, @type=:SYMBOL_BEGIN, @value=":", @location=#> ``` 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 --- lib/prism/parse_result.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/prism/parse_result.rb b/lib/prism/parse_result.rb index df1d66f44c..c3b4bc8887 100644 --- a/lib/prism/parse_result.rb +++ b/lib/prism/parse_result.rb @@ -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