(
tokens: &'a [Token],
position: &'a mut usize,
condition: fn(&Token) -> bool,
message: &'a str,
)
| 3985 | |
| 3986 | #[inline(always)] |
| 3987 | pub(crate) fn consume_conditional_token_or_errors<'a>( |
| 3988 | tokens: &'a [Token], |
| 3989 | position: &'a mut usize, |
| 3990 | condition: fn(&Token) -> bool, |
| 3991 | message: &'a str, |
| 3992 | ) -> Result<&'a Token, Box<Diagnostic>> { |
| 3993 | if *position < tokens.len() && condition(&tokens[*position]) { |
| 3994 | *position += 1; |
| 3995 | let index = *position - 1; |
| 3996 | return Ok(&tokens[index]); |
| 3997 | } |
| 3998 | |
| 3999 | Err(Diagnostic::error(message) |
| 4000 | .with_location(calculate_safe_location(tokens, *position)) |
| 4001 | .as_boxed()) |
| 4002 | } |
| 4003 | |
| 4004 | #[inline(always)] |
| 4005 | pub(crate) fn calculate_safe_location(tokens: &[Token], position: usize) -> SourceLocation { |
no test coverage detected
searching dependent graphs…