From 5e5f1a7f000dc227070ccb4bd8e0e3c1c4948282 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Mon, 2 Jul 2018 15:24:10 -0700 Subject: Fix test failures from upgrade to nom 4 --- src/path/parser.rs | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'src/path') diff --git a/src/path/parser.rs b/src/path/parser.rs index b998ee1..1ecd6e7 100644 --- a/src/path/parser.rs +++ b/src/path/parser.rs @@ -1,40 +1,37 @@ -use nom::*; +use nom::{ErrorKind, digit, IResult}; +use nom::types::CompleteStr; use std::str::{FromStr, from_utf8}; use super::Expression; -named!(ident_, - map!( - map_res!(is_a!( - "abcdefghijklmnopqrstuvwxyz \ - ABCDEFGHIJKLMNOPQRSTUVWXYZ \ - 0123456789 \ - _-" - ), from_utf8), - |s: &str| { - s.to_string() - } - ) +named!(raw_ident, + map!(is_a!( + "abcdefghijklmnopqrstuvwxyz \ + ABCDEFGHIJKLMNOPQRSTUVWXYZ \ + 0123456789 \ + _-" + ), |s: CompleteStr| { + s.to_string() + }) ); -named!(integer , +named!(integer, map_res!( - map_res!( - ws!(digit), - from_utf8 - ), - FromStr::from_str + ws!(digit), + |s: CompleteStr| { + s.parse() + } ) ); -named!(ident, map!(ident_, Expression::Identifier)); +named!(ident, map!(raw_ident, Expression::Identifier)); #[allow(cyclomatic_complexity)] -fn postfix(expr: Expression) -> Box IResult<&[u8], Expression>> { - Box::new(move |i: &[u8]| { +fn postfix(expr: Expression) -> Box IResult> { + Box::new(move |i: CompleteStr| { alt!(i, do_parse!( tag!(".") >> - id: ident_ >> + id: raw_ident >> (Expression::Child(Box::new(expr.clone()), id)) ) | delimited!( @@ -54,7 +51,7 @@ fn postfix(expr: Expression) -> Box IResult<&[u8], Expression>> { } pub fn from_str(input: &str) -> Result { - match ident(input.as_bytes()) { + match ident(CompleteStr(input)) { Ok((mut rem, mut expr)) => { while !rem.is_empty() { match postfix(expr)(rem) { -- cgit v1.2.3