2014-10-25 17:07:41 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-10-27 11:11:07 -05:00
|
|
|
// ignore-pretty
|
|
|
|
|
2015-01-07 19:25:56 -06:00
|
|
|
#![allow(unknown_features)]
|
|
|
|
#![feature(box_syntax)]
|
2014-10-25 17:07:41 -05:00
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
|
|
|
|
struct Parser<'a, I, O> {
|
2015-01-12 09:27:25 -06:00
|
|
|
parse: Box<FnMut(I) -> Result<O, String> + 'a>
|
2014-10-25 17:07:41 -05:00
|
|
|
}
|
|
|
|
|
2015-01-30 14:26:44 -06:00
|
|
|
impl<'a, I: 'a, O: 'a> Parser<'a, I, O> {
|
2014-10-27 13:03:25 -05:00
|
|
|
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
|
2014-10-25 17:07:41 -05:00
|
|
|
Parser {
|
2015-02-01 11:44:15 -06:00
|
|
|
parse: box move |x: I| {
|
2015-01-05 13:07:10 -06:00
|
|
|
match (self.parse)(x) {
|
|
|
|
Ok(r) => (rhs.parse)(r),
|
2014-10-25 17:07:41 -05:00
|
|
|
Err(e) => Err(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|