@@ -2346,15 +2346,16 @@ impl<'a> Parser<'a> {
2346
2346
}
2347
2347
}
2348
2348
2349
- /// Report unexpected token
2349
+ /// Report `found` was encountered instead of `expected`
2350
2350
pub fn expected < T > ( & self , expected : & str , found : TokenWithLocation ) -> Result < T , ParserError > {
2351
2351
parser_err ! (
2352
2352
format!( "Expected {expected}, found: {found}" ) ,
2353
2353
found. location
2354
2354
)
2355
2355
}
2356
2356
2357
- /// Look for an expected keyword and consume it if it exists
2357
+ /// If the current token is the `expected` keyword, consume it and returns
2358
+ /// true. Otherwise, no tokens are consumed and returns false.
2358
2359
#[ must_use]
2359
2360
pub fn parse_keyword ( & mut self , expected : Keyword ) -> bool {
2360
2361
match self . peek_token ( ) . token {
@@ -2366,7 +2367,9 @@ impl<'a> Parser<'a> {
2366
2367
}
2367
2368
}
2368
2369
2369
- /// Look for an expected sequence of keywords and consume them if they exist
2370
+ /// If the current and subsequent tokens exactly match the `keywords`
2371
+ /// sequence, consume them and returns true. Otherwise, no tokens are
2372
+ /// consumed and returns false
2370
2373
#[ must_use]
2371
2374
pub fn parse_keywords ( & mut self , keywords : & [ Keyword ] ) -> bool {
2372
2375
let index = self . index ;
@@ -2381,7 +2384,9 @@ impl<'a> Parser<'a> {
2381
2384
true
2382
2385
}
2383
2386
2384
- /// Look for one of the given keywords and return the one that matches.
2387
+ /// If the current token is one of the given `keywords`, consume the token
2388
+ /// and return the keyword that matches. Otherwise, no tokens are consumed
2389
+ /// and returns `None`.
2385
2390
#[ must_use]
2386
2391
pub fn parse_one_of_keywords ( & mut self , keywords : & [ Keyword ] ) -> Option < Keyword > {
2387
2392
match self . peek_token ( ) . token {
@@ -2398,7 +2403,8 @@ impl<'a> Parser<'a> {
2398
2403
}
2399
2404
}
2400
2405
2401
- /// Bail out if the current token is not one of the expected keywords, or consume it if it is
2406
+ /// If the current token is one of the expected keywords, consume the token
2407
+ /// and return the keyword that matches. Otherwise, return an error.
2402
2408
pub fn expect_one_of_keywords ( & mut self , keywords : & [ Keyword ] ) -> Result < Keyword , ParserError > {
2403
2409
if let Some ( keyword) = self . parse_one_of_keywords ( keywords) {
2404
2410
Ok ( keyword)
@@ -2411,7 +2417,8 @@ impl<'a> Parser<'a> {
2411
2417
}
2412
2418
}
2413
2419
2414
- /// Bail out if the current token is not an expected keyword, or consume it if it is
2420
+ /// If the current token is the `expected` keyword, consume the token.
2421
+ /// Otherwise return an error.
2415
2422
pub fn expect_keyword ( & mut self , expected : Keyword ) -> Result < ( ) , ParserError > {
2416
2423
if self . parse_keyword ( expected) {
2417
2424
Ok ( ( ) )
@@ -2420,8 +2427,8 @@ impl<'a> Parser<'a> {
2420
2427
}
2421
2428
}
2422
2429
2423
- /// Bail out if the following tokens are not the expected sequence of
2424
- /// keywords, or consume them if they are .
2430
+ /// If the current and subsequent tokens exactly match the `keywords`
2431
+ /// sequence, consume them and returns Ok. Otherwise, return an Error .
2425
2432
pub fn expect_keywords ( & mut self , expected : & [ Keyword ] ) -> Result < ( ) , ParserError > {
2426
2433
for & kw in expected {
2427
2434
self . expect_keyword ( kw) ?;
0 commit comments