Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-01-04 16:06:59 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-09-11 09:30:51 -0400
commit108ada745a0c4ba6d7a681a23811ed52dd0a250c (patch)
treeb686286d4a601f7c3a11542376adab02d1e338dc
parent2e453ee703fbfb91a037c4690a56738517215987 (diff)
downloadtame-108ada745a0c4ba6d7a681a23811ed52dd0a250c.tar.gz
tame-108ada745a0c4ba6d7a681a23811ed52dd0a250c.tar.bz2
tame-108ada745a0c4ba6d7a681a23811ed52dd0a250c.zip
tplgen: Add package
* test/core/suite.xml: Import new tplgen package. * test/core/tplgen.xml: Add test. * tplgen.xml: Add package.
-rw-r--r--core/test/core/suite.xml7
-rw-r--r--core/test/core/tplgen.xml67
-rw-r--r--core/tplgen.xml73
3 files changed, 145 insertions, 2 deletions
diff --git a/core/test/core/suite.xml b/core/test/core/suite.xml
index f53102d..ce02b4b 100644
--- a/core/test/core/suite.xml
+++ b/core/test/core/suite.xml
@@ -1,6 +1,6 @@
<?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.
@@ -26,12 +26,15 @@
<import package="../../base" />
<import package="../spec" />
- <import package="insurance" />
<import package="numeric/round" />
<import package="numeric/convert" />
<import package="numeric/percent" />
<import package="vector/interpolate" />
<import package="vector/length" />
+
+ <import package="insurance" />
+ <import package="tplgen" />
+
<!-- XXX broken!
<import package="ui" />
-->
diff --git a/core/test/core/tplgen.xml b/core/test/core/tplgen.xml
new file mode 100644
index 0000000..d3815b5
--- /dev/null
+++ b/core/test/core/tplgen.xml
@@ -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>
diff --git a/core/tplgen.xml b/core/tplgen.xml
new file mode 100644
index 0000000..b1f1373
--- /dev/null
+++ b/core/tplgen.xml
@@ -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>