MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / consume_conditional_token_or_errors

Function consume_conditional_token_or_errors

crates/gitql-parser/src/parser.rs:3987–4002  ·  view source on GitHub ↗
(
    tokens: &'a [Token],
    position: &'a mut usize,
    condition: fn(&Token) -> bool,
    message: &'a str,
)

Source from the content-addressed store, hash-verified

3985
3986#[inline(always)]
3987pub(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)]
4005pub(crate) fn calculate_safe_location(tokens: &[Token], position: usize) -> SourceLocation {

Callers 5

parse_from_optionFunction · 0.85
parse_primitive_typeFunction · 0.85

Calls 4

calculate_safe_locationFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…