Parse a string. Use a loop of parse_fragment and push all of the fragments into an output string.
(input: &'a str)
| 198 | /// Parse a string. Use a loop of parse_fragment and push all of the fragments |
| 199 | /// into an output string. |
| 200 | fn parse_string<'a, E>(input: &'a str) -> IResult<&'a str, String, E> |
| 201 | where |
| 202 | E: ParseError<&'a str> + FromExternalError<&'a str, std::num::ParseIntError>, |
| 203 | { |
| 204 | // fold is the equivalent of iterator::fold. It runs a parser in a loop, |
| 205 | // and for each output value, calls a folding function on each output value. |
| 206 | let build_string = fold_many0( |
| 207 | // Our parser function – parses a single string fragment |
| 208 | parse_fragment, |
| 209 | // Our init value, an empty string |
| 210 | String::new, |
| 211 | // Our folding function. For each fragment, append the fragment to the |
| 212 | // string. |
| 213 | |mut string, fragment| { |
| 214 | match fragment { |
| 215 | StringFragment::Literal(s) => string.push_str(s), |
| 216 | StringFragment::EscapedChar(c) => string.push(c), |
| 217 | StringFragment::EscapedWS => {} |
| 218 | } |
| 219 | string |
| 220 | }, |
| 221 | ); |
| 222 | |
| 223 | // Finally, parse the string. Note that, if `build_string` could accept a raw |
| 224 | // " character, the closing delimiter " would never match. When using |
| 225 | // `delimited` with a looping parser (like fold), be sure that the |
| 226 | // loop won't accidentally match your closing delimiter! |
| 227 | delimited(char('"'), build_string, char('"')).parse(input) |
| 228 | } |
| 229 | |
| 230 | fn parse_string_term(i: &str) -> IResult<&str, Term, Error> { |
| 231 | let (i, s) = parse_string(i)?; |
no test coverage detected