Skip to content

Commit a8f1795

Browse files
committed
Replace expect_keyword with expect_keyword_is
Except for a single instance, every use of expect_keyword was ignoring the returned token. This adds a new `expect_keyword_is` that avoids that unnecessary clone. I nearly added a `#[must_use]` attribute to the `expect_keyword` method, but decided against it as that feels like a breaking API change even if it would nudge folks toward the correct method.
1 parent 7922db0 commit a8f1795

File tree

4 files changed

+174
-164
lines changed

4 files changed

+174
-164
lines changed

src/dialect/postgresql.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ impl Dialect for PostgreSqlDialect {
235235

236236
pub fn parse_create(parser: &mut Parser) -> Option<Result<Statement, ParserError>> {
237237
let name = parser.maybe_parse(|parser| -> Result<ObjectName, ParserError> {
238-
parser.expect_keyword(Keyword::CREATE)?;
239-
parser.expect_keyword(Keyword::TYPE)?;
238+
parser.expect_keyword_is(Keyword::CREATE)?;
239+
parser.expect_keyword_is(Keyword::TYPE)?;
240240
let name = parser.parse_object_name(false)?;
241-
parser.expect_keyword(Keyword::AS)?;
242-
parser.expect_keyword(Keyword::ENUM)?;
241+
parser.expect_keyword_is(Keyword::AS)?;
242+
parser.expect_keyword_is(Keyword::ENUM)?;
243243
Ok(name)
244244
});
245245

src/dialect/snowflake.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub fn parse_create_table(
269269
match &next_token.token {
270270
Token::Word(word) => match word.keyword {
271271
Keyword::COPY => {
272-
parser.expect_keyword(Keyword::GRANTS)?;
272+
parser.expect_keyword_is(Keyword::GRANTS)?;
273273
builder = builder.copy_grants(true);
274274
}
275275
Keyword::COMMENT => {
@@ -293,7 +293,7 @@ pub fn parse_create_table(
293293
break;
294294
}
295295
Keyword::CLUSTER => {
296-
parser.expect_keyword(Keyword::BY)?;
296+
parser.expect_keyword_is(Keyword::BY)?;
297297
parser.expect_token(&Token::LParen)?;
298298
let cluster_by = Some(WrappedCollection::Parentheses(
299299
parser.parse_comma_separated(|p| p.parse_identifier(false))?,
@@ -356,14 +356,14 @@ pub fn parse_create_table(
356356
parser.prev_token();
357357
}
358358
Keyword::AGGREGATION => {
359-
parser.expect_keyword(Keyword::POLICY)?;
359+
parser.expect_keyword_is(Keyword::POLICY)?;
360360
let aggregation_policy = parser.parse_object_name(false)?;
361361
builder = builder.with_aggregation_policy(Some(aggregation_policy));
362362
}
363363
Keyword::ROW => {
364364
parser.expect_keywords(&[Keyword::ACCESS, Keyword::POLICY])?;
365365
let policy = parser.parse_object_name(false)?;
366-
parser.expect_keyword(Keyword::ON)?;
366+
parser.expect_keyword_is(Keyword::ON)?;
367367
parser.expect_token(&Token::LParen)?;
368368
let columns = parser.parse_comma_separated(|p| p.parse_identifier(false))?;
369369
parser.expect_token(&Token::RParen)?;
@@ -528,15 +528,15 @@ pub fn parse_copy_into(parser: &mut Parser) -> Result<Statement, ParserError> {
528528
let from_stage: ObjectName;
529529
let stage_params: StageParamsObject;
530530

531-
parser.expect_keyword(Keyword::FROM)?;
531+
parser.expect_keyword_is(Keyword::FROM)?;
532532
// check if data load transformations are present
533533
match parser.next_token().token {
534534
Token::LParen => {
535535
// data load with transformations
536-
parser.expect_keyword(Keyword::SELECT)?;
536+
parser.expect_keyword_is(Keyword::SELECT)?;
537537
from_transformations = parse_select_items_for_data_load(parser)?;
538538

539-
parser.expect_keyword(Keyword::FROM)?;
539+
parser.expect_keyword_is(Keyword::FROM)?;
540540
from_stage = parse_snowflake_stage_name(parser)?;
541541
stage_params = parse_stage_params(parser)?;
542542

@@ -852,7 +852,7 @@ fn parse_identity_property(parser: &mut Parser) -> Result<IdentityProperty, Pars
852852
))
853853
} else if parser.parse_keyword(Keyword::START) {
854854
let seed = parser.parse_number()?;
855-
parser.expect_keyword(Keyword::INCREMENT)?;
855+
parser.expect_keyword_is(Keyword::INCREMENT)?;
856856
let increment = parser.parse_number()?;
857857

858858
Some(IdentityPropertyFormatKind::StartAndIncrement(

src/parser/alter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ impl Parser<'_> {
5252
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-alterpolicy.html)
5353
pub fn parse_alter_policy(&mut self) -> Result<Statement, ParserError> {
5454
let name = self.parse_identifier(false)?;
55-
self.expect_keyword(Keyword::ON)?;
55+
self.expect_keyword_is(Keyword::ON)?;
5656
let table_name = self.parse_object_name(false)?;
5757

5858
if self.parse_keyword(Keyword::RENAME) {
59-
self.expect_keyword(Keyword::TO)?;
59+
self.expect_keyword_is(Keyword::TO)?;
6060
let new_name = self.parse_identifier(false)?;
6161
Ok(Statement::AlterPolicy {
6262
name,
@@ -232,7 +232,7 @@ impl Parser<'_> {
232232
Some(Keyword::BYPASSRLS) => RoleOption::BypassRLS(true),
233233
Some(Keyword::NOBYPASSRLS) => RoleOption::BypassRLS(false),
234234
Some(Keyword::CONNECTION) => {
235-
self.expect_keyword(Keyword::LIMIT)?;
235+
self.expect_keyword_is(Keyword::LIMIT)?;
236236
RoleOption::ConnectionLimit(Expr::Value(self.parse_number_value()?))
237237
}
238238
Some(Keyword::CREATEDB) => RoleOption::CreateDB(true),
@@ -256,7 +256,7 @@ impl Parser<'_> {
256256
Some(Keyword::SUPERUSER) => RoleOption::SuperUser(true),
257257
Some(Keyword::NOSUPERUSER) => RoleOption::SuperUser(false),
258258
Some(Keyword::VALID) => {
259-
self.expect_keyword(Keyword::UNTIL)?;
259+
self.expect_keyword_is(Keyword::UNTIL)?;
260260
RoleOption::ValidUntil(Expr::Value(self.parse_value()?))
261261
}
262262
_ => self.expected("option", self.peek_token())?,

0 commit comments

Comments
 (0)