tamer: nir::tplshort: Generate @desc for generated template
This is required by the XSLT-based compiler, since the `xmli` we're producing acts as a new source file. DEV-13708main
parent
590c4b7b06
commit
c367666d8e
|
@ -80,6 +80,7 @@ use arrayvec::ArrayVec;
|
||||||
|
|
||||||
use super::{Nir, NirEntity};
|
use super::{Nir, NirEntity};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
fmt::{DisplayWrapper, TtQuote},
|
||||||
parse::prelude::*,
|
parse::prelude::*,
|
||||||
span::Span,
|
span::Span,
|
||||||
sym::{
|
sym::{
|
||||||
|
@ -111,8 +112,9 @@ pub enum TplShortDesugar {
|
||||||
Scanning,
|
Scanning,
|
||||||
|
|
||||||
/// A shorthand template application associated with the provided
|
/// A shorthand template application associated with the provided
|
||||||
/// [`Span`] was encountered and shorthand params are being desugared.
|
/// [`SPair`] was encountered and shorthand params are being
|
||||||
DesugaringParams(Span),
|
/// desugared.
|
||||||
|
DesugaringParams(SPair),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for TplShortDesugar {
|
impl Display for TplShortDesugar {
|
||||||
|
@ -160,9 +162,10 @@ impl ParseState for TplShortDesugar {
|
||||||
let tpl_name =
|
let tpl_name =
|
||||||
format!("_{}_", qname.local_name().lookup_str()).intern();
|
format!("_{}_", qname.local_name().lookup_str()).intern();
|
||||||
|
|
||||||
stack.push(Ref(SPair(tpl_name, span)));
|
let name = SPair(tpl_name, span);
|
||||||
|
stack.push(Ref(name));
|
||||||
|
|
||||||
Transition(DesugaringParams(span)).ok(Open(TplApply, span))
|
Transition(DesugaringParams(name)).ok(Open(TplApply, span))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shorthand template params' names do not contain the
|
// Shorthand template params' names do not contain the
|
||||||
|
@ -186,8 +189,10 @@ impl ParseState for TplShortDesugar {
|
||||||
// and then place the body into that template.
|
// and then place the body into that template.
|
||||||
//
|
//
|
||||||
// TODO: This does not handle nested template applications.
|
// TODO: This does not handle nested template applications.
|
||||||
(DesugaringParams(ospan), tok @ Open(..)) => {
|
(DesugaringParams(name), tok @ Open(..)) => {
|
||||||
|
let ospan = name.span();
|
||||||
let gen_name = gen_tpl_name_at_offset(ospan);
|
let gen_name = gen_tpl_name_at_offset(ospan);
|
||||||
|
let gen_desc = values_tpl_desc(name);
|
||||||
|
|
||||||
// The spans are awkward here because we are streaming,
|
// The spans are awkward here because we are streaming,
|
||||||
// and so don't have much choice but to use the opening
|
// and so don't have much choice but to use the opening
|
||||||
|
@ -197,6 +202,7 @@ impl ParseState for TplShortDesugar {
|
||||||
// yet-to-be-defined means.
|
// yet-to-be-defined means.
|
||||||
//
|
//
|
||||||
// note: reversed (stack)
|
// note: reversed (stack)
|
||||||
|
stack.push(Desc(gen_desc));
|
||||||
stack.push(BindIdent(SPair(gen_name, ospan)));
|
stack.push(BindIdent(SPair(gen_name, ospan)));
|
||||||
stack.push(Open(Tpl, ospan));
|
stack.push(Open(Tpl, ospan));
|
||||||
|
|
||||||
|
@ -258,5 +264,24 @@ fn gen_tpl_name_at_offset(span: Span) -> SymbolId {
|
||||||
format!("___dsgr-{:x}___", span.offset()).intern()
|
format!("___dsgr-{:x}___", span.offset()).intern()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate a description for the template generated from the body of a
|
||||||
|
/// shorthand template application.
|
||||||
|
///
|
||||||
|
/// Descriptions are required on templates,
|
||||||
|
/// but we should also provide something that is useful in debugging.
|
||||||
|
/// The description will contain the name of the template being applied and
|
||||||
|
/// will share the same span as the provided [`SPair`] `applying`'s,
|
||||||
|
/// having been derived from it.
|
||||||
|
fn values_tpl_desc(applying: SPair) -> SPair {
|
||||||
|
SPair(
|
||||||
|
format!(
|
||||||
|
"Desugared body of shorthand template application of {}",
|
||||||
|
TtQuote::wrap(applying.symbol())
|
||||||
|
)
|
||||||
|
.intern(),
|
||||||
|
applying.span(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
|
@ -126,6 +126,7 @@ fn desugars_body_into_tpl_with_ref_in_values_param() {
|
||||||
// but it does allow us to be perfectly precise in the output
|
// but it does allow us to be perfectly precise in the output
|
||||||
// assertion.
|
// assertion.
|
||||||
let gen_name = gen_tpl_name_at_offset(S1);
|
let gen_name = gen_tpl_name_at_offset(S1);
|
||||||
|
let gen_desc = values_tpl_desc(name);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -146,6 +147,7 @@ fn desugars_body_into_tpl_with_ref_in_values_param() {
|
||||||
// It is closed and so expandable. // |
|
// It is closed and so expandable. // |
|
||||||
O(Open(Tpl, S1)), // /
|
O(Open(Tpl, S1)), // /
|
||||||
O(BindIdent(SPair(gen_name, S1))), //<`
|
O(BindIdent(SPair(gen_name, S1))), //<`
|
||||||
|
O(Desc(gen_desc)),
|
||||||
|
|
||||||
// And here we have the body of the above
|
// And here we have the body of the above
|
||||||
// shorthand application.
|
// shorthand application.
|
||||||
|
@ -181,6 +183,7 @@ fn desugar_nested_apply() {
|
||||||
];
|
];
|
||||||
|
|
||||||
let gen_name_outer = gen_tpl_name_at_offset(S1);
|
let gen_name_outer = gen_tpl_name_at_offset(S1);
|
||||||
|
let gen_desc = values_tpl_desc(name_outer);
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -197,6 +200,7 @@ fn desugar_nested_apply() {
|
||||||
// |
|
// |
|
||||||
O(Open(Tpl, S1)), // /
|
O(Open(Tpl, S1)), // /
|
||||||
O(BindIdent(SPair(gen_name_outer, S1))), //<`
|
O(BindIdent(SPair(gen_name_outer, S1))), //<`
|
||||||
|
O(Desc(gen_desc)),
|
||||||
|
|
||||||
// And within this template,
|
// And within this template,
|
||||||
// we generate another application.
|
// we generate another application.
|
||||||
|
|
|
@ -102,7 +102,8 @@
|
||||||
<apply-template name="_short-hand-nullary-body_">
|
<apply-template name="_short-hand-nullary-body_">
|
||||||
<with-param name="@values@" value="___dsgr-bfe___" />
|
<with-param name="@values@" value="___dsgr-bfe___" />
|
||||||
</apply-template>
|
</apply-template>
|
||||||
<template name="___dsgr-bfe___">
|
<template name="___dsgr-bfe___"
|
||||||
|
desc="Desugared body of shorthand template application of `_short-hand-nullary-body_`">
|
||||||
<c:product>
|
<c:product>
|
||||||
<c:sum />
|
<c:sum />
|
||||||
</c:product>
|
</c:product>
|
||||||
|
@ -112,9 +113,10 @@
|
||||||
<apply-template name="_short-hand-nary-body_">
|
<apply-template name="_short-hand-nary-body_">
|
||||||
<with-param name="@bar@" value="baz" />
|
<with-param name="@bar@" value="baz" />
|
||||||
<with-param name="@baz@" value="quux" />
|
<with-param name="@baz@" value="quux" />
|
||||||
<with-param name="@values@" value="___dsgr-cb4___" />
|
<with-param name="@values@" value="___dsgr-cb5___" />
|
||||||
</apply-template>
|
</apply-template>
|
||||||
<template name="___dsgr-cb4___">
|
<template name="___dsgr-cb5___"
|
||||||
|
desc="Desugared body of shorthand template application of `_short-hand-nary-body_`">
|
||||||
<c:sum>
|
<c:sum>
|
||||||
<c:product />
|
<c:product />
|
||||||
</c:sum>
|
</c:sum>
|
||||||
|
@ -123,9 +125,10 @@
|
||||||
<template name="_short-hand-nullary-outer_"
|
<template name="_short-hand-nullary-outer_"
|
||||||
desc="Outer template holding an inner" />
|
desc="Outer template holding an inner" />
|
||||||
<apply-template name="_short-hand-nullary-outer_">
|
<apply-template name="_short-hand-nullary-outer_">
|
||||||
<with-param name="@values@" value="___dsgr-d97___" />
|
<with-param name="@values@" value="___dsgr-d99___" />
|
||||||
</apply-template>
|
</apply-template>
|
||||||
<template name="___dsgr-d97___">
|
<template name="___dsgr-d99___"
|
||||||
|
desc="Desugared body of shorthand template application of `_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" />
|
desc="Inner template applied inner" />
|
||||||
<apply-template name="_short-hand-nullary-inner-dfn-inner_" />
|
<apply-template name="_short-hand-nullary-inner-dfn-inner_" />
|
||||||
|
@ -134,9 +137,10 @@
|
||||||
<template name="_short-hand-nullary-inner-dfn-outer_"
|
<template name="_short-hand-nullary-inner-dfn-outer_"
|
||||||
desc="Define template outer but apply inner" />
|
desc="Define template outer but apply inner" />
|
||||||
<apply-template name="_short-hand-nullary-outer_">
|
<apply-template name="_short-hand-nullary-outer_">
|
||||||
<with-param name="@values@" value="___dsgr-eea___" />
|
<with-param name="@values@" value="___dsgr-eed___" />
|
||||||
</apply-template>
|
</apply-template>
|
||||||
<template name="___dsgr-eea___">
|
<template name="___dsgr-eed___"
|
||||||
|
desc="Desugared body of shorthand template application of `_short-hand-nullary-outer_`">
|
||||||
<apply-template name="_short-hand-nullary-inner-dfn-outer_" />
|
<apply-template name="_short-hand-nullary-inner-dfn-outer_" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -144,9 +148,10 @@
|
||||||
desc="Unary with body" />
|
desc="Unary with body" />
|
||||||
<apply-template name="_short-hand-unary-with-body_">
|
<apply-template name="_short-hand-unary-with-body_">
|
||||||
<with-param name="@foo@" value="bar" />
|
<with-param name="@foo@" value="bar" />
|
||||||
<with-param name="@values@" value="___dsgr-fb0___" />
|
<with-param name="@values@" value="___dsgr-fb4___" />
|
||||||
</apply-template>
|
</apply-template>
|
||||||
<template name="___dsgr-fb0___">
|
<template name="___dsgr-fb4___"
|
||||||
|
desc="Desugared body of shorthand template application of `_short-hand-unary-with-body_`">
|
||||||
<template name="_short-hand-unary-with-body-inner_"
|
<template name="_short-hand-unary-with-body-inner_"
|
||||||
desc="Inner template" />
|
desc="Inner template" />
|
||||||
<apply-template name="_short-hand-unary-with-body-inner_" />
|
<apply-template name="_short-hand-unary-with-body-inner_" />
|
||||||
|
|
|
@ -108,6 +108,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<template name="_short-hand-nary-body_" desc="N-ary with body" />
|
<template name="_short-hand-nary-body_" desc="N-ary with body" />
|
||||||
<t:short-hand-nary-body bar="baz" baz="quux">
|
<t:short-hand-nary-body bar="baz" baz="quux">
|
||||||
<c:sum>
|
<c:sum>
|
||||||
|
@ -120,6 +121,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<template name="_short-hand-nullary-outer_"
|
<template name="_short-hand-nullary-outer_"
|
||||||
desc="Outer template holding an inner" />
|
desc="Outer template holding an inner" />
|
||||||
<t:short-hand-nullary-outer>
|
<t:short-hand-nullary-outer>
|
||||||
|
@ -131,6 +133,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<template name="_short-hand-nullary-inner-dfn-outer_"
|
<template name="_short-hand-nullary-inner-dfn-outer_"
|
||||||
desc="Define template outer but apply inner" />
|
desc="Define template outer but apply inner" />
|
||||||
<t:short-hand-nullary-outer>
|
<t:short-hand-nullary-outer>
|
||||||
|
@ -140,6 +143,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<template name="_short-hand-unary-with-body_"
|
<template name="_short-hand-unary-with-body_"
|
||||||
desc="Unary with body" />
|
desc="Unary with body" />
|
||||||
<t:short-hand-unary-with-body foo="bar">
|
<t:short-hand-unary-with-body foo="bar">
|
||||||
|
@ -152,6 +156,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<template name="_short-hand-in-expr_"
|
<template name="_short-hand-in-expr_"
|
||||||
desc="Template to be applied within an expression" />
|
desc="Template to be applied within an expression" />
|
||||||
<rate yields="shortHandTplInExpr">
|
<rate yields="shortHandTplInExpr">
|
||||||
|
|
Loading…
Reference in New Issue