From 995cfa621bf9e62e786fb76d14ea2a5877e02849 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Sun, 23 Nov 2014 12:10:05 +0100 Subject: [PATCH] remove useless code --- src/main.rs | 7 +---- src/nom.rs | 81 ----------------------------------------------------- 2 files changed, 1 insertion(+), 87 deletions(-) diff --git a/src/main.rs b/src/main.rs index 17bde94..89c9480 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ #![feature(globs,macro_rules)] -use nom::{FileProducer, Mapper, Ender, Parser, print, accline}; +use nom::{FileProducer, Mapper, Parser, print}; use nom::Parser::*; use std::str; @@ -16,15 +16,10 @@ fn main() { FileProducer::new("links.txt", 1024).map(|producer: FileProducer| { let mut p = producer; //p.push(|par| par.map(accline).mapf(|v2: &[u8]| str::from_utf8(v2.as_slice())).map(print)); - //p.push(|par| par.m3(accline).mapf(|v2: &[u8]| str::from_utf8(v2.as_slice())).map(print)); /*p.push(|par| { //let p2:Parser<&[u8],&str> = par.mapf(|v2: &[u8]| str::from_utf8(v2.as_slice())); - //p2.m4(print) - //p2.m4(|s:&str| {println!("str: {}", s); Done(s, ())}) - //p2.end(|s:&str| { println!("str: {}", s); ()});Done((),()) Done((), ()) });*/ - p.push(|par| { par.m2(print) }); p.push(|par| { par.map(print) }); //p.push(|par| {println!("par: {}", par); par}); //p.push(pr); diff --git a/src/nom.rs b/src/nom.rs index f629a04..ce2f81f 100644 --- a/src/nom.rs +++ b/src/nom.rs @@ -76,77 +76,6 @@ impl Mapper<(), T> for Parser { } } -pub trait Ender { - fn end(&self, f: |O| -> ()) -> (); -} - -impl<'a> Ender<&'a [u8]> for Parser<&'a [u8],&'a [u8]> { - fn end(&self, f: |&'a [u8]| -> ()) -> () { - match self { - &Error(_) => (), - //&Incomplete(ref cl) => Incomplete(f), //Incomplete(|input:I| { cl(input).map(f) }) - &Done(_, ref o) => { - f(*o) - } - } - } -} -impl<'a> Ender<&'a str> for Parser<&'a [u8],&'a str> { - fn end(&self, f: |&'a str| -> ()) -> () { - match self { - &Error(_) => (), - //&Incomplete(ref cl) => Incomplete(f), //Incomplete(|input:I| { cl(input).map(f) }) - &Done(_, ref o) => { - f(*o) - } - } - } -} - -impl<'a> Ender<&'a [u8]> for Parser<(),&'a [u8]> { - fn end(&self, f: |&'a [u8]| -> ()) -> () { - match self { - &Error(_) => (), - //&Incomplete(ref cl) => Incomplete(f), //Incomplete(|input:I| { cl(input).map(f) }) - &Done(_, ref o) => { - f(*o) - } - } - } -} - -/***/ -impl<'a> Parser<(),&'a [u8]> { - pub fn m2<'b,'c>(&'b self, f: |&'a [u8]| -> Parser<&'c [u8],()>) -> Parser<&'c [u8], ()> { - match self { - &Error(ref e) => Error(*e), - &Done(_, ref o) => f(*o) - } - } - pub fn m3<'b,'c>(&'b self, f: |&'a [u8]| -> Parser<&'c [u8],&'c [u8]>) -> Parser<&'c [u8], &'c [u8]> { - match self { - &Error(ref e) => Error(*e), - &Done(_, ref o) => f(*o) - } - } -} -impl<'a> Parser<&'a [u8],&'a str> { - pub fn m4<'b,'c>(&'b self, f: |&'a str| -> Parser<&'c str,()>) -> Parser<&'c str, ()> { - match self { - &Error(ref e) => Error(*e), - &Done(_, ref o) => f(*o) - } - } -} -/***/ - -pub fn accline<'a>(input: &'a [u8]) -> Parser<&'a [u8], &'a [u8]> { - match input.iter().position(|&c| c == '\n' as u8) { - None => Error(0),//Incomplete(accline), - Some(pos) => Done(input.slice_from(pos), input.slice(0, pos)) - } -} - pub fn print(input: T) -> Parser { println!("{}", input); Done(input, ()) @@ -383,16 +312,6 @@ fn t1() { assert_eq!(res, Done(v2.as_slice(), ())); } -#[test] -fn end_test() { - let v1:Vec = vec![1,2,3]; - let v2 = vec![4,5,6]; - let d = Done(v1.as_slice(), v2.as_slice()); - let mut res: Vec = Vec::new(); - d.end(|v:&[u8]| res.push_all(v)); - assert_eq!(res.as_slice(), v2.as_slice()); -} - #[test] fn mem_producer_test() { let mut p = MemProducer::new("abcdefgh".as_bytes(), 4);