tamer: NIR->xmli: Initial product expression
The element only, no attributes yet. I'll keep forming boilerplate until abstraction points become obvious with more variety; this is still pretty close to what was already supported. DEV-13708main
parent
ebc16b7bdb
commit
5865d86485
|
@ -309,11 +309,11 @@ fn yields(name: SPair, span: Span) -> Xirf {
|
|||
fn expr_ele(expr: &Expr, depth: Depth) -> Xirf {
|
||||
let qname = match expr.op() {
|
||||
ExprOp::Sum => QN_C_SUM,
|
||||
op => todo!("expr_ele qname: {op:?}"),
|
||||
ExprOp::Product => QN_C_PRODUCT,
|
||||
};
|
||||
|
||||
Xirf::open(qname, OpenSpan::without_name_span(expr.span()), depth)
|
||||
}
|
||||
|
||||
// System tests covering this functionality can be found in
|
||||
// `tamer/tests/xir/`.
|
||||
// `:tamer/tests/xir/`.
|
||||
|
|
|
@ -186,6 +186,8 @@ pub enum NirEntity {
|
|||
|
||||
/// Summation (Σ) expression.
|
||||
Sum,
|
||||
/// Product (Π) expression.
|
||||
Product,
|
||||
|
||||
/// Template parameter (metavariable).
|
||||
TplParam,
|
||||
|
@ -208,7 +210,8 @@ impl Display for NirEntity {
|
|||
match self {
|
||||
Package => write!(f, "package"),
|
||||
Rate => write!(f, "rate block"),
|
||||
Sum => write!(f, "sum expression"),
|
||||
Sum => write!(f, "sum (∑) expression"),
|
||||
Product => write!(f, "product (Π) expression"),
|
||||
TplParam => write!(f, "template param (metavariable)"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,11 +77,18 @@ impl ParseState for NirToAir {
|
|||
(Ready, Nir::Open(NirEntity::Rate | NirEntity::Sum, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Sum, span))
|
||||
}
|
||||
|
||||
(Ready, Nir::Close(NirEntity::Rate | NirEntity::Sum, span)) => {
|
||||
Transition(Ready).ok(Air::ExprClose(span))
|
||||
(Ready, Nir::Open(NirEntity::Product, span)) => {
|
||||
Transition(Ready).ok(Air::ExprOpen(ExprOp::Product, span))
|
||||
}
|
||||
|
||||
(
|
||||
Ready,
|
||||
Nir::Close(
|
||||
NirEntity::Rate | NirEntity::Sum | NirEntity::Product,
|
||||
span,
|
||||
),
|
||||
) => Transition(Ready).ok(Air::ExprClose(span)),
|
||||
|
||||
(Ready, Nir::BindIdent(spair)) => {
|
||||
Transition(Ready).ok(Air::ExprIdent(spair))
|
||||
}
|
||||
|
|
|
@ -58,16 +58,20 @@ fn rate_to_sum_expr() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn calc_expr() {
|
||||
fn calc_exprs() {
|
||||
let toks = vec![
|
||||
Nir::Open(NirEntity::Sum, S1),
|
||||
Nir::Close(NirEntity::Sum, S2),
|
||||
Nir::Open(NirEntity::Product, S2),
|
||||
Nir::Close(NirEntity::Product, S3),
|
||||
Nir::Close(NirEntity::Sum, S4),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
Ok(vec![
|
||||
O(Air::ExprOpen(ExprOp::Sum, S1)),
|
||||
O(Air::ExprClose(S2)),
|
||||
O(Air::ExprOpen(ExprOp::Product, S2)),
|
||||
O(Air::ExprClose(S3)),
|
||||
O(Air::ExprClose(S4)),
|
||||
]),
|
||||
Sut::parse(toks.into_iter()).collect(),
|
||||
);
|
||||
|
|
|
@ -686,7 +686,7 @@ ele_parse! {
|
|||
/// product can also be used to produce a generator where each
|
||||
/// iteration over `@of` yields a corresponding element in the vector
|
||||
/// identified by [`@generates`](QN_GENERATES).
|
||||
ProductExpr := QN_C_PRODUCT {
|
||||
ProductExpr := QN_C_PRODUCT(_, ospan) {
|
||||
@ {
|
||||
QN_OF => TodoAttr,
|
||||
QN_GENERATES => TodoAttr,
|
||||
|
@ -696,7 +696,8 @@ ele_parse! {
|
|||
QN_DOT => TodoAttr,
|
||||
QN_SYM => TodoAttr,
|
||||
QN_DIM => TodoAttr,
|
||||
} => Todo,
|
||||
} => NirEntity::Product.open(ospan),
|
||||
/(cspan) => NirEntity::Product.close(cspan),
|
||||
|
||||
WhenExpr,
|
||||
CalcExpr,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
<rate yields="rateBar">
|
||||
<c:sum />
|
||||
<c:product />
|
||||
</rate>
|
||||
|
||||
<rate yields="rateBaz">
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<rate yields="rateBar">
|
||||
<c:sum />
|
||||
<c:product />
|
||||
</rate>
|
||||
|
||||
<rate yields="rateBaz">
|
||||
|
|
Loading…
Reference in New Issue