{"action":"created","comment":{"url":"https://api.github.com/repos/antlr/antlr4/pulls/comments/244497122","pull_request_review_id":188414274,"id":244497122,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0NDQ5NzEyMg==","diff_hunk":"@@ -165,28 +172,31 @@ def _reduceToSingleOperationPerIndex(self, rewrites):\n         for i, iop in enumerate(rewrites):\n             if any((iop is None, not isinstance(iop, TokenStreamRewriter.InsertBeforeOp))):\n                 continue\n-            prevInserts = [op for op in rewrites[:i] if isinstance(iop, TokenStreamRewriter.InsertBeforeOp)]\n-            for prevIop in prevInserts:\n-                if prevIop.index == iop.index:\n+            prevInserts = [op for op in rewrites[:i] if isinstance(op, TokenStreamRewriter.InsertBeforeOp)]\n+            for i, prevIop in enumerate(prevInserts):\n+                if prevIop.index == iop.index and type(prevIop) is TokenStreamRewriter.InsertBeforeOp:\n                     iop.text += prevIop.text\n                     rewrites[i] = None\n+                elif prevIop.index == iop.index and type(prevIop) is TokenStreamRewriter.InsertAfterOp:\n+                    iop.text = prevIop.text + iop.text\n+                    rewrites[i] = None\n             # look for replaces where iop.index is in range; error\n             prevReplaces = [op for op in rewrites[:i] if isinstance(op, TokenStreamRewriter.ReplaceOp)]\n             for rop in prevReplaces:\n                 if iop.index == rop.index:\n                     rop.text = iop.text + rop.text\n                     rewrites[i] = None\n                     continue\n-                if all((iop.index >= rop.index, iop.index <= rop.index)):\n+                if all((iop.index >= rop.index, iop.index <= rop.last_index)):\n                     raise ValueError(\"insert op {} within boundaries of previous {}\".format(iop, rop))\n \n-            reduced = {}\n-            for i, op in enumerate(rewrites):\n-                if op is None: continue\n-                if reduced.get(op.index): raise ValueError('should be only one op per index')\n-                reduced[op.index] = op\n+        reduced = {}\n+        for i, op in enumerate(rewrites):\n+            if op is None: continue\n+            if reduced.get(op.index): raise ValueError('should be only one op per index')\n+            reduced[op.index] = op\n \n-            return reduced\n+        return reduced","path":"runtime/Python3/src/antlr4/TokenStreamRewriter.py","position":112,"original_position":112,"commit_id":"b0d8b452f8c07fbedf5bd32b2ac4a775f6fbba55","original_commit_id":"b0d8b452f8c07fbedf5bd32b2ac4a775f6fbba55","user":{"login":"youkaichao","id":23236638,"node_id":"MDQ6VXNlcjIzMjM2NjM4","avatar_url":"https://avatars0.githubusercontent.com/u/23236638?v=4","gravatar_id":"","url":"https://api.github.com/users/youkaichao","html_url":"https://github.com/youkaichao","followers_url":"https://api.github.com/users/youkaichao/followers","following_url":"https://api.github.com/users/youkaichao/following{/other_user}","gists_url":"https://api.github.com/users/youkaichao/gists{/gist_id}","starred_url":"https://api.github.com/users/youkaichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youkaichao/subscriptions","organizations_url":"https://api.github.com/users/youkaichao/orgs","repos_url":"https://api.github.com/users/youkaichao/repos","events_url":"https://api.github.com/users/youkaichao/events{/privacy}","received_events_url":"https://api.github.com/users/youkaichao/received_events","type":"User","site_admin":false},"body":"Just to find a mis-indented block ...... I don't know what to say","created_at":"2018-12-29T15:29:44Z","updated_at":"2018-12-29T15:31:18Z","html_url":"https://github.com/antlr/antlr4/pull/2452#discussion_r244497122","pull_request_url":"https://api.github.com/repos/antlr/antlr4/pulls/2452","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/comments/244497122"},"html":{"href":"https://github.com/antlr/antlr4/pull/2452#discussion_r244497122"},"pull_request":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/2452"}}},"pull_request":{"url":"https://api.github.com/repos/antlr/antlr4/pulls/2452","id":240765683,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwNzY1Njgz","html_url":"https://github.com/antlr/antlr4/pull/2452","diff_url":"https://github.com/antlr/antlr4/pull/2452.diff","patch_url":"https://github.com/antlr/antlr4/pull/2452.patch","issue_url":"https://api.github.com/repos/antlr/antlr4/issues/2452","number":2452,"state":"open","locked":false,"title":"bugfix for python-runtime/TokenStreamRewriter.getText","user":{"login":"youkaichao","id":23236638,"node_id":"MDQ6VXNlcjIzMjM2NjM4","avatar_url":"https://avatars0.githubusercontent.com/u/23236638?v=4","gravatar_id":"","url":"https://api.github.com/users/youkaichao","html_url":"https://github.com/youkaichao","followers_url":"https://api.github.com/users/youkaichao/followers","following_url":"https://api.github.com/users/youkaichao/following{/other_user}","gists_url":"https://api.github.com/users/youkaichao/gists{/gist_id}","starred_url":"https://api.github.com/users/youkaichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youkaichao/subscriptions","organizations_url":"https://api.github.com/users/youkaichao/orgs","repos_url":"https://api.github.com/users/youkaichao/repos","events_url":"https://api.github.com/users/youkaichao/events{/privacy}","received_events_url":"https://api.github.com/users/youkaichao/received_events","type":"User","site_admin":false},"body":"This is a bug. If I insert something after the last token, that ``insertation`` will be executed twice!\r\n\r\nA minimal working example is:\r\n\r\ntest.g4\r\n```\r\ngrammar test;\r\nruleABC : 'aa' EOF ;\r\n```\r\n\r\ntest.txt\r\n```\r\naa\r\n```\r\n\r\ntest.py\r\n```\r\nimport sys\r\nfrom antlr4 import *\r\nfrom testLexer import testLexer\r\nfrom testParser import testParser\r\nfrom antlr4.TokenStreamRewriter import TokenStreamRewriter\r\nfrom collections import namedtuple\r\nfrom testListener import testListener\r\nInterval = namedtuple(\"Interval\", [\"start\", \"stop\"])\r\n\r\nclass MyListener(testListener):\r\n\r\n    def __init__(self, tokens:BufferedTokenStream) -> None:\r\n        super().__init__()\r\n        self.writer = TokenStreamRewriter(tokens)\r\n\r\n    def getText(self):\r\n        return self.writer.getText(TokenStreamRewriter.DEFAULT_PROGRAM_NAME, Interval(0, len(self.writer.tokens.tokens)))\r\n\r\n    def enterRuleABC(self, ctx:testParser.RuleABCContext):\r\n        self.writer.insertAfterToken(ctx.stop, 'it appears first!\\n')\r\n\r\n\r\ndef main(argv):\r\n    input = FileStream('test.txt' if len(argv) <= 1 else argv[1])\r\n    lexer = testLexer(input)\r\n    stream = CommonTokenStream(lexer)\r\n    parser = testParser(stream)\r\n    tree = parser.ruleABC()\r\n    myListener = MyListener(stream)\r\n    walker = ParseTreeWalker()\r\n    walker.walk(myListener, tree)\r\n\r\n    print(myListener.getText())\r\n\r\n\r\nif __name__ == '__main__':\r\n    main(sys.argv)\r\n```\r\n\r\nthe output is : \r\n```\r\naait appears first!\r\nit appears first!\r\n```\r\n\r\nThe purpose here is to insert **one** sentence. However, it ends up that **two** sentences are inserted!","created_at":"2018-12-24T12:03:31Z","updated_at":"2018-12-29T15:31:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"04987bfafa0b164987de2876480b82284e0131a7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":230901251,"node_id":"MDU6TGFiZWwyMzA5MDEyNTE=","url":"https://api.github.com/repos/antlr/antlr4/labels/target:python2","name":"target:python2","color":"bfe5bf","default":false},{"id":230901266,"node_id":"MDU6TGFiZWwyMzA5MDEyNjY=","url":"https://api.github.com/repos/antlr/antlr4/labels/target:python3","name":"target:python3","color":"c7def8","default":false},{"id":237266,"node_id":"MDU6TGFiZWwyMzcyNjY=","url":"https://api.github.com/repos/antlr/antlr4/labels/type:bug","name":"type:bug","color":"e0b5b3","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/antlr/antlr4/pulls/2452/commits","review_comments_url":"https://api.github.com/repos/antlr/antlr4/pulls/2452/comments","review_comment_url":"https://api.github.com/repos/antlr/antlr4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/antlr/antlr4/issues/2452/comments","statuses_url":"https://api.github.com/repos/antlr/antlr4/statuses/b0d8b452f8c07fbedf5bd32b2ac4a775f6fbba55","head":{"label":"youkaichao:bugfix/python","ref":"bugfix/python","sha":"b0d8b452f8c07fbedf5bd32b2ac4a775f6fbba55","user":{"login":"youkaichao","id":23236638,"node_id":"MDQ6VXNlcjIzMjM2NjM4","avatar_url":"https://avatars0.githubusercontent.com/u/23236638?v=4","gravatar_id":"","url":"https://api.github.com/users/youkaichao","html_url":"https://github.com/youkaichao","followers_url":"https://api.github.com/users/youkaichao/followers","following_url":"https://api.github.com/users/youkaichao/following{/other_user}","gists_url":"https://api.github.com/users/youkaichao/gists{/gist_id}","starred_url":"https://api.github.com/users/youkaichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youkaichao/subscriptions","organizations_url":"https://api.github.com/users/youkaichao/orgs","repos_url":"https://api.github.com/users/youkaichao/repos","events_url":"https://api.github.com/users/youkaichao/events{/privacy}","received_events_url":"https://api.github.com/users/youkaichao/received_events","type":"User","site_admin":false},"repo":{"id":162873150,"node_id":"MDEwOlJlcG9zaXRvcnkxNjI4NzMxNTA=","name":"antlr4","full_name":"youkaichao/antlr4","private":false,"owner":{"login":"youkaichao","id":23236638,"node_id":"MDQ6VXNlcjIzMjM2NjM4","avatar_url":"https://avatars0.githubusercontent.com/u/23236638?v=4","gravatar_id":"","url":"https://api.github.com/users/youkaichao","html_url":"https://github.com/youkaichao","followers_url":"https://api.github.com/users/youkaichao/followers","following_url":"https://api.github.com/users/youkaichao/following{/other_user}","gists_url":"https://api.github.com/users/youkaichao/gists{/gist_id}","starred_url":"https://api.github.com/users/youkaichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/youkaichao/subscriptions","organizations_url":"https://api.github.com/users/youkaichao/orgs","repos_url":"https://api.github.com/users/youkaichao/repos","events_url":"https://api.github.com/users/youkaichao/events{/privacy}","received_events_url":"https://api.github.com/users/youkaichao/received_events","type":"User","site_admin":false},"html_url":"https://github.com/youkaichao/antlr4","description":"ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.","fork":true,"url":"https://api.github.com/repos/youkaichao/antlr4","forks_url":"https://api.github.com/repos/youkaichao/antlr4/forks","keys_url":"https://api.github.com/repos/youkaichao/antlr4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/youkaichao/antlr4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/youkaichao/antlr4/teams","hooks_url":"https://api.github.com/repos/youkaichao/antlr4/hooks","issue_events_url":"https://api.github.com/repos/youkaichao/antlr4/issues/events{/number}","events_url":"https://api.github.com/repos/youkaichao/antlr4/events","assignees_url":"https://api.github.com/repos/youkaichao/antlr4/assignees{/user}","branches_url":"https://api.github.com/repos/youkaichao/antlr4/branches{/branch}","tags_url":"https://api.github.com/repos/youkaichao/antlr4/tags","blobs_url":"https://api.github.com/repos/youkaichao/antlr4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/youkaichao/antlr4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/youkaichao/antlr4/git/refs{/sha}","trees_url":"https://api.github.com/repos/youkaichao/antlr4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/youkaichao/antlr4/statuses/{sha}","languages_url":"https://api.github.com/repos/youkaichao/antlr4/languages","stargazers_url":"https://api.github.com/repos/youkaichao/antlr4/stargazers","contributors_url":"https://api.github.com/repos/youkaichao/antlr4/contributors","subscribers_url":"https://api.github.com/repos/youkaichao/antlr4/subscribers","subscription_url":"https://api.github.com/repos/youkaichao/antlr4/subscription","commits_url":"https://api.github.com/repos/youkaichao/antlr4/commits{/sha}","git_commits_url":"https://api.github.com/repos/youkaichao/antlr4/git/commits{/sha}","comments_url":"https://api.github.com/repos/youkaichao/antlr4/comments{/number}","issue_comment_url":"https://api.github.com/repos/youkaichao/antlr4/issues/comments{/number}","contents_url":"https://api.github.com/repos/youkaichao/antlr4/contents/{+path}","compare_url":"https://api.github.com/repos/youkaichao/antlr4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/youkaichao/antlr4/merges","archive_url":"https://api.github.com/repos/youkaichao/antlr4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/youkaichao/antlr4/downloads","issues_url":"https://api.github.com/repos/youkaichao/antlr4/issues{/number}","pulls_url":"https://api.github.com/repos/youkaichao/antlr4/pulls{/number}","milestones_url":"https://api.github.com/repos/youkaichao/antlr4/milestones{/number}","notifications_url":"https://api.github.com/repos/youkaichao/antlr4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/youkaichao/antlr4/labels{/name}","releases_url":"https://api.github.com/repos/youkaichao/antlr4/releases{/id}","deployments_url":"https://api.github.com/repos/youkaichao/antlr4/deployments","created_at":"2018-12-23T08:04:26Z","updated_at":"2018-12-23T12:00:49Z","pushed_at":"2018-12-29T15:18:07Z","git_url":"git://github.com/youkaichao/antlr4.git","ssh_url":"git@github.com:youkaichao/antlr4.git","clone_url":"https://github.com/youkaichao/antlr4.git","svn_url":"https://github.com/youkaichao/antlr4","homepage":"http://antlr.org","size":62527,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"antlr:master","ref":"master","sha":"6808f9c4b435abdebb48f3254db699109910aa0c","user":{"login":"antlr","id":80584,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTg0","avatar_url":"https://avatars0.githubusercontent.com/u/80584?v=4","gravatar_id":"","url":"https://api.github.com/users/antlr","html_url":"https://github.com/antlr","followers_url":"https://api.github.com/users/antlr/followers","following_url":"https://api.github.com/users/antlr/following{/other_user}","gists_url":"https://api.github.com/users/antlr/gists{/gist_id}","starred_url":"https://api.github.com/users/antlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antlr/subscriptions","organizations_url":"https://api.github.com/users/antlr/orgs","repos_url":"https://api.github.com/users/antlr/repos","events_url":"https://api.github.com/users/antlr/events{/privacy}","received_events_url":"https://api.github.com/users/antlr/received_events","type":"Organization","site_admin":false},"repo":{"id":501687,"node_id":"MDEwOlJlcG9zaXRvcnk1MDE2ODc=","name":"antlr4","full_name":"antlr/antlr4","private":false,"owner":{"login":"antlr","id":80584,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwNTg0","avatar_url":"https://avatars0.githubusercontent.com/u/80584?v=4","gravatar_id":"","url":"https://api.github.com/users/antlr","html_url":"https://github.com/antlr","followers_url":"https://api.github.com/users/antlr/followers","following_url":"https://api.github.com/users/antlr/following{/other_user}","gists_url":"https://api.github.com/users/antlr/gists{/gist_id}","starred_url":"https://api.github.com/users/antlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antlr/subscriptions","organizations_url":"https://api.github.com/users/antlr/orgs","repos_url":"https://api.github.com/users/antlr/repos","events_url":"https://api.github.com/users/antlr/events{/privacy}","received_events_url":"https://api.github.com/users/antlr/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/antlr/antlr4","description":"ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.","fork":false,"url":"https://api.github.com/repos/antlr/antlr4","forks_url":"https://api.github.com/repos/antlr/antlr4/forks","keys_url":"https://api.github.com/repos/antlr/antlr4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/antlr/antlr4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/antlr/antlr4/teams","hooks_url":"https://api.github.com/repos/antlr/antlr4/hooks","issue_events_url":"https://api.github.com/repos/antlr/antlr4/issues/events{/number}","events_url":"https://api.github.com/repos/antlr/antlr4/events","assignees_url":"https://api.github.com/repos/antlr/antlr4/assignees{/user}","branches_url":"https://api.github.com/repos/antlr/antlr4/branches{/branch}","tags_url":"https://api.github.com/repos/antlr/antlr4/tags","blobs_url":"https://api.github.com/repos/antlr/antlr4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/antlr/antlr4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/antlr/antlr4/git/refs{/sha}","trees_url":"https://api.github.com/repos/antlr/antlr4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/antlr/antlr4/statuses/{sha}","languages_url":"https://api.github.com/repos/antlr/antlr4/languages","stargazers_url":"https://api.github.com/repos/antlr/antlr4/stargazers","contributors_url":"https://api.github.com/repos/antlr/antlr4/contributors","subscribers_url":"https://api.github.com/repos/antlr/antlr4/subscribers","subscription_url":"https://api.github.com/repos/antlr/antlr4/subscription","commits_url":"https://api.github.com/repos/antlr/antlr4/commits{/sha}","git_commits_url":"https://api.github.com/repos/antlr/antlr4/git/commits{/sha}","comments_url":"https://api.github.com/repos/antlr/antlr4/comments{/number}","issue_comment_url":"https://api.github.com/repos/antlr/antlr4/issues/comments{/number}","contents_url":"https://api.github.com/repos/antlr/antlr4/contents/{+path}","compare_url":"https://api.github.com/repos/antlr/antlr4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/antlr/antlr4/merges","archive_url":"https://api.github.com/repos/antlr/antlr4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/antlr/antlr4/downloads","issues_url":"https://api.github.com/repos/antlr/antlr4/issues{/number}","pulls_url":"https://api.github.com/repos/antlr/antlr4/pulls{/number}","milestones_url":"https://api.github.com/repos/antlr/antlr4/milestones{/number}","notifications_url":"https://api.github.com/repos/antlr/antlr4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/antlr/antlr4/labels{/name}","releases_url":"https://api.github.com/repos/antlr/antlr4/releases{/id}","deployments_url":"https://api.github.com/repos/antlr/antlr4/deployments","created_at":"2010-02-04T01:36:28Z","updated_at":"2018-12-29T10:37:28Z","pushed_at":"2018-12-29T15:16:28Z","git_url":"git://github.com/antlr/antlr4.git","ssh_url":"git@github.com:antlr/antlr4.git","clone_url":"https://github.com/antlr/antlr4.git","svn_url":"https://github.com/antlr/antlr4","homepage":"http://antlr.org","size":62517,"stargazers_count":4917,"watchers_count":4917,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1315,"mirror_url":null,"archived":false,"open_issues_count":382,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":1315,"open_issues":382,"watchers":4917,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/2452"},"html":{"href":"https://github.com/antlr/antlr4/pull/2452"},"issue":{"href":"https://api.github.com/repos/antlr/antlr4/issues/2452"},"comments":{"href":"https://api.github.com/repos/antlr/antlr4/issues/2452/comments"},"review_comments":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/2452/comments"},"review_comment":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/antlr/antlr4/pulls/2452/commits"},"statuses":{"href":"https://api.github.com/repos/antlr/antlr4/statuses/b0d8b452f8c07fbedf5bd32b2ac4a775f6fbba55"}},"author_association":"NONE"}}
{"actor":{"display_login":"youkaichao"}}