1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2dot.xsl - transform Bison XML Report into DOT.
7 Copyright (C) 2007 Free Software Foundation, Inc.
9 This file is part of Bison, the GNU Compiler Compiler.
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 Written by Wojciech Polak <polak@gnu.org>.
27 <xsl:stylesheet version=
"1.0"
28 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform">
30 <xsl:output method=
"text" encoding=
"UTF-8" indent=
"no"/>
32 <xsl:template match=
"/">
33 <xsl:apply-templates select=
"bison-xml-report"/>
36 <xsl:template match=
"bison-xml-report">
37 <xsl:apply-templates select=
"automaton"/>
40 <xsl:template match=
"automaton">
41 <xsl:text>digraph Automaton {
</xsl:text>
42 <xsl:apply-templates select=
"state"/>
43 <xsl:text>}
</xsl:text>
46 <xsl:template match=
"automaton/state">
47 <xsl:call-template name=
"output-node">
48 <xsl:with-param name=
"number" select=
"@number"/>
49 <xsl:with-param name=
"label">
50 <xsl:value-of select=
"@number"/>
51 <xsl:apply-templates select=
"itemset/rule"/>
54 <xsl:apply-templates select=
"actions/transitions"/>
57 <xsl:template match=
"actions/transitions">
58 <xsl:apply-templates select=
"transition"/>
61 <xsl:template match=
"rule">
62 <xsl:text>\n
</xsl:text>
63 <xsl:value-of select=
"lhs"/>
64 <xsl:text> -
></xsl:text>
65 <xsl:apply-templates select=
"rhs/symbol|rhs/point|rhs/empty"/>
66 <xsl:apply-templates select=
"lookaheads"/>
69 <xsl:template match=
"symbol">
70 <xsl:text> </xsl:text>
71 <xsl:value-of select=
"."/>
74 <xsl:template match=
"point">
75 <xsl:text> .
</xsl:text>
78 <xsl:template match=
"empty">
79 <xsl:text> /* empty */
</xsl:text>
82 <xsl:template match=
"lookaheads">
83 <xsl:text>[
</xsl:text>
84 <xsl:apply-templates select=
"symbol"/>
85 <xsl:text>]
</xsl:text>
88 <xsl:template match=
"lookaheads/symbol">
89 <xsl:value-of select=
"."/>
90 <xsl:if test=
"position() != last()">
91 <xsl:text>,
</xsl:text>
95 <xsl:template match=
"transition">
96 <xsl:call-template name=
"output-edge">
97 <xsl:with-param name=
"src" select=
"../../../@number"/>
98 <xsl:with-param name=
"dst" select=
"@state"/>
99 <xsl:with-param name=
"style">
101 <xsl:when test=
"@symbol = 'error'">
102 <xsl:text>dotted
</xsl:text>
104 <xsl:when test=
"@type = 'shift'">
105 <xsl:text>solid
</xsl:text>
108 <xsl:text>dashed
</xsl:text>
112 <xsl:with-param name=
"label">
113 <xsl:if test=
"not(@symbol = 'error')">
114 <xsl:value-of select=
"@symbol"/>
120 <xsl:template name=
"output-node">
121 <xsl:param name=
"number"/>
122 <xsl:param name=
"label"/>
123 <xsl:text> </xsl:text>
124 <xsl:value-of select=
"$number"/>
125 <xsl:text> [
label="
</xsl:text>
126 <xsl:call-template name=
"string-replace">
127 <xsl:with-param name=
"subject" select=
"$label"/>
128 <xsl:with-param name=
"search" select=
"'"'"/>
129 <xsl:with-param name=
"replace" select=
"'\"'"/>
131 <xsl:text>"] </xsl:text>
134 <xsl:template name="output-edge
">
135 <xsl:param name="src
"/>
136 <xsl:param name="dst
"/>
137 <xsl:param name="style
"/>
138 <xsl:param name="label
"/>
139 <xsl:text> </xsl:text>
140 <xsl:value-of select="$src
"/>
141 <xsl:text> -> </xsl:text>
142 <xsl:value-of select="$dst
"/>
143 <xsl:text> [style=</xsl:text>
144 <xsl:value-of select="$style
"/>
145 <xsl:if test="$label and $label != ''
">
146 <xsl:text> label="</xsl:text>
147 <xsl:call-template name=
"string-replace">
148 <xsl:with-param name=
"subject" select=
"$label"/>
149 <xsl:with-param name=
"search" select=
"'"'"/>
150 <xsl:with-param name=
"replace" select=
"'\"'"/>
152 <xsl:text>"</xsl:text>
154 <xsl:text>] </xsl:text>
157 <xsl:template name="string-replace
">
158 <xsl:param name="subject
"/>
159 <xsl:param name="search
"/>
160 <xsl:param name="replace
"/>
162 <xsl:when test="contains($subject, $search)
">
163 <xsl:variable name="before
" select="substring-before($subject, $search)
"/>
164 <xsl:variable name="after
" select="substring-after($subject, $search)
"/>
165 <xsl:value-of select="$before
"/>
166 <xsl:value-of select="$replace
"/>
167 <xsl:call-template name="string-replace
">
168 <xsl:with-param name="subject
" select="$after
"/>
169 <xsl:with-param name="search
" select="$search
"/>
170 <xsl:with-param name="replace
" select="$replace
"/>
174 <xsl:value-of select="$subject
"/>