1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" version="3.0" exclude-result-prefixes="xsl xs fn">
3 <!-- expects input as a single <value><malval .../></value> -->
4 <!-- output of form <value>literal string</value> -->
5 <xsl:template name="malprinter-pr_str">
6 <xsl:param name="readably" as="xs:boolean"/>
7 <xsl:variable name="value">
8 <xsl:sequence select="value/malval"/>
9 <xsl:sequence select="atoms"/>
11 <xsl:for-each select="$value">
13 <xsl:when test="malval/@kind = 'true'">
16 <xsl:when test="malval/@kind = 'false'">
19 <xsl:when test="malval/@kind = 'nil'">
22 <xsl:when test="malval/@kind = 'string'">
24 <xsl:value-of select="concat(
30 fn:desc_string(malval/@value, $readably),
38 <xsl:when test="malval/@kind = 'keyword'">
40 <xsl:value-of select="concat(':', malval/@value)"/>
43 <xsl:when test="malval/@kind = 'symbol'">
45 <xsl:value-of select="malval/@value"/>
48 <xsl:when test="malval/@kind = 'number'">
50 <xsl:value-of select="malval/@value"/>
53 <xsl:when test="malval/@kind = 'list'">
54 <xsl:variable name="val">
55 <xsl:for-each select="malval/lvalue/malval">
56 <xsl:variable name="ctx">
58 <xsl:copy-of select="."/>
61 <xsl:for-each select="$ctx">
62 <xsl:call-template name="malprinter-pr_str">
63 <xsl:with-param name="readably" select="$readably"/>
68 <xsl:for-each select="$val">
70 <xsl:value-of select="concat('(', string-join(/value, ' '), ')')"/>
74 <xsl:when test="malval/@kind = 'vector'">
75 <xsl:variable name="val">
76 <xsl:for-each select="malval/lvalue/malval">
77 <xsl:variable name="ctx">
79 <xsl:copy-of select="."/>
82 <xsl:for-each select="$ctx">
83 <xsl:call-template name="malprinter-pr_str">
84 <xsl:with-param name="readably" select="$readably"/>
89 <xsl:for-each select="$val">
91 <xsl:value-of select="concat('[', string-join(/value, ' '), ']')"/>
95 <xsl:when test="malval/@kind = 'hash'">
96 <xsl:variable name="val">
97 <xsl:for-each select="malval/lvalue/malval">
98 <xsl:variable name="ctx">
100 <xsl:copy-of select="."/>
103 <xsl:for-each select="$ctx">
104 <xsl:call-template name="malprinter-pr_str">
105 <xsl:with-param name="readably" select="$readably"/>
110 <xsl:for-each select="$val">
112 <xsl:value-of select="concat('{', string-join(/value, ' '), '}')"/>
116 <xsl:when test="malval/@kind = 'function'">
118 <xsl:variable name="gt">?</xsl:variable>
119 <xsl:variable name="lt">?</xsl:variable>
120 <xsl:value-of select="concat('#', $lt, 'fn ', malval/@name, $gt)"/>
123 <xsl:when test="malval/@kind = 'userfunction'">
125 <xsl:variable name="gt">?</xsl:variable>
126 <xsl:variable name="lt">?</xsl:variable>
127 <xsl:value-of select="concat('#', $lt, 'function', $gt)"/>
130 <xsl:when test="malval/@kind = 'atom'">
131 <xsl:variable name="val" select="malval"/>
132 <xsl:variable name="inner">
133 <xsl:variable name="ctx">
135 <xsl:sequence select="atoms/atom[@identity = $val/@value]/malval"/>
138 <xsl:for-each select="$ctx">
139 <xsl:call-template name="malprinter-pr_str">
140 <xsl:with-param name="readably" select="$readably"/>
145 <xsl:value-of select="concat(
147 (let $v := $inner/value
148 return if ($v = 'Unknown') then
149 concat('id=', string($val/@value), ' existing=', string-join(atoms/atom/@identity, ','))
156 <value>Unknown</value>
161 <xsl:function name="fn:desc_string" as="xs:string">
162 <xsl:param name="str" as="xs:string"/>
163 <xsl:param name="readable" as="xs:boolean"/>
165 <xsl:when test="($readable)">
166 <xsl:variable name="sx">
167 <xsl:analyze-string select="$str" regex="(\\|"| )">
168 <xsl:matching-substring>
171 <xsl:when test="regex-group(1) = '\'">
172 <xsl:value-of select="'\\'"/>
174 <xsl:when test="regex-group(1) = '"'">
175 <xsl:value-of select="'\"'"/>
178 <xsl:value-of select="'\n'"/>
182 </xsl:matching-substring>
183 <xsl:non-matching-substring>
185 <xsl:value-of select="."/>
187 </xsl:non-matching-substring>
188 </xsl:analyze-string>
190 <xsl:value-of select="string-join($sx/x, '')"/>
193 <xsl:value-of select="$str"/>