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">
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:copy-of select="value/malval" />
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('"', fn:desc_string(malval/@value, $readably), '"')" />
27 <xsl:when test="malval/@kind = 'keyword'">
29 <xsl:value-of select="concat(':', malval/@value)" />
32 <xsl:when test="malval/@kind = 'symbol'">
34 <xsl:value-of select="malval/@value" />
37 <xsl:when test="malval/@kind = 'number'">
39 <xsl:value-of select="malval/@value" />
42 <xsl:when test="malval/@kind = 'list'">
43 <xsl:variable name="val">
44 <xsl:for-each select="malval/lvalue/malval">
45 <xsl:variable name="ctx">
46 <value><xsl:copy-of select="." /></value>
48 <xsl:for-each select="$ctx">
49 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
53 <xsl:for-each select="$val">
55 <xsl:value-of select="concat('(', string-join(/value, ' '), ')')" />
59 <xsl:when test="malval/@kind = 'vector'">
60 <xsl:variable name="val">
61 <xsl:for-each select="malval/lvalue/malval">
62 <xsl:variable name="ctx">
63 <value><xsl:copy-of select="." /></value>
65 <xsl:for-each select="$ctx">
66 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
70 <xsl:for-each select="$val">
72 <xsl:value-of select="concat('[', string-join(/value, ' '), ']')" />
76 <xsl:when test="malval/@kind = 'hash'">
77 <xsl:variable name="val">
78 <xsl:for-each select="malval/lvalue/malval">
79 <xsl:variable name="ctx">
80 <value><xsl:copy-of select="." /></value>
82 <xsl:for-each select="$ctx">
83 <xsl:call-template name="malprinter-pr_str"><xsl:with-param name="readably" select="$readably"/></xsl:call-template>
87 <xsl:for-each select="$val">
89 <xsl:value-of select="concat('{', string-join(/value, ' '), '}')" />
93 <xsl:when test="malval/@kind = 'function'">
95 <xsl:variable name="gt">></xsl:variable>
96 <xsl:variable name="lt"><</xsl:variable>
97 <xsl:value-of select="concat('#', $lt, 'fn ', malval/@name, $gt)" />
101 <value>Unknown <xsl:copy-of select="." /></value>
107 <xsl:function name="fn:desc_string" as="xs:string">
108 <xsl:param name="str" as="xs:string" />
109 <xsl:param name="readable" as="xs:boolean" />
111 <xsl:when test="not($readable)">
112 <xsl:variable name="sx">
113 <xsl:analyze-string select="$str" regex="\\(n|"|\\)">
114 <xsl:matching-substring>
117 <xsl:when test="regex-group(1) = 'n'">
118 <xsl:value-of select="' '" />
121 <xsl:value-of select="regex-group(1)" />
125 </xsl:matching-substring>
126 <xsl:non-matching-substring><x><xsl:value-of select="." /></x></xsl:non-matching-substring>
127 </xsl:analyze-string>
129 <xsl:value-of select="string-join($sx/x, '')" />
132 <xsl:value-of select="$str" />