summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authorschneems <richard.schneeman+foo@gmail.com>2021-11-11 08:59:29 -0600
committerYusuke Endoh <mame@ruby-lang.org>2021-12-02 15:55:42 +0900
commit8944009be7418614ce7d4077807ac2b60d4d5d85 (patch)
treec643c1989db5800dd45b01e03b2d53c52b3a49e1 /ext/ripper
parent2b22c93533a3d94e5fc907682d862f89b62e5bf7 (diff)
Deprecate `Lexer::Elem#[]` and `Lexer::State#[]`
Discussed in https://github.com/ruby/ruby/pull/5093#issuecomment-964426481. > it would be enough to mimic only [] for almost all cases This adds back the `Lexer::Elem#[]` and `Lexer::State#[]` and adds deprecation warnings for them.
Diffstat (limited to 'ext/ripper')
-rw-r--r--ext/ripper/lib/ripper/lexer.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/ext/ripper/lib/ripper/lexer.rb b/ext/ripper/lib/ripper/lexer.rb
index a2d4d655b5..23db3a0570 100644
--- a/ext/ripper/lib/ripper/lexer.rb
+++ b/ext/ripper/lib/ripper/lexer.rb
@@ -62,6 +62,17 @@ class Ripper
freeze
end
+ def [](index)
+ case index
+ when 0
+ warn "Calling `Lexer::State#[0]` is deprecated, please use `Lexer::State#to_int` instead"
+ @to_int
+ when 1
+ warn "Calling `Lexer::State#[1]` is deprecated, please use `Lexer::State#to_s` instead"
+ @event
+ end
+ end
+
alias to_i to_int
alias inspect to_s
def pretty_print(q) q.text(to_s) end
@@ -84,6 +95,26 @@ class Ripper
@message = message
end
+ def [](index)
+ case index
+ when 0
+ warn "Calling `Lexer::Elem#[0]` is deprecated, please use `Lexer::Elem#pos` instead"
+ @pos
+ when 1
+ warn "Calling `Lexer::Elem#[1]` is deprecated, please use `Lexer::Elem#event` instead"
+ @event
+ when 2
+ warn "Calling `Lexer::Elem#[2]` is deprecated, please use `Lexer::Elem#tok` instead"
+ @tok
+ when 3
+ warn "Calling `Lexer::Elem#[3]` is deprecated, please use `Lexer::Elem#state` instead"
+ @state
+ when 4
+ warn "Calling `Lexer::Elem#[4]` is deprecated, please use `Lexer::Elem#message` instead"
+ @message
+ end
+ end
+
def inspect
"#<#{self.class}: #{event}@#{pos[0]}:#{pos[1]}:#{state}: #{tok.inspect}#{": " if message}#{message}>"
end