@@ -172,12 +172,12 @@ impl Parser {
172
172
} )
173
173
}
174
174
_ => match self . peek_token ( ) {
175
- Some ( Token :: LParen ) => self . parse_function ( & w . value ) ,
175
+ Some ( Token :: LParen ) => self . parse_function ( w . as_sql_ident ( ) ) ,
176
176
Some ( Token :: Period ) => {
177
- let mut id_parts: Vec < String > = vec ! [ w. value ] ;
177
+ let mut id_parts: Vec < SQLIdent > = vec ! [ w. as_sql_ident ( ) ] ;
178
178
while self . consume_token ( & Token :: Period ) {
179
179
match self . next_token ( ) {
180
- Some ( Token :: SQLWord ( w) ) => id_parts. push ( w. value ) ,
180
+ Some ( Token :: SQLWord ( w) ) => id_parts. push ( w. as_sql_ident ( ) ) ,
181
181
_ => {
182
182
return parser_err ! ( format!(
183
183
"Error parsing compound identifier"
@@ -187,7 +187,7 @@ impl Parser {
187
187
}
188
188
Ok ( ASTNode :: SQLCompoundIdentifier ( id_parts) )
189
189
}
190
- _ => Ok ( ASTNode :: SQLIdentifier ( w. value ) ) ,
190
+ _ => Ok ( ASTNode :: SQLIdentifier ( w. as_sql_ident ( ) ) ) ,
191
191
} ,
192
192
} ,
193
193
Token :: Mult => Ok ( ASTNode :: SQLWildcard ) ,
@@ -213,20 +213,17 @@ impl Parser {
213
213
}
214
214
}
215
215
216
- pub fn parse_function ( & mut self , id : & str ) -> Result < ASTNode , ParserError > {
216
+ pub fn parse_function ( & mut self , id : SQLIdent ) -> Result < ASTNode , ParserError > {
217
217
self . expect_token ( & Token :: LParen ) ?;
218
218
if self . consume_token ( & Token :: RParen ) {
219
219
Ok ( ASTNode :: SQLFunction {
220
- id : id. to_string ( ) ,
220
+ id : id,
221
221
args : vec ! [ ] ,
222
222
} )
223
223
} else {
224
224
let args = self . parse_expr_list ( ) ?;
225
225
self . expect_token ( & Token :: RParen ) ?;
226
- Ok ( ASTNode :: SQLFunction {
227
- id : id. to_string ( ) ,
228
- args,
229
- } )
226
+ Ok ( ASTNode :: SQLFunction { id, args } )
230
227
}
231
228
}
232
229
@@ -573,7 +570,7 @@ impl Parser {
573
570
Some ( Token :: Comma ) => {
574
571
self . next_token ( ) ;
575
572
columns. push ( SQLColumnDef {
576
- name : column_name. value ,
573
+ name : column_name. as_sql_ident ( ) ,
577
574
data_type : data_type,
578
575
allow_null,
579
576
is_primary,
@@ -584,7 +581,7 @@ impl Parser {
584
581
Some ( Token :: RParen ) => {
585
582
self . next_token ( ) ;
586
583
columns. push ( SQLColumnDef {
587
- name : column_name. value ,
584
+ name : column_name. as_sql_ident ( ) ,
588
585
data_type : data_type,
589
586
allow_null,
590
587
is_primary,
@@ -622,15 +619,15 @@ impl Parser {
622
619
}
623
620
}
624
621
625
- pub fn parse_table_key ( & mut self , constraint_name : & str ) -> Result < TableKey , ParserError > {
622
+ pub fn parse_table_key ( & mut self , constraint_name : SQLIdent ) -> Result < TableKey , ParserError > {
626
623
let is_primary_key = self . parse_keywords ( vec ! [ "PRIMARY" , "KEY" ] ) ;
627
624
let is_unique_key = self . parse_keywords ( vec ! [ "UNIQUE" , "KEY" ] ) ;
628
625
let is_foreign_key = self . parse_keywords ( vec ! [ "FOREIGN" , "KEY" ] ) ;
629
626
self . expect_token ( & Token :: LParen ) ?;
630
627
let column_names = self . parse_column_names ( ) ?;
631
628
self . expect_token ( & Token :: RParen ) ?;
632
629
let key = Key {
633
- name : constraint_name. to_string ( ) ,
630
+ name : constraint_name,
634
631
columns : column_names,
635
632
} ;
636
633
if is_primary_key {
@@ -664,7 +661,7 @@ impl Parser {
664
661
if self . parse_keywords ( vec ! [ "ADD" , "CONSTRAINT" ] ) {
665
662
match self . next_token ( ) {
666
663
Some ( Token :: SQLWord ( ref id) ) => {
667
- let table_key = self . parse_table_key ( & id. value ) ?;
664
+ let table_key = self . parse_table_key ( id. as_sql_ident ( ) ) ?;
668
665
Ok ( AlterOperation :: AddConstraint ( table_key) )
669
666
}
670
667
_ => {
@@ -1012,8 +1009,7 @@ impl Parser {
1012
1009
Some ( Token :: SQLWord ( ref w) )
1013
1010
if after_as || !reserved_kwds. contains ( & w. keyword . as_str ( ) ) =>
1014
1011
{
1015
- // have to clone here until #![feature(bind_by_move_pattern_guards)] is enabled by default
1016
- Ok ( Some ( w. value . clone ( ) ) )
1012
+ Ok ( Some ( w. as_sql_ident ( ) ) )
1017
1013
}
1018
1014
ref not_an_ident if after_as => parser_err ! ( format!(
1019
1015
"Expected an identifier after AS, got {:?}" ,
@@ -1036,7 +1032,7 @@ impl Parser {
1036
1032
match token {
1037
1033
Some ( Token :: SQLWord ( s) ) if expect_identifier => {
1038
1034
expect_identifier = false ;
1039
- idents. push ( s. to_string ( ) ) ;
1035
+ idents. push ( s. as_sql_ident ( ) ) ;
1040
1036
}
1041
1037
Some ( token) if token == separator && !expect_identifier => {
1042
1038
expect_identifier = true ;
@@ -1386,3 +1382,9 @@ impl Parser {
1386
1382
}
1387
1383
}
1388
1384
}
1385
+
1386
+ impl SQLWord {
1387
+ pub fn as_sql_ident ( & self ) -> SQLIdent {
1388
+ self . to_string ( )
1389
+ }
1390
+ }
0 commit comments