From: "nobu (Nobuyoshi Nakada)" Date: 2022-06-12T02:06:34+00:00 Subject: [ruby-core:108859] [Ruby master Feature#18159] Integrate functionality of dead_end gem into Ruby Issue #18159 has been updated by nobu (Nobuyoshi Nakada). schneems (Richard Schneeman) wrote in #note-19: > One idea: In addition to the `SyntaxError#path`, is it possible to also attach the source code the parser was just looking at maybe an API like `SyntaxError#source_contents`? `AbstractSyntaxTree` already has `script_lines` for the sake of `AST.of` method. I think it's reasonable to make these lines accessible from `SyntaxError` too. My draft still fails since I've not updated the tests using `SyntaxError` yet. ```shell-session $ ./ruby -r ../../dead_end/monkeypatch.rb ../../dead_end/bad.rb ../../dead_end/bad.rb:1: syntax error, unexpected end-of-input def foo ^ Monkeypatch worked [["../../dead_end/bad.rb:1: syntax error, unexpected end-of-input", 1, 7, 7, "def foo\n"]] ["def foo\n"] ``` This monkeypatch.rb is: ```ruby SyntaxError.prepend Module.new { def detailed_message(highlight: nil, **) message = super message += "Monkeypatch worked\n" message << errors.inspect << "\n" message << script_lines.inspect << "\n" message end } ``` ---------------------------------------- Feature #18159: Integrate functionality of dead_end gem into Ruby https://bugs.ruby-lang.org/issues/18159#change-97939 * Author: duerst (Martin D��rst) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: 3.1 ---------------------------------------- Missing 'end' errors are difficult to fix. We should integrate the functionality of the dead_end gem (https://github.com/zombocom/dead_end) into Ruby similar to how we integrated did_you_mean. It would greatly help programming Ruby, in particular for beginners. See also Ruby Kaigi Takeout 2021 talk by Richard Schneeman https://rubykaigi.org/2021-takeout/presentations/schneems.html. -- https://bugs.ruby-lang.org/ Unsubscribe: