diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 68d0778..5121aa9 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,5 +1,6 @@ use nom::branch::alt; use nom::bytes::complete::escaped; +use nom::bytes::complete::escaped_transform; use nom::bytes::complete::is_a; use nom::bytes::complete::is_not; use nom::bytes::complete::tag; @@ -328,10 +329,10 @@ pub fn template(i: &str) -> IResult<&str, Template> { Ok((remaining, Template { contents: contents })) } -fn quoted_string(i: &str) -> IResult<&str, &str> { +fn quoted_string(i: &str) -> IResult<&str, String> { delimited( tag(r#"""#), - escaped(is_not(r#"\""#), '\\', one_of(r#"\""#)), + escaped_transform(is_not(r#"\""#), '\\', one_of(r#"\""#)), tag(r#"""#), )(i) } @@ -614,6 +615,9 @@ mod tests { #[test] fn test_temp_string() { - assert_eq!(quoted_string(r#""foo\"bar""#), Ok(("", r#"foo\"bar"#))); + assert_eq!( + quoted_string(r#""foo\"bar""#), + Ok(("", r#"foo"bar"#.to_owned())) + ); } }