MCPcopy Create free account
hub / github.com/hashintel/hash / peek_expect

Method peek_expect

libs/@local/hashql/syntax-jexpr/src/parser/state.rs:276–289  ·  view source on GitHub ↗

Returns a reference to the next token without consuming it, validating it against the expected syntax kinds. The argument `expected` is used to validate the next token. It can be a `SyntaxKind` or `SyntaxKindSet` directly, or `Expected::hint(...)` to accept any token regardless of kind. # Errors - `UnexpectedEof` if there are no more tokens - `UnexpectedToken` if the token doesn't match the exp

(
        &mut self,
        expected: impl Into<Expected>,
    )

Source from the content-addressed store, hash-verified

274 /// - `UnexpectedEof` if there are no more tokens
275 /// - `UnexpectedToken` if the token doesn't match the expected kinds (when validating)
276 pub(crate) fn peek_expect(
277 &mut self,
278 expected: impl Into<Expected>,
279 ) -> Result<&Token<'source>, LexerDiagnostic> {
280 let expected = expected.into();
281
282 match self.lexer.peek_n_span(&mut self.context.lexer(), 0)? {
283 Ok(token) => self.context.validate_token(token, expected),
284 Err(span) => {
285 let span = self.context.insert_range(span);
286 Err(unexpected_eof(span, expected.into_set()))
287 }
288 }
289 }
290
291 pub(crate) fn enter<T>(
292 &mut self,

Callers 7

verify_no_repeatFunction · 0.80
visit_arrayFunction · 0.80
visit_objectFunction · 0.80

Calls 7

ErrInterface · 0.85
unexpected_eofFunction · 0.85
peek_n_spanMethod · 0.80
lexerMethod · 0.80
validate_tokenMethod · 0.80
into_setMethod · 0.80
insert_rangeMethod · 0.45