{"action":"created","issue":{"url":"https://api.github.com/repos/Geal/nom/issues/317","repository_url":"https://api.github.com/repos/Geal/nom","labels_url":"https://api.github.com/repos/Geal/nom/issues/317/labels{/name}","comments_url":"https://api.github.com/repos/Geal/nom/issues/317/comments","events_url":"https://api.github.com/repos/Geal/nom/issues/317/events","html_url":"https://github.com/Geal/nom/pull/317","id":181046594,"number":317,"title":"Including doc comments in named! macro (Not complete)","user":{"login":"giodamelio","id":441646,"avatar_url":"https://avatars.githubusercontent.com/u/441646?v=3","gravatar_id":"","url":"https://api.github.com/users/giodamelio","html_url":"https://github.com/giodamelio","followers_url":"https://api.github.com/users/giodamelio/followers","following_url":"https://api.github.com/users/giodamelio/following{/other_user}","gists_url":"https://api.github.com/users/giodamelio/gists{/gist_id}","starred_url":"https://api.github.com/users/giodamelio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giodamelio/subscriptions","organizations_url":"https://api.github.com/users/giodamelio/orgs","repos_url":"https://api.github.com/users/giodamelio/repos","events_url":"https://api.github.com/users/giodamelio/events{/privacy}","received_events_url":"https://api.github.com/users/giodamelio/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-05T01:43:31Z","updated_at":"2016-10-20T09:54:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Geal/nom/pulls/317","html_url":"https://github.com/Geal/nom/pull/317","diff_url":"https://github.com/Geal/nom/pull/317.diff","patch_url":"https://github.com/Geal/nom/pull/317.patch"},"body":"I am making a bunch of parsers with the `named!` macro and I want to be able to include doc comments for them so I can make doc tests. I tried putting them directly before the macro but they don't seem to be picked up by the compiler. So I decided to try to modify the `named!` macro to support them myself. I knew nothing about macros when I started this little experiment, so please be gentle. Hopefully there is a simple solution that I missed.\r\n\r\nAfter a bit of research I found out that doc comments are actually converted to attributes during compilation, so `/// This is a doc comment` becomes `#[doc = \"This is a doc comment\"]`. Since we can [match meta attributes](https://doc.rust-lang.org/book/macros.html#syntactic-requirements) in macros, it should be possible to grab them and stick them before the output function. It seems to work with a [simple example](https://play.rust-lang.org/?code=macro_rules!%20test%20%7B%0A%20%20%20%20(%24(%23%5B%24attr%3Ameta%5D)*)%20%3D%3E%20%7B%0A%20%20%20%20%20%20%20%20%24(%23%5B%24attr%5D)*%0A%20%20%20%20%20%20%20%20fn%20print()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20println!(%22Test!%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20print()%3B%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20test!(%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20Testing%0A%20%20%20%20%20%20%20%20%2F%2F%2F%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%60%60%60%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20assert_eq!(true%2C%20true)%3B%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%60%60%60%0A%20%20%20%20)%3B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20%22Hello%20World%22)%3B%0A%7D&version=nightly&backtrace=0)(running `cargo rustc --lib -- -Z unstable-options --pretty=expanded` shows the `#[doc]` attributes directly above the print function). Unfortunately when I tried to modify the `named!` macro(with the changes in the commit in this pull request) to do the same thing, I ran info some ambiguity issues that are a bit above my skill level.\r\n\r\n    error: local ambiguity: multiple parsing options: built-in NTs ident ('name') or 1 other option.\r\n\r\nI found an [issue](https://github.com/rust-lang/rust/issues/24189) about this exact problem, and it does have a work-around, but it seems like a hack, and I don't really understand it enough to try it. Plus I think it would require some pretty big changes to the implementation of the `named!` macro, which might not be such a good idea.\r\n\r\nI am wondering what your thoughts on this are @Geal? Is it even good idea at all. Is the solution worth the changes?"},"comment":{"url":"https://api.github.com/repos/Geal/nom/issues/comments/255062032","html_url":"https://github.com/Geal/nom/pull/317#issuecomment-255062032","issue_url":"https://api.github.com/repos/Geal/nom/issues/317","id":255062032,"user":{"login":"keeperofdakeys","id":141626,"avatar_url":"https://avatars.githubusercontent.com/u/141626?v=3","gravatar_id":"","url":"https://api.github.com/users/keeperofdakeys","html_url":"https://github.com/keeperofdakeys","followers_url":"https://api.github.com/users/keeperofdakeys/followers","following_url":"https://api.github.com/users/keeperofdakeys/following{/other_user}","gists_url":"https://api.github.com/users/keeperofdakeys/gists{/gist_id}","starred_url":"https://api.github.com/users/keeperofdakeys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keeperofdakeys/subscriptions","organizations_url":"https://api.github.com/users/keeperofdakeys/orgs","repos_url":"https://api.github.com/users/keeperofdakeys/repos","events_url":"https://api.github.com/users/keeperofdakeys/events{/privacy}","received_events_url":"https://api.github.com/users/keeperofdakeys/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T09:54:30Z","updated_at":"2016-10-20T09:54:30Z","body":"I've updated my branch with the addition to `named!`, which seems like a positive change. So `named_attr!` is still exported, but `named!` can be used with or without attributes."}}
{"actor":{"display_login":"keeperofdakeys"}}