-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop reimplementation of Ripper lex state #1118
Conversation
This code was for ruby 2.4 compatibility, but rdoc dropped support for ruby 2.4 about three years ago, in f480b97. This code was almost half of the lines of code in rdoc/parser/ripper_state_lex.
138acb9
to
5772f60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, and I think we can go a bit further to remove other unused stuff:
diff --git a/lib/rdoc/parser/ripper_state_lex.rb b/lib/rdoc/parser/ripper_state_lex.rb
index 928f2011..80de0d0e 100644
--- a/lib/rdoc/parser/ripper_state_lex.rb
+++ b/lib/rdoc/parser/ripper_state_lex.rb
@@ -9,24 +9,11 @@ class RDoc::Parser::RipperStateLex
Token = Struct.new(:line_no, :char_no, :kind, :text, :state)
- EXPR_NONE = 0
- EXPR_BEG = 1
EXPR_END = 2
- EXPR_ENDARG = 4
EXPR_ENDFN = 8
EXPR_ARG = 16
- EXPR_CMDARG = 32
- EXPR_MID = 64
EXPR_FNAME = 128
- EXPR_DOT = 256
- EXPR_CLASS = 512
EXPR_LABEL = 1024
- EXPR_LABELED = 2048
- EXPR_FITEM = 4096
- EXPR_VALUE = EXPR_BEG
- EXPR_BEG_ANY = (EXPR_BEG | EXPR_MID | EXPR_CLASS)
- EXPR_ARG_ANY = (EXPR_ARG | EXPR_CMDARG)
- EXPR_END_ANY = (EXPR_END | EXPR_ENDARG | EXPR_ENDFN)
class InnerStateLex < Ripper::Filter
def initialize(code)
@@ -53,7 +40,7 @@ class RDoc::Parser::RipperStateLex
when :on_backtick then
if (tk[:state] & (EXPR_FNAME | EXPR_ENDFN)) != 0
tk[:kind] = :on_ident
- tk[:state] = Ripper::Lexer.const_defined?(:State) ? Ripper::Lexer::State.new(EXPR_ARG) : EXPR_ARG
+ tk[:state] = Ripper::Lexer::State.new(EXPR_ARG)
else
tk = get_string_tk(tk)
end
@@ -266,7 +253,7 @@ class RDoc::Parser::RipperStateLex
private def get_op_tk(tk)
redefinable_operators = %w[! != !~ % & * ** + +@ - -@ / < << <= <=> == === =~ > >= >> [] []= ^ ` | ~]
if redefinable_operators.include?(tk[:text]) and tk[:state] == EXPR_ARG then
- tk[:state] = Ripper::Lexer.const_defined?(:State) ? Ripper::Lexer::State.new(EXPR_ARG) : EXPR_ARG
+ tk[:state] = Ripper::Lexer::State.new(EXPR_ARG)
tk[:kind] = :on_ident
elsif tk[:text] =~ /^[-+]$/ then
tk_ahead = get_squashed_tk
Ripper::Lexer::State
exists in Ruby 2.5 already, and the current RDoc requires Ruby 2.6 so it's safe to assume it's defined.
Ah, good point. Yeah. I haven't previously done more than tinker with Ripper and I'm only just starting to familiarize myself with how this part of rdoc is working, so I hadn't looked at it deeply enough to find those. I'll add your patch to the PR when I get a moment. |
I was actually only in this code to see if I could figure out how much work #885 would be... and I was reading through this old code for quite a while before I got to the |
This was mostly copied from the diff in @st0012's PR comment. The remaining constants have been updated to get their value directly from Ripper. Co-authored-by: Stan Lo <[email protected]>
Since this is only used from outside RipperStateLex, there's no longer any benefit to using the indirect reference rather than just going straight to Ripper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks right to me from a non-maintainer's perspective. I support merging this as long as the maintainers also approve and checks pass. Maybe we should merge the Ruby-core test workflow #1115 first so the rest of these can be revalidated under that environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the cleanup!
(ruby/rdoc#1118) * Drop reimplementation of Ripper lex state This code was for ruby 2.4 compatibility, but rdoc dropped support for ruby 2.4 about three years ago, in f480b970c. This code was almost half of the lines of code in rdoc/parser/ripper_state_lex. * Remove unused Ripper constants and const_defined? This was mostly copied from the diff in @st0012's PR comment. The remaining constants have been updated to get their value directly from Ripper. Co-authored-by: Stan Lo <[email protected]> * Use Ripper::EXPR_LABEL directly Since this is only used from outside RipperStateLex, there's no longer any benefit to using the indirect reference rather than just going straight to Ripper. --------- ruby/rdoc@dd8c216263 Co-authored-by: Stan Lo <[email protected]>
This code was for ruby 2.4 compatibility, but rdoc dropped support for ruby 2.4 about three years ago, in f480b97. This code was almost half of the lines of code in rdoc/parser/ripper_state_lex.