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)
| 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. |
| 264 | pub 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. |
no test coverage detected