Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Frazer <joseph.frazer@ryansg.com>2020-04-17 12:15:43 -0400
committerJoseph Frazer <joseph.frazer@ryansg.com>2020-04-17 12:15:43 -0400
commit3ba587c9f9125ade32deb97d361a10eaf4e4c126 (patch)
tree54caedb3ec1e3773f19c8894cdf3ec4e66b4c934
parent3dabc126f2000ec3cd11f25bf9a92cb96446b7f6 (diff)
parent15f586750879a848b2ec1bc80207567a8a896de6 (diff)
downloadtame-3ba587c9f9125ade32deb97d361a10eaf4e4c126.tar.gz
tame-3ba587c9f9125ade32deb97d361a10eaf4e4c126.tar.bz2
tame-3ba587c9f9125ade32deb97d361a10eaf4e4c126.zip
[DEV-7198] Replace macros with a templates
Merge branch 'jira-7198' * jira-7198: [DEV-7198] Replace `rate-each` macro with a template [DEV-7198] Create a "yield" template
-rw-r--r--core/base.xml64
-rw-r--r--src/current/calc.xsd4
-rw-r--r--src/current/compiler/js.xsl4
-rw-r--r--src/current/include/preproc/macros.xsl125
4 files changed, 79 insertions, 118 deletions
diff --git a/core/base.xml b/core/base.xml
index 696ba9e..37b757f 100644
--- a/core/base.xml
+++ b/core/base.xml
@@ -216,5 +216,69 @@
<warning>Ignored block!</warning>
</template>
</section>
+
+ <template name="_yield_"
+ desc="Final scalar result provided to caller">
+ <param name="@values@" desc="Yield calculation" />
+
+ <rate yields="___yield" local="true">
+ <param-copy name="@values@" />
+ </rate>
+ </template>
+
+ <template name="_rate-each_"
+ desc="Convenience template that expands to a lv:rate block summing over
+ the magic _CMATCH_ set with the product of its value">
+ <param name="@values@"
+ desc="Yield calculation" />
+
+ <param name="@generates@" desc="Generator name (optional)">
+ <text></text>
+ </param>
+
+ <param name="@yields@" desc="Yield (optional)">
+ <text>_</text>
+ <param-value name="@generates@" />
+ </param>
+
+ <!-- at least one of generates or yields is required -->
+ <if name="@yields@" eq="">
+ <if name="@generates@" eq="">
+ <error>must provide at least one of @generates or @yields</error>
+ </if>
+ </if>
+
+ <param name="@class@"
+ desc="Space-delimited classifications for predicated iteration" />
+ <param name="@no@"
+ desc="Space-delimited classifications for predicated iteration to prevent matches">
+ <text></text>
+ </param>
+
+ <param name="@index@"
+ desc="Generator index" />
+
+ <param name="@dim@" desc="Dim (optional)">
+ <text></text>
+ </param>
+
+ <param name="@gensym@" desc="Generator TeX symbol">
+ <text></text>
+ </param>
+
+ <rate class="@class@" no="@no@" yields="@yields@"
+ gentle-no="true"
+ desc="Total {@yields@} premium">
+ <c:sum of="_CMATCH_" dim="@dim@" sym="@gensym@"
+ generates="@generates@" index="@index@"
+ desc="Set of individual {@yields@} premiums">
+ <c:product>
+ <c:value-of name="_CMATCH_" index="@index@"
+ label="One if {@class@} and not {@no@} (if provided), otherwise zero" />
+ <param-copy name="@values@" />
+ </c:product>
+ </c:sum>
+ </rate>
+ </template>
</package>
diff --git a/src/current/calc.xsd b/src/current/calc.xsd
index b19996b..8f8ed4a 100644
--- a/src/current/calc.xsd
+++ b/src/current/calc.xsd
@@ -88,8 +88,8 @@
</xs:documentation>
</xs:annotation>
- <xs:restriction base="xs:NCName">
- <xs:pattern value="[a-z]" />
+ <xs:restriction base="xs:string">
+ <xs:pattern value="[a-z]|\{?@[a-z][a-zA-Z0-9_]*@\}?" />
</xs:restriction>
</xs:simpleType>
diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl
index 15faa15..7c0c94f 100644
--- a/src/current/compiler/js.xsl
+++ b/src/current/compiler/js.xsl
@@ -1137,7 +1137,7 @@
<variable name="rate" select="." />
<!-- Generate expression for class list (leave the @no check to the cmatch
- algorithm, since we want per-index @no's). If @preproc:gentle-no is
+ algorithm, since we want per-index @no's). If @gentle-no is
set by rate-each expansion, then we want to ignore them entirely,
since we do not want it to clear our the final yield (generators take
care of this using _CMATCH_). -->
@@ -1145,7 +1145,7 @@
<variable name="class-set"
select="./lv:class[
( @no = 'true'
- and not( $rate/@preproc:gentle-no = 'true' ) )
+ and not( $rate/@gentle-no = 'true' ) )
or not( @no = 'true' ) ]" />
<choose>
diff --git a/src/current/include/preproc/macros.xsl b/src/current/include/preproc/macros.xsl
index 33c68b7..54f6d88 100644
--- a/src/current/include/preproc/macros.xsl
+++ b/src/current/include/preproc/macros.xsl
@@ -348,128 +348,25 @@
<!--
- lv:yield is simply another rate block with a special name that is recognized
- by the linker
+ wrapper around `<t:yield />`
-->
<template match="lv:yield" mode="preproc:macros" priority="5">
- <lv:rate yields="___yield" local="true">
- <apply-templates mode="preproc:macros" />
- </lv:rate>
-</template>
-
-
-<!-- this situation may occur both manually and from lv:rate-each-template -->
-<template match="lv:rate-each[ lv:apply-template ]" mode="preproc:macros" priority="9">
- <variable name="apply">
- <preproc:apply>
- <apply-templates select="lv:apply-template" mode="preproc:macros" />
- </preproc:apply>
- </variable>
-
- <choose>
- <!-- did the template apply? (note that we only check for a single one,
- since that's all that we should have) -->
- <when test="$apply/preproc:apply/lv:apply-template">
- <sequence select="." />
-
- <message>
- <text>[preproc] waiting to expand rate-each </text>
- <value-of select="@yields" />
- <text> (immediate template(s) need expansion)...</text>
- </message>
- </when>
+ <t:yield>
+ <copy-of select="@*" />
- <otherwise>
- <!-- it applied! -->
- <copy>
- <sequence select="@*, *[ not( local-name()='apply-template' ) ]" />
- <sequence select="$apply/preproc:apply/*" />
- </copy>
-
- <!-- we'll process this block next time around -->
- <preproc:repass src="lv:rate-each lv:apply-template" />
- </otherwise>
- </choose>
+ <apply-templates mode="preproc:expand" />
+ </t:yield>
</template>
-
<!--
- Convenience macro that expands to a lv:rate block summing over the magic
- _CMATCH_ set with the product of its value
-
- The intent here is to reduce highly repetitive code.
+ wrapper around `<t:rate-each />`
-->
<template match="lv:rate-each" mode="preproc:macros" priority="5">
- <!-- TODO: debug flag
- <message>
- <text>[preproc] expanding rate-each </text>
- <value-of select="@yields" />
- <text>...</text>
- </message>
- -->
-
- <lv:rate preproc:gentle-no="true">
- <sequence select="@*[
- not( local-name() = 'index' )
- and not( local-name() = 'generates' )
- ]" />
-
- <if test="not( @yields )">
- <!-- if @generates is not supplied either, then we cannot continue -->
- <choose>
- <when test="not( @generates )">
- <!-- TODO: some means of identifying this...the error isn't terribly
- helpful... :x -->
- <preproc:error>
- <text>rate-each must provide either @yields or @generates</text>
- </preproc:error>
- </when>
-
- <otherwise>
- <attribute name="yields"
- select="concat( '_', @generates )" />
- <attribute name="preproc:yields-generated"
- select="'true'" />
- </otherwise>
- </choose>
- </if>
-
- <sequence select="./lv:class" />
-
- <c:sum of="_CMATCH_" index="{@index}" sym="{@gensym}">
- <if test="@dim">
- <copy-of select="@dim" />
- </if>
-
- <!-- copy @generates, if it exists (has the benefit of copying nothing
- if it does not exist) -->
- <sequence select="@generates" />
-
- <attribute name="desc">
- <text>Set of individual </text>
- <value-of select="@yields" />
- <text> premiums</text>
- </attribute>
-
- <c:product>
- <c:value-of name="_CMATCH_" index="{@index}">
- <attribute name="label">
- <text>Zero if not </text>
- <value-of select="@class" />
- <text>, otherwise one</text>
- </attribute>
- </c:value-of>
-
- <apply-templates
- select="*[
- not(
- local-name() = 'class'
- )
- ]"
- mode="preproc:macros" />
- </c:product>
- </c:sum>
- </lv:rate>
+ <t:rate-each>
+ <copy-of select="@*" />
+ <apply-templates mode="preproc:expand"
+ select="*[ not( local-name() = 'class' ) ]" />
+ </t:rate-each>
</template>
</stylesheet>