Extracted param symbol generation

The `preproc:param-dim' template must remain for now, as it is used by
others.

* src/current/include/preproc/symtable.xsl
  (preproc:symtable)[lv:param]: Extracted template.

* src/symtable/symbols.xsl
  (preproc:symtable)[lv:param]: Added template.

* test/symtable/symbols.xsl
  (lv:param): Scenario added.
master
Mike Gerwitz 2016-11-17 08:56:40 -05:00
parent f396858fb1
commit 1d3aaf3339
3 changed files with 162 additions and 20 deletions

View File

@ -71,6 +71,7 @@
<xsl:include href="path.xsl" />
<xsl:include href="../../tame/src/symtable.xsl" />
<xsl:include href="../../tame/src/symtable/symbols.xsl" />
<!-- we will recurse through the entire tree rather than performing a series of
@ -757,23 +758,6 @@
</xsl:template>
<!-- Will be completed during post-processing so that typedefs can be
properly resolved -->
<xsl:template match="lv:param" mode="preproc:symtable" priority="5">
<xsl:variable name="dim">
<xsl:call-template name="preproc:param-dim" />
</xsl:variable>
<!-- we use the primitive data type derived from the typedef to ensure that
the system can still make use of the type even when the typedef is not
exported; indeed, typedefs are simply restrictions that need only be
known for compiling (at least at present). Also note the keep="true" to
ensure that all param symbols are retained after linking -->
<preproc:sym name="{@name}" keep="true"
type="param" dtype="{@type}" dim="{$dim}" desc="{@desc}" tex="{@sym}" />
</xsl:template>
<xsl:template match="lv:typedef" mode="preproc:symtable" priority="5">
<!-- FIXME: this is a kluge -->
<xsl:variable name="dtype" as="xs:string?"

View File

@ -32,6 +32,7 @@
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lv="http://www.lovullo.com/rater"
xmlns:symtable="http://www.lovullo.com/tame/symtable"
xmlns:_symtable="http://www.lovullo.com/tame/symtable/_priv"
xmlns:preproc="http://www.lovullo.com/rater/preproc">
<import href="symbols.xsl.apply" />
@ -72,9 +73,7 @@
@item dim
Dimensions of@tie{}@obj{} as an integer.
Standard dimensions are scalar@tie{}(0),
vector@tie{}(1),
and matrix@tie{}(2).
See @ref{_symtable:str-to-dim#1} for supported strings.
@emph{Required}
@item dtype
@ -128,6 +127,42 @@
-->
<!--
Convert a string dimension representation into an integer.
Standard dimensions are @samp{scalar}@tie{}(0),
@samp{vector}@tie{}(1),
and @samp{matrix}@tie{}(2).
If no value is provided,
then @samp{scalar} is assumed.
All unknown strings will yield a value of @samp{-1}.@footnote{
That's not to say that @tame{} can't support an arbitrary number
of dimensions;
this syntax just doesn't provide that utility.}
-->
<function name="_symtable:str-to-dim" as="xs:integer">
<param name="str" as="xs:string?" />
<choose>
<when test="empty( $str ) or ( $str = 'scalar' )">
<sequence select="0" />
</when>
<when test="$str = 'vector'">
<sequence select="1" />
</when>
<when test="$str = 'matrix'">
<sequence select="2" />
</when>
<otherwise>
<sequence select="-1" />
</otherwise>
</choose>
</function>
<!--
@node Symbol Types
@section Symbol Types
@ -249,12 +284,64 @@
@menu
* Parameters: Parameter Symbols. @code{param}
* Templates: Template Symbols. @code{tpl}
* Program Metadata: Program Metadata Symbols. @code{meta}
@end menu
-->
<!--
@node Parameter Symbols
@subsection Parameter Symbols
Global parameters define all inputs to the program.
-->
<!--
Produce a @code{param} symbol with the following attributes:
@table @code
@item name
Name of the parameter as provided by @pkgns{param/@@name}.
@item type
The datatype defining the parameter's domain,
as provided by @pkgns{param/@@type}.
@item dim
Numeric dimension converted from its string representation in
@pkgns{param/@@set}.@footnote{
The attribute name @pkgns{param/@@set} is unfortunate and simply
incorrect terminology with how it is used.
It will be changed in the future.}
@item desc
Description as provided by @pkgns{param/@@desc}.
@item tex
TeX symbol used when rendering parameter in an equation.
@item keep
Always @samp{true} to ensure that the symbol is retained after
linking.
@end table
-->
<template match="lv:param" mode="preproc:symtable" priority="5">
<variable name="dim" as="xs:integer"
select="_symtable:str-to-dim( @set )" />
<preproc:sym type="param"
name="{@name}"
dim="{$dim}"
desc="{@desc}"
dtype="{@type}"
tex="{@sym}"
keep="true" />
</template>
<!--
@node Template Symbols
@subsection Template Symbols

View File

@ -29,6 +29,77 @@
stylesheet="../../src/symtable/symbols.xsl">
<scenario label="lv:param">
<context mode="preproc:symtable">
<lv:param name="foo_bar"
type="footype"
desc="Vector param"
set="vector" />
<lv:param name="tex_param"
type="tex"
desc="Matrix param with TeX"
set="matrix"
sym="\tex" />
<lv:param name="scalar_param"
type="bar"
desc="Scalar param (implicit)" />
<lv:param name="scalar_param_explicit"
type="bar"
set="scalar"
desc="Scalar param (explicit)" />
<lv:param name="unknown_dim"
type="wtf"
set="calabi-yau"
desc="Unknown dimension" />
</context>
<expect label="derives symbol data from param">
<preproc:sym type="param"
name="foo_bar"
dim="1"
desc="Vector param"
dtype="footype"
tex=""
keep="true" />
<preproc:sym type="param"
name="tex_param"
dim="2"
desc="Matrix param with TeX"
dtype="tex"
tex="\tex"
keep="true" />
<preproc:sym type="param"
name="scalar_param"
dim="0"
desc="Scalar param (implicit)"
dtype="bar"
tex=""
keep="true" />
<preproc:sym type="param"
name="scalar_param_explicit"
dim="0"
desc="Scalar param (explicit)"
dtype="bar"
tex=""
keep="true" />
<preproc:sym type="param"
name="unknown_dim"
dim="-1"
desc="Unknown dimension"
dtype="wtf"
tex=""
keep="true" />
</expect>
</scenario>
<scenario label="lv:template">
<context mode="preproc:symtable">
<lv:template name="_foo_"