-
Notifications
You must be signed in to change notification settings - Fork 456
Don't create tokens by hand #1696
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -314,7 +314,7 @@ def parse_comment_tomdoc(container, comment, line_no, start_line) | |
|
|
||
| meth.start_collecting_tokens(:ruby) | ||
| node = @line_nodes[line_no] | ||
| tokens = node ? visible_tokens_from_location(node.location) : [file_line_comment_token(start_line)] | ||
| tokens = node ? visible_tokens_from_location(node.location) : [] | ||
| tokens.each { |token| meth.token_stream << token } | ||
|
|
||
|
Comment on lines
315
to
319
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems correct. Previously they were not empty because it contained the comment |
||
| container.add_method meth | ||
|
|
@@ -385,7 +385,7 @@ def handle_meta_method_comment(comment, directives, node) | |
| tokens = visible_tokens_from_location(node.location) | ||
| line_no = node.location.start_line | ||
| else | ||
| tokens = [file_line_comment_token(line_no)] | ||
| tokens = [] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| end | ||
| internal_add_method( | ||
| method_name, | ||
|
|
@@ -498,23 +498,13 @@ def slice_tokens(start_pos, end_pos) # :nodoc: | |
| tokens | ||
| end | ||
|
|
||
| def file_line_comment_token(line_no) # :nodoc: | ||
| position_comment = RDoc::Parser::RipperStateLex::Token.new(line_no - 1, 0, :on_comment) | ||
| position_comment[:text] = "# File #{@top_level.relative_name}, line #{line_no}" | ||
| position_comment | ||
| end | ||
|
|
||
| # Returns tokens from the given location | ||
|
|
||
| def visible_tokens_from_location(location) | ||
| position_comment = file_line_comment_token(location.start_line) | ||
| newline_token = RDoc::Parser::RipperStateLex::Token.new(0, 0, :on_nl, "\n") | ||
| indent_token = RDoc::Parser::RipperStateLex::Token.new(location.start_line, 0, :on_sp, ' ' * location.start_character_column) | ||
| tokens = slice_tokens( | ||
| slice_tokens( | ||
| [location.start_line, location.start_character_column], | ||
| [location.end_line, location.end_character_column] | ||
| ) | ||
| [position_comment, newline_token, indent_token, *tokens] | ||
| end | ||
|
|
||
| # Handles `public :foo, :bar` `private :foo, :bar` and `protected :foo, :bar` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,42 +149,57 @@ def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq | |
| end | ||
|
|
||
| def test_markup_code | ||
| tokens = [ | ||
| { :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This testcase didn't make much sense since only methods have their source code shown. I simply removed it. |
||
| ] | ||
|
|
||
| tokens = RDoc::Parser::RipperStateLex.parse("A\nB") | ||
| @c2_a.collect_tokens(:ruby) | ||
| @c2_a.add_tokens(tokens) | ||
|
|
||
| expected = '<span class="ruby-constant">CONSTANT</span>' | ||
|
|
||
| assert_equal expected, @c2_a.markup_code | ||
| assert_equal <<~EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-comment"># File xref_data.rb, line 1</span> | ||
| <span class="ruby-constant">A</span> | ||
| <span class="ruby-constant">B</span> | ||
| EXPECTED | ||
| end | ||
|
|
||
| def test_markup_code_with_line_numbers | ||
| position_comment = "# File #{@file_name}, line 1" | ||
| tokens = [ | ||
| { :line_no => 1, :char_no => 0, :kind => :on_comment, :text => position_comment }, | ||
| { :line_no => 1, :char_no => position_comment.size, :kind => :on_nl, :text => "\n" }, | ||
| { :line_no => 2, :char_no => 0, :kind => :on_const, :text => 'A' }, | ||
| { :line_no => 2, :char_no => 1, :kind => :on_nl, :text => "\n" }, | ||
| { :line_no => 3, :char_no => 0, :kind => :on_const, :text => 'B' } | ||
| ] | ||
| tokens = RDoc::Parser::RipperStateLex.parse("A\nB") | ||
| @c2_a.collect_tokens(:ruby) | ||
| @c2_a.add_tokens(tokens) | ||
|
|
||
| @c2_a.options.line_numbers = true | ||
| assert_equal <<~EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-comment"># File xref_data.rb</span> | ||
| <span class="line-num">1</span> <span class="ruby-constant">A</span> | ||
| <span class="line-num">2</span> <span class="ruby-constant">B</span> | ||
| EXPECTED | ||
| end | ||
|
|
||
| def test_markup_code_dedent | ||
| tokens = RDoc::Parser::RipperStateLex.parse(<<-RUBY.rstrip) | ||
| foo | ||
| bar | ||
| baz | ||
| RUBY | ||
| @c2_a.collect_tokens(:ruby) | ||
| @c2_a.add_tokens(tokens) | ||
|
|
||
| assert_equal <<-EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-comment"># File xref_data.rb, line 1</span> | ||
| <span class="ruby-constant">A</span> | ||
| <span class="ruby-constant">B</span> | ||
| assert_equal <<~EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-comment"># File xref_data.rb, line 1</span> | ||
| <span class="ruby-identifier">foo</span> | ||
| <span class="ruby-identifier">bar</span> | ||
| <span class="ruby-identifier">baz</span> | ||
| EXPECTED | ||
| end | ||
|
|
||
| def test_markup_code_c | ||
| # This is not C code or tokens created by the C parser. It just | ||
| # makes sure that the file comment and line numbers are omitted. | ||
| tokens = RDoc::Parser::RipperStateLex.parse('foo') | ||
| @c2_a.collect_tokens(:c) | ||
| @c2_a.add_tokens(tokens) | ||
|
|
||
| @c2_a.options.line_numbers = true | ||
| assert_equal <<-EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-comment"># File xref_data.rb</span> | ||
| <span class="line-num">1</span> <span class="ruby-constant">A</span> | ||
| <span class="line-num">2</span> <span class="ruby-constant">B</span> | ||
| assert_equal <<~EXPECTED.chomp, @c2_a.markup_code | ||
| <span class="ruby-identifier">foo</span> | ||
| EXPECTED | ||
| end | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.