From fe35ce7ed183fc0d62e52b6ba121a6af5bccac7a Mon Sep 17 00:00:00 2001 From: vthriller Date: Sat, 11 Sep 2021 03:01:46 +0300 Subject: [PATCH] nom: replace remaining streaming macros with complete functions, rendering remaining parser tests successful --- src/expr.rs | 7 +++++-- src/str.rs | 16 ++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index d73e83e..0743f06 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1,5 +1,8 @@ use nom::IResult; -use nom::bytes::complete::tag; +use nom::bytes::complete::{ + tag, + tag_no_case, +}; use nom::character::complete::char; use nom::number::complete::recognize_float; use str::string; @@ -200,7 +203,7 @@ fn atom(input: &[u8], allow_periods: bool) -> IResult<&[u8], Node> { ws!( input, alt!( - map!(tag_no_case!("NaN"), |_| Node::Scalar(::std::f32::NAN)) // XXX define Node::NaN instead? + map!(call!(tag_no_case("NaN")), |_| Node::Scalar(::std::f32::NAN)) // XXX define Node::NaN instead? | map!( flat_map!(call!(recognize_float), parse_to!(f32)), diff --git a/src/str.rs b/src/str.rs index 0eb0f18..cd5a64f 100644 --- a/src/str.rs +++ b/src/str.rs @@ -1,3 +1,7 @@ +use nom::bytes::complete::{ + is_not, + take, +}; use nom::character::complete::char; // > Label values may contain any Unicode characters. @@ -24,7 +28,7 @@ macro_rules! fixed_length_radix { // besides u123::from_str_radix will validate chars anyways, so why do extra work? map_res!( $i, - take!($len), + call!(take($len)), |n: &[u8]| -> Result<_, UnicodeRuneError> { Ok($type::from_str_radix( &String::from_utf8(n.to_vec())?, @@ -58,19 +62,19 @@ named!(rune <&[u8], Vec>, | call!(char('\'')) => { |_| vec![0x27] } | call!(char('"')) => { |_| vec![0x22] } | map!( - fixed_length_radix!(u8, 3, 8), + fixed_length_radix!(u8, 3u8, 8), |n| vec![n] ) | map!( - preceded!(call!(char('x')), fixed_length_radix!(u8, 2, 16)), + preceded!(call!(char('x')), fixed_length_radix!(u8, 2u8, 16)), |n| vec![n] ) | map_opt!( - preceded!(call!(char('u')), fixed_length_radix!(u32, 4, 16)), + preceded!(call!(char('u')), fixed_length_radix!(u32, 4u8, 16)), validate_unicode_scalar ) | map_opt!( - preceded!(call!(char('U')), fixed_length_radix!(u32, 8, 16)), + preceded!(call!(char('U')), fixed_length_radix!(u32, 8u8, 16)), validate_unicode_scalar ) ) @@ -81,7 +85,7 @@ named!(rune <&[u8], Vec>, // returns Vec (unlike none_of!() which returns &[char], or is_not!() which returns &[u8]) macro_rules! is_not_v { ($i:expr, $arg:expr) => { - map!($i, is_not!($arg), |bytes| bytes.to_vec()) + map!($i, call!(is_not($arg)), |bytes| bytes.to_vec()) }; }