MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / parse_exact_string

Function parse_exact_string

crates/hyperqueue/src/common/parser2.rs:264–285  ·  view source on GitHub ↗

Parses an exact string. Use this instead of `chomsky::text::keyword` or `chomsky::primitive::just` for better error messages if the expected string has more than a single character.

(keyword: &'static str)

Source from the content-addressed store, hash-verified

262/// Use this instead of `chomsky::text::keyword` or `chomsky::primitive::just` for better error
263/// messages if the expected string has more than a single character.
264pub fn parse_exact_string(keyword: &'static str) -> impl CharParser<()> {
265 ident()
266 // This produces nice error even when the input is missing completely
267 .map_err_with_span(|error: ParseError, span| {
268 error.merge(ParseError::expected_input_found_string(
269 span,
270 Some(Some(keyword.to_string())),
271 None,
272 ))
273 })
274 .try_map(move |s: String, span| {
275 if s.as_str() == keyword {
276 Ok(())
277 } else {
278 Err(ParseError::expected_input_found_string(
279 span,
280 Some(Some(keyword.to_string())),
281 Some(s),
282 ))
283 }
284 })
285}
286
287/// Return a parser that will fail if there is any input following the text parsed by the
288/// provided parser.

Callers 3

p_allocation_requestFunction · 0.85
parse_resource_rangeFunction · 0.85
parse_resource_sumFunction · 0.85

Calls 2

mergeMethod · 0.80
to_stringMethod · 0.80

Tested by

no test coverage detected