Skip to content

Commit 559de71

Browse files
authored
Add location to SFW clauses (#114)
1 parent d13ed61 commit 559de71

File tree

2 files changed

+111
-96
lines changed

2 files changed

+111
-96
lines changed

partiql-ast/src/ast.rs

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -217,29 +217,40 @@ pub struct Expr {
217217
}
218218

219219
/// Represents an AST Node of type T with BytePosition Location
220-
type AstBytePos<T> = AstNode<T, BytePosition>;
221-
222-
type LitAst = AstBytePos<Lit>;
223-
type VarRefAst = AstBytePos<VarRef>;
224-
type ParamAst = AstBytePos<VarRef>;
225-
type StructAst = AstBytePos<Struct>;
226-
type BagAst = AstBytePos<Bag>;
227-
type ListAst = AstBytePos<List>;
228-
type SexpAst = AstBytePos<Sexp>;
229-
type BinOpAst = AstBytePos<BinOp>;
230-
type UniOpAst = AstBytePos<UniOp>;
231-
type LikeAst = AstBytePos<Like>;
232-
type BetweenAst = AstBytePos<Between>;
233-
type InAst = AstBytePos<In>;
234-
type SimpleCaseAst = AstBytePos<SimpleCase>;
235-
type SearchCaseAst = AstBytePos<SearchCase>;
236-
type UnionAst = AstBytePos<Union>;
237-
type ExceptAst = AstBytePos<Except>;
238-
type IntersectAst = AstBytePos<Intersect>;
239-
type PathAst = AstBytePos<Path>;
240-
type CallAst = AstBytePos<Call>;
241-
type CallAggAst = AstBytePos<CallAgg>;
242-
type SelectAst = AstBytePos<Select>;
220+
pub type AstBytePos<T> = AstNode<T, BytePosition>;
221+
222+
pub type LitAst = AstBytePos<Lit>;
223+
pub type VarRefAst = AstBytePos<VarRef>;
224+
pub type ParamAst = AstBytePos<VarRef>;
225+
pub type StructAst = AstBytePos<Struct>;
226+
pub type BagAst = AstBytePos<Bag>;
227+
pub type ListAst = AstBytePos<List>;
228+
pub type SexpAst = AstBytePos<Sexp>;
229+
pub type BinOpAst = AstBytePos<BinOp>;
230+
pub type UniOpAst = AstBytePos<UniOp>;
231+
pub type LikeAst = AstBytePos<Like>;
232+
pub type BetweenAst = AstBytePos<Between>;
233+
pub type InAst = AstBytePos<In>;
234+
pub type SimpleCaseAst = AstBytePos<SimpleCase>;
235+
pub type SearchCaseAst = AstBytePos<SearchCase>;
236+
pub type UnionAst = AstBytePos<Union>;
237+
pub type ExceptAst = AstBytePos<Except>;
238+
pub type IntersectAst = AstBytePos<Intersect>;
239+
pub type PathAst = AstBytePos<Path>;
240+
pub type CallAst = AstBytePos<Call>;
241+
pub type CallAggAst = AstBytePos<CallAgg>;
242+
pub type SelectAst = AstBytePos<Select>;
243+
pub type ProjectionAst = AstBytePos<Projection>;
244+
pub type ProjectItemAst = AstBytePos<ProjectItem>;
245+
pub type FromClauseAst = AstBytePos<FromClause>;
246+
pub type FromLetAst = AstBytePos<FromLet>;
247+
pub type JoinAst = AstBytePos<Join>;
248+
pub type JoinSpecAst = AstBytePos<JoinSpec>;
249+
pub type LetAst = AstBytePos<Let>;
250+
pub type GroupByExprAst = AstBytePos<GroupByExpr>;
251+
pub type GroupKeyAst = AstBytePos<GroupKey>;
252+
pub type OrderByExprAst = AstBytePos<OrderByExpr>;
253+
pub type SortSpecAst = AstBytePos<SortSpec>;
243254

244255
/// The expressions that can result in values.
245256
#[derive(Clone, Debug, PartialEq)]
@@ -511,13 +522,13 @@ pub struct Coalesce {
511522
#[derive(Clone, Debug, PartialEq)]
512523
pub struct Select {
513524
pub setq: Option<SetQuantifier>,
514-
pub project: Projection,
515-
pub from: Option<FromClause>,
516-
pub from_let: Option<Let>,
525+
pub project: ProjectionAst,
526+
pub from: Option<FromClauseAst>,
527+
pub from_let: Option<LetAst>,
517528
pub where_clause: Option<Box<Expr>>,
518-
pub group_by: Option<Box<GroupByExpr>>,
529+
pub group_by: Option<Box<GroupByExprAst>>,
519530
pub having: Option<Box<Expr>>,
520-
pub order_by: Option<Box<OrderByExpr>>,
531+
pub order_by: Option<Box<OrderByExprAst>>,
521532
pub limit: Option<Box<Expr>>,
522533
pub offset: Option<Box<Expr>>,
523534
}
@@ -558,16 +569,11 @@ pub enum CaseSensitivity {
558569
#[derive(Clone, Debug, PartialEq)]
559570
pub enum Projection {
560571
ProjectStar,
561-
ProjectList(Vec<ProjectItem>),
572+
ProjectList(Vec<ProjectItemAst>),
562573
ProjectPivot { key: Box<Expr>, value: Box<Expr> },
563574
ProjectValue(Box<Expr>),
564575
}
565576

566-
#[derive(Clone, Debug, PartialEq)]
567-
pub struct ProjectValue {
568-
pub value: Box<Expr>,
569-
}
570-
571577
/// An item to be projected in a `SELECT`-list.
572578
#[derive(Clone, Debug, PartialEq)]
573579
pub enum ProjectItem {
@@ -603,9 +609,9 @@ pub struct LetBinding {
603609
/// FROM clause of an SFW query
604610
#[derive(Clone, Debug, PartialEq)]
605611
pub enum FromClause {
606-
FromLet(FromLet),
612+
FromLet(FromLetAst),
607613
/// <from_source> JOIN \[INNER | LEFT | RIGHT | FULL\] <from_source> ON <expr>
608-
Join(Join),
614+
Join(JoinAst),
609615
}
610616

611617
#[derive(Clone, Debug, PartialEq)]
@@ -620,9 +626,9 @@ pub struct FromLet {
620626
#[derive(Clone, Debug, PartialEq)]
621627
pub struct Join {
622628
pub kind: JoinKind,
623-
pub left: Box<FromClause>,
624-
pub right: Box<FromClause>,
625-
pub predicate: Option<JoinSpec>,
629+
pub left: Box<FromClauseAst>,
630+
pub right: Box<FromClauseAst>,
631+
pub predicate: Option<JoinSpecAst>,
626632
}
627633

628634
#[derive(Clone, Debug, PartialEq)]
@@ -677,7 +683,7 @@ pub enum GroupingStrategy {
677683
/// <group_key>[, <group_key>]...
678684
#[derive(Clone, Debug, PartialEq)]
679685
pub struct GroupKeyList {
680-
pub keys: Vec<GroupKey>,
686+
pub keys: Vec<GroupKeyAst>,
681687
}
682688

683689
/// <expr> [AS <symbol>]
@@ -690,7 +696,7 @@ pub struct GroupKey {
690696
/// ORDER BY <sort_spec>...
691697
#[derive(Clone, Debug, PartialEq)]
692698
pub struct OrderByExpr {
693-
pub sort_specs: Vec<SortSpec>,
699+
pub sort_specs: Vec<SortSpecAst>,
694700
}
695701

696702
/// <expr> [ASC | DESC] ?

0 commit comments

Comments
 (0)