[ruby-core:124435] [Ruby Feature#6012] Proc#source_location also return the column
Issue #6012 has been updated by mame (Yusuke Endoh).
A quick search shows some examples which do not use an AST:
A "use case" is the ultimate goal that the examples aim to achieve via `Method#source`. By the way, I tried the `method_source` gem, and I noticed that it includes heredoc content that lies outside the method definition block. ```ruby require "method_source" def foo; <<END; end FOO END p method(:foo).source #=> "def foo; <<END; end\nFOO\nEND\n" p method(:foo).source_location #=> ["/tmp/t.rb", 3, 0, 3, 19] ``` On the other hand, the current `source_location` (as shown above) only includes the range of `def ... end`. I am not arguing that `source_location` needs to be fixed. My point is that the "better" return value depends entirely on the final use case. If the goal of `Method#source` is to return a parsable code fragment (I don't know if that is the official goal), then its current behavior might be expected. However, since @eregon seems to want to use `source_location` to identify AST subtrees, `source_location` should not be fine-tuned for one specific use case. I don't think there is a single, perfect "correct" `source_location` that everyone can agree on. It will likely vary depending on the ultimate use case. Instead, I believe users should extract the AST and decide for themselves what location information to obtain.
Do you have a counter-example where this wouldn't hold?
I don't have one at present. However, such a case could arise through future extensions. For example, @ko1 might add a new TracePoint type in the future, and depending on the type, it might be necessary to distinguish between `StatementsNode` and `CallNode`. More importantly, CRuby can implement `Prism.node_for` using `node_id` without the risk of future ambiguity. There is no reason to implement such a heuristic hack that tries to select overlapping nodes based on Ruby object type. ---------------------------------------- Feature #6012: Proc#source_location also return the column https://bugs.ruby-lang.org/issues/6012#change-115984 * Author: rogerdpack (Roger Pack) * Status: Closed * Assignee: nobu (Nobuyoshi Nakada) ---------------------------------------- As originally suggested in http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/42418 Suggestion/feature request: have #source_location also return the beginning column where it was defined. ["test.rb", 8, 33] Thanks! -roger- -- https://bugs.ruby-lang.org/
participants (1)
-
mame (Yusuke Endoh)