Skip to content

Commit b5fe68c

Browse files
committed
feat(parser): parse CREATE TEXT SEARCH statements
1 parent 089a07b commit b5fe68c

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
@@ -5212,6 +5212,8 @@ impl<'a> Parser<'a> {
52125212
}
52135213
} else if self.parse_keyword(Keyword::SERVER) {
52145214
self.parse_pg_create_server()
5215+
} else if self.parse_keywords(&[Keyword::TEXT, Keyword::SEARCH]) {
5216+
self.parse_create_text_search()
52155217
} else {
52165218
self.expected_ref("an object type after CREATE", self.peek_token_ref())
52175219
}
@@ -8176,6 +8178,49 @@ impl<'a> Parser<'a> {
81768178
})
81778179
}
81788180

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

0 commit comments

Comments
 (0)