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>,
)
| 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, |