Skip to content

Commit 82d6848

Browse files
committed
feat(parser): parse CREATE TEXT SEARCH statements
1 parent 3d90838 commit 82d6848

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/parser/mod.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,6 +5213,8 @@ impl<'a> Parser<'a> {
52135213
}
52145214
} else if self.parse_keyword(Keyword::SERVER) {
52155215
self.parse_pg_create_server()
5216+
} else if self.parse_keywords(&[Keyword::TEXT, Keyword::SEARCH]) {
5217+
self.parse_create_text_search()
52165218
} else {
52175219
self.expected_ref("an object type after CREATE", self.peek_token_ref())
52185220
}
@@ -8177,6 +8179,49 @@ impl<'a> Parser<'a> {
81778179
})
81788180
}
81798181

8182+
/// Parse a PostgreSQL-specific `CREATE TEXT SEARCH CONFIGURATION | DICTIONARY | PARSER | TEMPLATE` statement.
8183+
pub fn parse_create_text_search(&mut self) -> Result<Statement, ParserError> {
8184+
if self.parse_keyword(Keyword::CONFIGURATION) {
8185+
let name = self.parse_object_name(false)?;
8186+
self.expect_token(&Token::LParen)?;
8187+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8188+
self.expect_token(&Token::RParen)?;
8189+
Ok(Statement::CreateTextSearchConfiguration(
8190+
CreateTextSearchConfiguration { name, options },
8191+
))
8192+
} else if self.parse_keyword(Keyword::DICTIONARY) {
8193+
let name = self.parse_object_name(false)?;
8194+
self.expect_token(&Token::LParen)?;
8195+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8196+
self.expect_token(&Token::RParen)?;
8197+
Ok(Statement::CreateTextSearchDictionary(
8198+
CreateTextSearchDictionary { name, options },
8199+
))
8200+
} else if self.parse_keyword(Keyword::PARSER) {
8201+
let name = self.parse_object_name(false)?;
8202+
self.expect_token(&Token::LParen)?;
8203+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8204+
self.expect_token(&Token::RParen)?;
8205+
Ok(Statement::CreateTextSearchParser(CreateTextSearchParser {
8206+
name,
8207+
options,
8208+
}))
8209+
} else if self.parse_keyword(Keyword::TEMPLATE) {
8210+
let name = self.parse_object_name(false)?;
8211+
self.expect_token(&Token::LParen)?;
8212+
let options = self.parse_comma_separated(Parser::parse_sql_option)?;
8213+
self.expect_token(&Token::RParen)?;
8214+
Ok(Statement::CreateTextSearchTemplate(
8215+
CreateTextSearchTemplate { name, options },
8216+
))
8217+
} else {
8218+
self.expected_ref(
8219+
"CONFIGURATION, DICTIONARY, PARSER, or TEMPLATE after CREATE TEXT SEARCH",
8220+
self.peek_token_ref(),
8221+
)
8222+
}
8223+
}
8224+
81808225
/// Parse a PostgreSQL-specific [Statement::DropExtension] statement.
81818226
pub fn parse_drop_extension(&mut self) -> Result<Statement, ParserError> {
81828227
let if_exists = self.parse_keywords(&[Keyword::IF, Keyword::EXISTS]);

0 commit comments

Comments
 (0)