@@ -201,11 +201,11 @@ impl Parser {
201201 // identifier, a function call, or a simple identifier:
202202 _ => match self . peek_token ( ) {
203203 Some ( Token :: LParen ) | Some ( Token :: Period ) => {
204- let mut id_parts: Vec < Ident > = vec ! [ w. as_ident ( ) ] ;
204+ let mut id_parts: Vec < Ident > = vec ! [ w. to_ident ( ) ] ;
205205 let mut ends_with_wildcard = false ;
206206 while self . consume_token ( & Token :: Period ) {
207207 match self . next_token ( ) {
208- Some ( Token :: Word ( w) ) => id_parts. push ( w. as_ident ( ) ) ,
208+ Some ( Token :: Word ( w) ) => id_parts. push ( w. to_ident ( ) ) ,
209209 Some ( Token :: Mult ) => {
210210 ends_with_wildcard = true ;
211211 break ;
@@ -225,7 +225,7 @@ impl Parser {
225225 Ok ( Expr :: CompoundIdentifier ( id_parts) )
226226 }
227227 }
228- _ => Ok ( Expr :: Identifier ( w. as_ident ( ) ) ) ,
228+ _ => Ok ( Expr :: Identifier ( w. to_ident ( ) ) ) ,
229229 } ,
230230 } , // End of Token::Word
231231 Token :: Mult => Ok ( Expr :: Wildcard ) ,
@@ -871,7 +871,7 @@ impl Parser {
871871 let table_name = self . parse_object_name ( ) ?;
872872 let ( columns, constraints) = self . parse_columns ( ) ?;
873873 self . expect_keywords ( & [ "STORED" , "AS" ] ) ?;
874- let file_format = self . parse_identifier ( ) ?. parse :: < FileFormat > ( ) ?;
874+ let file_format = self . parse_identifier ( ) ?. value . parse :: < FileFormat > ( ) ?;
875875
876876 self . expect_keyword ( "LOCATION" ) ?;
877877 let location = self . parse_literal_string ( ) ?;
@@ -976,7 +976,7 @@ impl Parser {
976976 }
977977
978978 columns. push ( ColumnDef {
979- name : column_name. as_ident ( ) ,
979+ name : column_name. to_ident ( ) ,
980980 data_type,
981981 collation,
982982 options,
@@ -1318,11 +1318,11 @@ impl Parser {
13181318 Some ( Token :: Word ( ref w) )
13191319 if after_as || !reserved_kwds. contains ( & w. keyword . as_str ( ) ) =>
13201320 {
1321- Ok ( Some ( w. as_ident ( ) ) )
1321+ Ok ( Some ( w. to_ident ( ) ) )
13221322 }
13231323 // MSSQL supports single-quoted strings as aliases for columns
13241324 // We accept them as table aliases too, although MSSQL does not.
1325- Some ( Token :: SingleQuotedString ( ref s) ) => Ok ( Some ( format ! ( "'{}'" , s) ) ) ,
1325+ Some ( Token :: SingleQuotedString ( ref s) ) => Ok ( Some ( Ident :: with_quote ( '\'' , s. clone ( ) ) ) ) ,
13261326 not_an_ident => {
13271327 if after_as {
13281328 return self . expected ( "an identifier after AS" , not_an_ident) ;
@@ -1366,7 +1366,7 @@ impl Parser {
13661366 /// Parse a simple one-word identifier (possibly quoted, possibly a keyword)
13671367 pub fn parse_identifier ( & mut self ) -> Result < Ident , ParserError > {
13681368 match self . next_token ( ) {
1369- Some ( Token :: Word ( w) ) => Ok ( w. as_ident ( ) ) ,
1369+ Some ( Token :: Word ( w) ) => Ok ( w. to_ident ( ) ) ,
13701370 unexpected => self . expected ( "identifier" , unexpected) ,
13711371 }
13721372 }
@@ -1609,15 +1609,15 @@ impl Parser {
16091609 let token = self . peek_token ( ) ;
16101610 let value = match ( self . parse_value ( ) , token) {
16111611 ( Ok ( value) , _) => SetVariableValue :: Literal ( value) ,
1612- ( Err ( _) , Some ( Token :: Word ( ident) ) ) => SetVariableValue :: Ident ( ident. as_ident ( ) ) ,
1612+ ( Err ( _) , Some ( Token :: Word ( ident) ) ) => SetVariableValue :: Ident ( ident. to_ident ( ) ) ,
16131613 ( Err ( _) , other) => self . expected ( "variable value" , other) ?,
16141614 } ;
16151615 Ok ( Statement :: SetVariable {
16161616 local : modifier == Some ( "LOCAL" ) ,
16171617 variable,
16181618 value,
16191619 } )
1620- } else if variable == "TRANSACTION" && modifier. is_none ( ) {
1620+ } else if variable. value == "TRANSACTION" && modifier. is_none ( ) {
16211621 Ok ( Statement :: SetTransaction {
16221622 modes : self . parse_transaction_modes ( ) ?,
16231623 } )
@@ -2066,8 +2066,11 @@ impl Parser {
20662066}
20672067
20682068impl Word {
2069- pub fn as_ident ( & self ) -> Ident {
2070- self . to_string ( )
2069+ pub fn to_ident ( & self ) -> Ident {
2070+ Ident {
2071+ value : self . value . clone ( ) ,
2072+ quote_style : self . quote_style ,
2073+ }
20712074 }
20722075}
20732076
0 commit comments