{"action":"created","issue":{"url":"https://api.github.com/repos/whitequark/parser/issues/194","labels_url":"https://api.github.com/repos/whitequark/parser/issues/194/labels{/name}","comments_url":"https://api.github.com/repos/whitequark/parser/issues/194/comments","events_url":"https://api.github.com/repos/whitequark/parser/issues/194/events","html_url":"https://github.com/whitequark/parser/issues/194","id":77717976,"number":194,"title":"Improve trailing comment association.","user":{"login":"RGBD","id":8408991,"avatar_url":"https://avatars.githubusercontent.com/u/8408991?v=3","gravatar_id":"","url":"https://api.github.com/users/RGBD","html_url":"https://github.com/RGBD","followers_url":"https://api.github.com/users/RGBD/followers","following_url":"https://api.github.com/users/RGBD/following{/other_user}","gists_url":"https://api.github.com/users/RGBD/gists{/gist_id}","starred_url":"https://api.github.com/users/RGBD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RGBD/subscriptions","organizations_url":"https://api.github.com/users/RGBD/orgs","repos_url":"https://api.github.com/users/RGBD/repos","events_url":"https://api.github.com/users/RGBD/events{/privacy}","received_events_url":"https://api.github.com/users/RGBD/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-18T16:28:34Z","updated_at":"2015-05-19T10:34:13Z","closed_at":null,"body":"### Reasoning\r\n\r\nConsider this code:\r\n\r\n``` ruby\r\nclass C\r\n  def foo # def C#foo\r\n    puts 'foo' # puts 'foo'\r\n  end # def C#foo end\r\n\r\n  def bar # def C#bar\r\n    puts 'bar' # puts 'bar'\r\n  end # def C#bar end\r\n  \r\n  #totally unrelated comment\r\nend\r\n```\r\n\r\nIt associates comments in the following way:\r\n\r\n```\r\n(class\r\n  (const nil :C) nil\r\n  (begin\r\n    (def :foo\r\n      (args)\r\n      (send nil :puts\r\n        (str \"foo\")))\r\n    (def :bar\r\n      (args)\r\n      (send nil :puts\r\n        (str \"bar\")))))\r\n>>> 1: 0:# class C before\r\n(def :foo\r\n  (args)\r\n  (send nil :puts\r\n    (str \"foo\")))\r\n>>> 3:10:# def C#foo\r\n(str \"foo\")\r\n>>> 4:15:# puts 'foo'\r\n(def :bar\r\n  (args)\r\n  (send nil :puts\r\n    (str \"bar\")))\r\n>>> 5: 6:# def C#foo end\r\n>>> 7:10:# def C#bar\r\n(str \"bar\")\r\n>>> 8:15:# puts 'bar'\r\n(begin\r\n  (def :foo\r\n    (args)\r\n    (send nil :puts\r\n      (str \"foo\")))\r\n  (def :bar\r\n    (args)\r\n    (send nil :puts\r\n      (str \"bar\"))))\r\n>>> 9: 6:# def C#bar end\r\n>>>11: 2:#totally unrelated comment\r\n```\r\n\r\nSee bigger example: [source](https://gist.github.com/RGBD/0fc6e0377fdefbbf721b#file-test-rb) and [output](https://gist.github.com/RGBD/0fc6e0377fdefbbf721b#file-default-log).\r\nAlso, it partly hides bug in [rubocop](https://github.com/bbatsov/rubocop).\r\n\r\n### My opinion\r\n\r\nI think, this is a bit counter-intuitive. Also now\r\nParser::Source::Comment::Associator#accociate contains a workaround for\r\ntrailing (akasparse in tests) comments, which might, or might not be associated\r\nwith enclosing or preceding block (see gist).\r\n\r\n### What can be done\r\n\r\nI propose another principle of comment association.\r\n\r\n#### Features\r\n\r\n- It is unambiguous\r\n- It is scalable, association for the whole tree is exactly the same as\r\n  united association for every node (on sparse comments later)\r\n- It has the same behaviour for preceding comments, so that any documentation\r\n  generator using this gem will keep working (correct me if I'm wrong).\r\n- It is configurable, you can deside, whether you need these or that kind of\r\n  comments\r\n\r\n#### Definitions\r\n\r\nSuppose previous node has been processed.\r\n\r\n- Comment is **preceding**, if it starts before the beginning of current node.\r\n  **preceding** comments are supposed to be documenting.\r\n- Comment is **sparse**, if it is inside the body of current node, and after\r\n  the last child node. **sparse** comments' purpose is ambiguous, they could be\r\n  ignored.\r\n- Comment is **decorating**, if it starts at the current node ending line.\r\n\t**decorating** comments comment expression before them, or block endings.\r\n\r\n### Summary\r\n\r\nI hope you will consider my proposal and check out my implementation in (#195)\r\n"},"comment":{"url":"https://api.github.com/repos/whitequark/parser/issues/comments/103431941","html_url":"https://github.com/whitequark/parser/issues/194#issuecomment-103431941","issue_url":"https://api.github.com/repos/whitequark/parser/issues/194","id":103431941,"user":{"login":"mbj","id":117966,"avatar_url":"https://avatars.githubusercontent.com/u/117966?v=3","gravatar_id":"","url":"https://api.github.com/users/mbj","html_url":"https://github.com/mbj","followers_url":"https://api.github.com/users/mbj/followers","following_url":"https://api.github.com/users/mbj/following{/other_user}","gists_url":"https://api.github.com/users/mbj/gists{/gist_id}","starred_url":"https://api.github.com/users/mbj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbj/subscriptions","organizations_url":"https://api.github.com/users/mbj/orgs","repos_url":"https://api.github.com/users/mbj/repos","events_url":"https://api.github.com/users/mbj/events{/privacy}","received_events_url":"https://api.github.com/users/mbj/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T10:34:13Z","updated_at":"2015-05-19T10:34:13Z","body":"Also looks good from my side, unparser will produce better results."}}