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

Type explainer can't parse methods ending in '?' and '!' #1077

Closed
backus opened this issue Mar 13, 2017 · 7 comments
Closed

Type explainer can't parse methods ending in '?' and '!' #1077

backus opened this issue Mar 13, 2017 · 7 comments

Comments

@backus
Copy link

backus commented Mar 13, 2017

It would be nice to be able to document methods as @param foo [#all?] but the type explainer currently fails on methods like this. I realize it is really hard to parse ruby methods so I'm definitely not asking for something comprehensive, but adding ? and ! would be nice.

Steps to reproduce

$ irb
>> require 'yard'
>> YARD::Tags::TypesExplainer::Parser.parse('#all?')
SyntaxError: invalid character at ?
from /Users/johnbackus/.gem/ruby/2.3.1/gems/yard-0.9.8/lib/yard/tags/types_explainer.rb:154:in `block in parse'
>> YARD::Tags::TypesExplainer::Parser.parse('#gsub!')
SyntaxError: invalid character at !
from /Users/johnbackus/.gem/ruby/2.3.1/gems/yard-0.9.8/lib/yard/tags/types_explainer.rb:154:in `block in parse'

I would be happy to do a PR fixing this

@backus
Copy link
Author

backus commented Mar 23, 2017

For context, I opened this issue because I am currently using the type explainer for backus/yardcheck. I realize it is private API and I intend on replacing it with my own parser, but I figured this would still be something YARD might want to fix

@lsegal
Copy link
Owner

lsegal commented Mar 25, 2017

You can actually probably use CodeObjects::METHODNAMEMATCH to parse most method names. The type explainer module could be improved to use that instead of what it currently does.

@backus
Copy link
Author

backus commented Mar 25, 2017

Cool. I can open a PR in the future to support that. Any interest in making the type explainer API public at some point?

@lsegal
Copy link
Owner

lsegal commented Mar 25, 2017

I don't see where it's marked private. You should be able to use it already.

@backus
Copy link
Author

backus commented Mar 25, 2017

Oh I assumed that it was private I guess because all of the namespaces within it are marked @private but that makes sense. Cool. I'm already using it in Yardcheck so glad to know it is public API

@backus
Copy link
Author

backus commented Mar 25, 2017

Ah ok I see what I was concerned about before. TypeExplainer.explain! is public but I need to actually invoke the parser and get back objects. explain! just gives me a string

@lsegal lsegal closed this as completed in 0271dab Apr 24, 2017
@lsegal
Copy link
Owner

lsegal commented Apr 24, 2017

Root issue is fixed. As far as making it public I'd be more open to it if it were documented. If you wanted to contribute docs that would help.

lsegal added a commit that referenced this issue Nov 18, 2017
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

No branches or pull requests

2 participants