Skip to content
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

Fix random NameError of RipperStateLex #631

Merged
merged 1 commit into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix random NameError of RipperStateLex
Because RDoc::RipperStatelex is loaded by RDoc::Parser, some tests that
need RDoc::RipperStateLex fail when RDoc::Parser isn't autoloaded. That
whether RDoc::RipperStateLex is loaded or not depends on RDoc::Parser is
autoloaded. Therefore NameError of RDoc::RipperStateLex is occurred at
random.

This patch fixes it with that RDoc::RipperStateLex is moved to
RDoc::Parser::RipperStateLex.
  • Loading branch information
aycabta committed Jun 23, 2018
commit ff2073f4ade75bea4f5ec3330bdbdbc5b37e30db
2 changes: 1 addition & 1 deletion lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def accept_verbatim verbatim

content = if verbatim.ruby? or parseable? text then
begin
tokens = RDoc::RipperStateLex.parse text
tokens = RDoc::Parser::RipperStateLex.parse text
klass = ' class="ruby"'

result = RDoc::TokenStream.to_html tokens
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/parser/ripper_state_lex.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'ripper'

class RDoc::RipperStateLex
class RDoc::Parser::RipperStateLex
# TODO: Remove this constants after Ruby 2.4 EOL
RIPPER_HAS_LEX_STATE = Ripper::Filter.method_defined?(:state)

Expand Down
18 changes: 9 additions & 9 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def initialize(top_level, file_name, content, options, stats)
@size = 0
@token_listeners = nil
content = RDoc::Encoding.remove_magic_comment content
@scanner = RDoc::RipperStateLex.parse(content)
@scanner = RDoc::Parser::RipperStateLex.parse(content)
@content = content
@scanner_point = 0
@prev_seek = nil
Expand Down Expand Up @@ -741,9 +741,9 @@ def parse_call_parameters(tk)
when end_token
if end_token == :on_rparen
nest -= 1
break if RDoc::RipperStateLex.end?(tk) and nest <= 0
break if RDoc::Parser::RipperStateLex.end?(tk) and nest <= 0
else
break if RDoc::RipperStateLex.end?(tk)
break if RDoc::Parser::RipperStateLex.end?(tk)
end
when :on_comment, :on_embdoc
unget_tk(tk)
Expand Down Expand Up @@ -961,15 +961,15 @@ def parse_constant_body container, constant, is_array_or_hash # :nodoc:
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::RipperStateLex::EXPR_LABEL) == 0
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
nest += 1
end
elsif [:on_rparen, :on_rbrace, :on_rbracket].include?(tk[:kind]) ||
(:on_kw == tk[:kind] && 'end' == tk[:text]) then
nest -= 1
elsif (:on_comment == tk[:kind] or :on_embdoc == tk[:kind]) then
unget_tk tk
if nest <= 0 and RDoc::RipperStateLex.end?(tk) then
if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
body = get_tkread_clean(/^[ \t]+/, '')
read_documentation_modifiers constant, RDoc::CONSTANT_MODIFIERS
break
Expand All @@ -985,7 +985,7 @@ def parse_constant_body container, constant, is_array_or_hash # :nodoc:
break
end
elsif :on_nl == tk[:kind] then
if nest <= 0 and RDoc::RipperStateLex.end?(tk) then
if nest <= 0 and RDoc::Parser::RipperStateLex.end?(tk) then
unget_tk tk
break
end
Expand Down Expand Up @@ -1555,7 +1555,7 @@ def parse_method_or_yield_parameters(method = nil,
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::RipperStateLex::EXPR_LABEL) != 0) then
(!continue or (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) != 0) then
if method && method.block_params.nil? then
unget_tk tk
read_documentation_modifiers method, modifiers
Expand Down Expand Up @@ -1772,7 +1772,7 @@ def parse_statements(container, single = NORMAL, current_method = nil,
end

when 'until', 'while' then
if (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) == 0
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
nest += 1
skip_optional_do_after_expression
end
Expand All @@ -1788,7 +1788,7 @@ def parse_statements(container, single = NORMAL, current_method = nil,
skip_optional_do_after_expression

when 'case', 'do', 'if', 'unless', 'begin' then
if (tk[:state] & RDoc::RipperStateLex::EXPR_LABEL) == 0
if (tk[:state] & RDoc::Parser::RipperStateLex::EXPR_LABEL) == 0
nest += 1
end

Expand Down