{"action":"created","issue":{"url":"https://api.github.com/repos/Geal/nom/issues/58","labels_url":"https://api.github.com/repos/Geal/nom/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/Geal/nom/issues/58/comments","events_url":"https://api.github.com/repos/Geal/nom/issues/58/events","html_url":"https://github.com/Geal/nom/issues/58","id":92700970,"number":58,"title":"`alt!` + `map!` + `call!` strange behavior","user":{"login":"kgv","id":863800,"avatar_url":"https://avatars.githubusercontent.com/u/863800?v=3","gravatar_id":"","url":"https://api.github.com/users/kgv","html_url":"https://github.com/kgv","followers_url":"https://api.github.com/users/kgv/followers","following_url":"https://api.github.com/users/kgv/following{/other_user}","gists_url":"https://api.github.com/users/kgv/gists{/gist_id}","starred_url":"https://api.github.com/users/kgv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kgv/subscriptions","organizations_url":"https://api.github.com/users/kgv/orgs","repos_url":"https://api.github.com/users/kgv/repos","events_url":"https://api.github.com/users/kgv/events{/privacy}","received_events_url":"https://api.github.com/users/kgv/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-02T18:23:37Z","updated_at":"2015-07-03T15:21:04Z","closed_at":"2015-07-03T15:19:59Z","body":"`alt!` + `map!` + `call!` have strange behavior.\r\n\r\nThis code work. See to closure in `map!`:\r\n\r\n```Rust\r\nnamed!(range<&[u8], Range>,\r\n    alt!(\r\n        chain!(\r\n            start: take_char ~\r\n            tag!(\"-\") ~\r\n            end: take_char,\r\n            || {\r\n                debug!(\"range: (start, end): ({:?}, {:?})\", start, end);\r\n                Range {\r\n                    start: start,\r\n                    end: end,\r\n                }\r\n            }\r\n        ) |\r\n        map!(\r\n            take_char,\r\n            |c| {\r\n                debug!(\"range: c: {:?}\", c);\r\n                Range {\r\n                    start: c,\r\n                    end: c,\r\n                }\r\n            }\r\n        )\r\n    )\r\n);\r\n```\r\n\r\nIf we try to wrap closure in `map!` by `call!`, it will not work:\r\n\r\n```Rust\r\n...\r\n        map!(\r\n            take_char,\r\n            call!(|c| {\r\n                debug!(\"range: c: {:?}\", c);\r\n                Range {\r\n                    start: c,\r\n                    end: c,\r\n                }\r\n            })\r\n        )\r\n...\r\n```\r\n\r\nError:\r\n\r\n```sh\r\nsrc/parser.rs:212:13: 212:14 error: unexpected end of macro invocation\r\nsrc/parser.rs:212             })\r\n                              ^\r\n```\r\n\r\n----\r\n\r\nBut if we use `map!` without `alt!` it have different behavior. Next code work:\r\n\r\n```Rust\r\nnamed!(literal<&[u8], Expr>,\r\n    map!(\r\n        many1!(take_char),\r\n        call!(|cs| {\r\n            debug!(\"literal: cs: {:?}\", cs);\r\n            Expr::Literal {\r\n                chars: cs,\r\n            }\r\n        })\r\n    )\r\n);\r\n```\r\n\r\nWithout `call!` it not work:\r\n\r\n```Rust\r\nnamed!(literal<&[u8], Expr>,\r\n    map!(\r\n        many1!(take_char),\r\n        |cs| {\r\n            debug!(\"literal: cs: {:?}\", cs);\r\n            Expr::Literal {\r\n                chars: cs,\r\n            }\r\n        }\r\n    )\r\n);\r\n```\r\n\r\nError:\r\n\r\n```sh\r\nsrc/parser.rs:220:9: 220:10 error: expected ident, found |\r\nsrc/parser.rs:220         |cs| {\r\n                          ^\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Geal/nom/issues/comments/118372450","html_url":"https://github.com/Geal/nom/issues/58#issuecomment-118372450","issue_url":"https://api.github.com/repos/Geal/nom/issues/58","id":118372450,"user":{"login":"Geal","id":119296,"avatar_url":"https://avatars.githubusercontent.com/u/119296?v=3","gravatar_id":"","url":"https://api.github.com/users/Geal","html_url":"https://github.com/Geal","followers_url":"https://api.github.com/users/Geal/followers","following_url":"https://api.github.com/users/Geal/following{/other_user}","gists_url":"https://api.github.com/users/Geal/gists{/gist_id}","starred_url":"https://api.github.com/users/Geal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Geal/subscriptions","organizations_url":"https://api.github.com/users/Geal/orgs","repos_url":"https://api.github.com/users/Geal/repos","events_url":"https://api.github.com/users/Geal/events{/privacy}","received_events_url":"https://api.github.com/users/Geal/received_events","type":"User","site_admin":false},"created_at":"2015-07-03T15:21:04Z","updated_at":"2015-07-03T15:21:04Z","body":"It should work with that commit. You do not have to use `call!` in `map!`, `flat_map!` and others like these, they use it already."}}