1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="3.0" 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" 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" />
8 <xsl:variable name="value">
9 <xsl:sequence select="value/malval" />
10 <xsl:sequence select="atoms"/>
12 <xsl:for-each select="$value">
14 <xsl:when test="malval/@kind = 'true'">
17 <xsl:when test="malval/@kind = 'false'">
20 <xsl:when test="malval/@kind = 'nil'">
23 <xsl:when test="malval/@kind = 'string'">
25 <xsl:value-of select="concat(if ($readably) then '"' else '', fn:desc_string(malval/@value, $readably), if ($readably) then '"' else '')" />
28 <xsl:when test="malval/@kind = 'keyword'">
30 <xsl:value-of select="concat(':', malval/@value)" />
33 <xsl:when test="malval/@kind = 'symbol'">
35 <xsl:value-of select="malval/@value" />
38 <xsl:when test="malval/@kind = 'number'">
40 <xsl:value-of select="malval/@value" />
43 <xsl:when test="malval/@kind = 'list'">
44 <xsl:variable name="val">
45 <xsl:for-each select="malval/lvalue/malval">
46 <xsl:variable name="ctx">
47 <value><xsl:copy-of select="." /></value>
49 <xsl:for-each select="$ctx">
50 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
54 <xsl:for-each select="$val">
56 <xsl:value-of select="concat('(', string-join(/value, ' '), ')')" />
60 <xsl:when test="malval/@kind = 'vector'">
61 <xsl:variable name="val">
62 <xsl:for-each select="malval/lvalue/malval">
63 <xsl:variable name="ctx">
64 <value><xsl:copy-of select="." /></value>
66 <xsl:for-each select="$ctx">
67 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
71 <xsl:for-each select="$val">
73 <xsl:value-of select="concat('[', string-join(/value, ' '), ']')" />
77 <xsl:when test="malval/@kind = 'hash'">
78 <xsl:variable name="val">
79 <xsl:for-each select="malval/lvalue/malval">
80 <xsl:variable name="ctx">
81 <value><xsl:copy-of select="." /></value>
83 <xsl:for-each select="$ctx">
84 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
88 <xsl:for-each select="$val">
90 <xsl:value-of select="concat('{', string-join(/value, ' '), '}')" />
94 <xsl:when test="malval/@kind = 'function'">
96 <xsl:variable name="gt">></xsl:variable>
97 <xsl:variable name="lt"><</xsl:variable>
98 <xsl:value-of select="concat('#', $lt, 'fn ', malval/@name, $gt)" />
101 <xsl:when test="malval/@kind = 'userfunction'">
103 <xsl:variable name="gt">></xsl:variable>
104 <xsl:variable name="lt"><</xsl:variable>
105 <xsl:value-of select="concat('#', $lt, 'function', $gt)" />
108 <xsl:when test="malval/@kind = 'atom'">
109 <xsl:variable name="val" select="malval"></xsl:variable>
110 <xsl:variable name="inner">
111 <xsl:variable name="ctx">
113 <xsl:sequence select="atoms/atom[@identity = $val/@value]/malval"/>
116 <xsl:for-each select="$ctx">
117 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
121 <xsl:value-of select="concat('(atom ', $inner/value, ')')" />
125 <value>Unknown <xsl:copy-of select="." /></value>
131 <xsl:function name="fn:desc_string" as="xs:string">
132 <xsl:param name="str" as="xs:string" />
133 <xsl:param name="readable" as="xs:boolean" />
135 <xsl:when test="($readable)">
136 <xsl:variable name="sx">
137 <xsl:analyze-string select="$str" regex="(\\|"| )">
138 <xsl:matching-substring>
141 <xsl:when test="regex-group(1) = '\'">
142 <xsl:value-of select="'\\'" />
144 <xsl:when test="regex-group(1) = '"'">
145 <xsl:value-of select="'\"'" />
148 <xsl:value-of select="'\n'" />
152 </xsl:matching-substring>
153 <xsl:non-matching-substring><x><xsl:value-of select="." /></x></xsl:non-matching-substring>
154 </xsl:analyze-string>
156 <xsl:value-of select="string-join($sx/x, '')" />
159 <xsl:value-of select="$str" />