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

Added YARD::Parser::CParser#find_override_comments #177

Closed
wants to merge 1 commit into from

Conversation

srawlins
Copy link
Contributor

This method is used when the body of a Ruby method (but really its corresponding C function) is not found (in the cases in my code it is because they are defined in C macros). In existing (your) code, it is referenced in comments in parser/c_parser.rb, under find_method_body. I un-commented these, changing the calling syntax for find_override_comment. I then borrowed the gist of find_override_comment from RDoc (just as most of this file is borrowed from RDoc), tweaking the arguments etc to use your more OO-approach. The muscle of this method is the Regex, which is taken directly from RDoc. The first regex matches something like:

/*
 * Document-method: Array#join
 */

The second matches the same without the class explicitly written.

I added a test C source file, spec/parser/examples/override.c.txt. It is taken from my GMP bindings, a C Extension: http://github.com/srawlins/gmp. It contains some Ruby methods (but really, their associated C functions) with and without bodies visible to YARD. For example, GMP::Z#+ and GMP::Z#add! have visible function bodies, and GMP::Z#neg and GMP::Z#neg! do not. So these examples contain comments like:

/*
 * call-seq:
 *   a + b
 *   ...

for a visible-bodied method, and:

/*
 * Document-method: neg!
 *
 * call-seq:
 *   a.neg!
 *   ...

for an invisible-bodied method. YARD should seek out both.

I added tests to spec/parser/c_parser_spec.rb

You mentioned the spec/parser specs are weak. I should look at spec/handler instead. I had already written these. I would enjoy writing more specs if I knew exactly where to put them... it looks like method_handler_spec.rb ?

Let me know where you want to go from here.

@lsegal
Copy link
Owner

lsegal commented Oct 3, 2010

5c2038a was just merged. There are no method handlers for C sources, so this will do quite well, thanks for the patch!

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants