]>
Commit | Line | Data |
---|---|---|
dc6025ff WP |
1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | ||
3 | <!-- | |
4 | xml2dot.xsl - transform Bison XML Report into DOT. | |
dc6025ff | 5 | |
c932d613 | 6 | Copyright (C) 2007-2012 Free Software Foundation, Inc. |
dc6025ff WP |
7 | |
8 | This file is part of Bison, the GNU Compiler Compiler. | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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/>. | |
22 | ||
23 | Written by Wojciech Polak <polak@gnu.org>. | |
24 | --> | |
25 | ||
26 | <xsl:stylesheet version="1.0" | |
255a6b90 JD |
27 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
28 | xmlns:bison="http://www.gnu.org/software/bison/"> | |
29 | ||
30 | <xsl:import href="bison.xsl"/> | |
dc6025ff WP |
31 | <xsl:output method="text" encoding="UTF-8" indent="no"/> |
32 | ||
33 | <xsl:template match="/"> | |
34 | <xsl:apply-templates select="bison-xml-report"/> | |
35 | </xsl:template> | |
36 | ||
37 | <xsl:template match="bison-xml-report"> | |
ca7a59e8 JD |
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> | |
dc6025ff WP |
50 | </xsl:template> |
51 | ||
52 | <xsl:template match="automaton"> | |
ca7a59e8 JD |
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"/> | |
57 | </xsl:call-template> | |
a8ad0481 AD |
58 | <xsl:text> { |
59 | node [fontname = courier, shape = box, colorscheme = paired6] | |
60 | edge [fontname = courier] | |
61 | ||
62 | </xsl:text> | |
dc6025ff WP |
63 | <xsl:apply-templates select="state"/> |
64 | <xsl:text>} </xsl:text> | |
65 | </xsl:template> | |
66 | ||
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"/> | |
255a6b90 | 72 | <xsl:apply-templates select="itemset/item"/> |
dc6025ff WP |
73 | </xsl:with-param> |
74 | </xsl:call-template> | |
75 | <xsl:apply-templates select="actions/transitions"/> | |
76 | </xsl:template> | |
77 | ||
78 | <xsl:template match="actions/transitions"> | |
79 | <xsl:apply-templates select="transition"/> | |
80 | </xsl:template> | |
81 | ||
255a6b90 | 82 | <xsl:template match="item"> |
d4a26c48 | 83 | <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)"> |
255a6b90 JD |
84 | <xsl:with-param name="point" select="@point"/> |
85 | </xsl:apply-templates> | |
86 | <xsl:apply-templates select="lookaheads"/> | |
87 | </xsl:template> | |
88 | ||
dc6025ff | 89 | <xsl:template match="rule"> |
255a6b90 | 90 | <xsl:param name="point"/> |
21f1b063 | 91 | <xsl:text> </xsl:text> |
dc6025ff WP |
92 | <xsl:value-of select="lhs"/> |
93 | <xsl:text> -></xsl:text> | |
255a6b90 JD |
94 | <xsl:if test="$point = 0"> |
95 | <xsl:text> .</xsl:text> | |
96 | </xsl:if> | |
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> | |
101 | </xsl:if> | |
102 | </xsl:for-each> | |
dc6025ff WP |
103 | </xsl:template> |
104 | ||
105 | <xsl:template match="symbol"> | |
106 | <xsl:text> </xsl:text> | |
107 | <xsl:value-of select="."/> | |
108 | </xsl:template> | |
109 | ||
255a6b90 | 110 | <xsl:template match="empty"/> |
dc6025ff WP |
111 | |
112 | <xsl:template match="lookaheads"> | |
113 | <xsl:text>[</xsl:text> | |
114 | <xsl:apply-templates select="symbol"/> | |
115 | <xsl:text>]</xsl:text> | |
116 | </xsl:template> | |
117 | ||
118 | <xsl:template match="lookaheads/symbol"> | |
119 | <xsl:value-of select="."/> | |
120 | <xsl:if test="position() != last()"> | |
121 | <xsl:text>, </xsl:text> | |
122 | </xsl:if> | |
123 | </xsl:template> | |
124 | ||
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"> | |
130 | <xsl:choose> | |
131 | <xsl:when test="@symbol = 'error'"> | |
132 | <xsl:text>dotted</xsl:text> | |
133 | </xsl:when> | |
134 | <xsl:when test="@type = 'shift'"> | |
135 | <xsl:text>solid</xsl:text> | |
136 | </xsl:when> | |
137 | <xsl:otherwise> | |
138 | <xsl:text>dashed</xsl:text> | |
139 | </xsl:otherwise> | |
140 | </xsl:choose> | |
141 | </xsl:with-param> | |
142 | <xsl:with-param name="label"> | |
143 | <xsl:if test="not(@symbol = 'error')"> | |
144 | <xsl:value-of select="@symbol"/> | |
145 | </xsl:if> | |
146 | </xsl:with-param> | |
147 | </xsl:call-template> | |
148 | </xsl:template> | |
149 | ||
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> | |
21f1b063 | 156 | <xsl:call-template name="escape"> |
dc6025ff | 157 | <xsl:with-param name="subject" select="$label"/> |
dc6025ff WP |
158 | </xsl:call-template> |
159 | <xsl:text>"] </xsl:text> | |
160 | </xsl:template> | |
161 | ||
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> | |
21f1b063 | 175 | <xsl:call-template name="escape"> |
dc6025ff | 176 | <xsl:with-param name="subject" select="$label"/> |
dc6025ff WP |
177 | </xsl:call-template> |
178 | <xsl:text>"</xsl:text> | |
179 | </xsl:if> | |
180 | <xsl:text>] </xsl:text> | |
181 | </xsl:template> | |
182 | ||
21f1b063 | 183 | <xsl:template name="escape"> |
85a6eb13 | 184 | <xsl:param name="subject"/> <!-- required --> |
21f1b063 JD |
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="'\\'"/> | |
193 | </xsl:call-template> | |
194 | </xsl:with-param> | |
195 | <xsl:with-param name="search" select="'"'"/> | |
196 | <xsl:with-param name="replace" select="'\"'"/> | |
197 | </xsl:call-template> | |
198 | </xsl:with-param> | |
199 | <xsl:with-param name="search" select="' '"/> | |
200 | <xsl:with-param name="replace" select="'\n'"/> | |
201 | </xsl:call-template> | |
202 | </xsl:template> | |
203 | ||
204 | <xsl:template name="string-replace"> | |
205 | <xsl:param name="subject"/> | |
206 | <xsl:param name="search"/> | |
207 | <xsl:param name="replace"/> | |
208 | <xsl:choose> | |
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"/> | |
218 | </xsl:call-template> | |
83b66ddd | 219 | </xsl:when> |
21f1b063 | 220 | <xsl:otherwise> |
83b66ddd | 221 | <xsl:value-of select="$subject"/> |
21f1b063 | 222 | </xsl:otherwise> |
83b66ddd | 223 | </xsl:choose> |
21f1b063 | 224 | </xsl:template> |
dc6025ff WP |
225 | |
226 | </xsl:stylesheet> |