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