Skip to content

Commit

Permalink
nom: replace remaining streaming macros with complete functions, rend…
Browse files Browse the repository at this point in the history
…ering remaining parser tests successful
  • Loading branch information
vthriller committed Sep 11, 2021
1 parent 4f125b4 commit fe35ce7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions 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;
Expand Down Expand Up @@ -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)),
Expand Down
16 changes: 10 additions & 6 deletions 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.
Expand All @@ -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())?,
Expand Down Expand Up @@ -58,19 +62,19 @@ named!(rune <&[u8], Vec<u8>>,
| 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
)
)
Expand All @@ -81,7 +85,7 @@ named!(rune <&[u8], Vec<u8>>,
// returns Vec<u8> (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())
};
}

Expand Down

0 comments on commit fe35ce7

Please sign in to comment.