@@ -970,15 +970,15 @@ impl<'a> Parser<'a> {
970
970
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => {
971
971
if self.peek_token().token == Token::Period {
972
972
let mut id_parts: Vec<Ident> = vec![match t {
973
- Token::Word(w) => w.to_ident (next_token.span),
973
+ Token::Word(w) => w.into_ident (next_token.span),
974
974
Token::SingleQuotedString(s) => Ident::with_quote('\'', s),
975
975
_ => unreachable!(), // We matched above
976
976
}];
977
977
978
978
while self.consume_token(&Token::Period) {
979
979
let next_token = self.next_token();
980
980
match next_token.token {
981
- Token::Word(w) => id_parts.push(w.to_ident (next_token.span)),
981
+ Token::Word(w) => id_parts.push(w.into_ident (next_token.span)),
982
982
Token::SingleQuotedString(s) => {
983
983
// SQLite has single-quoted identifiers
984
984
id_parts.push(Ident::with_quote('\'', s))
@@ -1108,7 +1108,7 @@ impl<'a> Parser<'a> {
1108
1108
if dialect_of!(self is PostgreSqlDialect | GenericDialect) =>
1109
1109
{
1110
1110
Ok(Some(Expr::Function(Function {
1111
- name: ObjectName(vec![w.to_ident (w_span)]),
1111
+ name: ObjectName(vec![w.clone().into_ident (w_span)]),
1112
1112
uses_odbc_syntax: false,
1113
1113
parameters: FunctionArguments::None,
1114
1114
args: FunctionArguments::None,
@@ -1123,7 +1123,7 @@ impl<'a> Parser<'a> {
1123
1123
| Keyword::CURRENT_DATE
1124
1124
| Keyword::LOCALTIME
1125
1125
| Keyword::LOCALTIMESTAMP => {
1126
- Ok(Some(self.parse_time_functions(ObjectName(vec![w.to_ident (w_span)]))?))
1126
+ Ok(Some(self.parse_time_functions(ObjectName(vec![w.clone().into_ident (w_span)]))?))
1127
1127
}
1128
1128
Keyword::CASE => Ok(Some(self.parse_case_expr()?)),
1129
1129
Keyword::CONVERT => Ok(Some(self.parse_convert_expr(false)?)),
@@ -1148,7 +1148,7 @@ impl<'a> Parser<'a> {
1148
1148
Keyword::CEIL => Ok(Some(self.parse_ceil_floor_expr(true)?)),
1149
1149
Keyword::FLOOR => Ok(Some(self.parse_ceil_floor_expr(false)?)),
1150
1150
Keyword::POSITION if self.peek_token_ref().token == Token::LParen => {
1151
- Ok(Some(self.parse_position_expr(w.to_ident (w_span))?))
1151
+ Ok(Some(self.parse_position_expr(w.clone().into_ident (w_span))?))
1152
1152
}
1153
1153
Keyword::SUBSTRING => Ok(Some(self.parse_substring_expr()?)),
1154
1154
Keyword::OVERLAY => Ok(Some(self.parse_overlay_expr()?)),
@@ -1167,7 +1167,7 @@ impl<'a> Parser<'a> {
1167
1167
let query = self.parse_query()?;
1168
1168
self.expect_token(&Token::RParen)?;
1169
1169
Ok(Some(Expr::Function(Function {
1170
- name: ObjectName(vec![w.to_ident (w_span)]),
1170
+ name: ObjectName(vec![w.clone().into_ident (w_span)]),
1171
1171
uses_odbc_syntax: false,
1172
1172
parameters: FunctionArguments::None,
1173
1173
args: FunctionArguments::Subquery(query),
@@ -1203,11 +1203,12 @@ impl<'a> Parser<'a> {
1203
1203
w_span: Span,
1204
1204
) -> Result<Expr, ParserError> {
1205
1205
match self.peek_token().token {
1206
- Token::Period => {
1207
- self.parse_compound_field_access(Expr::Identifier(w.to_ident(w_span)), vec![])
1208
- }
1206
+ Token::Period => self.parse_compound_field_access(
1207
+ Expr::Identifier(w.clone().into_ident(w_span)),
1208
+ vec![],
1209
+ ),
1209
1210
Token::LParen => {
1210
- let id_parts = vec![w.to_ident (w_span)];
1211
+ let id_parts = vec![w.clone().into_ident (w_span)];
1211
1212
if let Some(expr) = self.parse_outer_join_expr(&id_parts) {
1212
1213
Ok(expr)
1213
1214
} else {
@@ -1220,7 +1221,7 @@ impl<'a> Parser<'a> {
1220
1221
}
1221
1222
Token::LBracket if dialect_of!(self is PostgreSqlDialect | DuckDbDialect | GenericDialect | ClickHouseDialect | BigQueryDialect) =>
1222
1223
{
1223
- let ident = Expr::Identifier(w.to_ident (w_span));
1224
+ let ident = Expr::Identifier(w.clone().into_ident (w_span));
1224
1225
let mut fields = vec![];
1225
1226
self.parse_multi_dim_subscript(&mut fields)?;
1226
1227
self.parse_compound_field_access(ident, fields)
@@ -1250,11 +1251,11 @@ impl<'a> Parser<'a> {
1250
1251
Token::Arrow if self.dialect.supports_lambda_functions() => {
1251
1252
self.expect_token(&Token::Arrow)?;
1252
1253
Ok(Expr::Lambda(LambdaFunction {
1253
- params: OneOrManyWithParens::One(w.to_ident (w_span)),
1254
+ params: OneOrManyWithParens::One(w.clone().into_ident (w_span)),
1254
1255
body: Box::new(self.parse_expr()?),
1255
1256
}))
1256
1257
}
1257
- _ => Ok(Expr::Identifier(w.to_ident (w_span))),
1258
+ _ => Ok(Expr::Identifier(w.clone().into_ident (w_span))),
1258
1259
}
1259
1260
}
1260
1261
@@ -1438,7 +1439,7 @@ impl<'a> Parser<'a> {
1438
1439
} else {
1439
1440
let tok = self.next_token();
1440
1441
let key = match tok.token {
1441
- Token::Word(word) => word.to_ident (tok.span),
1442
+ Token::Word(word) => word.into_ident (tok.span),
1442
1443
_ => {
1443
1444
return parser_err!(
1444
1445
format!("Expected identifier, found: {tok}"),
@@ -1490,7 +1491,7 @@ impl<'a> Parser<'a> {
1490
1491
let next_token = self.next_token();
1491
1492
match next_token.token {
1492
1493
Token::Word(w) => {
1493
- let expr = Expr::Identifier(w.to_ident (next_token.span));
1494
+ let expr = Expr::Identifier(w.into_ident (next_token.span));
1494
1495
chain.push(AccessExpr::Dot(expr));
1495
1496
if self.peek_token().token == Token::LBracket {
1496
1497
if self.dialect.supports_partiql() {
@@ -1670,7 +1671,7 @@ impl<'a> Parser<'a> {
1670
1671
while p.consume_token(&Token::Period) {
1671
1672
let tok = p.next_token();
1672
1673
let name = match tok.token {
1673
- Token::Word(word) => word.to_ident (tok.span),
1674
+ Token::Word(word) => word.into_ident (tok.span),
1674
1675
_ => return p.expected("identifier", tok),
1675
1676
};
1676
1677
let func = match p.parse_function(ObjectName(vec![name]))? {
@@ -8242,7 +8243,7 @@ impl<'a> Parser<'a> {
8242
8243
// This because snowflake allows numbers as placeholders
8243
8244
let next_token = self.next_token();
8244
8245
let ident = match next_token.token {
8245
- Token::Word(w) => Ok(w.to_ident (next_token.span)),
8246
+ Token::Word(w) => Ok(w.into_ident (next_token.span)),
8246
8247
Token::Number(w, false) => Ok(Ident::new(w)),
8247
8248
_ => self.expected("placeholder", next_token),
8248
8249
}?;
@@ -8753,7 +8754,7 @@ impl<'a> Parser<'a> {
8753
8754
// (For example, in `FROM t1 JOIN` the `JOIN` will always be parsed as a keyword,
8754
8755
// not an alias.)
8755
8756
Token::Word(w) if after_as || !reserved_kwds.contains(&w.keyword) => {
8756
- Ok(Some(w.to_ident (next_token.span)))
8757
+ Ok(Some(w.into_ident (next_token.span)))
8757
8758
}
8758
8759
// MSSQL supports single-quoted strings as aliases for columns
8759
8760
// We accept them as table aliases too, although MSSQL does not.
@@ -8920,7 +8921,7 @@ impl<'a> Parser<'a> {
8920
8921
loop {
8921
8922
match &self.peek_token_ref().token {
8922
8923
Token::Word(w) => {
8923
- idents.push(w.to_ident (self.peek_token_ref().span));
8924
+ idents.push(w.clone().into_ident (self.peek_token_ref().span));
8924
8925
}
8925
8926
Token::EOF | Token::Eq => break,
8926
8927
_ => {}
@@ -8975,7 +8976,7 @@ impl<'a> Parser<'a> {
8975
8976
// expecting at least one word for identifier
8976
8977
let next_token = self.next_token();
8977
8978
match next_token.token {
8978
- Token::Word(w) => idents.push(w.to_ident (next_token.span)),
8979
+ Token::Word(w) => idents.push(w.into_ident (next_token.span)),
8979
8980
Token::EOF => {
8980
8981
return Err(ParserError::ParserError(
8981
8982
"Empty input when parsing identifier".to_string(),
@@ -8995,7 +8996,7 @@ impl<'a> Parser<'a> {
8995
8996
Token::Period => {
8996
8997
let next_token = self.next_token();
8997
8998
match next_token.token {
8998
- Token::Word(w) => idents.push(w.to_ident (next_token.span)),
8999
+ Token::Word(w) => idents.push(w.into_ident (next_token.span)),
8999
9000
Token::EOF => {
9000
9001
return Err(ParserError::ParserError(
9001
9002
"Trailing period in identifier".to_string(),
@@ -9024,7 +9025,7 @@ impl<'a> Parser<'a> {
9024
9025
pub fn parse_identifier(&mut self) -> Result<Ident, ParserError> {
9025
9026
let next_token = self.next_token();
9026
9027
match next_token.token {
9027
- Token::Word(w) => Ok(w.to_ident (next_token.span)),
9028
+ Token::Word(w) => Ok(w.into_ident (next_token.span)),
9028
9029
Token::SingleQuotedString(s) => Ok(Ident::with_quote('\'', s)),
9029
9030
Token::DoubleQuotedString(s) => Ok(Ident::with_quote('\"', s)),
9030
9031
_ => self.expected("identifier", next_token),
@@ -9044,9 +9045,10 @@ impl<'a> Parser<'a> {
9044
9045
fn parse_unquoted_hyphenated_identifier(&mut self) -> Result<(Ident, bool), ParserError> {
9045
9046
match self.peek_token().token {
9046
9047
Token::Word(w) => {
9048
+ let quote_style_is_none = w.quote_style.is_none();
9047
9049
let mut requires_whitespace = false;
9048
- let mut ident = w.to_ident (self.next_token().span);
9049
- if w.quote_style.is_none() {
9050
+ let mut ident = w.into_ident (self.next_token().span);
9051
+ if quote_style_is_none {
9050
9052
while matches!(self.peek_token_no_skip().token, Token::Minus) {
9051
9053
self.next_token();
9052
9054
ident.value.push('-');
@@ -13475,13 +13477,23 @@ impl<'a> Parser<'a> {
13475
13477
}
13476
13478
13477
13479
impl Word {
13480
+ #[deprecated(since = "0.54.0", note = "please use `into_ident` instead")]
13478
13481
pub fn to_ident(&self, span: Span) -> Ident {
13479
13482
Ident {
13480
13483
value: self.value.clone(),
13481
13484
quote_style: self.quote_style,
13482
13485
span,
13483
13486
}
13484
13487
}
13488
+
13489
+ /// Convert this word into an [`Ident`] identifier
13490
+ pub fn into_ident(self, span: Span) -> Ident {
13491
+ Ident {
13492
+ value: self.value,
13493
+ quote_style: self.quote_style,
13494
+ span,
13495
+ }
13496
+ }
13485
13497
}
13486
13498
13487
13499
#[cfg(test)]
0 commit comments