Upgraded to Nom 2.x

This commit is contained in:
Nathan Vegdahl 2018-03-04 22:06:20 -08:00
parent b5bcf8965b
commit b2576c20e7
5 changed files with 98 additions and 77 deletions

22
Cargo.lock generated
View File

@ -8,7 +8,7 @@ name = "atty"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -87,7 +87,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.37"
version = "0.2.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -103,7 +103,7 @@ version = "0.1.0"
[[package]]
name = "nom"
version = "1.2.4"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -111,7 +111,7 @@ name = "num_cpus"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -120,7 +120,7 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"half 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
"openexr-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -130,7 +130,7 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -159,7 +159,7 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"math3d 0.1.0",
"mem_arena 0.1.0",
"nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"nom 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"openexr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"png_encode_mini 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -221,7 +221,7 @@ name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -239,7 +239,7 @@ name = "time"
version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -284,8 +284,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
"checksum half 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1aad9c31c71e74a1476316df059e235b67a3b625dd9e404bf94b1c19789f880b"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)" = "56aebce561378d99a0bb578f8cb15b6114d2a1814a6c7949bbe646d968bb4fa9"
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
"checksum libc 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)" = "84a7beecb6b131a81c7d6c7b90cdaa1155b8531b4808bd3bc23bf4b3c33f4d9e"
"checksum nom 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf51a729ecf40266a2368ad335a5fdde43471f545a967109cd62146ecf8b66ff"
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum openexr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "849a5af32d6b0716cf44a8b18c1b611b8448aec44a9b1c59b6199bf9d22aba94"
"checksum openexr-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d597730c7049d9098ce64bb97c6eb4e6f96fa55d5ced7eba74a01c224fe0bcc4"

View File

@ -28,7 +28,7 @@ clap = "2.30"
crossbeam = "0.3"
half = "1.0"
lazy_static = "1.0"
nom = "1.2"
nom = "2.2"
num_cpus = "1.8"
openexr = "0.5.0"
png_encode_mini = "0.1.2"

View File

@ -5,7 +5,6 @@
#![cfg_attr(feature = "cargo-clippy", allow(needless_return))]
#![cfg_attr(feature = "cargo-clippy", allow(or_fun_call))]
#![cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
extern crate bvh_order;
extern crate color as color_util;
extern crate float4;

View File

@ -6,86 +6,103 @@ use std::str;
use nom::{digit, multispace, IResult, Needed};
use nom::IResult::*;
// Consumes any whitespace, including zero whitespace
named!(any_space<Option<&[u8]>>, opt!(complete!(multispace)));
// Parsers for numbers surrounded by whitespace
named!(pub ws_u32<u32>, delimited!(opt!(multispace), u32_utf8, opt!(multispace)));
named!(pub ws_u64<u64>, delimited!(opt!(multispace), u64_utf8, opt!(multispace)));
named!(pub ws_usize<usize>, delimited!(opt!(multispace), usize_utf8, opt!(multispace)));
named!(pub ws_i32<i32>, delimited!(opt!(multispace), i32_utf8, opt!(multispace)));
named!(pub ws_i64<i64>, delimited!(opt!(multispace), i64_utf8, opt!(multispace)));
named!(pub ws_isize<isize>, delimited!(opt!(multispace), isize_utf8, opt!(multispace)));
named!(pub ws_f32<f32>, delimited!(opt!(multispace), f32_utf8, opt!(multispace)));
named!(pub ws_f64<f64>, delimited!(opt!(multispace), f64_utf8, opt!(multispace)));
named!(pub ws_u32<u32>, delimited!(any_space, u32_utf8, any_space));
named!(pub ws_u64<u64>, delimited!(any_space, u64_utf8, any_space));
named!(pub ws_usize<usize>, delimited!(any_space, usize_utf8, any_space));
named!(pub ws_i32<i32>, delimited!(any_space, i32_utf8, any_space));
named!(pub ws_i64<i64>, delimited!(any_space, i64_utf8, any_space));
named!(pub ws_isize<isize>, delimited!(any_space, isize_utf8, any_space));
named!(pub ws_f32<f32>, delimited!(any_space, f32_utf8, any_space));
named!(pub ws_f64<f64>, delimited!(any_space, f64_utf8, any_space));
// ========================================================
named!(pub u32_utf8<u32>, chain!(
bytes: digit,
|| { str::from_utf8(bytes).unwrap().parse::<u32>().unwrap() }
));
named!(pub u32_utf8<u32>,
do_parse!(
bytes: digit >>
(str::from_utf8(bytes).unwrap().parse::<u32>().unwrap())
)
);
named!(pub i32_utf8<i32>, chain!(
sign: one_of!("-+")? ~
bytes: digit,
|| {
named!(pub i32_utf8<i32>,
do_parse!(
sign: opt!(one_of!("-+")) >>
bytes: digit >>
({
match sign {
Some(s) if s == '-' => -str::from_utf8(bytes).unwrap().parse::<i32>().unwrap(),
_ => str::from_utf8(bytes).unwrap().parse::<i32>().unwrap(),
}
}
));
})
)
);
named!(pub u64_utf8<u64>, chain!(
bytes: digit,
|| { str::from_utf8(bytes).unwrap().parse::<u64>().unwrap() }
));
named!(pub u64_utf8<u64>,
do_parse!(
bytes: digit >>
(str::from_utf8(bytes).unwrap().parse::<u64>().unwrap())
)
);
named!(pub i64_utf8<i64>, chain!(
sign: one_of!("-+")? ~
bytes: digit,
|| {
named!(pub i64_utf8<i64>,
do_parse!(
sign: opt!(one_of!("-+")) >>
bytes: digit >>
({
match sign {
Some(s) if s == '-' => -str::from_utf8(bytes).unwrap().parse::<i64>().unwrap(),
_ => str::from_utf8(bytes).unwrap().parse::<i64>().unwrap(),
}
}
));
})
)
);
named!(pub usize_utf8<usize>, chain!(
bytes: digit,
|| { str::from_utf8(bytes).unwrap().parse::<usize>().unwrap() }
));
named!(pub usize_utf8<usize>,
do_parse!(
bytes: digit >>
(str::from_utf8(bytes).unwrap().parse::<usize>().unwrap())
)
);
named!(pub isize_utf8<isize>, chain!(
sign: one_of!("-+")? ~
bytes: digit,
|| {
named!(pub isize_utf8<isize>,
do_parse!(
sign: opt!(one_of!("-+")) >>
bytes: digit >>
({
match sign {
Some(s) if s == '-' => -str::from_utf8(bytes).unwrap().parse::<isize>().unwrap(),
_ => str::from_utf8(bytes).unwrap().parse::<isize>().unwrap(),
}
}
));
})
)
);
named!(pub f32_utf8<f32>, chain!(
bytes: take_decimal_real,
|| {
str::from_utf8(bytes).unwrap().parse::<f32>().unwrap()
}
));
named!(pub f32_utf8<f32>,
do_parse!(
bytes: take_decimal_real >>
(str::from_utf8(bytes).unwrap().parse::<f32>().unwrap())
)
);
named!(pub f64_utf8<f64>, chain!(
bytes: take_decimal_real,
|| {
str::from_utf8(bytes).unwrap().parse::<f64>().unwrap()
}
));
named!(pub f64_utf8<f64>,
do_parse!(
bytes: take_decimal_real >>
(str::from_utf8(bytes).unwrap().parse::<f64>().unwrap())
)
);
fn take_decimal_integer(i: &[u8]) -> IResult<&[u8], &[u8]> {
named!(rr<&[u8], ()>, chain!(
one_of!("-+")? ~
digit,
||{()}
));
named!(rr<&[u8], ()>,
do_parse!(
opt!(one_of!("-+")) >>
digit >>
()
)
);
match rr(i) {
Done(remaining, _) => {
@ -104,12 +121,18 @@ fn take_decimal_integer(i: &[u8]) -> IResult<&[u8], &[u8]> {
}
fn take_decimal_real(i: &[u8]) -> IResult<&[u8], &[u8]> {
named!(rr<&[u8], ()>, chain!(
one_of!("-+")? ~
digit ~
complete!(chain!(tag!(".") ~ digit, ||{()}))?,
||{()}
));
named!(rr<&[u8], ()>,
do_parse!(
opt!(one_of!("-+")) >>
digit >>
opt!(complete!(do_parse!(
tag!(".") >>
digit >>
()
))) >>
()
)
);
match rr(i) {
Done(remaining, _) => {

View File

@ -3,7 +3,6 @@
use std::result::Result;
use std::f32;
use nom;
use nom::IResult;
use mem_arena::MemArena;
@ -274,7 +273,7 @@ fn parse_render_settings(tree: &DataTree) -> Result<((u32, u32), u32, u32), PsyP
} if type_name == "Resolution" =>
{
if let IResult::Done(_, (w, h)) =
closure!(terminated!(tuple!(ws_u32, ws_u32), nom::eof))(contents.as_bytes())
closure!(terminated!(tuple!(ws_u32, ws_u32), eof!()))(contents.as_bytes())
{
found_res = true;
res = (w, h);
@ -583,7 +582,7 @@ pub fn parse_matrix(contents: &str) -> Result<Matrix4x4, PsyParseError> {
ws_f32,
ws_f32
),
nom::eof
eof!()
))(contents.as_bytes())
{
return Ok(Matrix4x4::new_from_values(