-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Experiment with getting @!group directive working for C parser. #1238
base: main
Are you sure you want to change the base?
Conversation
@lsegal - any chance you are able to shed some light on the differences between the Ruby and the C parser? Something that let me avoid the kludge I currently got? |
@thomthom I think the implementation seems kludgey because adding to the OverrideCommentHandler is mixing multiple concerns together. If you had a separate handler just for directives it would probably look a lot simpler: class YARD::Handlers::C::DirectiveParserHandler < YARD::Handlers::C::Base
handles(/./)
statement_class Comment
process do
Docstring.parser.parse(statement.source, namespace, self)
end
end I believe this works. |
Add assert that verified @!endgroup works. Address RuboCop
I had another look at this again. Reverted my hacks, kept the spec. What I'm seeing is that the I added similar spec to the Ruby parser, trying to see how they behave differently, but so far failing. Any suggestions to how to ensure the |
Can this relate to differences in how Ruby and C is parsed? Ruby appear to traverse via the AST tree, where as C appear to be parsed by regex extraction, which makes things not to be processes in the order they appear in the source? |
Here are my observations:
After
Even though the comments are in the same scope as the body statements the parser extracts them such that they comments end up in the outer "scope". It looks like the logic is that the comments are bounded in post processing. But that means the With my kludge in
Getting the directives processed within the same scope as the body statements appear to be important for this state to be turned on and off properly. Trying to figure out a way that is less hacky than my proof of concept. But it seems it require some more fundamental change to the C parser. Unless I'm missing some other mechanism I ca use? |
This reverts commit 0e5567a.
b02a7e9
to
7bb63be
Compare
I haven't been able to figure out a solution that avoids copying the Do you have any further suggestions I can try? |
44c07a8
to
112a890
Compare
@lsegal - any chance you have time to consider questions in earlier comment? #1238 (comment) The current way C source is parsed and information stores doesn't seem to fit with the actual scope of the sources. |
@lsegal It looks like the rename of the primary branch to |
Oh good catch. Let's reopen them |
I'm having another look at this. @lsegal do you have a spare moment to look at my earlier question in this comment: #1238 (comment) ? I'd help me in what direction to attempt next. |
Description
This is experimenting into allowing
@!group
directive tags to be picked up byCParser
. (#1237) This is a kludgy approach - but I wanted to get the conversation going as I'm not sure exactly where the correct fix should be applied.From debugging it appear that
CParser
ignore all comments withingconsume_body_statements
- this prevents the directives from being activated for the scope of the function body that defines the class/method along with it's methods and constants.In my experimental exploring I found that I could wrangle it to pick up the directives by capturing any comments starting with
@!
and assuming they are directive tags. Doing so ensured thegroup
got applied to the objects withinYARD::Registry
.The rest of the test suite also passes - but as you can see, I'm really forcing things here. If you have time to provide some insights to how this can be more appropriately addressed I'd appreciate it.
I stepped through both the C parser and Ruby parser comparing their logic - but I struggled to find a common pattern for the parsing that I could apply to backport to the
CParser
. The main thing I noticed was that the Ruby parser picked up the directive comments and registered them viaregister_docstring
before the constants were processed. That's what this experiment applies.Completed Tasks
bundle exec rake
locally (if code is attached to PR).