Skip to content

Fix showing syntax error line #572

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 2 commits into from
Jan 30, 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
12 changes: 6 additions & 6 deletions lib/rdoc/parser/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2074,13 +2074,16 @@ def scan
$stderr.puts @file_name
return
end
bytes = ''

if @scanner_point >= @scanner.size
now_line_no = @scanner[@scanner.size - 1][:line_no]
else
now_line_no = peek_tk[:line_no]
end
first_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no }
last_tk_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no + 1 }
last_tk_index = last_tk_index ? last_tk_index - 1 : @scanner.size - 1
code = @scanner[first_tk_index..last_tk_index].map{ |t| t[:text] }.join

$stderr.puts <<-EOF

Expand All @@ -2089,12 +2092,9 @@ def scan

EOF

unless bytes.empty? then
unless code.empty? then
$stderr.puts code
$stderr.puts
now_line_no = peek_tk[:line_no]
start_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no }
end_index = @scanner.find_index { |tk| tk[:line_no] == now_line_no + 1 } - 1
$stderr.puts @scanner[start_index..end_index].join
end

raise e
Expand Down
25 changes: 25 additions & 0 deletions test/test_rdoc_parser_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,31 @@ def test_parse_class_lower_name_warning
assert_match(/Expected class name or '<<'\. Got/, err)
end

def test_parse_syntax_error_code
@options.verbosity = 2
stds = capture_io do
begin
util_parser <<INVALID_CODE
# invalid class name
class Invalid::@@Code
end
INVALID_CODE
@parser.scan
rescue
end
end
err = stds[1]

expected = <<EXPECTED
RDoc::Parser::Ruby failure around line 2 of
#{@filename}

class Invalid::@@Code
EXPECTED

assert_match(expected, err)
end

def test_parse_multi_ghost_methods
util_parser <<-'CLASS'
class Foo
Expand Down