{"action":"created","issue":{"url":"https://api.github.com/repos/pegjs/pegjs/issues/310","repository_url":"https://api.github.com/repos/pegjs/pegjs","labels_url":"https://api.github.com/repos/pegjs/pegjs/issues/310/labels{/name}","comments_url":"https://api.github.com/repos/pegjs/pegjs/issues/310/comments","events_url":"https://api.github.com/repos/pegjs/pegjs/issues/310/events","html_url":"https://github.com/pegjs/pegjs/issues/310","id":54017692,"number":310,"title":"Parser doesn't recover if optional token steals match from a required token.","user":{"login":"DigiTec","id":1650078,"avatar_url":"https://avatars.githubusercontent.com/u/1650078?v=3","gravatar_id":"","url":"https://api.github.com/users/DigiTec","html_url":"https://github.com/DigiTec","followers_url":"https://api.github.com/users/DigiTec/followers","following_url":"https://api.github.com/users/DigiTec/following{/other_user}","gists_url":"https://api.github.com/users/DigiTec/gists{/gist_id}","starred_url":"https://api.github.com/users/DigiTec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DigiTec/subscriptions","organizations_url":"https://api.github.com/users/DigiTec/orgs","repos_url":"https://api.github.com/users/DigiTec/repos","events_url":"https://api.github.com/users/DigiTec/events{/privacy}","received_events_url":"https://api.github.com/users/DigiTec/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-12T03:29:35Z","updated_at":"2016-02-26T21:25:56Z","closed_at":"2015-01-12T21:34:58Z","body":"Note, I haven't fully debugged this and there are many workarounds that I have found to get around the bug. However, it would be interesting to understand why it fails to match and what might be wrong in the backtracking behavior.\r\n\r\nNote the parser in this case isn't very strong because of its use of _, its only to demonstrate the issue. By making mods and type more specific and by requiring trailing [ ]+ instead of [ ]* between tokens then things work out a lot better and the parser works.\r\n\r\n/*\r\nInput\r\nfinal LatLng(\r\n\r\nExpected:\r\nmods resolves 'final'\r\n_ resolves space\r\ntype? resolves LatLng then fails then _ and fails ident\r\ntype? advances then _ resolves nothing ident resolves LatLng...\r\n */\r\n\r\nstart = mods _ type? _ ident _ '('\r\n\r\nmods = 'public'? _ 'private'? _ 'final'?\r\n\r\ntype = IDENT\r\n\r\nident = IDENT\r\n\r\nIDENT = [A-Za-z_]+\r\n\r\n_ = [ ]*"},"comment":{"url":"https://api.github.com/repos/pegjs/pegjs/issues/comments/189488527","html_url":"https://github.com/pegjs/pegjs/issues/310#issuecomment-189488527","issue_url":"https://api.github.com/repos/pegjs/pegjs/issues/310","id":189488527,"user":{"login":"lonniev","id":2193384,"avatar_url":"https://avatars.githubusercontent.com/u/2193384?v=3","gravatar_id":"","url":"https://api.github.com/users/lonniev","html_url":"https://github.com/lonniev","followers_url":"https://api.github.com/users/lonniev/followers","following_url":"https://api.github.com/users/lonniev/following{/other_user}","gists_url":"https://api.github.com/users/lonniev/gists{/gist_id}","starred_url":"https://api.github.com/users/lonniev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lonniev/subscriptions","organizations_url":"https://api.github.com/users/lonniev/orgs","repos_url":"https://api.github.com/users/lonniev/repos","events_url":"https://api.github.com/users/lonniev/events{/privacy}","received_events_url":"https://api.github.com/users/lonniev/received_events","type":"User","site_admin":false},"created_at":"2016-02-26T21:25:56Z","updated_at":"2016-02-26T21:25:56Z","body":"Ah, for me, P Q? R works as expected. However, I had a case of:\r\n\r\nrule =\r\n          T\r\n        \\ T B\r\n        \\ B\r\n\r\nin addition to the use of some term? expressions.\r\n\r\nMy error was because subrule T came before subrule T B. When I rewrote the rule with T B first, it matched all 3 cases. Order matters."}}