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

Handling of reserved identifiers and operators in the identifier parser #817

Open
sjakobi opened this issue May 8, 2018 · 6 comments
Open

Comments

@sjakobi
Copy link
Member

sjakobi commented May 8, 2018

I've noticed that the identifier parser will accept e.g. 'case' or '..' as identifiers although both are reserved and can't be hyperlinked. This isn't much of a problem as the renamer will mark them as DocMonospaced instead of DocIdentifier but maybe there are arguments for correcting this nonetheless?

Relatedly, maybe haddock should emit a warning when it can't resolve an identifier and applies DocMonospaced?

@alexbiehl
Copy link
Member

Good call. I have prepared haddock-api to emit renamer warnings already. Feel free to make a PR to output actual warnings.

@sjakobi
Copy link
Member Author

sjakobi commented May 8, 2018

Strangely, when I tried to use my patch for #819 to produce warnings for 'case' and '..', I didn't get any.

A bit of print-debugging revealed that e.g. 'case' was handled as a DocString "'case'". I don't understand why haddock-library's ParserSpec then parses them as DocIdentifiers. Any ideas?

@alexbiehl
Copy link
Member

Maybe a difference between parseString and parseParas? Unlikely but an association I had.

@sjakobi
Copy link
Member Author

sjakobi commented May 8, 2018

Maybe a difference between parseString and parseParas? Unlikely but an association I had.

No, parseString and parseParas both parse reserved identifiers as DocIdentifiers.

@harpocrates
Copy link
Collaborator

Strangely, when I tried to use my patch for #819 to produce warnings for 'case' and '..', I didn't get any.

A bit of print-debugging revealed that e.g. 'case' was handled as a DocString "'case'". I don't understand why haddock-library's ParserSpec then parses them as DocIdentifiers. Any ideas?

This happens entirely on the haddock-api side in parseString and parseParas. Note that both of these have a call to P.overIdentifier (parseIdent d).

parseParas :: DynFlags -> Maybe Package -> String -> MetaDoc mod RdrName
parseParas d p = overDoc (P.overIdentifier (parseIdent d)) . P.parseParas p

parseString :: DynFlags -> String -> DocH mod RdrName
parseString d = P.overIdentifier (parseIdent d) . P.parseString

parseIdent calls out to GHC and returns Nothing for things that aren't valid identifiers according to the GHC parser. overIdentifier converts identifiers that were mapped to Nothing into DocString (here).

@sjakobi
Copy link
Member Author

sjakobi commented May 8, 2018

Thanks @harpocrates. I hadn't noticed that haddock-api also has functions called parseParas and parseString.

I'm wondering though if users of haddock-library shouldn't be able to expect the parser to handle the question of valid or invalid identifiers.

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

3 participants