Skip to content

Commit a872e2b

Browse files
committed
Don't include C comment in token stream
1 parent a2008fc commit a872e2b

File tree

5 files changed

+54
-23
lines changed

5 files changed

+54
-23
lines changed

History.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
* Converted to minitest.
1818

1919
* Z Bug Fixes
20-
* Fix missing superclass in ri output.
21-
* Fix an RDoc crash when told to parse an empty file.
22-
* Ignore nonexistent files instead of crashing.
20+
* Fix missing superclass in ri output
21+
* Fix an RDoc crash when told to parse an empty file
22+
* Ignore nonexistent files instead of crashing
2323
* .txt and .rdoc files are always considered text. Patch #22897 by Aaron
2424
Patterson.
25-
* When merging ri data with a nonexistant directory, RDoc no longer crashes.
25+
* When merging ri data with a nonexistant directory, RDoc no longer crashes
2626
* Fix visibility of methods in XML output. Issue by Yehuda Katz.
27-
* Fixed relative link generation.
27+
* Fixed relative link generation
2828
* Fix crash, RDoc now ignores comments above local variable assignments in
29-
modules.
29+
modules
3030
* RDoc now only accepts adjacent comments for rb_define_module and
3131
rb_define_class
32+
* C file RDoc is no longer included in token stream
3233

3334
=== 2.2.1 / 2008-09-24
3435
This version provides some minor fixes and enhancements to 2.2.0 intended

lib/rdoc/code_objects.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,7 @@ def superclass
830830
def superclass=(superclass)
831831
raise NoMethodError, "#{full_name} is a module" if module?
832832

833-
if @superclass.nil? or @superclass == 'Object' then
834-
@superclass = superclass
835-
end
833+
@superclass = superclass if @superclass.nil? or @superclass == 'Object'
836834
end
837835

838836
def to_s

lib/rdoc/generator.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -913,15 +913,16 @@ def initialize(context, html_class, options)
913913

914914
context.viewer = self
915915

916-
if (ts = @context.token_stream)
917-
@source_code = markup_code(ts)
918-
unless @options.inline_source
919-
@src_url = create_source_code_file(@source_code)
916+
if ts = @context.token_stream then
917+
@source_code = markup_code ts
918+
919+
unless @options.inline_source then
920+
@src_url = create_source_code_file @source_code
920921
@img_url = RDoc::Markup::ToHtml.gen_relative_url path, 'source.png'
921922
end
922923
end
923924

924-
AllReferences.add(name, self)
925+
AllReferences.add name, self
925926
end
926927

927928
##

lib/rdoc/parser/c.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,13 @@ def find_attr_comment(attr_name)
283283

284284
def find_body(class_name, meth_name, meth_obj, body, quiet = false)
285285
case body
286-
when %r"((?>/\*.*?\*/\s*))(?:(?:static|SWIGINTERN)\s+)?(?:intern\s+)?VALUE\s+#{meth_name}
287-
\s*(\([^)]*\))([^;]|$)"xm
288-
comment, params = $1, $2
289-
body_text = $&
286+
when %r"((?>/\*.*?\*/\s*))((?:(?:static|SWIGINTERN)\s+)?(?:intern\s+)?VALUE\s+#{meth_name}
287+
\s*(\([^)]*\))([^;]|$))"xm
288+
comment = $1
289+
body_text = $2
290+
params = $3
290291

291-
remove_private_comments(comment) if comment
292+
remove_private_comments comment if comment
292293

293294
# see if we can find the whole body
294295

@@ -301,15 +302,15 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
301302
# distinct (for example Kernel.hash and Kernel.object_id share the same
302303
# implementation
303304

304-
override_comment = find_override_comment(class_name, meth_obj.name)
305+
override_comment = find_override_comment class_name, meth_obj.name
305306
comment = override_comment if override_comment
306307

307-
find_modifiers(comment, meth_obj) if comment
308+
find_modifiers comment, meth_obj if comment
308309

309310
# meth_obj.params = params
310311
meth_obj.start_collecting_tokens
311-
meth_obj.add_token(RDoc::RubyToken::Token.new(1,1).set_text(body_text))
312-
meth_obj.comment = mangle_comment(comment)
312+
meth_obj.add_token RDoc::RubyToken::Token.new(1,1).set_text(body_text)
313+
meth_obj.comment = mangle_comment comment
313314
when %r{((?>/\*.*?\*/\s*))^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
314315
comment = $1
315316
find_body(class_name, $2, meth_obj, body, true)

test/test_rdoc_parser_c.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,36 @@ def test_find_class_comment_define_class_bogus_comment
268268
assert_equal '', klass.comment
269269
end
270270

271+
def test_find_body
272+
content = <<-EOF
273+
/*
274+
* a comment for other_function
275+
*/
276+
VALUE
277+
other_function() {
278+
}
279+
280+
void
281+
Init_Foo(void) {
282+
VALUE foo = rb_define_class("Foo", rb_cObject);
283+
284+
rb_define_method(foo, "my_method", other_function, 0);
285+
}
286+
EOF
287+
288+
klass = util_get_class content, 'foo'
289+
other_function = klass.method_list.first
290+
291+
assert_equal 'my_method', other_function.name
292+
assert_equal " \n a comment for other_function\n \n",
293+
other_function.comment
294+
assert_equal '()', other_function.params
295+
296+
code = other_function.token_stream.first.text
297+
298+
assert_equal "VALUE\nother_function() ", code
299+
end
300+
271301
def test_define_method
272302
content = <<-EOF
273303
/*Method Comment! */

0 commit comments

Comments
 (0)