Skip to content

Commit 4260dcd

Browse files
replace impl with a fn
1 parent 70aba82 commit 4260dcd

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/ast/mod.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use serde::{Deserialize, Serialize};
3737
#[cfg(feature = "visitor")]
3838
use sqlparser_derive::{Visit, VisitMut};
3939

40-
use crate::{keywords::Keyword, tokenizer::Span};
40+
use crate::tokenizer::Span;
4141

4242
pub use self::data_type::{
4343
ArrayElemTypeDef, BinaryLength, CharLengthUnits, CharacterLength, DataType, EnumMember,
@@ -7899,7 +7899,7 @@ impl fmt::Display for FlushLocation {
78997899
}
79007900
}
79017901

7902-
/// Optional context modifier for statements that can be or `LOCAL`, 'GLOBAL', or `SESSION`.
7902+
/// Optional context modifier for statements that can be or `LOCAL`, `GLOBAL`, or `SESSION`.
79037903
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
79047904
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
79057905
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
@@ -7933,20 +7933,6 @@ impl fmt::Display for ContextModifier {
79337933
}
79347934
}
79357935

7936-
impl From<Option<Keyword>> for ContextModifier {
7937-
fn from(kw: Option<Keyword>) -> Self {
7938-
match kw {
7939-
Some(kw) => match kw {
7940-
Keyword::LOCAL => Self::Local,
7941-
Keyword::SESSION => Self::Session,
7942-
Keyword::GLOBAL => Self::Global,
7943-
_ => Self::None,
7944-
},
7945-
None => Self::None,
7946-
}
7947-
}
7948-
}
7949-
79507936
/// Function describe in DROP FUNCTION.
79517937
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
79527938
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

src/parser/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,15 @@ impl<'a> Parser<'a> {
17991799
})
18001800
}
18011801

1802+
fn keyword_to_modifier(k: Option<Keyword>) -> ContextModifier {
1803+
match k {
1804+
Some(Keyword::LOCAL) => ContextModifier::Local,
1805+
Some(Keyword::GLOBAL) => ContextModifier::Global,
1806+
Some(Keyword::SESSION) => ContextModifier::Session,
1807+
_ => ContextModifier::None,
1808+
}
1809+
}
1810+
18021811
/// Check if the root is an identifier and all fields are identifiers.
18031812
fn is_all_ident(root: &Expr, fields: &[AccessExpr]) -> bool {
18041813
if !matches!(root, Expr::Identifier(_)) {
@@ -11100,7 +11109,7 @@ impl<'a> Parser<'a> {
1110011109
/// Parse a `SET ROLE` statement. Expects SET to be consumed already.
1110111110
fn parse_set_role(&mut self, modifier: Option<Keyword>) -> Result<Statement, ParserError> {
1110211111
self.expect_keyword_is(Keyword::ROLE)?;
11103-
let context_modifier = ContextModifier::from(modifier);
11112+
let context_modifier = Self::keyword_to_modifier(modifier);
1110411113

1110511114
let role_name = if self.parse_keyword(Keyword::NONE) {
1110611115
None
@@ -11193,7 +11202,7 @@ impl<'a> Parser<'a> {
1119311202
{
1119411203
if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
1119511204
return Ok(Set::SingleAssignment {
11196-
scope: ContextModifier::from(modifier),
11205+
scope: Self::keyword_to_modifier(modifier),
1119711206
hivevar: modifier == Some(Keyword::HIVEVAR),
1119811207
variable: ObjectName::from(vec!["TIMEZONE".into()]),
1119911208
values: self.parse_set_values(false)?,
@@ -11283,7 +11292,7 @@ impl<'a> Parser<'a> {
1128311292
}?;
1128411293

1128511294
Ok(Set::SingleAssignment {
11286-
scope: ContextModifier::from(modifier),
11295+
scope: Self::keyword_to_modifier(modifier),
1128711296
hivevar: modifier == Some(Keyword::HIVEVAR),
1128811297
variable,
1128911298
values,
@@ -11311,7 +11320,7 @@ impl<'a> Parser<'a> {
1131111320
if self.consume_token(&Token::Eq) || self.parse_keyword(Keyword::TO) {
1131211321
let stmt = match variables {
1131311322
OneOrManyWithParens::One(var) => Set::SingleAssignment {
11314-
scope: ContextModifier::from(modifier),
11323+
scope: Self::keyword_to_modifier(modifier),
1131511324
hivevar: modifier == Some(Keyword::HIVEVAR),
1131611325
variable: var,
1131711326
values: self.parse_set_values(false)?,

0 commit comments

Comments
 (0)