Remove some warnings and update the slicing syntax

This commit is contained in:
Geoffroy Couprie 2015-02-17 18:33:10 +01:00
parent 37dfdf1122
commit 8a46dd2bcc
7 changed files with 34 additions and 36 deletions

View File

@ -17,10 +17,12 @@ impl<'a,I,O> Debug for IResultClosure<'a,I,O> {
}
impl<'a,I:PartialEq,O:PartialEq> PartialEq for IResultClosure<'a,I,O> {
#[allow(unused_variables)]
fn eq<'b>(&self, other: &IResultClosure<'b,I,O>) -> bool {
false
}
#[allow(unused_variables)]
fn ne<'b>(&self, other: &IResultClosure<'b,I,O>) -> bool {
false
}

View File

@ -537,9 +537,7 @@ mod tests {
#[test]
fn t1() {
let v1:Vec<u8> = vec![1,2,3];
let v2:Vec<u8> = vec![4,5,6];
let d = Done(&v1[], &v2[]);
let res = local_print(&v2[]);
assert_eq!(res, Done(&v2[], ()));
let res = local_print(&v1[]);
assert_eq!(res, Done(&v1[], ()));
}
}

View File

@ -25,7 +25,7 @@ use internal::IResult::*;
macro_rules! tag(
($name:ident $inp:expr) => (
fn $name(i:&[u8]) -> IResult<&[u8], &[u8]>{
if i.len() >= $inp.len() && i.slice(0, $inp.len()) == $inp {
if i.len() >= $inp.len() && &i[0..$inp.len()] == $inp {
Done(&i[$inp.len()..], &i[0..$inp.len()])
} else {
Error(0)
@ -36,7 +36,7 @@ macro_rules! tag(
pub fn tag_cl<'a,'b>(rec:&'a[u8]) -> Box<Fn(&'b[u8]) -> IResult<&'b[u8], &'b[u8]> + 'a> {
Box::new(move |i: &'b[u8]| -> IResult<&'b[u8], &'b[u8]> {
if i.len() >= rec.len() && i.slice(0, rec.len()) == rec {
if i.len() >= rec.len() && &i[0..rec.len()] == rec {
Done(&i[rec.len()..], &i[0..rec.len()])
} else {
Error(0)
@ -326,10 +326,10 @@ pub fn begin<'a,'y>(input: &'a [u8]) -> IResult<'y,(), &'a [u8]> {
macro_rules! is_not(
($name:ident $arr:expr) => (
fn $name(input:&[u8]) -> IResult<&[u8], &[u8]> {
for idx in range(0, input.len()) {
for idx in 0..input.len() {
for &i in $arr.iter() {
if input[idx] == i {
return IResult::Done(input.slice_from(idx), input.slice(0, idx))
return IResult::Done(&input[idx..], &input[0..idx])
}
}
}
@ -342,7 +342,7 @@ macro_rules! is_not(
macro_rules! is_a(
($name:ident $arr:expr) => (
fn $name(input:&[u8]) -> IResult<&[u8], &[u8]> {
for idx in range(0, input.len()) {
for idx in 0..input.len() {
var res = false
for &i in $arr.iter() {
if input[idx] == i {
@ -350,7 +350,7 @@ macro_rules! is_a(
}
}
if !res {
return IResult::Done(input.slice_from(idx), input.slice(0, idx))
return IResult::Done(&input[idx..], &input[0..idx])
}
}
IResult::Done("".as_bytes(), input)
@ -493,7 +493,7 @@ macro_rules! many0(
let mut remaining = input.len();
let mut res: Vec<$o> = Vec::new();
loop {
match $f(input.slice_from(begin)) {
match $f(&input[begin..]) {
IResult::Done(i,o) => {
res.push(o);
begin += remaining - i.len();
@ -503,7 +503,7 @@ macro_rules! many0(
}
},
_ => {
return IResult::Done(input.slice_from(begin), res)
return IResult::Done(&input[begin..], res)
}
}
}
@ -520,7 +520,7 @@ macro_rules! many1(
let mut remaining = input.len();
let mut res: Vec<$o> = Vec::new();
loop {
match $f(input.slice_from(begin)) {
match $f(&input[begin..]) {
IResult::Done(i,o) => {
res.push(o);
begin += remaining - i.len();
@ -533,7 +533,7 @@ macro_rules! many1(
if begin == 0 {
return IResult::Error(0)
} else {
return IResult::Done(input.slice_from(begin), res)
return IResult::Done(&input[begin..], res)
}
}
}
@ -559,7 +559,7 @@ macro_rules! fold0_impl(
let mut remaining = $input.len();
let mut res: $o = $z;
loop {
match $f($input.slice_from(begin)) {
match $f(&$input[begin..]) {
IResult::Done(i,o) => {
//res.push(o);
res = $assemble(res, o);
@ -570,7 +570,7 @@ macro_rules! fold0_impl(
}
},
_ => {
return IResult::Done($input.slice_from(begin), res)
return IResult::Done(&$input[begin..], res)
}
}
}
@ -595,7 +595,7 @@ macro_rules! fold1_impl(
let mut remaining = $input.len();
let mut res: $o = $z;
loop {
match $f($input.slice_from(begin)) {
match $f(&$input[begin..]) {
IResult::Done(i,o) => {
//res.push(o);
res = $assemble(res, o);
@ -609,7 +609,7 @@ macro_rules! fold1_impl(
if begin == 0 {
return IResult::Error(0)
} else {
return IResult::Done($input.slice_from(begin), res)
return IResult::Done(&$input[begin..], res)
}
}
}
@ -654,7 +654,7 @@ macro_rules! take_until(
if idx + $inp.len() > i.len() {
return Incomplete(0)
}
if i.slice(idx, idx+$inp.len()) == $inp {
if &i[idx..idx+$inp.len()] == $inp {
if idx + $inp.len() > i.len() {
return Done("".as_bytes(), &i[0..idx])
} else {
@ -675,7 +675,7 @@ macro_rules! take_until_and_leave(
if idx + $inp.len() > i.len() {
return Incomplete(0)
}
if i.slice(idx, idx+$inp.len()) == $inp {
if &i[idx..idx+$inp.len()] == $inp {
return Done(&i[idx..], &i[0..idx])
}
}

View File

@ -27,7 +27,6 @@
//! });
//! ```
use util::HexDisplay;
use internal::*;
use self::ProducerState::*;
@ -87,7 +86,7 @@ impl Producer for FileProducer {
_ => ProducerError(0)
}
},
Ok(i) => {
Ok(_) => {
//println!("read: {:?}\nbytes:\n{}", i, (&self.v).to_hex(8));
Data(&self.v[])
}
@ -159,6 +158,7 @@ impl<'x> Producer for MemProducer<'x> {
#[macro_export]
macro_rules! pusher (
($name:ident, $f:expr) => (
#[allow(unused_variables)]
fn $name(producer: &mut Producer) {
let mut acc: Vec<u8> = Vec::new();
loop {

View File

@ -8,12 +8,12 @@ pub trait HexDisplay {
static CHARS: &'static[u8] = b"0123456789abcdef";
impl HexDisplay for [u8] {
#[allow(unused_variables)]
fn to_hex(&self, chunk_size: usize) -> String {
let mut v = Vec::with_capacity(self.len() * 3);
let mut i = 0;
for chunk in self.chunks(chunk_size) {
let s = format!("{:08x}", i);
let s2: &str = &s;
for &ch in s.as_bytes().iter() {
v.push(ch);
}
@ -27,7 +27,7 @@ impl HexDisplay for [u8] {
v.push(' ' as u8);
}
if chunk_size > chunk.len() {
for i in 0..(chunk_size - chunk.len()) {
for j in 0..(chunk_size - chunk.len()) {
v.push(' ' as u8);
v.push(' ' as u8);
v.push(' ' as u8);

View File

@ -1,7 +1,7 @@
#[macro_use]
extern crate nom;
use nom::{IResult,FlatMap,FlatMapOpt,line_ending,not_line_ending, space, alphanumeric, multispace};
use nom::{IResult,FlatMapOpt,line_ending,not_line_ending, space, alphanumeric, multispace};
use nom::IResult::*;
use std::str;

View File

@ -5,8 +5,6 @@ use nom::{HexDisplay,IResult,FlatMap,FlatMapOpt,Functor,Producer,ProducerState,F
use nom::IResult::*;
use std::str;
use std::collections::HashMap;
fn mp4_box(input:&[u8]) -> IResult<&[u8], &[u8]> {
@ -139,32 +137,32 @@ tag!(moov_tag "moov".as_bytes());
tag!(mdra "mdra".as_bytes());
fn moov_mdra(input:&[u8]) -> IResult<&[u8], MoovBox> {
mdra(input).map(|o| MoovBox::Mdra)
mdra(input).map(|_| MoovBox::Mdra)
}
tag!(dref "dref".as_bytes());
fn moov_dref(input:&[u8]) -> IResult<&[u8], MoovBox> {
dref(input).map(|o| MoovBox::Dref)
dref(input).map(|_| MoovBox::Dref)
}
tag!(cmov "cmov".as_bytes());
fn moov_cmov(input:&[u8]) -> IResult<&[u8], MoovBox> {
cmov(input).map(|o| MoovBox::Cmov)
cmov(input).map(|_| MoovBox::Cmov)
}
tag!(rmra "rmra".as_bytes());
fn moov_rmra(input:&[u8]) -> IResult<&[u8], MoovBox> {
rmra(input).map(|o| MoovBox::Rmra)
rmra(input).map(|_| MoovBox::Rmra)
}
tag!(iods "iods".as_bytes());
fn moov_iods(input:&[u8]) -> IResult<&[u8], MoovBox> {
iods(input).map(|o| MoovBox::Iods)
iods(input).map(|_| MoovBox::Iods)
}
tag!(mvhd "mvhd".as_bytes());
fn moov_mvhd(input:&[u8]) -> IResult<&[u8], MoovBox> {
mvhd(input).map(|o| MoovBox::Mvhd)
mvhd(input).map(|_| MoovBox::Mvhd)
/*let res = mvhd(input).map(|o| MoovBox::Mvhd);
match res {
Error(a) => Error(a),
@ -178,17 +176,17 @@ fn moov_mvhd(input:&[u8]) -> IResult<&[u8], MoovBox> {
tag!(clip "clip".as_bytes());
fn moov_clip(input:&[u8]) -> IResult<&[u8], MoovBox> {
clip(input).map(|o| MoovBox::Clip)
clip(input).map(|_| MoovBox::Clip)
}
tag!(trak "trak".as_bytes());
fn moov_trak(input:&[u8]) -> IResult<&[u8], MoovBox> {
trak(input).map(|o| MoovBox::Trak)
trak(input).map(|_| MoovBox::Trak)
}
tag!(udta "udta".as_bytes());
fn moov_udta(input:&[u8]) -> IResult<&[u8], MoovBox> {
udta(input).map(|o| MoovBox::Udta)
udta(input).map(|_| MoovBox::Udta)
}
alt!(moov_internal<&[u8], MoovBox>, moov_mdra | moov_dref | moov_cmov |