Skip to content

Commit 3ceedd6

Browse files
authored
Add AST source NodeId to lower's expression stack (#567)
1 parent 4db715e commit 3ceedd6

File tree

4 files changed

+104
-50
lines changed

4 files changed

+104
-50
lines changed

partiql-ast/src/ast/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use rust_decimal::Decimal as RustDecimal;
1212

1313
use partiql_ast_macros::Visit;
14-
use partiql_common::node::NodeId;
14+
use partiql_common::node::{IdAnnotated, NodeId};
1515
#[cfg(feature = "serde")]
1616
use serde::{Deserialize, Serialize};
1717
use std::fmt;
@@ -36,6 +36,12 @@ impl<T> Deref for AstNode<T> {
3636
}
3737
}
3838

39+
impl<T> IdAnnotated<NodeId> for AstNode<T> {
40+
fn id(&self) -> NodeId {
41+
self.id
42+
}
43+
}
44+
3945
#[derive(Visit, Clone, Debug, PartialEq)]
4046
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4147
pub enum Item {
@@ -421,6 +427,30 @@ pub enum Expr {
421427
Error,
422428
}
423429

430+
impl IdAnnotated<NodeId> for Expr {
431+
fn id(&self) -> NodeId {
432+
match self {
433+
Expr::Lit(l) => l.id(),
434+
Expr::VarRef(v) => v.id(),
435+
Expr::BinOp(b) => b.id(),
436+
Expr::UniOp(u) => u.id(),
437+
Expr::Like(l) => l.id(),
438+
Expr::Between(l) => l.id(),
439+
Expr::In(l) => l.id(),
440+
Expr::Case(c) => c.id(),
441+
Expr::Struct(s) => s.id(),
442+
Expr::Bag(b) => b.id(),
443+
Expr::List(l) => l.id(),
444+
Expr::Path(p) => p.id(),
445+
Expr::Call(c) => c.id(),
446+
Expr::CallAgg(c) => c.id(),
447+
Expr::GraphMatch(g) => g.id(),
448+
Expr::Query(q) => q.id(),
449+
Expr::Error => unreachable!(),
450+
}
451+
}
452+
}
453+
424454
/// `Lit` is mostly inspired by SQL-92 Literals standard and `PartiQL` specification.
425455
/// See section 5.3 in the following:
426456
/// <https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt>

partiql-common/src/node.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ use serde::{Deserialize, Serialize};
66

77
pub type NodeMap<T> = IndexMap<NodeId, T>;
88

9+
pub trait IdAnnotated<T: Copy> {
10+
fn id(&self) -> T;
11+
}
12+
913
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
1014
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1115
pub struct NodeId(pub u32);
1216

17+
impl IdAnnotated<NodeId> for NodeId {
18+
fn id(&self) -> NodeId {
19+
*self
20+
}
21+
}
22+
1323
#[derive(Debug)]
1424
/// Auto-incrementing [`NodeIdGenerator`]
1525
pub struct AutoNodeIdGenerator {

partiql-conformance-tests/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ pub(crate) fn pass_eval(
213213
Ok(v) => {
214214
assert_eq!(&TestValue::from(v), expected)
215215
},
216-
Err(TestError::Parse(_)) => {
217-
panic!("When evaluating (mode = {mode:#?}) `{statement}`, unexpected parse error")
216+
Err(TestError::Parse(err)) => {
217+
panic!("When evaluating (mode = {mode:#?}) `{statement}`, unexpected parse error: {err:#?}")
218218
}
219219
Err(TestError::Lower(err)) => panic!("When evaluating (mode = {mode:#?}) `{statement}`, unexpected lowering error `{err:?}`"),
220220
Err(TestError::Plan(err)) => panic!("When evaluating (mode = {mode:#?}) `{statement}`, unexpected planning error `{err:?}`"),

0 commit comments

Comments
 (0)