Expect a token that matches a predicate
(predicate: &F)
| 3474 | |
| 3475 | /// Expect a token that matches a predicate |
| 3476 | fn expect_token_variant<F>(predicate: &F) -> impl Fn(&[Token]) -> IResult<&[Token], Token> + '_ |
| 3477 | where |
| 3478 | F: Fn(&Token) -> bool, |
| 3479 | { |
| 3480 | move |tokens: &[Token]| { |
| 3481 | if let Some(token) = tokens.first() { |
| 3482 | if predicate(token) { |
| 3483 | Ok((&tokens[1..], token.clone())) |
| 3484 | } else { |
| 3485 | Err(nom::Err::Error(nom::error::Error::new( |
| 3486 | tokens, |
| 3487 | nom::error::ErrorKind::Tag, |
| 3488 | ))) |
| 3489 | } |
| 3490 | } else { |
| 3491 | Err(nom::Err::Error(nom::error::Error::new( |
| 3492 | tokens, |
| 3493 | nom::error::ErrorKind::Tag, |
| 3494 | ))) |
| 3495 | } |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | /// Helper function to expect a specific identifier (case-insensitive) |
| 3500 | fn expect_identifier(name: &str) -> impl Fn(&[Token]) -> IResult<&[Token], Token> + '_ { |
no test coverage detected