MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / expect_token_variant

Function expect_token_variant

graphlite/src/ast/parser.rs:3476–3497  ·  view source on GitHub ↗

Expect a token that matches a predicate

(predicate: &F)

Source from the content-addressed store, hash-verified

3474
3475/// Expect a token that matches a predicate
3476fn expect_token_variant<F>(predicate: &F) -> impl Fn(&[Token]) -> IResult<&[Token], Token> + '_
3477where
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)
3500fn expect_identifier(name: &str) -> impl Fn(&[Token]) -> IResult<&[Token], Token> + '_ {

Callers 1

path_constructorFunction · 0.85

Calls 3

ErrorEnum · 0.85
cloneMethod · 0.80
firstMethod · 0.45

Tested by

no test coverage detected