@@ -265,7 +265,7 @@ enum ParserState {
265
265
}
266
266
267
267
pub struct Parser<'a> {
268
- tokens: Vec<TokenWithLocation >,
268
+ tokens: Vec<TokenWithSpan >,
269
269
/// The index of the first unprocessed token in [`Parser::tokens`].
270
270
index: usize,
271
271
/// The current state of the parser.
@@ -359,7 +359,7 @@ impl<'a> Parser<'a> {
359
359
}
360
360
361
361
/// Reset this parser to parse the specified token stream
362
- pub fn with_tokens_with_locations(mut self, tokens: Vec<TokenWithLocation >) -> Self {
362
+ pub fn with_tokens_with_locations(mut self, tokens: Vec<TokenWithSpan >) -> Self {
363
363
self.tokens = tokens;
364
364
self.index = 0;
365
365
self
@@ -368,9 +368,9 @@ impl<'a> Parser<'a> {
368
368
/// Reset this parser state to parse the specified tokens
369
369
pub fn with_tokens(self, tokens: Vec<Token>) -> Self {
370
370
// Put in dummy locations
371
- let tokens_with_locations: Vec<TokenWithLocation > = tokens
371
+ let tokens_with_locations: Vec<TokenWithSpan > = tokens
372
372
.into_iter()
373
- .map(|token| TokenWithLocation {
373
+ .map(|token| TokenWithSpan {
374
374
token,
375
375
span: Span::empty(),
376
376
})
@@ -1147,7 +1147,7 @@ impl<'a> Parser<'a> {
1147
1147
match self.peek_token().token {
1148
1148
Token::LParen | Token::Period => {
1149
1149
let mut id_parts: Vec<Ident> = vec![w.to_ident(w_span)];
1150
- let mut ending_wildcard: Option<TokenWithLocation > = None;
1150
+ let mut ending_wildcard: Option<TokenWithSpan > = None;
1151
1151
while self.consume_token(&Token::Period) {
1152
1152
let next_token = self.next_token();
1153
1153
match next_token.token {
@@ -3273,7 +3273,7 @@ impl<'a> Parser<'a> {
3273
3273
3274
3274
/// Return the first non-whitespace token that has not yet been processed
3275
3275
/// (or None if reached end-of-file)
3276
- pub fn peek_token(&self) -> TokenWithLocation {
3276
+ pub fn peek_token(&self) -> TokenWithSpan {
3277
3277
self.peek_nth_token(0)
3278
3278
}
3279
3279
@@ -3308,38 +3308,38 @@ impl<'a> Parser<'a> {
3308
3308
/// yet been processed.
3309
3309
///
3310
3310
/// See [`Self::peek_token`] for an example.
3311
- pub fn peek_tokens_with_location<const N: usize>(&self) -> [TokenWithLocation ; N] {
3311
+ pub fn peek_tokens_with_location<const N: usize>(&self) -> [TokenWithSpan ; N] {
3312
3312
let mut index = self.index;
3313
3313
core::array::from_fn(|_| loop {
3314
3314
let token = self.tokens.get(index);
3315
3315
index += 1;
3316
- if let Some(TokenWithLocation {
3316
+ if let Some(TokenWithSpan {
3317
3317
token: Token::Whitespace(_),
3318
3318
span: _,
3319
3319
}) = token
3320
3320
{
3321
3321
continue;
3322
3322
}
3323
- break token.cloned().unwrap_or(TokenWithLocation {
3323
+ break token.cloned().unwrap_or(TokenWithSpan {
3324
3324
token: Token::EOF,
3325
3325
span: Span::empty(),
3326
3326
});
3327
3327
})
3328
3328
}
3329
3329
3330
3330
/// Return nth non-whitespace token that has not yet been processed
3331
- pub fn peek_nth_token(&self, mut n: usize) -> TokenWithLocation {
3331
+ pub fn peek_nth_token(&self, mut n: usize) -> TokenWithSpan {
3332
3332
let mut index = self.index;
3333
3333
loop {
3334
3334
index += 1;
3335
3335
match self.tokens.get(index - 1) {
3336
- Some(TokenWithLocation {
3336
+ Some(TokenWithSpan {
3337
3337
token: Token::Whitespace(_),
3338
3338
span: _,
3339
3339
}) => continue,
3340
3340
non_whitespace => {
3341
3341
if n == 0 {
3342
- return non_whitespace.cloned().unwrap_or(TokenWithLocation {
3342
+ return non_whitespace.cloned().unwrap_or(TokenWithSpan {
3343
3343
token: Token::EOF,
3344
3344
span: Span::empty(),
3345
3345
});
@@ -3352,16 +3352,16 @@ impl<'a> Parser<'a> {
3352
3352
3353
3353
/// Return the first token, possibly whitespace, that has not yet been processed
3354
3354
/// (or None if reached end-of-file).
3355
- pub fn peek_token_no_skip(&self) -> TokenWithLocation {
3355
+ pub fn peek_token_no_skip(&self) -> TokenWithSpan {
3356
3356
self.peek_nth_token_no_skip(0)
3357
3357
}
3358
3358
3359
3359
/// Return nth token, possibly whitespace, that has not yet been processed.
3360
- pub fn peek_nth_token_no_skip(&self, n: usize) -> TokenWithLocation {
3360
+ pub fn peek_nth_token_no_skip(&self, n: usize) -> TokenWithSpan {
3361
3361
self.tokens
3362
3362
.get(self.index + n)
3363
3363
.cloned()
3364
- .unwrap_or(TokenWithLocation {
3364
+ .unwrap_or(TokenWithSpan {
3365
3365
token: Token::EOF,
3366
3366
span: Span::empty(),
3367
3367
})
@@ -3378,25 +3378,25 @@ impl<'a> Parser<'a> {
3378
3378
/// Return the first non-whitespace token that has not yet been processed
3379
3379
/// (or None if reached end-of-file) and mark it as processed. OK to call
3380
3380
/// repeatedly after reaching EOF.
3381
- pub fn next_token(&mut self) -> TokenWithLocation {
3381
+ pub fn next_token(&mut self) -> TokenWithSpan {
3382
3382
loop {
3383
3383
self.index += 1;
3384
3384
match self.tokens.get(self.index - 1) {
3385
- Some(TokenWithLocation {
3385
+ Some(TokenWithSpan {
3386
3386
token: Token::Whitespace(_),
3387
3387
span: _,
3388
3388
}) => continue,
3389
3389
token => {
3390
3390
return token
3391
3391
.cloned()
3392
- .unwrap_or_else(|| TokenWithLocation ::wrap(Token::EOF))
3392
+ .unwrap_or_else(|| TokenWithSpan ::wrap(Token::EOF))
3393
3393
}
3394
3394
}
3395
3395
}
3396
3396
}
3397
3397
3398
3398
/// Return the first unprocessed token, possibly whitespace.
3399
- pub fn next_token_no_skip(&mut self) -> Option<&TokenWithLocation > {
3399
+ pub fn next_token_no_skip(&mut self) -> Option<&TokenWithSpan > {
3400
3400
self.index += 1;
3401
3401
self.tokens.get(self.index - 1)
3402
3402
}
@@ -3408,7 +3408,7 @@ impl<'a> Parser<'a> {
3408
3408
loop {
3409
3409
assert!(self.index > 0);
3410
3410
self.index -= 1;
3411
- if let Some(TokenWithLocation {
3411
+ if let Some(TokenWithSpan {
3412
3412
token: Token::Whitespace(_),
3413
3413
span: _,
3414
3414
}) = self.tokens.get(self.index)
@@ -3420,7 +3420,7 @@ impl<'a> Parser<'a> {
3420
3420
}
3421
3421
3422
3422
/// Report `found` was encountered instead of `expected`
3423
- pub fn expected<T>(&self, expected: &str, found: TokenWithLocation ) -> Result<T, ParserError> {
3423
+ pub fn expected<T>(&self, expected: &str, found: TokenWithSpan ) -> Result<T, ParserError> {
3424
3424
parser_err!(
3425
3425
format!("Expected: {expected}, found: {found}"),
3426
3426
found.span.start
@@ -3435,7 +3435,7 @@ impl<'a> Parser<'a> {
3435
3435
}
3436
3436
3437
3437
#[must_use]
3438
- pub fn parse_keyword_token(&mut self, expected: Keyword) -> Option<TokenWithLocation > {
3438
+ pub fn parse_keyword_token(&mut self, expected: Keyword) -> Option<TokenWithSpan > {
3439
3439
match self.peek_token().token {
3440
3440
Token::Word(w) if expected == w.keyword => Some(self.next_token()),
3441
3441
_ => None,
@@ -3524,7 +3524,7 @@ impl<'a> Parser<'a> {
3524
3524
3525
3525
/// If the current token is the `expected` keyword, consume the token.
3526
3526
/// Otherwise, return an error.
3527
- pub fn expect_keyword(&mut self, expected: Keyword) -> Result<TokenWithLocation , ParserError> {
3527
+ pub fn expect_keyword(&mut self, expected: Keyword) -> Result<TokenWithSpan , ParserError> {
3528
3528
if let Some(token) = self.parse_keyword_token(expected) {
3529
3529
Ok(token)
3530
3530
} else {
@@ -3568,7 +3568,7 @@ impl<'a> Parser<'a> {
3568
3568
}
3569
3569
3570
3570
/// Bail out if the current token is not an expected keyword, or consume it if it is
3571
- pub fn expect_token(&mut self, expected: &Token) -> Result<TokenWithLocation , ParserError> {
3571
+ pub fn expect_token(&mut self, expected: &Token) -> Result<TokenWithSpan , ParserError> {
3572
3572
if self.peek_token() == *expected {
3573
3573
Ok(self.next_token())
3574
3574
} else {
@@ -4107,7 +4107,7 @@ impl<'a> Parser<'a> {
4107
4107
Keyword::ARCHIVE => Ok(Some(CreateFunctionUsing::Archive(uri))),
4108
4108
_ => self.expected(
4109
4109
"JAR, FILE or ARCHIVE, got {:?}",
4110
- TokenWithLocation ::wrap(Token::make_keyword(format!("{keyword:?}").as_str())),
4110
+ TokenWithSpan ::wrap(Token::make_keyword(format!("{keyword:?}").as_str())),
4111
4111
),
4112
4112
}
4113
4113
}
@@ -6832,7 +6832,7 @@ impl<'a> Parser<'a> {
6832
6832
if let Some(name) = name {
6833
6833
return self.expected(
6834
6834
"FULLTEXT or SPATIAL option without constraint name",
6835
- TokenWithLocation {
6835
+ TokenWithSpan {
6836
6836
token: Token::make_keyword(&name.to_string()),
6837
6837
span: next_token.span,
6838
6838
},
@@ -7808,15 +7808,15 @@ impl<'a> Parser<'a> {
7808
7808
Some('\'') => Ok(Value::SingleQuotedString(w.value)),
7809
7809
_ => self.expected(
7810
7810
"A value?",
7811
- TokenWithLocation {
7811
+ TokenWithSpan {
7812
7812
token: Token::Word(w),
7813
7813
span,
7814
7814
},
7815
7815
)?,
7816
7816
},
7817
7817
_ => self.expected(
7818
7818
"a concrete value",
7819
- TokenWithLocation {
7819
+ TokenWithSpan {
7820
7820
token: Token::Word(w),
7821
7821
span,
7822
7822
},
@@ -7878,7 +7878,7 @@ impl<'a> Parser<'a> {
7878
7878
}
7879
7879
unexpected => self.expected(
7880
7880
"a value",
7881
- TokenWithLocation {
7881
+ TokenWithSpan {
7882
7882
token: unexpected,
7883
7883
span,
7884
7884
},
@@ -7927,7 +7927,7 @@ impl<'a> Parser<'a> {
7927
7927
Token::HexStringLiteral(ref s) => Ok(Value::HexStringLiteral(s.to_string())),
7928
7928
unexpected => self.expected(
7929
7929
"a string value",
7930
- TokenWithLocation {
7930
+ TokenWithSpan {
7931
7931
token: unexpected,
7932
7932
span,
7933
7933
},
@@ -8618,7 +8618,7 @@ impl<'a> Parser<'a> {
8618
8618
let token = self
8619
8619
.next_token_no_skip()
8620
8620
.cloned()
8621
- .unwrap_or(TokenWithLocation ::wrap(Token::EOF));
8621
+ .unwrap_or(TokenWithSpan ::wrap(Token::EOF));
8622
8622
requires_whitespace = match token.token {
8623
8623
Token::Word(next_word) if next_word.quote_style.is_none() => {
8624
8624
ident.value.push_str(&next_word.value);
@@ -11683,7 +11683,7 @@ impl<'a> Parser<'a> {
11683
11683
/// If it is not possible to parse it, will return an option.
11684
11684
pub fn parse_wildcard_additional_options(
11685
11685
&mut self,
11686
- wildcard_token: TokenWithLocation ,
11686
+ wildcard_token: TokenWithSpan ,
11687
11687
) -> Result<WildcardAdditionalOptions, ParserError> {
11688
11688
let opt_ilike = if dialect_of!(self is GenericDialect | SnowflakeDialect) {
11689
11689
self.parse_optional_select_item_ilike()?
@@ -12708,7 +12708,7 @@ impl<'a> Parser<'a> {
12708
12708
}
12709
12709
12710
12710
/// Consume the parser and return its underlying token buffer
12711
- pub fn into_tokens(self) -> Vec<TokenWithLocation > {
12711
+ pub fn into_tokens(self) -> Vec<TokenWithSpan > {
12712
12712
self.tokens
12713
12713
}
12714
12714
0 commit comments