{"action":"created","issue":{"url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/3","repository_url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime","labels_url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/3/comments","events_url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/3/events","html_url":"https://github.com/janyou/Antlr-Swift-Runtime/issues/3","id":146289608,"number":3,"title":"Grammar with semantic predicates produces parser that won't compile","user":{"login":"artyom-razinov","id":6263432,"avatar_url":"https://avatars.githubusercontent.com/u/6263432?v=3","gravatar_id":"","url":"https://api.github.com/users/artyom-razinov","html_url":"https://github.com/artyom-razinov","followers_url":"https://api.github.com/users/artyom-razinov/followers","following_url":"https://api.github.com/users/artyom-razinov/following{/other_user}","gists_url":"https://api.github.com/users/artyom-razinov/gists{/gist_id}","starred_url":"https://api.github.com/users/artyom-razinov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artyom-razinov/subscriptions","organizations_url":"https://api.github.com/users/artyom-razinov/orgs","repos_url":"https://api.github.com/users/artyom-razinov/repos","events_url":"https://api.github.com/users/artyom-razinov/events{/privacy}","received_events_url":"https://api.github.com/users/artyom-razinov/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-06T11:50:31Z","updated_at":"2016-04-06T13:42:58Z","closed_at":"2016-04-06T13:42:58Z","body":"Steps to reproduce:\r\n1. Get ANTLRv4 grammars: https://github.com/antlr/grammars-v4\r\n2. Run antlr for Swift.g4: `java -cp antlr4-4.5.1.jar org.antlr.v4.Tool -Dlanguage=Swift -o gen Swift.g4`\r\n\r\nActutal result:\r\n1. Swift parser has compilation errors\r\n\r\nExpected result:\r\n1. Swift parser can be compiled\r\n\r\nThe cause of problem is this rule for that grammar:\r\n```\r\noperator\r\n  : operator_head     ({_input.get(_input.index()-1).getType()!=WS}? operator_character)*\r\n  | dot_operator_head ({_input.get(_input.index()-1).getType()!=WS}? dot_operator_character)*\r\n  ;\r\n```\r\n\r\nSwift treat \"!=\" as implicit unwrapping operator \"!\". Parser generator should replace binary operators with those that would be compiled in Swift with Antlr-Swift-Runtime.\r\n\r\nThis regex will fix issue: \"([^ ])!=([^ ])\" -> \"$1 != $2\", other binary operators can be compiled, because Swift Reference defines binary operator as operator surrounded with spaces on both sides or on neither side. I don't know why \"!=\" isn't tokenized as a binary operator. Maybe it's even a compiler bug.\r\n\r\nI also don't know if it is necessary to fix this issue."},"comment":{"url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/comments/206378960","html_url":"https://github.com/janyou/Antlr-Swift-Runtime/issues/3#issuecomment-206378960","issue_url":"https://api.github.com/repos/janyou/Antlr-Swift-Runtime/issues/3","id":206378960,"user":{"login":"janyou","id":8850681,"avatar_url":"https://avatars.githubusercontent.com/u/8850681?v=3","gravatar_id":"","url":"https://api.github.com/users/janyou","html_url":"https://github.com/janyou","followers_url":"https://api.github.com/users/janyou/followers","following_url":"https://api.github.com/users/janyou/following{/other_user}","gists_url":"https://api.github.com/users/janyou/gists{/gist_id}","starred_url":"https://api.github.com/users/janyou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janyou/subscriptions","organizations_url":"https://api.github.com/users/janyou/orgs","repos_url":"https://api.github.com/users/janyou/repos","events_url":"https://api.github.com/users/janyou/events{/privacy}","received_events_url":"https://api.github.com/users/janyou/received_events","type":"User","site_admin":false},"created_at":"2016-04-06T13:42:58Z","updated_at":"2016-04-06T13:42:58Z","body":"** {_input.get(_input.index()-1).getType()!=WS}**  is inline code. \r\nNeed to change according to different programming languages. "}}