Skip to content

Commit

Permalink
move number parsers to the number module
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Apr 13, 2019
1 parent dfb9dc3 commit 64eb6bd
Show file tree
Hide file tree
Showing 11 changed files with 855 additions and 825 deletions.
10 changes: 5 additions & 5 deletions benches/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate jemallocator;
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use criterion::Criterion;
use nom::{ErrorKind, alphanumeric, recognize_float};
use nom::{ErrorKind, alphanumeric, number::recognize_float};


use std::str;
Expand Down Expand Up @@ -98,28 +98,28 @@ fn json_bench(c: &mut Criterion) {
}

fn recognize_float_bytes(c: &mut Criterion) {
use nom::recognize_float;
use nom::number::recognize_float;
c.bench_function("recognize float bytes", |b| {
b.iter(|| recognize_float::<_, (_,ErrorKind)>(&b"-1.234E-12"[..]));
});
}

fn recognize_float_str(c: &mut Criterion) {
use nom::recognize_float;
use nom::number::recognize_float;
c.bench_function("recognize float str", |b| {
b.iter(|| recognize_float::<_, (_,ErrorKind)>("-1.234E-12"));
});
}

fn float_bytes(c: &mut Criterion) {
use nom::float;
use nom::number::float;
c.bench_function("float bytes", |b| {
b.iter(|| float::<_, (_,ErrorKind)>(&b"-1.234E-12"[..]));
});
}

fn float_str(c: &mut Criterion) {
use nom::float_s;
use nom::number::float_s;
c.bench_function("float str", |b| {
b.iter(|| float_s::<_, (_,ErrorKind)>("-1.234E-12"));
});
Expand Down
3 changes: 2 additions & 1 deletion examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ extern crate jemallocator;
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;

use nom::{Err, ErrorKind, IResult, Offset, ParseError, VerboseError, VerboseErrorKind};
use nom::{alphanumeric, recognize_float, take_while, tag, separated_listc, alt};
use nom::{alphanumeric, take_while, tag, separated_listc, alt};
use nom::{delimited, preceded, separated_list, terminated, context};
use nom::character::complete::char;
use nom::number::recognize_float;
use std::str;
use std::iter::repeat;
use std::collections::HashMap;
Expand Down
4 changes: 2 additions & 2 deletions src/bytes/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ macro_rules! take_until_either1 (
/// # Example
/// ```
/// # #[macro_use] extern crate nom;
/// # use nom::be_u8;
/// # use nom::number::be_u8;
/// # fn main() {
/// named!(with_length, length_bytes!( be_u8 ));
/// let r = with_length(&b"\x05abcdefgh"[..]);
Expand Down Expand Up @@ -1622,7 +1622,7 @@ mod tests {

#[test]
fn length_bytes() {
use nom::le_u8;
use number::le_u8;
named!(x, length_bytes!(le_u8));
assert_eq!(x(b"\x02..>>"), Ok((&b">>"[..], &b".."[..])));
assert_eq!(x(b"\x02.."), Ok((&[][..], &b".."[..])));
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
//! ```rust
//! # #[macro_use] extern crate nom;
//! # fn main() {
//! use nom::{ErrorKind, Needed,be_u16};
//! use nom::{ErrorKind, Needed, number::be_u16};
//!
//! named!(tpl<&[u8], (u16, &[u8], &[u8]) >,
//! tuple!(
Expand Down Expand Up @@ -459,4 +459,7 @@ mod regexp;

mod str;

#[macro_use]
pub mod number;

pub mod types;
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ macro_rules! complete (
/// # use nom::IResult;
///
/// fn take_add(input:&[u8], size: u8) -> IResult<&[u8], &[u8]> {
/// let (i1, sz) = try_parse!(input, nom::be_u8);
/// let (i1, sz) = try_parse!(input, nom::number::be_u8);
/// let (i2, length) = try_parse!(i1, expr_opt!(size.checked_add(sz)));
/// let (i3, data) = try_parse!(i2, take!(length));
/// return Ok((i3, data));
Expand Down Expand Up @@ -818,7 +818,7 @@ macro_rules! parse_to (
/// ```
/// # #[macro_use] extern crate nom;
/// # fn main() {
/// named!(check<u32>, verify!(nom::be_u32, |val:u32| val >= 0 && val < 3));
/// named!(check<u32>, verify!(nom::number::be_u32, |val:u32| val >= 0 && val < 3));
/// # }
/// ```
#[macro_export(local_inner_macros)]
Expand Down Expand Up @@ -926,7 +926,7 @@ macro_rules! expr_res (
/// # #[macro_use] extern crate nom;
/// # use nom::Err;
/// # use nom::IResult;
/// # use nom::{be_u8, ErrorKind};
/// # use nom::{number::be_u8, ErrorKind};
///
/// fn take_add(input:&[u8], size: u8) -> IResult<&[u8], &[u8]> {
/// do_parse!(input,
Expand Down
3 changes: 2 additions & 1 deletion src/multi/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ mod tests {
use lib::std::str::{self, FromStr};
#[cfg(feature = "alloc")]
use lib::std::vec::Vec;
use nom::{be_u16, be_u8, digit, le_u16};
use nom::digit;
use number::{be_u16, be_u8, le_u16};
use util::ErrorKind;

// reproduce the tag and take macros, because of module import order
Expand Down
Loading

0 comments on commit 64eb6bd

Please sign in to comment.