Skip to content

Commit 3fa3766

Browse files
committed
pr feedback
1 parent 4dda1fe commit 3fa3766

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

src/ast/helpers/ignore_field.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,50 @@ use core::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
1919
use core::fmt::{self, Debug, Formatter};
2020
use core::hash::{Hash, Hasher};
2121

22-
/// A wrapper type that ignores the field when comparing or hashing.
23-
pub struct IgnoreField<T>(pub T);
22+
use crate::tokenizer::TokenWithLocation;
23+
24+
/// A wrapper type for attaching tokens to AST nodes that should be ignored in comparisons and hashing.
25+
/// This should be used when a token is not relevant for semantics, but is still needed for
26+
/// accurate source location tracking.
27+
#[derive(Clone)]
28+
pub struct AttachedToken(pub TokenWithLocation);
2429

2530
// Conditional Implementations
26-
impl<T: Debug> Debug for IgnoreField<T> {
31+
impl Debug for AttachedToken {
2732
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
2833
self.0.fmt(f)
2934
}
3035
}
3136

32-
impl<T: Clone> Clone for IgnoreField<T> {
33-
fn clone(&self) -> Self {
34-
IgnoreField(self.0.clone())
35-
}
36-
}
37-
3837
// Blanket Implementations
39-
impl<T> PartialEq for IgnoreField<T> {
38+
impl PartialEq for AttachedToken {
4039
fn eq(&self, _: &Self) -> bool {
4140
true
4241
}
4342
}
4443

45-
impl<T> Eq for IgnoreField<T> {}
44+
impl Eq for AttachedToken {}
4645

47-
impl<T> PartialOrd for IgnoreField<T> {
48-
fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
49-
Some(Ordering::Equal)
46+
impl PartialOrd for AttachedToken {
47+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
48+
Some(self.cmp(other))
5049
}
5150
}
5251

53-
impl<T: Ord> Ord for IgnoreField<T> {
52+
impl Ord for AttachedToken {
5453
fn cmp(&self, _: &Self) -> Ordering {
5554
Ordering::Equal
5655
}
5756
}
5857

59-
impl<T> Hash for IgnoreField<T> {
58+
impl Hash for AttachedToken {
6059
fn hash<H: Hasher>(&self, _state: &mut H) {
6160
// Do nothing
6261
}
6362
}
6463

65-
impl<T> From<T> for IgnoreField<T> {
66-
fn from(value: T) -> Self {
67-
IgnoreField(value)
64+
impl From<TokenWithLocation> for AttachedToken {
65+
fn from(value: TokenWithLocation) -> Self {
66+
AttachedToken(value)
6867
}
6968
}

src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl PartialEq for Ident {
157157
let Ident {
158158
value,
159159
quote_style,
160-
// backwards compat
160+
// exhaustiveness check; we ignore spans in comparisons
161161
span: _,
162162
} = self;
163163

@@ -170,7 +170,7 @@ impl core::hash::Hash for Ident {
170170
let Ident {
171171
value,
172172
quote_style,
173-
// backwards compat
173+
// exhaustiveness check; we ignore spans in hashes
174174
span: _,
175175
} = self;
176176

src/ast/query.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#[cfg(not(feature = "std"))]
1919
use alloc::{boxed::Box, vec::Vec};
2020

21-
use helpers::ignore_field::IgnoreField;
21+
use helpers::ignore_field::AttachedToken;
2222
#[cfg(feature = "serde")]
2323
use serde::{Deserialize, Serialize};
2424

@@ -280,8 +280,8 @@ impl fmt::Display for Table {
280280
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
281281
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
282282
pub struct Select {
283-
/// SELECT
284-
pub select_token: IgnoreField<TokenWithLocation>,
283+
/// Token for the `SELECT` keyword
284+
pub select_token: AttachedToken,
285285
pub distinct: Option<Distinct>,
286286
/// MSSQL syntax: `TOP (<N>) [ PERCENT ] [ WITH TIES ]`
287287
pub top: Option<Top>,
@@ -511,7 +511,8 @@ impl fmt::Display for NamedWindowDefinition {
511511
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
512512
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
513513
pub struct With {
514-
pub with_token: IgnoreField<TokenWithLocation>,
514+
// Token for the "WITH" keyword
515+
pub with_token: AttachedToken,
515516
pub recursive: bool,
516517
pub cte_tables: Vec<Cte>,
517518
}
@@ -563,8 +564,8 @@ pub struct Cte {
563564
pub query: Box<Query>,
564565
pub from: Option<Ident>,
565566
pub materialized: Option<CteAsMaterialized>,
566-
// needed for accurate span reporting
567-
pub closing_paren_token: IgnoreField<TokenWithLocation>,
567+
// Token for the closing parenthesis
568+
pub closing_paren_token: AttachedToken,
568569
}
569570

570571
impl fmt::Display for Cte {
@@ -620,7 +621,8 @@ impl fmt::Display for IdentWithAlias {
620621
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
621622
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
622623
pub struct WildcardAdditionalOptions {
623-
pub wildcard_token: IgnoreField<TokenWithLocation>,
624+
/// The wildcard token `*`
625+
pub wildcard_token: AttachedToken,
624626
/// `[ILIKE...]`.
625627
/// Snowflake syntax: <https://docs.snowflake.com/en/sql-reference/sql/select#parameters>
626628
pub opt_ilike: Option<IlikeSelectItem>,

src/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use core::{
2424
fmt::{self, Display},
2525
str::FromStr,
2626
};
27-
use helpers::ignore_field::IgnoreField;
27+
use helpers::ignore_field::AttachedToken;
2828

2929
use log::debug;
3030

@@ -9370,7 +9370,7 @@ impl<'a> Parser<'a> {
93709370
};
93719371

93729372
Ok(Select {
9373-
select_token: IgnoreField(select_token),
9373+
select_token: AttachedToken(select_token),
93749374
distinct,
93759375
top,
93769376
top_before_distinct,

0 commit comments

Comments
 (0)