@@ -802,6 +802,15 @@ impl Parser {
802
802
}
803
803
}
804
804
805
+ /// Bail out if the following tokens are not the expected sequence of
806
+ /// keywords, or consume them if they are.
807
+ pub fn expect_keywords ( & mut self , expected : & [ & ' static str ] ) -> Result < ( ) , ParserError > {
808
+ for kw in expected {
809
+ self . expect_keyword ( kw) ?;
810
+ }
811
+ Ok ( ( ) )
812
+ }
813
+
805
814
/// Consume the next token if it matches the expected token, otherwise return false
806
815
#[ must_use]
807
816
pub fn consume_token ( & mut self , expected : & Token ) -> bool {
@@ -856,8 +865,7 @@ impl Parser {
856
865
self . expect_keyword ( "TABLE" ) ?;
857
866
let table_name = self . parse_object_name ( ) ?;
858
867
let ( columns, constraints) = self . parse_columns ( ) ?;
859
- self . expect_keyword ( "STORED" ) ?;
860
- self . expect_keyword ( "AS" ) ?;
868
+ self . expect_keywords ( & [ "STORED" , "AS" ] ) ?;
861
869
let file_format = self . parse_identifier ( ) ?. parse :: < FileFormat > ( ) ?;
862
870
863
871
self . expect_keyword ( "LOCATION" ) ?;
@@ -1111,8 +1119,7 @@ impl Parser {
1111
1119
pub fn parse_copy ( & mut self ) -> Result < Statement , ParserError > {
1112
1120
let table_name = self . parse_object_name ( ) ?;
1113
1121
let columns = self . parse_parenthesized_column_list ( Optional ) ?;
1114
- self . expect_keyword ( "FROM" ) ?;
1115
- self . expect_keyword ( "STDIN" ) ?;
1122
+ self . expect_keywords ( & [ "FROM" , "STDIN" ] ) ?;
1116
1123
self . expect_token ( & Token :: SemiColon ) ?;
1117
1124
let values = self . parse_tsv ( ) ?;
1118
1125
Ok ( Statement :: Copy {
@@ -1240,16 +1247,14 @@ impl Parser {
1240
1247
"TIMESTAMP" => {
1241
1248
// TBD: we throw away "with/without timezone" information
1242
1249
if self . parse_keyword ( "WITH" ) || self . parse_keyword ( "WITHOUT" ) {
1243
- self . expect_keyword ( "TIME" ) ?;
1244
- self . expect_keyword ( "ZONE" ) ?;
1250
+ self . expect_keywords ( & [ "TIME" , "ZONE" ] ) ?;
1245
1251
}
1246
1252
Ok ( DataType :: Timestamp )
1247
1253
}
1248
1254
"TIME" => {
1249
1255
// TBD: we throw away "with/without timezone" information
1250
1256
if self . parse_keyword ( "WITH" ) || self . parse_keyword ( "WITHOUT" ) {
1251
- self . expect_keyword ( "TIME" ) ?;
1252
- self . expect_keyword ( "ZONE" ) ?;
1257
+ self . expect_keywords ( & [ "TIME" , "ZONE" ] ) ?;
1253
1258
}
1254
1259
Ok ( DataType :: Time )
1255
1260
}
0 commit comments