From e165d92d37ab1b32d505977d685993cba3131298 Mon Sep 17 00:00:00 2001 From: "nicholas a. evans" Date: Sat, 6 Jul 2024 17:41:52 -0400 Subject: [ruby/rdoc] Drop reimplementation of Ripper lex state (https://github.com/ruby/rdoc/pull/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 * 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. --------- https://github.com/ruby/rdoc/commit/dd8c216263 Co-authored-by: Stan Lo --- lib/rdoc/parser/ruby.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/rdoc/parser/ruby.rb') diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 85f1cd0391..47ad770daf 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -513,7 +513,7 @@ class RDoc::Parser::Ruby < RDoc::Parser when :on_comment, :on_embdoc then @read.pop if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and - (!continue or (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0) then + (!continue or (tk[:state] & Ripper::EXPR_LABEL) != 0) then break if !continue and nest <= 0 end when :on_comma then @@ -526,7 +526,7 @@ class RDoc::Parser::Ruby < RDoc::Parser nest += 1 when 'if', 'unless', 'while', 'until', 'rescue' # postfix if/unless/while/until/rescue must be EXPR_LABEL - nest += 1 unless (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0 + nest += 1 unless (tk[:state] & Ripper::EXPR_LABEL) != 0 when 'end' nest -= 1 break if nest == 0 @@ -1041,7 +1041,7 @@ class RDoc::Parser::Ruby < RDoc::Parser elsif (:on_kw == tk[:kind] && 'def' == tk[:text]) then nest += 1 elsif (:on_kw == tk[:kind] && %w{do if unless case begin}.include?(tk[:text])) then - if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0 + if (tk[:state] & Ripper::EXPR_LABEL) == 0 nest += 1 end elsif [:on_rparen, :on_rbrace, :on_rbracket].include?(tk[:kind]) || @@ -1662,7 +1662,7 @@ class RDoc::Parser::Ruby < RDoc::Parser when :on_comment, :on_embdoc then @read.pop if :on_nl == end_token[:kind] and "\n" == tk[:text][-1] and - (!continue or (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0) then + (!continue or (tk[:state] & Ripper::EXPR_LABEL) != 0) then if method && method.block_params.nil? then unget_tk tk read_documentation_modifiers method, modifiers @@ -1882,7 +1882,7 @@ class RDoc::Parser::Ruby < RDoc::Parser end when 'until', 'while' then - if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0 + if (tk[:state] & Ripper::EXPR_LABEL) == 0 nest += 1 skip_optional_do_after_expression end @@ -1898,7 +1898,7 @@ class RDoc::Parser::Ruby < RDoc::Parser skip_optional_do_after_expression when 'case', 'do', 'if', 'unless', 'begin' then - if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0 + if (tk[:state] & Ripper::EXPR_LABEL) == 0 nest += 1 end -- cgit v1.2.3