2019-11-04 00:00:00 +00:00
|
|
|
//@ check-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
2014-10-25 22:07:41 +00:00
|
|
|
struct Parser<'a, I, O> {
|
2019-05-28 18:46:13 +00:00
|
|
|
parse: Box<dyn FnMut(I) -> Result<O, String> + 'a>
|
2014-10-25 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 20:26:44 +00:00
|
|
|
impl<'a, I: 'a, O: 'a> Parser<'a, I, O> {
|
2014-10-27 18:03:25 +00:00
|
|
|
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
|
2014-10-25 22:07:41 +00:00
|
|
|
Parser {
|
2015-02-15 08:52:21 +00:00
|
|
|
parse: Box::new(move |x: I| {
|
2015-01-05 19:07:10 +00:00
|
|
|
match (self.parse)(x) {
|
|
|
|
Ok(r) => (rhs.parse)(r),
|
2014-10-25 22:07:41 +00:00
|
|
|
Err(e) => Err(e)
|
|
|
|
}
|
2015-02-15 08:52:21 +00:00
|
|
|
})
|
2014-10-25 22:07:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|