2014-10-26 00:07:41 +02: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 09:11:07 -07:00
|
|
|
// ignore-pretty
|
|
|
|
|
2015-01-08 02:25:56 +01:00
|
|
|
#![allow(unknown_features)]
|
|
|
|
#![feature(box_syntax)]
|
2014-10-26 00:07:41 +02:00
|
|
|
#![feature(unboxed_closures)]
|
|
|
|
|
|
|
|
struct Parser<'a, I, O> {
|
2015-01-12 10:27:25 -05:00
|
|
|
parse: Box<FnMut(I) -> Result<O, String> + 'a>
|
2014-10-26 00:07:41 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 12:26:44 -08:00
|
|
|
impl<'a, I: 'a, O: 'a> Parser<'a, I, O> {
|
2014-10-27 14:03:25 -04:00
|
|
|
fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> {
|
2014-10-26 00:07:41 +02:00
|
|
|
Parser {
|
2015-02-01 12:44:15 -05:00
|
|
|
parse: box move |x: I| {
|
2015-01-05 14:07:10 -05:00
|
|
|
match (self.parse)(x) {
|
|
|
|
Ok(r) => (rhs.parse)(r),
|
2014-10-26 00:07:41 +02:00
|
|
|
Err(e) => Err(e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|