1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2dot.xsl - transform Bison XML Report into DOT.
6 Copyright (C) 2007-2012 Free Software Foundation, Inc.
8 This file is part of Bison, the GNU Compiler Compiler.
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Written by Wojciech Polak <polak@gnu.org>.
26 <xsl:stylesheet version=
"1.0"
27 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
28 xmlns:
bison=
"http://www.gnu.org/software/bison/">
30 <xsl:import href=
"bison.xsl"/>
31 <xsl:output method=
"text" encoding=
"UTF-8" indent=
"no"/>
33 <xsl:template match=
"/">
34 <xsl:apply-templates select=
"bison-xml-report"/>
37 <xsl:template match=
"bison-xml-report">
38 <xsl:text>// Generated by GNU Bison
</xsl:text>
39 <xsl:value-of select=
"@version"/>
40 <xsl:text>.
</xsl:text>
41 <xsl:text>// Report bugs to
<</xsl:text>
42 <xsl:value-of select=
"@bug-report"/>
43 <xsl:text>>.
</xsl:text>
44 <xsl:text>// Home page:
<</xsl:text>
45 <xsl:value-of select=
"@url"/>
46 <xsl:text>>.
</xsl:text>
47 <xsl:apply-templates select=
"automaton">
48 <xsl:with-param name=
"filename" select=
"filename"/>
49 </xsl:apply-templates>
52 <xsl:template match=
"automaton">
53 <xsl:param name=
"filename"/>
54 <xsl:text>digraph "
</xsl:text>
55 <xsl:call-template name=
"escape">
56 <xsl:with-param name=
"subject" select=
"$filename"/>
59 node [fontname = courier, shape = box, colorscheme = paired6]
60 edge [fontname = courier]
63 <xsl:apply-templates select=
"state"/>
64 <xsl:text>}
</xsl:text>
67 <xsl:template match=
"automaton/state">
68 <xsl:call-template name=
"output-node">
69 <xsl:with-param name=
"number" select=
"@number"/>
70 <xsl:with-param name=
"label">
71 <xsl:value-of select=
"@number"/>
72 <xsl:apply-templates select=
"itemset/item"/>
75 <xsl:apply-templates select=
"actions/transitions"/>
78 <xsl:template match=
"actions/transitions">
79 <xsl:apply-templates select=
"transition"/>
82 <xsl:template match=
"item">
83 <xsl:apply-templates select=
"key('bison:ruleByNumber', @rule-number)">
84 <xsl:with-param name=
"point" select=
"@point"/>
85 </xsl:apply-templates>
86 <xsl:apply-templates select=
"lookaheads"/>
89 <xsl:template match=
"rule">
90 <xsl:param name=
"point"/>
91 <xsl:text> </xsl:text>
92 <xsl:value-of select=
"lhs"/>
93 <xsl:text> -
></xsl:text>
94 <xsl:if test=
"$point = 0">
95 <xsl:text> .
</xsl:text>
97 <xsl:for-each select=
"rhs/symbol|rhs/empty">
98 <xsl:apply-templates select=
"."/>
99 <xsl:if test=
"$point = position()">
100 <xsl:text> .
</xsl:text>
105 <xsl:template match=
"symbol">
106 <xsl:text> </xsl:text>
107 <xsl:value-of select=
"."/>
110 <xsl:template match=
"empty"/>
112 <xsl:template match=
"lookaheads">
113 <xsl:text>[
</xsl:text>
114 <xsl:apply-templates select=
"symbol"/>
115 <xsl:text>]
</xsl:text>
118 <xsl:template match=
"lookaheads/symbol">
119 <xsl:value-of select=
"."/>
120 <xsl:if test=
"position() != last()">
121 <xsl:text>,
</xsl:text>
125 <xsl:template match=
"transition">
126 <xsl:call-template name=
"output-edge">
127 <xsl:with-param name=
"src" select=
"../../../@number"/>
128 <xsl:with-param name=
"dst" select=
"@state"/>
129 <xsl:with-param name=
"style">
131 <xsl:when test=
"@symbol = 'error'">
132 <xsl:text>dotted
</xsl:text>
134 <xsl:when test=
"@type = 'shift'">
135 <xsl:text>solid
</xsl:text>
138 <xsl:text>dashed
</xsl:text>
142 <xsl:with-param name=
"label">
143 <xsl:if test=
"not(@symbol = 'error')">
144 <xsl:value-of select=
"@symbol"/>
150 <xsl:template name=
"output-node">
151 <xsl:param name=
"number"/>
152 <xsl:param name=
"label"/>
153 <xsl:text> </xsl:text>
154 <xsl:value-of select=
"$number"/>
155 <xsl:text> [
label="
</xsl:text>
156 <xsl:call-template name=
"escape">
157 <xsl:with-param name=
"subject" select=
"$label"/>
159 <xsl:text>"] </xsl:text>
162 <xsl:template name="output-edge
">
163 <xsl:param name="src
"/>
164 <xsl:param name="dst
"/>
165 <xsl:param name="style
"/>
166 <xsl:param name="label
"/>
167 <xsl:text> </xsl:text>
168 <xsl:value-of select="$src
"/>
169 <xsl:text> -> </xsl:text>
170 <xsl:value-of select="$dst
"/>
171 <xsl:text> [style=</xsl:text>
172 <xsl:value-of select="$style
"/>
173 <xsl:if test="$label and $label != ''
">
174 <xsl:text> label="</xsl:text>
175 <xsl:call-template name=
"escape">
176 <xsl:with-param name=
"subject" select=
"$label"/>
178 <xsl:text>"</xsl:text>
180 <xsl:text>] </xsl:text>
183 <xsl:template name="escape
">
184 <xsl:param name="subject
"/> <!-- required -->
185 <xsl:call-template name="string-replace
">
186 <xsl:with-param name="subject
">
187 <xsl:call-template name="string-replace
">
188 <xsl:with-param name="subject
">
189 <xsl:call-template name="string-replace
">
190 <xsl:with-param name="subject
" select="$subject
"/>
191 <xsl:with-param name="search
" select="'\'
"/>
192 <xsl:with-param name="replace
" select="'\\'
"/>
195 <xsl:with-param name="search
" select="'
"'
"/>
196 <xsl:with-param name="replace
" select="'\
"'
"/>
199 <xsl:with-param name="search
" select="'
'
"/>
200 <xsl:with-param name="replace
" select="'\n'
"/>
204 <xsl:template name="string-replace
">
205 <xsl:param name="subject
"/>
206 <xsl:param name="search
"/>
207 <xsl:param name="replace
"/>
209 <xsl:when test="contains($subject, $search)
">
210 <xsl:variable name="before
" select="substring-before($subject, $search)
"/>
211 <xsl:variable name="after
" select="substring-after($subject, $search)
"/>
212 <xsl:value-of select="$before
"/>
213 <xsl:value-of select="$replace
"/>
214 <xsl:call-template name="string-replace
">
215 <xsl:with-param name="subject
" select="$after
"/>
216 <xsl:with-param name="search
" select="$search
"/>
217 <xsl:with-param name="replace
" select="$replace
"/>
221 <xsl:value-of select="$subject
"/>