Skip to content

Commit 5120d8c

Browse files
Fixed code smells
1 parent c6c391c commit 5120d8c

File tree

6 files changed

+20
-113
lines changed

6 files changed

+20
-113
lines changed

src/ast/ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! (commonly referred to as Data Definition Language, or DDL)
2020
2121
#[cfg(not(feature = "std"))]
22-
use alloc::{boxed::Box, format, string::String, vec, vec::Vec};
22+
use alloc::{boxed::Box, format, string::String, vec::Vec};
2323
use core::fmt::{self, Display, Write};
2424

2525
#[cfg(feature = "serde")]

src/ast/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,10 +2787,11 @@ impl fmt::Display for Declare {
27872787
}
27882788

27892789
/// Sql options of a `CREATE TABLE` statement.
2790-
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2790+
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
27912791
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
27922792
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
27932793
pub enum CreateTableOptions {
2794+
#[default]
27942795
None,
27952796
/// Options specified using the `WITH` keyword.
27962797
/// e.g. `WITH (description = "123")`
@@ -2819,12 +2820,6 @@ pub enum CreateTableOptions {
28192820
TableProperties(Vec<SqlOption>),
28202821
}
28212822

2822-
impl Default for CreateTableOptions {
2823-
fn default() -> Self {
2824-
Self::None
2825-
}
2826-
}
2827-
28282823
impl fmt::Display for CreateTableOptions {
28292824
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28302825
match self {

src/dialect/snowflake.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,14 +1079,7 @@ pub fn parse_stage_name_identifier(parser: &mut Parser) -> Result<Ident, ParserE
10791079
break;
10801080
}
10811081
}
1082-
token => {
1083-
return {
1084-
println!(
1085-
"Unexpected token {token:?} while parsing stage name identifier {ident:?}"
1086-
);
1087-
parser.expected("stage name identifier", parser.peek_token())
1088-
}
1089-
}
1082+
_ => return parser.expected("stage name identifier", parser.peek_token()),
10901083
}
10911084
}
10921085
Ok(Ident::new(ident))

src/parser/mod.rs

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,13 +4031,13 @@ impl<'a> Parser<'a> {
40314031
/// See [`Self::peek_token`] for an example.
40324032
pub fn peek_tokens_with_location<const N: usize>(&self) -> [TokenWithSpan; N] {
40334033
let mut index = self.index;
4034-
core::array::from_fn(|_| loop {
4034+
core::array::from_fn(|_| {
40354035
let token = self.tokens.get(index);
40364036
index += 1;
4037-
break token.cloned().unwrap_or(TokenWithSpan {
4037+
token.cloned().unwrap_or(TokenWithSpan {
40384038
token: Token::EOF,
40394039
span: Span::empty(),
4040-
});
4040+
})
40414041
})
40424042
}
40434043

@@ -4047,10 +4047,10 @@ impl<'a> Parser<'a> {
40474047
/// See [`Self::peek_tokens`] for an example.
40484048
pub fn peek_tokens_ref<const N: usize>(&self) -> [&TokenWithSpan; N] {
40494049
let mut index = self.index;
4050-
core::array::from_fn(|_| loop {
4050+
core::array::from_fn(|_| {
40514051
let token = self.tokens.get(index);
40524052
index += 1;
4053-
break token.unwrap_or(&EOF_TOKEN);
4053+
token.unwrap_or(&EOF_TOKEN)
40544054
})
40554055
}
40564056

@@ -8546,7 +8546,7 @@ impl<'a> Parser<'a> {
85468546
return self.expected(
85478547
"FULLTEXT or SPATIAL option without constraint name",
85488548
TokenWithSpan {
8549-
token: Token::make_keyword(&name.to_string()),
8549+
token: Token::make_keyword(name.to_string()),
85508550
span: next_token.span,
85518551
},
85528552
);
@@ -11125,9 +11125,9 @@ impl<'a> Parser<'a> {
1112511125
let mut parts = vec![];
1112611126
if dialect_of!(self is BigQueryDialect) && in_table_clause {
1112711127
loop {
11128-
let (ident, end_with_period) = self.parse_unquoted_hyphenated_identifier()?;
11128+
let ident = self.parse_identifier()?;
1112911129
parts.push(ObjectNamePart::Identifier(ident));
11130-
if !self.consume_token(&Token::Period) && !end_with_period {
11130+
if !self.consume_token(&Token::Period) {
1113111131
break;
1113211132
}
1113311133
}
@@ -11141,9 +11141,9 @@ impl<'a> Parser<'a> {
1114111141
span,
1114211142
}));
1114311143
} else if dialect_of!(self is BigQueryDialect) && in_table_clause {
11144-
let (ident, end_with_period) = self.parse_unquoted_hyphenated_identifier()?;
11144+
let ident = self.parse_identifier()?;
1114511145
parts.push(ObjectNamePart::Identifier(ident));
11146-
if !self.consume_token(&Token::Period) && !end_with_period {
11146+
if !self.consume_token(&Token::Period) {
1114711147
break;
1114811148
}
1114911149
} else if self.dialect.supports_object_name_double_dot_notation()
@@ -11322,85 +11322,6 @@ impl<'a> Parser<'a> {
1132211322
}
1132311323
}
1132411324

11325-
/// On BigQuery, hyphens are permitted in unquoted identifiers inside of a FROM or
11326-
/// TABLE clause.
11327-
///
11328-
/// The first segment must be an ordinary unquoted identifier, e.g. it must not start
11329-
/// with a digit. Subsequent segments are either must either be valid identifiers or
11330-
/// integers, e.g. foo-123 is allowed, but foo-123a is not.
11331-
///
11332-
/// [BigQuery-lexical](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical)
11333-
///
11334-
/// Return a tuple of the identifier and a boolean indicating it ends with a period.
11335-
fn parse_unquoted_hyphenated_identifier(&mut self) -> Result<(Ident, bool), ParserError> {
11336-
match self.peek_token().token {
11337-
// Token::Word(w) => {
11338-
// let quote_style_is_none = w.quote_style.is_none();
11339-
// let mut requires_whitespace = false;
11340-
// let mut ident = w.into_ident(self.next_token().span);
11341-
// if quote_style_is_none {
11342-
// while matches!(self.peek_token().token, Token::Minus) {
11343-
// unreachable!("Something went wrong in the tokenizer!");
11344-
// // self.next_token();
11345-
// // ident.value.push('-');
11346-
11347-
// // let token = self
11348-
// // .next_token_no_skip()
11349-
// // .cloned()
11350-
// // .unwrap_or(TokenWithSpan::wrap(Token::EOF));
11351-
// // requires_whitespace = match token.token {
11352-
// // Token::Word(next_word) if next_word.quote_style.is_none() => {
11353-
// // ident.value.push_str(&next_word.value);
11354-
// // false
11355-
// // }
11356-
// // Token::Number(s, false) => {
11357-
// // // A number token can represent a decimal value ending with a period, e.g., `Number('123.')`.
11358-
// // // However, for an [ObjectName], it is part of a hyphenated identifier, e.g., `foo-123.bar`.
11359-
// // //
11360-
// // // If a number token is followed by a period, it is part of an [ObjectName].
11361-
// // // Return the identifier with `true` if the number token is followed by a period, indicating that
11362-
// // // parsing should continue for the next part of the hyphenated identifier.
11363-
// // if s.ends_with('.') {
11364-
// // let Some(s) = s.split('.').next().filter(|s| {
11365-
// // !s.is_empty() && s.chars().all(|c| c.is_ascii_digit())
11366-
// // }) else {
11367-
// // return self.expected(
11368-
// // "continuation of hyphenated identifier",
11369-
// // TokenWithSpan::new(Token::Number(s, false), token.span),
11370-
// // );
11371-
// // };
11372-
// // ident.value.push_str(s);
11373-
// // return Ok((ident, true));
11374-
// // } else {
11375-
// // ident.value.push_str(&s);
11376-
// // }
11377-
// // // If next token is period, then it is part of an ObjectName and we don't expect whitespace
11378-
// // // after the number.
11379-
// // !matches!(self.peek_token().token, Token::Period)
11380-
// // }
11381-
// // _ => {
11382-
// // return self
11383-
// // .expected("continuation of hyphenated identifier", token);
11384-
// // }
11385-
// // }
11386-
// }
11387-
11388-
// // If the last segment was a number, we must check that it's followed by whitespace,
11389-
// // otherwise foo-123a will be parsed as `foo-123` with the alias `a`.
11390-
// if requires_whitespace {
11391-
// let token = self.next_token();
11392-
// if !matches!(token.token, Token::EOF) {
11393-
// return self
11394-
// .expected("whitespace following hyphenated identifier", token);
11395-
// }
11396-
// }
11397-
// }
11398-
// Ok((ident, false))
11399-
// }
11400-
_ => Ok((self.parse_identifier()?, false)),
11401-
}
11402-
}
11403-
1140411325
/// Parses a parenthesized, comma-separated list of column definitions within a view.
1140511326
fn parse_view_columns(&mut self) -> Result<Vec<ViewColumnDef>, ParserError> {
1140611327
if self.consume_token(&Token::LParen) {

src/test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl TestedDialects {
154154
///
155155
/// For multiple statements, use [`statements_parse_to`].
156156
pub fn one_statement_parses_to(&self, sql: &str, canonical: &str) -> Statement {
157-
println!("Testing SQL: {}", sql);
158157
let mut statements = self.parse_sql_statements(sql).expect(sql);
159158
assert_eq!(statements.len(), 1);
160159
if !canonical.is_empty() && sql != canonical {

src/tokenizer.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
2424
#[cfg(not(feature = "std"))]
2525
use alloc::{
26-
borrow::ToOwned,
2726
format,
2827
string::{String, ToString},
2928
vec,
@@ -1319,12 +1318,12 @@ impl<'a> Tokenizer<'a> {
13191318
// If so, what follows is definitely not part of a decimal number and
13201319
// we should yield the dot as a dedicated token so compound identifiers
13211320
// starting with digits can be parsed correctly.
1322-
if s == "." && self.dialect.supports_numeric_prefix() {
1323-
if !preceded_by_whitespace
1324-
&& !matches!(prev_token, Some(Token::Plus | Token::Minus))
1325-
{
1326-
return Ok(Some(Token::Period));
1327-
}
1321+
if s == "."
1322+
&& self.dialect.supports_numeric_prefix()
1323+
&& !preceded_by_whitespace
1324+
&& !matches!(prev_token, Some(Token::Plus | Token::Minus))
1325+
{
1326+
return Ok(Some(Token::Period));
13281327
}
13291328

13301329
// Consume fractional digits.

0 commit comments

Comments
 (0)