Skip to content

Commit

Permalink
implement spanned for ObjectNamePart
Browse files Browse the repository at this point in the history
  • Loading branch information
ayman-sigma committed Dec 2, 2024
1 parent a77b1ea commit 7791973
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use super::{
FunctionArgumentClause, FunctionArgumentList, FunctionArguments, GroupByExpr, HavingBound,
IlikeSelectItem, Insert, Interpolate, InterpolateExpr, Join, JoinConstraint, JoinOperator,
JsonPath, JsonPathElem, LateralView, MatchRecognizePattern, Measure, NamedWindowDefinition,
ObjectName, Offset, OnConflict, OnConflictAction, OnInsert, OrderBy, OrderByExpr, Partition,
PivotValueSource, ProjectionSelect, Query, ReferentialAction, RenameSelectItem,
ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem, SetExpr, SqlOption,
Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef, TableConstraint,
TableFactor, TableOptionsClustered, TableWithJoins, Use, Value, Values, ViewColumnDef,
WildcardAdditionalOptions, With, WithFill,
ObjectName, ObjectNamePart, Offset, OnConflict, OnConflictAction, OnInsert, OrderBy,
OrderByExpr, Partition, PivotValueSource, ProjectionSelect, Query, ReferentialAction,
RenameSelectItem, ReplaceSelectElement, ReplaceSelectItem, Select, SelectInto, SelectItem,
SetExpr, SqlOption, Statement, Subscript, SymbolDefinition, TableAlias, TableAliasColumnDef,
TableConstraint, TableFactor, TableOptionsClustered, TableWithJoins, Use, Value, Values,
ViewColumnDef, WildcardAdditionalOptions, With, WithFill,
};

/// Given an iterator of spans, return the [Span::union] of all spans.
Expand Down Expand Up @@ -1302,7 +1302,7 @@ impl Spanned for Expr {
.union_opt(&overlay_for.as_ref().map(|i| i.span())),
Expr::Collate { expr, collation } => expr
.span()
.union(&union_spans(collation.0.iter().map(|i| i.span))),
.union(&union_spans(collation.0.iter().map(|i| i.span()))),
Expr::Nested(expr) => expr.span(),
Expr::Value(value) => value.span(),
Expr::TypedString { .. } => Span::empty(),
Expand Down Expand Up @@ -1411,7 +1411,7 @@ impl Spanned for Expr {
object_name
.0
.iter()
.map(|i| i.span)
.map(|i| i.span())
.chain(iter::once(token.0.span)),
),
Expr::OuterJoin(expr) => expr.span(),
Expand Down Expand Up @@ -1447,7 +1447,15 @@ impl Spanned for ObjectName {
fn span(&self) -> Span {
let ObjectName(segments) = self;

union_spans(segments.iter().map(|i| i.span))
union_spans(segments.iter().map(|i| i.span()))
}
}

impl Spanned for ObjectNamePart {
fn span(&self) -> Span {
match self {
ObjectNamePart::Identifier(ident) => ident.span,
}
}
}

Expand Down Expand Up @@ -1477,7 +1485,7 @@ impl Spanned for Function {
union_spans(
name.0
.iter()
.map(|i| i.span)
.map(|i| i.span())
.chain(iter::once(args.span()))
.chain(iter::once(parameters.span()))
.chain(filter.iter().map(|i| i.span()))
Expand Down Expand Up @@ -1563,7 +1571,7 @@ impl Spanned for SelectItem {
object_name
.0
.iter()
.map(|i| i.span)
.map(|i| i.span())
.chain(iter::once(wildcard_additional_options.span())),
),
SelectItem::Wildcard(wildcard_additional_options) => wildcard_additional_options.span(),
Expand Down Expand Up @@ -1672,7 +1680,7 @@ impl Spanned for TableFactor {
} => union_spans(
name.0
.iter()
.map(|i| i.span)
.map(|i| i.span())
.chain(alias.as_ref().map(|alias| {
union_spans(
iter::once(alias.name.span)
Expand Down Expand Up @@ -1717,7 +1725,7 @@ impl Spanned for TableFactor {
} => union_spans(
name.0
.iter()
.map(|i| i.span)
.map(|i| i.span())
.chain(args.iter().map(|i| i.span()))
.chain(alias.as_ref().map(|alias| alias.span())),
),
Expand Down Expand Up @@ -1868,7 +1876,7 @@ impl Spanned for FunctionArgExpr {
match self {
FunctionArgExpr::Expr(expr) => expr.span(),
FunctionArgExpr::QualifiedWildcard(object_name) => {
union_spans(object_name.0.iter().map(|i| i.span))
union_spans(object_name.0.iter().map(|i| i.span()))
}
FunctionArgExpr::Wildcard => Span::empty(),
}
Expand Down

0 comments on commit 7791973

Please sign in to comment.