tplgen: Add package
* test/core/suite.xml: Import new tplgen package. * test/core/tplgen.xml: Add test. * tplgen.xml: Add package.master
parent
2e453ee703
commit
108ada745a
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<!--
|
<!--
|
||||||
Copyright (C) 2015 R-T Specialty, LLC.
|
Copyright (C) 2015, 2018 R-T Specialty, LLC.
|
||||||
|
|
||||||
This file is part of tame-core.
|
This file is part of tame-core.
|
||||||
|
|
||||||
|
@ -26,12 +26,15 @@
|
||||||
<import package="../../base" />
|
<import package="../../base" />
|
||||||
<import package="../spec" />
|
<import package="../spec" />
|
||||||
|
|
||||||
<import package="insurance" />
|
|
||||||
<import package="numeric/round" />
|
<import package="numeric/round" />
|
||||||
<import package="numeric/convert" />
|
<import package="numeric/convert" />
|
||||||
<import package="numeric/percent" />
|
<import package="numeric/percent" />
|
||||||
<import package="vector/interpolate" />
|
<import package="vector/interpolate" />
|
||||||
<import package="vector/length" />
|
<import package="vector/length" />
|
||||||
|
|
||||||
|
<import package="insurance" />
|
||||||
|
<import package="tplgen" />
|
||||||
|
|
||||||
<!-- XXX broken!
|
<!-- XXX broken!
|
||||||
<import package="ui" />
|
<import package="ui" />
|
||||||
-->
|
-->
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2018 R-T Specialty, LLC.
|
||||||
|
|
||||||
|
This file is part of tame-core.
|
||||||
|
|
||||||
|
tame-core is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
<package xmlns="http://www.lovullo.com/rater"
|
||||||
|
xmlns:c="http://www.lovullo.com/calc"
|
||||||
|
xmlns:t="http://www.lovullo.com/rater/apply-template"
|
||||||
|
desc="Template Generation Package Specification">
|
||||||
|
|
||||||
|
<import package="../../test/spec" />
|
||||||
|
|
||||||
|
<import package="../../base" />
|
||||||
|
<import package="../../tplgen" />
|
||||||
|
|
||||||
|
|
||||||
|
<t:describe name="_for-each-n_">
|
||||||
|
<t:describe name="given a positive step">
|
||||||
|
<t:it desc="produces body N times exposing current N">
|
||||||
|
<t:given>
|
||||||
|
<c:sum>
|
||||||
|
<t:for-each-n start="2" end="6" step="2">
|
||||||
|
<c:const value="@current_n@" desc="Current N" />
|
||||||
|
</t:for-each-n>
|
||||||
|
</c:sum>
|
||||||
|
</t:given>
|
||||||
|
|
||||||
|
<t:expect>
|
||||||
|
<!-- 2 + 4 + 6 -->
|
||||||
|
<t:match-result eq="12" />
|
||||||
|
</t:expect>
|
||||||
|
</t:it>
|
||||||
|
</t:describe>
|
||||||
|
|
||||||
|
|
||||||
|
<t:describe name="given a negative step">
|
||||||
|
<t:it desc="produces body N times exposing current N">
|
||||||
|
<t:given>
|
||||||
|
<c:sum>
|
||||||
|
<t:for-each-n start="4" end="1" step="-1">
|
||||||
|
<c:const value="@current_n@" desc="Current N" />
|
||||||
|
</t:for-each-n>
|
||||||
|
</c:sum>
|
||||||
|
</t:given>
|
||||||
|
|
||||||
|
<t:expect>
|
||||||
|
<!-- 4 + 3 + 2 + 1 = 4! (4 factorial) -->
|
||||||
|
<t:match-result eq="10" />
|
||||||
|
</t:expect>
|
||||||
|
</t:it>
|
||||||
|
</t:describe>
|
||||||
|
</t:describe>
|
||||||
|
</package>
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2018 R-T Specialty, LLC.
|
||||||
|
|
||||||
|
This file is part of tame-core.
|
||||||
|
|
||||||
|
tame-core is free software: you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
<package xmlns="http://www.lovullo.com/rater"
|
||||||
|
xmlns:c="http://www.lovullo.com/calc"
|
||||||
|
xmlns:t="http://www.lovullo.com/rater/apply-template"
|
||||||
|
core="true"
|
||||||
|
desc="Template Generation">
|
||||||
|
|
||||||
|
|
||||||
|
This package provides various templates for generating templates and
|
||||||
|
iterating using templates.
|
||||||
|
In essense,
|
||||||
|
this package is intended to abstract away certain implementation details
|
||||||
|
and complexities that make groking code more difficult;
|
||||||
|
they should be used when possible to improve code maintenance.
|
||||||
|
|
||||||
|
|
||||||
|
<section title="Iteration">
|
||||||
|
\ref{_for-each-n_} recurisvely produces the body~\tt{@values@} given a
|
||||||
|
numeric range and step.
|
||||||
|
This can also be used to generate sequences at compile-time rather than
|
||||||
|
using functions,
|
||||||
|
provided that the sequence data are static.
|
||||||
|
|
||||||
|
<template name="_for-each-n_"
|
||||||
|
desc="Recursively apply body with counter and step">
|
||||||
|
<param name="@values@" desc="Body" />
|
||||||
|
<param name="@start@" desc="Counter start" />
|
||||||
|
<param name="@end@" desc="Counter end" />
|
||||||
|
<param name="@step@" desc="Counter step" />
|
||||||
|
|
||||||
|
|
||||||
|
<param name="@next_n@" desc="Next iteration value">
|
||||||
|
<param-add name="@start@" value="@step@" />
|
||||||
|
</param>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- inefficient trick to expose @current_n@ to the body -->
|
||||||
|
<inline-template>
|
||||||
|
<for-each>
|
||||||
|
<set current_n="@start@" />
|
||||||
|
</for-each>
|
||||||
|
|
||||||
|
<param-copy name="@values@" />
|
||||||
|
</inline-template>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- repeat body for each step, as sibling -->
|
||||||
|
<unless name="@start@" eq="@end@">
|
||||||
|
<t:for-each-n start="@next_n@" end="@end@" step="@step@">
|
||||||
|
<param-copy name="@values@" />
|
||||||
|
</t:for-each-n>
|
||||||
|
</unless>
|
||||||
|
</template>
|
||||||
|
</section>
|
||||||
|
</package>
|
Loading…
Reference in New Issue