tamer: NIR->xmli: Support template/@desc

This is needed to then support `@desc` for shorthand desugaring; it's
required by the XSLT-based compiler (and will eventually be required by
TAMER too).

DEV-13708
main
Mike Gerwitz 2023-04-12 15:53:16 -04:00
parent 5dd77e7b41
commit 590c4b7b06
9 changed files with 120 additions and 97 deletions

View File

@ -206,16 +206,9 @@ impl ParseState for AirTplAggregate {
Transition(Toplevel(tpl)).incomplete()
}
(Toplevel(tpl), tok @ AirDoc(DocIndepClause(_))) => {
diagnostic_todo!(
vec![
tpl.oi().note("in this template"),
tok.internal_error(
"this template description is not yet supported"
)
],
"template description is not yet supported by TAMER",
)
(Toplevel(tpl), AirDoc(DocIndepClause(clause))) => {
tpl.oi().desc_short(ctx.asg_mut(), clause);
Transition(Toplevel(tpl)).incomplete()
}
(Toplevel(tpl), AirDoc(DocText(text))) => {

View File

@ -24,7 +24,7 @@ use crate::asg::{
test::{asg_from_toks, parse_as_pkg_body},
Air, AirAggregate,
},
graph::object::{Meta, ObjectRel},
graph::object::{Doc, Meta, ObjectRel},
Expr, ExprOp, Ident,
};
use crate::span::dummy::*;
@ -651,3 +651,29 @@ fn tpl_apply_nested_missing() {
.collect::<Vec<_>>(),
);
}
#[test]
fn tpl_doc_short_desc() {
let id_tpl = SPair("foo".into(), S2);
let clause = SPair("short desc".into(), S3);
#[rustfmt::skip]
let toks = vec![
Air::TplStart(S1),
Air::BindIdent(id_tpl),
Air::DocIndepClause(clause),
Air::TplEnd(S4),
];
let asg = asg_from_toks(toks);
let oi_expr = asg.expect_ident_oi::<Tpl>(id_tpl);
let oi_docs = oi_expr
.edges_filtered::<Doc>(&asg)
.map(ObjectIndex::cresolve(&asg));
assert_eq!(
vec![&Doc::new_indep_clause(clause)],
oi_docs.collect::<Vec<_>>(),
);
}

View File

@ -772,6 +772,20 @@ impl<O: ObjectKind> ObjectIndex<O> {
.map(ObjectIndex::cresolve(asg))
.next()
}
/// Describe this expression using a short independent clause.
///
/// This is intended to be a concise description for use either as a
/// simple sentence or as part of a compound sentence.
/// There should only be one such clause for any given object,
/// but that is not enforced here.
pub fn desc_short(&self, asg: &mut Asg, clause: SPair) -> Self
where
O: ObjectRelTo<Doc>,
{
let oi_doc = asg.create(Doc::new_indep_clause(clause));
self.add_edge_to(asg, oi_doc, None)
}
}
impl ObjectIndex<Object> {

View File

@ -253,15 +253,4 @@ impl ObjectIndex<Expr> {
let identi = asg.lookup_global_or_missing(ident);
self.add_edge_to(asg, identi, Some(ident.span()))
}
/// Describe this expression using a short independent clause.
///
/// This is intended to be a concise description for use either as a
/// simple sentence or as part of a compound sentence.
/// There should only be one such clause for any given object,
/// but that is not enforced here.
pub fn desc_short(&self, asg: &mut Asg, clause: SPair) -> Self {
let oi_doc = asg.create(Doc::new_indep_clause(clause));
self.add_edge_to(asg, oi_doc, None)
}
}

View File

@ -69,8 +69,8 @@ object_rel! {
// Template application.
tree Tpl,
// Arbitrary documentation to be expanded into the application
// site.
// Short template description and arbitrary documentation to be
// expanded into the application site.
tree Doc,
}
}

View File

@ -491,7 +491,7 @@ impl<'a> TreeContext<'a> {
) -> Option<Xirf> {
match (src, doc) {
// TODO: Non-stmt exprs should use `@label` instead.
(Object::Expr(..), Doc::IndepClause(desc)) => {
(Object::Expr(..) | Object::Tpl(..), Doc::IndepClause(desc)) => {
Some(attr_desc(*desc))
}

View File

@ -1400,7 +1400,7 @@ ele_parse! {
TemplateStmt := QN_TEMPLATE(_, ospan) {
@ {
QN_NAME => BindIdent,
QN_DESC => TodoAttr,
QN_DESC => Desc,
} => NirEntity::Tpl.open(ospan),
/(cspan) => NirEntity::Tpl.close(cspan),

View File

@ -3,12 +3,10 @@
xmlns:c="http://www.lovullo.com/calc"
xmlns:t="http://www.lovullo.com/rater/apply-template">
<template name="_empty_" />
<template name="_with-static-reachable_">
<template name="_empty_" desc="Empty" />
<template name="_with-static-identified_"
desc="Template with identified expressions">
<rate yields="tplStaticA">
<c:sum />
</rate>
@ -17,10 +15,8 @@
</classify>
</template>
<template name="_with-static-unreachable_">
<template name="_with-static-unidentified_"
desc="Unidentified expressions in body">
<c:sum>
<c:product />
</c:sum>
@ -30,11 +26,9 @@
</c:product>
</template>
<template name="_with-static-mix-reachability_">
<template name="_with-static-mix_"
desc="Both identified and unidentified that may or may
not be reachable in expansion context">
<c:sum>
<c:product />
</c:sum>
@ -66,15 +60,15 @@
<template name="_short-hand-nullary_" />
<template name="_short-hand-nullary_" desc="No params" />
<apply-template name="_short-hand-nullary_" />
<template name="_short-hand-unary_" />
<template name="_short-hand-unary_" desc="One param" />
<apply-template name="_short-hand-unary_">
<with-param name="@foo@" value="bar" />
</apply-template>
<template name="_short-hand-nary_" />
<template name="_short-hand-nary_" desc="N params" />
<apply-template name="_short-hand-nary_">
<with-param name="@foo@" value="bar" />
<with-param name="@bar@" value="baz" />
@ -104,63 +98,70 @@
<template name="_short-hand-nullary-body_" />
<template name="_short-hand-nullary-body_" desc="Nullary with body" />
<apply-template name="_short-hand-nullary-body_">
<with-param name="@values@" value="___dsgr-c23___" />
<with-param name="@values@" value="___dsgr-bfe___" />
</apply-template>
<template name="___dsgr-c23___">
<template name="___dsgr-bfe___">
<c:product>
<c:sum />
</c:product>
</template>
<template name="_short-hand-nary-body_" />
<template name="_short-hand-nary-body_" desc="N-ary with body" />
<apply-template name="_short-hand-nary-body_">
<with-param name="@bar@" value="baz" />
<with-param name="@baz@" value="quux" />
<with-param name="@values@" value="___dsgr-cc2___" />
<with-param name="@values@" value="___dsgr-cb4___" />
</apply-template>
<template name="___dsgr-cc2___">
<template name="___dsgr-cb4___">
<c:sum>
<c:product />
</c:sum>
</template>
<template name="_short-hand-nullary-outer_" />
<template name="_short-hand-nullary-outer_"
desc="Outer template holding an inner" />
<apply-template name="_short-hand-nullary-outer_">
<with-param name="@values@" value="___dsgr-d72___" />
<with-param name="@values@" value="___dsgr-d97___" />
</apply-template>
<template name="___dsgr-d72___">
<template name="_short-hand-nullary-inner-dfn-inner_" />
<template name="___dsgr-d97___">
<template name="_short-hand-nullary-inner-dfn-inner_"
desc="Inner template applied inner" />
<apply-template name="_short-hand-nullary-inner-dfn-inner_" />
</template>
<template name="_short-hand-nullary-inner-dfn-outer_" />
<template name="_short-hand-nullary-inner-dfn-outer_"
desc="Define template outer but apply inner" />
<apply-template name="_short-hand-nullary-outer_">
<with-param name="@values@" value="___dsgr-e59___" />
<with-param name="@values@" value="___dsgr-eea___" />
</apply-template>
<template name="___dsgr-e59___">
<template name="___dsgr-eea___">
<apply-template name="_short-hand-nullary-inner-dfn-outer_" />
</template>
<template name="_short-hand-unary-with-values_" />
<apply-template name="_short-hand-unary-with-values_">
<template name="_short-hand-unary-with-body_"
desc="Unary with body" />
<apply-template name="_short-hand-unary-with-body_">
<with-param name="@foo@" value="bar" />
<with-param name="@values@" value="___dsgr-eff___" />
<with-param name="@values@" value="___dsgr-fb0___" />
</apply-template>
<template name="___dsgr-eff___">
<template name="_short-hand-unary-with-values-inner_" />
<apply-template name="_short-hand-unary-with-values-inner_" />
<template name="___dsgr-fb0___">
<template name="_short-hand-unary-with-body-inner_"
desc="Inner template" />
<apply-template name="_short-hand-unary-with-body-inner_" />
</template>
<template name="_short-hand-in-expr_" />
<template name="_short-hand-in-expr_"
desc="Template to be applied within an expression" />
<rate yields="shortHandTplInExpr">
<apply-template name="_short-hand-in-expr_">
<with-param name="@in@" value="rate" />
</apply-template>
</rate>
<template name="_tpl-with-short-hand-inner_">
<template name="_tpl-with-short-hand-inner_"
desc="Template with a shorthand application in its body">
<template name="_tpl-with-short-hand-inner-inner_" />
<apply-template name="_tpl-with-short-hand-inner-inner_" />
@ -181,7 +182,7 @@
<template name="_match-child_">
<template name="_match-child_" desc="Template with a match child">
<match on="foo" value="TRUE" />
</template>
</package>

View File

@ -3,12 +3,10 @@
xmlns:c="http://www.lovullo.com/calc"
xmlns:t="http://www.lovullo.com/rater/apply-template">
<template name="_empty_" />
<template name="_with-static-reachable_">
All expressions here are reachable
(having been derived from named statements).
<template name="_empty_" desc="Empty" />
<template name="_with-static-identified_"
desc="Template with identified expressions">
<rate yields="tplStaticA">
<c:sum />
</rate>
@ -17,10 +15,8 @@
</classify>
</template>
<template name="_with-static-unreachable_">
This expression is on its own unreachable,
intended to be expanded into another expression.
<template name="_with-static-unidentified_"
desc="Unidentified expressions in body">
<c:sum>
<c:product />
</c:sum>
@ -30,11 +26,9 @@
</c:product>
</template>
<template name="_with-static-mix-reachability_">
Both reachable and unreachable,
with the intent of expanding into an expression but also providing
itself with supporting expressions.
<template name="_with-static-mix_"
desc="Both identified and unidentified that may or may
not be reachable in expansion context">
<c:sum>
<c:product />
</c:sum>
@ -66,15 +60,15 @@
`apply-template` form,
asserting their equivalency.
<template name="_short-hand-nullary_" />
<template name="_short-hand-nullary_" desc="No params" />
<t:short-hand-nullary />
<template name="_short-hand-unary_" />
<template name="_short-hand-unary_" desc="One param" />
<t:short-hand-unary foo="bar" />
<template name="_short-hand-nary_" />
<template name="_short-hand-nary_" desc="N params" />
<t:short-hand-nary foo="bar" bar="baz" baz="quux" />
@ -104,7 +98,7 @@
and it may break often;
just take the hex span from the test failure in that case.
<template name="_short-hand-nullary-body_" />
<template name="_short-hand-nullary-body_" desc="Nullary with body" />
<t:short-hand-nullary-body>
<c:product>
<c:sum />
@ -114,7 +108,7 @@
<template name="_short-hand-nary-body_" />
<template name="_short-hand-nary-body_" desc="N-ary with body" />
<t:short-hand-nary-body bar="baz" baz="quux">
<c:sum>
<c:product />
@ -126,15 +120,19 @@
<template name="_short-hand-nullary-outer_" />
<template name="_short-hand-nullary-outer_"
desc="Outer template holding an inner" />
<t:short-hand-nullary-outer>
<template name="_short-hand-nullary-inner-dfn-inner_" />
<template name="_short-hand-nullary-inner-dfn-inner_"
desc="Inner template applied inner" />
<t:short-hand-nullary-inner-dfn-inner />
</t:short-hand-nullary-outer>
<template name="_short-hand-nullary-inner-dfn-outer_" />
<template name="_short-hand-nullary-inner-dfn-outer_"
desc="Define template outer but apply inner" />
<t:short-hand-nullary-outer>
<t:short-hand-nullary-inner-dfn-outer />
</t:short-hand-nullary-outer>
@ -142,26 +140,28 @@
<template name="_short-hand-unary-with-values_" />
<t:short-hand-unary-with-values foo="bar">
<template name="_short-hand-unary-with-values-inner_" />
<t:short-hand-unary-with-values-inner />
</t:short-hand-unary-with-values>
<template name="_short-hand-unary-with-body_"
desc="Unary with body" />
<t:short-hand-unary-with-body foo="bar">
<template name="_short-hand-unary-with-body-inner_"
desc="Inner template" />
<t:short-hand-unary-with-body-inner />
</t:short-hand-unary-with-body>
<template name="_short-hand-in-expr_" />
<template name="_short-hand-in-expr_"
desc="Template to be applied within an expression" />
<rate yields="shortHandTplInExpr">
<t:short-hand-in-expr in="rate" />
</rate>
<template name="_tpl-with-short-hand-inner_">
<template name="_tpl-with-short-hand-inner_"
desc="Template with a shorthand application in its body">
<template name="_tpl-with-short-hand-inner-inner_" />
<t:tpl-with-short-hand-inner-inner />
@ -181,7 +181,7 @@
we cannot support the generation of each of those things within
templates.
<template name="_match-child_">
<template name="_match-child_" desc="Template with a match child">
<match on="foo" />
</template>
</package>