MCPcopy Create free account
hub / github.com/adam-mcdaniel/reckon / parse_string

Function parse_string

src/parse.rs:200–228  ·  view source on GitHub ↗

Parse a string. Use a loop of parse_fragment and push all of the fragments into an output string.

(input: &'a str)

Source from the content-addressed store, hash-verified

198/// Parse a string. Use a loop of parse_fragment and push all of the fragments
199/// into an output string.
200fn parse_string<'a, E>(input: &'a str) -> IResult<&'a str, String, E>
201where
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
230fn parse_string_term(i: &str) -> IResult<&str, Term, Error> {
231 let (i, s) = parse_string(i)?;

Callers 1

parse_string_termFunction · 0.85

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected