summaryrefslogtreecommitdiff
path: root/ext/ripper/lib
diff options
context:
space:
mode:
authorNobuhiro IMAI <nov@yo.rim.or.jp>2020-12-19 01:31:12 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-19 17:32:39 +0900
commite33eb09b76e9070fd49837e8b896319636501b38 (patch)
treec677c09711635a4c9e9d40e9de77f509ba519633 /ext/ripper/lib
parent52b1716c78a7ad9daa317e3eb43f744744b9f736 (diff)
ripper: fix `#tok` on some error events [Bug 17345]
sorting alias target by event arity, and setup suitable `Elem` for error.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3936
Diffstat (limited to 'ext/ripper/lib')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index 6a9a9cb39a2..cff38c617d7 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -190,13 +190,18 @@ class Ripper
e
end
- def on_error(mesg, tok = token())
- @errors.push Elem.new([lineno(), column()], __callee__, tok, state(), mesg)
+ def on_error1(mesg)
+ @errors.push Elem.new([lineno(), column()], __callee__, token(), state(), mesg)
+ end
+
+ def on_error2(mesg, elem)
+ @errors.push Elem.new(elem.pos, __callee__, elem.tok, elem.state, mesg)
end
PARSER_EVENTS.grep(/_error\z/) do |e|
- alias_method "on_#{e}", :on_error
+ arity = PARSER_EVENT_TABLE.fetch(e)
+ alias_method "on_#{e}", "on_error#{arity}"
end
- alias compile_error on_error
+ alias compile_error on_error1
(SCANNER_EVENTS.map {|event|:"on_#{event}"} - private_instance_methods(false)).each do |event|
alias_method event, :_push_token