Skip to content

Fix regexp literal in oneliner #497

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

Merged
merged 5 commits into from
Aug 29, 2017
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
1 change: 1 addition & 0 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,7 @@ def parse_method_or_yield_parameters(method = nil,
end
tk = get_tk
end
@scanner.first_in_method_statement = true

get_tkread_clean(/\s+/, ' ')
end
Expand Down
5 changes: 4 additions & 1 deletion lib/rdoc/ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Error < RDoc::Error

attr_accessor :continue
attr_accessor :lex_state
attr_accessor :first_in_method_statement
attr_reader :reader

class << self
Expand Down Expand Up @@ -112,6 +113,7 @@ def initialize(content, options)
@indent_stack = []
@lex_state = :EXPR_BEG
@space_seen = false
@first_in_method_statement = false
@after_question = false

@continue = false
Expand Down Expand Up @@ -353,6 +355,7 @@ def token
begin
tk = @OP.match(self)
@space_seen = tk.kind_of?(TkSPACE)
@first_in_method_statement = false if !@space_seen && @first_in_method_statement
rescue SyntaxError => e
raise Error, "syntax error: #{e.message}" if
@exception_on_syntax_error
Expand Down Expand Up @@ -739,7 +742,7 @@ def lex_int2
if :EXPR_FNAME == @lex_state or :EXPR_DOT == @lex_state
@lex_state = :EXPR_ARG
Token(TkId, op)
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID
elsif @lex_state == :EXPR_BEG || @lex_state == :EXPR_MID || @first_in_method_statement
identify_string(op)
elsif peek(0) == '='
getc
Expand Down
22 changes: 22 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,28 @@ def blah()
assert_equal markup_code, expected
end

def test_parse_statements_method_oneliner_with_regexp
util_parser <<RUBY
class Foo
def blah() /bar/ end
end
RUBY

expected = <<EXPTECTED
<span class="ruby-keyword">def</span> <span class="ruby-identifier">blah</span>() <span class="ruby-regexp">/bar/</span> <span class="ruby-keyword">end</span>
EXPTECTED
expected = expected.rstrip

@parser.scan

foo = @top_level.classes.first
assert_equal 'Foo', foo.full_name

blah = foo.method_list.first
markup_code = blah.markup_code.sub(/^.*\n/, '')
assert_equal expected, markup_code
end

def test_parse_statements_embdoc_in_document
@filename = 'file.rb'
util_parser <<RUBY
Expand Down