Remove useless lifetime declarations

This commit is contained in:
Geoffroy Couprie 2015-02-20 18:51:40 +01:00
parent 1eecaba724
commit e121f0aa6f
6 changed files with 73 additions and 73 deletions

View File

@ -7,7 +7,7 @@ use std::fmt::{Debug,Display,Formatter,Result};
pub type Err = u32;
/// (Experimental) Closure used to hold the temporary state of resumable parsing
pub type IResultClosure<'a,I,O> = Box<FnMut(I) -> IResult<'a,I,O> +'a>;
pub type IResultClosure<'a,I,O> = Box<FnMut(I) -> IResult<I,O> +'a>;
//cf libcore/fmt/mod.rs:674
impl<'a,I,O> Debug for IResultClosure<'a,I,O> {
@ -46,18 +46,18 @@ impl<'a,I:Eq,O:Eq> Eq for IResultClosure<'a,I,O> {}
/// * Incomplete will hold the closure used to restart the computation once more data is available.
/// Current attemps at implementation of Incomplete are progressing, but slowed down by lifetime problems
#[derive(Debug,PartialEq,Eq)]
pub enum IResult<'z,I,O> {
pub enum IResult<I,O> {
Done(I,O),
Error(Err),
//Incomplete(proc(I):'a -> IResult<I,O>)
Incomplete(u32)
//Incomplete(Box<FnMut(I) -> IResult<I,O>>)
//Incomplete(IResultClosure<'z,I,O>)
//Incomplete(IResultClosure<I,O>)
//Incomplete(|I|:'a -> IResult<'a,I,O>)
//Incomplete(fn(I) -> IResult<'a,I,O>)
}
impl<'z,I,O> IResult<'z,I,O> {
impl<I,O> IResult<I,O> {
pub fn is_done(&self) -> bool {
match self {
&Done(_,_) => true,
@ -88,7 +88,7 @@ pub trait GetOutput<O> {
fn output(&self) -> Option<O>;
}
impl<'a,'z,I,O> GetInput<&'a[I]> for IResult<'z,&'a[I],O> {
impl<'a,I,O> GetInput<&'a[I]> for IResult<&'a[I],O> {
fn remaining_input(&self) -> Option<&'a[I]> {
match self {
&Done(ref i,_) => Some(*i),
@ -97,7 +97,7 @@ impl<'a,'z,I,O> GetInput<&'a[I]> for IResult<'z,&'a[I],O> {
}
}
impl<'a,'z,O> GetInput<()> for IResult<'z,(),O> {
impl<'a,O> GetInput<()> for IResult<(),O> {
fn remaining_input(&self) -> Option<()> {
match self {
&Done((),_) => Some(()),
@ -106,7 +106,7 @@ impl<'a,'z,O> GetInput<()> for IResult<'z,(),O> {
}
}
impl<'a,'z,I,O> GetOutput<&'a[O]> for IResult<'z,I,&'a[O]> {
impl<'a,I,O> GetOutput<&'a[O]> for IResult<I,&'a[O]> {
fn output(&self) -> Option<&'a[O]> {
match self {
&Done(_, ref o) => Some(*o),
@ -115,7 +115,7 @@ impl<'a,'z,I,O> GetOutput<&'a[O]> for IResult<'z,I,&'a[O]> {
}
}
impl<'a,'z,I> GetOutput<()> for IResult<'z,I,()> {
impl<'a,I> GetOutput<()> for IResult<I,()> {
fn output(&self) -> Option<()> {
match self {
&Done(_,()) => Some(()),

View File

@ -17,10 +17,10 @@ use internal::IResult::*;
/// Done((),()).flat_map(|data| { println!("data: {:?}", data); Done(data,())});
/// ```
pub trait FlatMap<I:?Sized,O:?Sized,N:?Sized> {
fn flat_map<'y,F:Fn(O) -> IResult<'y,O,N>>(& self, f: F) -> IResult<'y,I,N>;
fn flat_map<'y,F:Fn(O) -> IResult<O,N>>(& self, f: F) -> IResult<I,N>;
}
/*
pub fn compose<'x,'y,'z,R,S,T,F:Fn(S) -> IResult<'y,S,T>>(f:F, g:IResultClosure<'z,R,S>) -> IResultClosure<'x,R,T> {
pub fn compose<'x,'y,'z,R,S,T,F:Fn(S) -> IResult<S,T>>(f:F, g:IResultClosure<'z,R,S>) -> IResultClosure<'x,R,T> {
Box::new(move |input: R| -> IResult<'x,R,T> {
g(input).flat_map(f)
})
@ -35,9 +35,9 @@ pub fn compose<'x,'y,'z,R,S,T,F:Fn(S) -> IResult<'y,S,T>>(f:F, g:IResultClosure<
#[macro_export]
macro_rules! flat_map_ref_impl {
($($t:ty)*) => ($(
impl<'a,'b,'z,R,T> FlatMap<&'b R,&'a $t, T> for IResult<'z,&'b R,&'a $t> {
impl<'a,'b,'z,R,T> FlatMap<&'b R,&'a $t, T> for IResult<&'b R,&'a $t> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn(&'a $t) -> IResult<'y,&'a $t,T>>(&self, f: F) -> IResult<'y,&'b R,T> {
fn flat_map<'y,F:Fn(&'a $t) -> IResult<&'a $t,T>>(&self, f: F) -> IResult<&'b R,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(|input:&'b R| { cl(input).map(f) }),
@ -49,9 +49,9 @@ macro_rules! flat_map_ref_impl {
}
}
}
impl<'a,'z,T> FlatMap<(),&'a $t, T> for IResult<'z,(),&'a $t> {
impl<'a,'z,T> FlatMap<(),&'a $t, T> for IResult<(),&'a $t> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn(&'a $t) -> IResult<'y,&'a $t,T>>(&self, f: F) -> IResult<'y,(),T> {
fn flat_map<'y,F:Fn(&'a $t) -> IResult<&'a $t,T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i), //Incomplete(|input:I| { cl(input).map(f) })
@ -71,9 +71,9 @@ flat_map_ref_impl! {
}
impl<'a,'b,'z, T> FlatMap<&'b [u8],&'a [u8], T> for IResult<'z,&'b [u8],&'a [u8]> {
impl<'a,'b,'z, T> FlatMap<&'b [u8],&'a [u8], T> for IResult<&'b [u8],&'a [u8]> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn(&'a [u8]) -> IResult<'y,&'a [u8],T>>(&self, f: F) -> IResult<'y,&'b [u8],T> {
fn flat_map<'y,F:Fn(&'a [u8]) -> IResult<&'a [u8],T>>(&self, f: F) -> IResult<&'b [u8],T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(|input:&'b R| { cl(input).map(f) }),
@ -93,9 +93,9 @@ impl<'a,'b,'z, T> FlatMap<&'b [u8],&'a [u8], T> for IResult<'z,&'b [u8],&'a [u8]
#[macro_export]
macro_rules! flat_map_impl {
($($t:ty)*) => ($(
impl<'a,'z,R,T> FlatMap<&'a R,$t, T> for IResult<'z,&'a R,$t> {
impl<'a,'z,R,T> FlatMap<&'a R,$t, T> for IResult<&'a R,$t> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn($t) -> IResult<'y,$t,T>>(&self, f: F) -> IResult<'y,&'a R,T> {
fn flat_map<'y,F:Fn($t) -> IResult<$t,T>>(&self, f: F) -> IResult<&'a R,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -107,9 +107,9 @@ macro_rules! flat_map_impl {
}
}
}
impl<'z,T> FlatMap<(),$t, T> for IResult<'z,(),$t> {
impl<'z,T> FlatMap<(),$t, T> for IResult<(),$t> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn($t) -> IResult<'y,$t,T>>(&self, f: F) -> IResult<'y,(),T> {
fn flat_map<'y,F:Fn($t) -> IResult<$t,T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -129,9 +129,9 @@ flat_map_impl! {
}
impl<'a,'z,R,T> FlatMap<&'a R,(), T> for IResult<'z,&'a R,()> {
impl<'a,'z,R,T> FlatMap<&'a R,(), T> for IResult<&'a R,()> {
#[allow(unused_variables)]
fn flat_map<'y,F: Fn(()) -> IResult<'y,(),T>>(&self, f: F) -> IResult<'y,&'a R,T> {
fn flat_map<'y,F: Fn(()) -> IResult<(),T>>(&self, f: F) -> IResult<&'a R,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -146,9 +146,9 @@ impl<'a,'z,R,T> FlatMap<&'a R,(), T> for IResult<'z,&'a R,()> {
}
}
impl<'a,'x,'z,S,T> FlatMap<(),&'a S,T> for IResult<'z,(),&'a S> {
impl<'a,'x,'z,S,T> FlatMap<(),&'a S,T> for IResult<(),&'a S> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn(&'a S) -> IResult<'y,&'a S,T>>(&self, f: F) -> IResult<'y,(),T> {
fn flat_map<'y,F:Fn(&'a S) -> IResult<&'a S,T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -162,9 +162,9 @@ impl<'a,'x,'z,S,T> FlatMap<(),&'a S,T> for IResult<'z,(),&'a S> {
}
}
impl<'x,'z,T> FlatMap<(),(),T> for IResult<'z,(),()> {
impl<'x,'z,T> FlatMap<(),(),T> for IResult<(),()> {
#[allow(unused_variables)]
fn flat_map<'y,F:Fn(()) -> IResult<'y,(),T>>(&self, f: F) -> IResult<'y,(),T> {
fn flat_map<'y,F:Fn(()) -> IResult<(),T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -188,8 +188,8 @@ impl<'x,'z,T> FlatMap<(),(),T> for IResult<'z,(),()> {
/// assert_eq!(res, Done((), "abcd"));
/// ```
pub trait FlatMapOpt<I,O,N> {
fn map_opt<'y,F: Fn(O) -> Option<N>>(& self, f: F) -> IResult<'y,I,N>;
fn map_res<'y,P,F: Fn(O) -> Result<N,P>>(& self, f: F) -> IResult<'y,I,N>;
fn map_opt<'y,F: Fn(O) -> Option<N>>(& self, f: F) -> IResult<I,N>;
fn map_res<'y,P,F: Fn(O) -> Result<N,P>>(& self, f: F) -> IResult<I,N>;
}
/// derives map_opt and map_res implementations for a list of IResult types with referenced types
@ -197,9 +197,9 @@ pub trait FlatMapOpt<I,O,N> {
#[macro_export]
macro_rules! map_ref_impl {
($i:ty, $o:ty) => (
impl<'a,'b,'z,T> FlatMapOpt<&'b $i,&'a $o, T> for IResult<'z,&'b $i,&'a $o> {
impl<'a,'b,'z,T> FlatMapOpt<&'b $i,&'a $o, T> for IResult<&'b $i,&'a $o> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(&'a $o) -> Option<T>>(&self, f: F) -> IResult<'y,&'b $i,T> {
fn map_opt<'y,F:Fn(&'a $o) -> Option<T>>(&self, f: F) -> IResult<&'b $i,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -212,7 +212,7 @@ macro_rules! map_ref_impl {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(&'a $o) -> Result<T,U>>(&self, f: F) -> IResult<'y,&'b $i,T> {
fn map_res<'y,U, F: Fn(&'a $o) -> Result<T,U>>(&self, f: F) -> IResult<&'b $i,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -232,9 +232,9 @@ map_ref_impl!([u8], str);
map_ref_impl!(str, [u8]);
map_ref_impl!(str, str);
impl<'a,'z,S,T> FlatMapOpt<(), &'a[S], T> for IResult<'z,(),&'a [S]> {
impl<'a,'z,S,T> FlatMapOpt<(), &'a[S], T> for IResult<(),&'a [S]> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(&'a[S]) -> Option<T>>(&self, f: F) -> IResult<'y,(),T> {
fn map_opt<'y,F:Fn(&'a[S]) -> Option<T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -247,7 +247,7 @@ impl<'a,'z,S,T> FlatMapOpt<(), &'a[S], T> for IResult<'z,(),&'a [S]> {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(&'a[S]) -> Result<T,U>>(&self, f: F) -> IResult<'y,(),T> {
fn map_res<'y,U, F: Fn(&'a[S]) -> Result<T,U>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -260,9 +260,9 @@ impl<'a,'z,S,T> FlatMapOpt<(), &'a[S], T> for IResult<'z,(),&'a [S]> {
}
}
impl<'a,'z,T> FlatMapOpt<(),&'a str, T> for IResult<'z,(),&'a str> {
impl<'a,'z,T> FlatMapOpt<(),&'a str, T> for IResult<(),&'a str> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(&'a str) -> Option<T>>(&self, f: F) -> IResult<'y,(),T> {
fn map_opt<'y,F:Fn(&'a str) -> Option<T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -275,7 +275,7 @@ impl<'a,'z,T> FlatMapOpt<(),&'a str, T> for IResult<'z,(),&'a str> {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(&'a str) -> Result<T,U>>(&self, f: F) -> IResult<'y,(),T> {
fn map_res<'y,U, F: Fn(&'a str) -> Result<T,U>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -288,9 +288,9 @@ impl<'a,'z,T> FlatMapOpt<(),&'a str, T> for IResult<'z,(),&'a str> {
}
}
impl<'a,'z,R,T> FlatMapOpt<&'a[R], (), T> for IResult<'z,&'a[R],()> {
impl<'a,'z,R,T> FlatMapOpt<&'a[R], (), T> for IResult<&'a[R],()> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<'y,&'a[R],T> {
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<&'a[R],T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -303,7 +303,7 @@ impl<'a,'z,R,T> FlatMapOpt<&'a[R], (), T> for IResult<'z,&'a[R],()> {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<'y,&'a [R],T> {
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<&'a [R],T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -316,9 +316,9 @@ impl<'a,'z,R,T> FlatMapOpt<&'a[R], (), T> for IResult<'z,&'a[R],()> {
}
}
impl<'a,'z,T> FlatMapOpt<&'a str, (), T> for IResult<'z,&'a str,()> {
impl<'a,'z,T> FlatMapOpt<&'a str, (), T> for IResult<&'a str,()> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<'y,&'a str,T> {
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<&'a str,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -331,7 +331,7 @@ impl<'a,'z,T> FlatMapOpt<&'a str, (), T> for IResult<'z,&'a str,()> {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<'y,&'a str,T> {
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<&'a str,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),// Incomplete(*i),
@ -344,9 +344,9 @@ impl<'a,'z,T> FlatMapOpt<&'a str, (), T> for IResult<'z,&'a str,()> {
}
}
impl<'z,T> FlatMapOpt<(),(), T> for IResult<'z,(),()> {
impl<'z,T> FlatMapOpt<(),(), T> for IResult<(),()> {
#[allow(unused_variables)]
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<'y,(),T> {
fn map_opt<'y,F:Fn(()) -> Option<T>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -359,7 +359,7 @@ impl<'z,T> FlatMapOpt<(),(), T> for IResult<'z,(),()> {
}
#[allow(unused_variables)]
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<'y,(),T> {
fn map_res<'y,U, F: Fn(()) -> Result<T,U>>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -382,15 +382,15 @@ impl<'z,T> FlatMapOpt<(),(), T> for IResult<'z,(),()> {
/// assert_eq!(res, Done((), "abcd"));
///```
pub trait Functor<I,O,N> {
fn map<'y,F: Fn(O) -> N>(& self, f: F) -> IResult<'y,I,N>;
fn map<'y,F: Fn(O) -> N>(& self, f: F) -> IResult<I,N>;
}
#[macro_export]
macro_rules! map2_ref_impl {
($i:ty, $o:ty) => (
impl<'a,'b,'z,T> Functor<&'b $i,&'a $o, T> for IResult<'z,&'b $i,&'a $o> {
impl<'a,'b,'z,T> Functor<&'b $i,&'a $o, T> for IResult<&'b $i,&'a $o> {
#[allow(unused_variables)]
fn map<'y,F: Fn(&'a $o) -> T>(&self, f: F) -> IResult<'y,&'b $i,T> {
fn map<'y,F: Fn(&'a $o) -> T>(&self, f: F) -> IResult<&'b $i,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -407,9 +407,9 @@ map2_ref_impl!([u8], str);
map2_ref_impl!(str, [u8]);
map2_ref_impl!(str, str);
impl<'a,'z,S,T> Functor<(), &'a[S], T> for IResult<'z,(),&'a [S]> {
impl<'a,'z,S,T> Functor<(), &'a[S], T> for IResult<(),&'a [S]> {
#[allow(unused_variables)]
fn map<'y,F: Fn(&'a[S]) -> T>(&self, f: F) -> IResult<'y,(),T> {
fn map<'y,F: Fn(&'a[S]) -> T>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -419,9 +419,9 @@ impl<'a,'z,S,T> Functor<(), &'a[S], T> for IResult<'z,(),&'a [S]> {
}
}
impl<'a,'z,R,T> Functor<&'a R, (), T> for IResult<'z,&'a R,()> {
impl<'a,'z,R,T> Functor<&'a R, (), T> for IResult<&'a R,()> {
#[allow(unused_variables)]
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<'y,&'a R,T> {
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<&'a R,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -431,9 +431,9 @@ impl<'a,'z,R,T> Functor<&'a R, (), T> for IResult<'z,&'a R,()> {
}
}
impl<'a,'z,R,T> Functor<&'a [R], (), T> for IResult<'z,&'a [R],()> {
impl<'a,'z,R,T> Functor<&'a [R], (), T> for IResult<&'a [R],()> {
#[allow(unused_variables)]
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<'y,&'a [R],T> {
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<&'a [R],T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -443,9 +443,9 @@ impl<'a,'z,R,T> Functor<&'a [R], (), T> for IResult<'z,&'a [R],()> {
}
}
impl<'a,'z,T> Functor<&'a str, (), T> for IResult<'z,&'a str,()> {
impl<'a,'z,T> Functor<&'a str, (), T> for IResult<&'a str,()> {
#[allow(unused_variables)]
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<'y,&'a str,T> {
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<&'a str,T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -455,9 +455,9 @@ impl<'a,'z,T> Functor<&'a str, (), T> for IResult<'z,&'a str,()> {
}
}
impl<'a,'z,T> Functor<(), (), T> for IResult<'z,(),()> {
impl<'a,'z,T> Functor<(), (), T> for IResult<(),()> {
#[allow(unused_variables)]
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<'y,(),T> {
fn map<'y,F: Fn(()) -> T>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
&Incomplete(ref i) => Incomplete(*i),//Incomplete(*i),
@ -467,9 +467,9 @@ impl<'a,'z,T> Functor<(), (), T> for IResult<'z,(),()> {
}
}
impl<'a,'z,T> Functor<(), &'a str, T> for IResult<'z,(),&'a str> {
impl<'a,'z,T> Functor<(), &'a str, T> for IResult<(),&'a str> {
#[allow(unused_variables)]
fn map<'y,F: Fn(&'a str) -> T>(&self, f: F) -> IResult<'y,(),T> {
fn map<'y,F: Fn(&'a str) -> T>(&self, f: F) -> IResult<(),T> {
//fn map<F: Fn(&'a str) -> T>(&self, f: F) -> IResult<(),T> {
match self {
&Error(ref e) => Error(*e),
@ -488,7 +488,7 @@ mod tests {
use std::str;
use std::fmt::Debug;
fn local_print<'a,T: Debug>(input: T) -> IResult<'a,T,()> {
fn local_print<T: Debug>(input: T) -> IResult<T,()> {
println!("{:?}", input);
Done(input, ())
}

View File

@ -314,12 +314,12 @@ macro_rules! alt_parser (
)
);
pub fn print<'y,T: Debug>(input: T) -> IResult<'y,T, ()> {
pub fn print<T: Debug>(input: T) -> IResult<T, ()> {
println!("{:?}", input);
Done(input, ())
}
pub fn begin<'a,'y>(input: &'a [u8]) -> IResult<'y,(), &'a [u8]> {
pub fn begin<'a>(input: &'a [u8]) -> IResult<(), &'a [u8]> {
Done((), input)
}

View File

@ -257,7 +257,7 @@ mod tests {
use std::str;
use map::*;
fn local_print<'a,T: Debug>(input: T) -> IResult<'a,T, ()> {
fn local_print<'a,T: Debug>(input: T) -> IResult<T, ()> {
println!("{:?}", input);
Done(input, ())
}
@ -270,7 +270,7 @@ mod tests {
#[test]
fn mem_producer_2() {
let mut p = MemProducer::new("abcdefgh".as_bytes(), 8);
fn pr<'a,'b>(data: &'a [u8]) -> IResult<'b,&'a [u8],()> {
fn pr<'a,'b>(data: &'a [u8]) -> IResult<&'a [u8],()> {
local_print(data)
}
pusher!(ps, pr);
@ -288,7 +288,7 @@ mod tests {
let mut p = producer;
//p.push(|par| {println!("parsed file: {}", par); par});
//p.push(|par| par.flat_map(print));
fn pr<'a,'b,'c>(data: &[u8]) -> IResult<'b,&[u8], &[u8]> {
fn pr<'a,'b,'c>(data: &[u8]) -> IResult<&[u8], &[u8]> {
Done("".as_bytes(), data).map_res(str::from_utf8); //.flat_map(local_print);
Done("".as_bytes(),"".as_bytes())
}
@ -309,7 +309,7 @@ mod tests {
}
let mut p = MemProducer::new("abcdefgh".as_bytes(), 4);
fn pr<'a,'b>(data: &'b [u8]) -> IResult<'b,&'b [u8],&'b [u8]> {
fn pr<'a,'b>(data: &'b [u8]) -> IResult<&'b [u8],&'b [u8]> {
let r = f(data);
println!("f: {:?}", r);
r
@ -330,7 +330,7 @@ mod tests {
}
let mut p = MemProducer::new("abcdefgh".as_bytes(), 4);
fn pr<'a,'b,'c>(data: &'b [u8]) -> IResult<'b,&'b [u8],&'b [u8]> {
fn pr<'a,'b,'c>(data: &'b [u8]) -> IResult<&'b [u8],&'b [u8]> {
let r = f(data);
println!("f: {:?}", r);
r

View File

@ -54,14 +54,14 @@ chain!(key_value <&[u8],(&str,&str)>,
||{(key, val)}
);
fn keys_and_values<'a,'b>(input: &'a[u8], mut z: HashMap<&'a str, &'a str>) -> IResult<'b,&'a[u8], HashMap<&'a str, &'a str> > {
fn keys_and_values<'a>(input: &'a[u8], mut z: HashMap<&'a str, &'a str>) -> IResult<&'a[u8], HashMap<&'a str, &'a str> > {
fold0_impl!(<&[u8], HashMap<&str, &str> >, | mut h:HashMap<&'a str, &'a str>, (k, v)| {
h.insert(k,v);
h
}, key_value, input, z);
}
fn keys_and_values_wrapper<'a,'b>(input:&'a[u8]) -> IResult<'b,&'a[u8], HashMap<&'a str, &'a str> > {
fn keys_and_values_wrapper<'a>(input:&'a[u8]) -> IResult<&'a[u8], HashMap<&'a str, &'a str> > {
let h: HashMap<&str, &str> = HashMap::new();
let res = keys_and_values(input, h);
//println!("{:?}", res);

View File

@ -20,7 +20,7 @@ fn tag() {
let mut p = producer;
tag!(f "https://".as_bytes());
//p.push(|par| par.flat_map(f).flat_map(print));
fn pr<'a,'b>(data:&'a [u8]) -> IResult<'b,&'a [u8],()> {
fn pr<'a>(data:&'a [u8]) -> IResult<&'a [u8],()> {
let p = f(data).map_res(str::from_utf8);//.flat_map(print);
println!("p : {:?}", p);
Done("".as_bytes(), ())
@ -31,7 +31,7 @@ fn tag() {
});
}
pub fn print<'a,T: Debug>(input: T) -> IResult<'a,T, ()> {
pub fn print<T: Debug>(input: T) -> IResult<T,()> {
println!("{:?}", input);
Done(input, ())
}