]>
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 | |
7d424de1 | 6 | Copyright (C) 2007, 2008, 2009, 2010 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"> | |
bc81de36 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"> | |
bc81de36 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> | |
58 | <xsl:text>" { </xsl:text> | |
dc6025ff WP |
59 | <xsl:apply-templates select="state"/> |
60 | <xsl:text>} </xsl:text> | |
61 | </xsl:template> | |
62 | ||
63 | <xsl:template match="automaton/state"> | |
64 | <xsl:call-template name="output-node"> | |
65 | <xsl:with-param name="number" select="@number"/> | |
66 | <xsl:with-param name="label"> | |
67 | <xsl:value-of select="@number"/> | |
255a6b90 | 68 | <xsl:apply-templates select="itemset/item"/> |
dc6025ff WP |
69 | </xsl:with-param> |
70 | </xsl:call-template> | |
71 | <xsl:apply-templates select="actions/transitions"/> | |
72 | </xsl:template> | |
73 | ||
74 | <xsl:template match="actions/transitions"> | |
75 | <xsl:apply-templates select="transition"/> | |
76 | </xsl:template> | |
77 | ||
255a6b90 | 78 | <xsl:template match="item"> |
d4a26c48 | 79 | <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)"> |
255a6b90 JD |
80 | <xsl:with-param name="point" select="@point"/> |
81 | </xsl:apply-templates> | |
82 | <xsl:apply-templates select="lookaheads"/> | |
83 | </xsl:template> | |
84 | ||
dc6025ff | 85 | <xsl:template match="rule"> |
255a6b90 | 86 | <xsl:param name="point"/> |
21f1b063 | 87 | <xsl:text> </xsl:text> |
dc6025ff WP |
88 | <xsl:value-of select="lhs"/> |
89 | <xsl:text> -></xsl:text> | |
255a6b90 JD |
90 | <xsl:if test="$point = 0"> |
91 | <xsl:text> .</xsl:text> | |
92 | </xsl:if> | |
93 | <xsl:for-each select="rhs/symbol|rhs/empty"> | |
94 | <xsl:apply-templates select="."/> | |
95 | <xsl:if test="$point = position()"> | |
96 | <xsl:text> .</xsl:text> | |
97 | </xsl:if> | |
98 | </xsl:for-each> | |
dc6025ff WP |
99 | </xsl:template> |
100 | ||
101 | <xsl:template match="symbol"> | |
102 | <xsl:text> </xsl:text> | |
103 | <xsl:value-of select="."/> | |
104 | </xsl:template> | |
105 | ||
255a6b90 | 106 | <xsl:template match="empty"/> |
dc6025ff WP |
107 | |
108 | <xsl:template match="lookaheads"> | |
109 | <xsl:text>[</xsl:text> | |
110 | <xsl:apply-templates select="symbol"/> | |
111 | <xsl:text>]</xsl:text> | |
112 | </xsl:template> | |
113 | ||
114 | <xsl:template match="lookaheads/symbol"> | |
115 | <xsl:value-of select="."/> | |
116 | <xsl:if test="position() != last()"> | |
117 | <xsl:text>, </xsl:text> | |
118 | </xsl:if> | |
119 | </xsl:template> | |
120 | ||
121 | <xsl:template match="transition"> | |
122 | <xsl:call-template name="output-edge"> | |
123 | <xsl:with-param name="src" select="../../../@number"/> | |
124 | <xsl:with-param name="dst" select="@state"/> | |
125 | <xsl:with-param name="style"> | |
126 | <xsl:choose> | |
127 | <xsl:when test="@symbol = 'error'"> | |
128 | <xsl:text>dotted</xsl:text> | |
129 | </xsl:when> | |
130 | <xsl:when test="@type = 'shift'"> | |
131 | <xsl:text>solid</xsl:text> | |
132 | </xsl:when> | |
133 | <xsl:otherwise> | |
134 | <xsl:text>dashed</xsl:text> | |
135 | </xsl:otherwise> | |
136 | </xsl:choose> | |
137 | </xsl:with-param> | |
138 | <xsl:with-param name="label"> | |
139 | <xsl:if test="not(@symbol = 'error')"> | |
140 | <xsl:value-of select="@symbol"/> | |
141 | </xsl:if> | |
142 | </xsl:with-param> | |
143 | </xsl:call-template> | |
144 | </xsl:template> | |
145 | ||
146 | <xsl:template name="output-node"> | |
147 | <xsl:param name="number"/> | |
148 | <xsl:param name="label"/> | |
149 | <xsl:text> </xsl:text> | |
150 | <xsl:value-of select="$number"/> | |
151 | <xsl:text> [label="</xsl:text> | |
21f1b063 | 152 | <xsl:call-template name="escape"> |
dc6025ff | 153 | <xsl:with-param name="subject" select="$label"/> |
dc6025ff WP |
154 | </xsl:call-template> |
155 | <xsl:text>"] </xsl:text> | |
156 | </xsl:template> | |
157 | ||
158 | <xsl:template name="output-edge"> | |
159 | <xsl:param name="src"/> | |
160 | <xsl:param name="dst"/> | |
161 | <xsl:param name="style"/> | |
162 | <xsl:param name="label"/> | |
163 | <xsl:text> </xsl:text> | |
164 | <xsl:value-of select="$src"/> | |
165 | <xsl:text> -> </xsl:text> | |
166 | <xsl:value-of select="$dst"/> | |
167 | <xsl:text> [style=</xsl:text> | |
168 | <xsl:value-of select="$style"/> | |
169 | <xsl:if test="$label and $label != ''"> | |
170 | <xsl:text> label="</xsl:text> | |
21f1b063 | 171 | <xsl:call-template name="escape"> |
dc6025ff | 172 | <xsl:with-param name="subject" select="$label"/> |
dc6025ff WP |
173 | </xsl:call-template> |
174 | <xsl:text>"</xsl:text> | |
175 | </xsl:if> | |
176 | <xsl:text>] </xsl:text> | |
177 | </xsl:template> | |
178 | ||
21f1b063 | 179 | <xsl:template name="escape"> |
85a6eb13 | 180 | <xsl:param name="subject"/> <!-- required --> |
21f1b063 JD |
181 | <xsl:call-template name="string-replace"> |
182 | <xsl:with-param name="subject"> | |
183 | <xsl:call-template name="string-replace"> | |
184 | <xsl:with-param name="subject"> | |
185 | <xsl:call-template name="string-replace"> | |
186 | <xsl:with-param name="subject" select="$subject"/> | |
187 | <xsl:with-param name="search" select="'\'"/> | |
188 | <xsl:with-param name="replace" select="'\\'"/> | |
189 | </xsl:call-template> | |
190 | </xsl:with-param> | |
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="'\n'"/> | |
197 | </xsl:call-template> | |
198 | </xsl:template> | |
199 | ||
200 | <xsl:template name="string-replace"> | |
201 | <xsl:param name="subject"/> | |
202 | <xsl:param name="search"/> | |
203 | <xsl:param name="replace"/> | |
204 | <xsl:choose> | |
205 | <xsl:when test="contains($subject, $search)"> | |
206 | <xsl:variable name="before" select="substring-before($subject, $search)"/> | |
207 | <xsl:variable name="after" select="substring-after($subject, $search)"/> | |
208 | <xsl:value-of select="$before"/> | |
209 | <xsl:value-of select="$replace"/> | |
210 | <xsl:call-template name="string-replace"> | |
211 | <xsl:with-param name="subject" select="$after"/> | |
212 | <xsl:with-param name="search" select="$search"/> | |
213 | <xsl:with-param name="replace" select="$replace"/> | |
214 | </xsl:call-template> | |
41976786 | 215 | </xsl:when> |
21f1b063 | 216 | <xsl:otherwise> |
41976786 | 217 | <xsl:value-of select="$subject"/> |
21f1b063 | 218 | </xsl:otherwise> |
41976786 | 219 | </xsl:choose> |
21f1b063 | 220 | </xsl:template> |
dc6025ff WP |
221 | |
222 | </xsl:stylesheet> |