@@ -216,11 +216,11 @@ impl Parser {
216
216
// identifier, a function call, or a simple identifier:
217
217
_ => match self . peek_token ( ) {
218
218
Some ( Token :: LParen ) | Some ( Token :: Period ) => {
219
- let mut id_parts: Vec < Ident > = vec ! [ w. as_ident ( ) ] ;
219
+ let mut id_parts: Vec < Ident > = vec ! [ w. to_ident ( ) ] ;
220
220
let mut ends_with_wildcard = false ;
221
221
while self . consume_token ( & Token :: Period ) {
222
222
match self . next_token ( ) {
223
- Some ( Token :: Word ( w) ) => id_parts. push ( w. as_ident ( ) ) ,
223
+ Some ( Token :: Word ( w) ) => id_parts. push ( w. to_ident ( ) ) ,
224
224
Some ( Token :: Mult ) => {
225
225
ends_with_wildcard = true ;
226
226
break ;
@@ -240,7 +240,7 @@ impl Parser {
240
240
Ok ( Expr :: CompoundIdentifier ( id_parts) )
241
241
}
242
242
}
243
- _ => Ok ( Expr :: Identifier ( w. as_ident ( ) ) ) ,
243
+ _ => Ok ( Expr :: Identifier ( w. to_ident ( ) ) ) ,
244
244
} ,
245
245
} , // End of Token::Word
246
246
Token :: Mult => Ok ( Expr :: Wildcard ) ,
@@ -1129,7 +1129,7 @@ impl Parser {
1129
1129
let table_name = self . parse_object_name ( ) ?;
1130
1130
let ( columns, constraints) = self . parse_columns ( ) ?;
1131
1131
self . expect_keywords ( & [ "STORED" , "AS" ] ) ?;
1132
- let file_format = self . parse_identifier ( ) ?. parse :: < FileFormat > ( ) ?;
1132
+ let file_format = self . parse_identifier ( ) ?. value . parse :: < FileFormat > ( ) ?;
1133
1133
1134
1134
self . expect_keyword ( "LOCATION" ) ?;
1135
1135
let location = self . parse_literal_string ( ) ?;
@@ -1257,7 +1257,7 @@ impl Parser {
1257
1257
}
1258
1258
1259
1259
columns. push ( ColumnDef {
1260
- name : column_name. as_ident ( ) ,
1260
+ name : column_name. to_ident ( ) ,
1261
1261
data_type,
1262
1262
collation,
1263
1263
options,
@@ -1599,11 +1599,11 @@ impl Parser {
1599
1599
Some ( Token :: Word ( ref w) )
1600
1600
if after_as || !reserved_kwds. contains ( & w. keyword . as_str ( ) ) =>
1601
1601
{
1602
- Ok ( Some ( w. as_ident ( ) ) )
1602
+ Ok ( Some ( w. to_ident ( ) ) )
1603
1603
}
1604
1604
// MSSQL supports single-quoted strings as aliases for columns
1605
1605
// We accept them as table aliases too, although MSSQL does not.
1606
- Some ( Token :: SingleQuotedString ( ref s) ) => Ok ( Some ( format ! ( "'{}'" , s) ) ) ,
1606
+ Some ( Token :: SingleQuotedString ( ref s) ) => Ok ( Some ( Ident :: with_quote ( '\'' , s. clone ( ) ) ) ) ,
1607
1607
not_an_ident => {
1608
1608
if after_as {
1609
1609
return self . expected ( "an identifier after AS" , not_an_ident) ;
@@ -1647,7 +1647,7 @@ impl Parser {
1647
1647
/// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
1648
1648
pub fn parse_identifier ( & mut self ) -> Result < Ident , ParserError > {
1649
1649
match self . next_token ( ) {
1650
- Some ( Token :: Word ( w) ) => Ok ( w. as_ident ( ) ) ,
1650
+ Some ( Token :: Word ( w) ) => Ok ( w. to_ident ( ) ) ,
1651
1651
unexpected => self . expected ( "identifier" , unexpected) ,
1652
1652
}
1653
1653
}
@@ -1890,15 +1890,15 @@ impl Parser {
1890
1890
let token = self . peek_token ( ) ;
1891
1891
let value = match ( self . parse_value ( ) , token) {
1892
1892
( Ok ( value) , _) => SetVariableValue :: Literal ( value) ,
1893
- ( Err ( _) , Some ( Token :: Word ( ident) ) ) => SetVariableValue :: Ident ( ident. as_ident ( ) ) ,
1893
+ ( Err ( _) , Some ( Token :: Word ( ident) ) ) => SetVariableValue :: Ident ( ident. to_ident ( ) ) ,
1894
1894
( Err ( _) , other) => self . expected ( "variable value" , other) ?,
1895
1895
} ;
1896
1896
Ok ( Statement :: SetVariable {
1897
1897
local : modifier == Some ( "LOCAL" ) ,
1898
1898
variable,
1899
1899
value,
1900
1900
} )
1901
- } else if variable == "TRANSACTION" && modifier. is_none ( ) {
1901
+ } else if variable. value == "TRANSACTION" && modifier. is_none ( ) {
1902
1902
Ok ( Statement :: SetTransaction {
1903
1903
modes : self . parse_transaction_modes ( ) ?,
1904
1904
} )
@@ -2386,8 +2386,11 @@ impl Parser {
2386
2386
}
2387
2387
2388
2388
impl Word {
2389
- pub fn as_ident ( & self ) -> Ident {
2390
- self . to_string ( )
2389
+ pub fn to_ident ( & self ) -> Ident {
2390
+ Ident {
2391
+ value : self . value . clone ( ) ,
2392
+ quote_style : self . quote_style ,
2393
+ }
2391
2394
}
2392
2395
}
2393
2396
0 commit comments