Provide symtable to all map compilation steps

* src/current/compiler/map.xsl: Pass symtable to all templates.
master
Mike Gerwitz 2017-07-11 08:50:43 -04:00
parent 86ac6546dc
commit c156c10989
1 changed files with 18 additions and 9 deletions

View File

@ -406,9 +406,6 @@
<!-- <!--
Generate a direct input mapping or, if a default exists for the field, use the Generate a direct input mapping or, if a default exists for the field, use the
default if the input is an empty string default if the input is an empty string
XXX: This is broken; $rater is not provided at the entry point, and
if it were, this needs to reference its symbol table.
--> -->
<template name="lvmc:gen-input-default"> <template name="lvmc:gen-input-default">
<param name="symtable" as="element( preproc:symtable )" /> <param name="symtable" as="element( preproc:symtable )" />
@ -632,7 +629,9 @@
<!-- note that we're casting the value to a string; this is important, <!-- note that we're casting the value to a string; this is important,
since case comparisons are strict (===) --> since case comparisons are strict (===) -->
<text>switch(''+val[i]){</text> <text>switch(''+val[i]){</text>
<apply-templates mode="lvmc:compile" /> <apply-templates mode="lvmc:compile">
<with-param name="symtable" select="$symtable" />
</apply-templates>
<if test="not( lvm:default )"> <if test="not( lvm:default )">
<text>default: ret.push(</text> <text>default: ret.push(</text>
@ -706,10 +705,12 @@
<template match="lvm:from/lvm:default" <template match="lvm:from/lvm:default"
mode="lvmc:compile" priority="5"> mode="lvmc:compile" priority="5">
<param name="symtable" as="element( preproc:symtable )" />
<sequence select="concat( <sequence select="concat(
'default:ret.push(', 'default:ret.push(',
string-join( string-join(
lvmc:concat-compile( element(), () ), lvmc:concat-compile( element(), (), $symtable ),
'' ), '' ),
');' )" /> ');' )" />
</template> </template>
@ -722,20 +723,26 @@
<template match="lvm:map//lvm:from/lvm:translate" mode="lvmc:compile" priority="5"> <template match="lvm:map//lvm:from/lvm:translate" mode="lvmc:compile" priority="5">
<param name="symtable" as="element( preproc:symtable )" />
<text>case '</text> <text>case '</text>
<value-of select="@key" /> <value-of select="@key" />
<text>':</text> <text>':</text>
<apply-templates select="." mode="lvmc:compile-translate" /> <apply-templates select="." mode="lvmc:compile-translate">
<with-param name="symtable" select="$symtable" />
</apply-templates>
<text> break;</text> <text> break;</text>
</template> </template>
<template match="lvm:translate[ element() ]" <template match="lvm:translate[ element() ]"
mode="lvmc:compile-translate" priority="5"> mode="lvmc:compile-translate" priority="5">
<param name="symtable" as="element( preproc:symtable )" />
<sequence select="concat( <sequence select="concat(
'ret.push(', 'ret.push(',
string-join( string-join(
lvmc:concat-compile( element(), @empty ), lvmc:concat-compile( element(), @empty, $symtable ),
'' ), '' ),
');' )" /> ');' )" />
</template> </template>
@ -744,6 +751,7 @@
<function name="lvmc:concat-compile" as="xs:string+"> <function name="lvmc:concat-compile" as="xs:string+">
<param name="children" as="element()+" /> <param name="children" as="element()+" />
<param name="default" as="xs:string?" /> <param name="default" as="xs:string?" />
<param name="symtable" as="element( preproc:symtable )" />
<text>(function(){</text> <text>(function(){</text>
<!-- end result should compile into a (dynamic) string --> <!-- end result should compile into a (dynamic) string -->
@ -753,8 +761,9 @@
<text> + </text> <text> + </text>
</if> </if>
<apply-templates mode="lvmc:compile" <apply-templates mode="lvmc:compile" select=".">
select="." /> <with-param name="symtable" select="$symtable" />
</apply-templates>
</for-each> </for-each>
<text>;</text> <text>;</text>