1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2text.xsl - transform Bison XML Report into plain text.
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=
"reductions"/>
38 <xsl:apply-templates select=
"rules-never-reduced"/>
39 <xsl:apply-templates select=
"conflicts"/>
40 <xsl:apply-templates select=
"grammar"/>
41 <xsl:apply-templates select=
"automaton"/>
44 <xsl:template match=
"rules-never-reduced">
46 <xsl:text>Rules never reduced
</xsl:text>
47 <xsl:apply-templates select=
"rule">
48 <xsl:with-param name=
"pad" select=
"'3'"/>
49 </xsl:apply-templates>
50 <xsl:text> </xsl:text>
54 <xsl:template match=
"reductions">
55 <xsl:apply-templates select=
"useless/nonterminals"/>
56 <xsl:apply-templates select=
"unused/terminals"/>
57 <xsl:apply-templates select=
"useless/rules"/>
60 <xsl:template match=
"useless/nonterminals">
61 <xsl:if test=
"nonterminal">
62 <xsl:text>Useless nonterminals
</xsl:text>
63 <xsl:for-each select=
"nonterminal">
64 <xsl:text> </xsl:text>
65 <xsl:value-of select=
"."/>
66 <xsl:text> </xsl:text>
68 <xsl:text> </xsl:text>
72 <xsl:template match=
"useless/rules">
74 <xsl:text>Useless rules
</xsl:text>
75 <xsl:apply-templates select=
"rule">
76 <xsl:with-param name=
"pad" select=
"'3'"/>
77 </xsl:apply-templates>
78 <xsl:text> </xsl:text>
82 <xsl:template match=
"unused/terminals">
83 <xsl:if test=
"terminal">
84 <xsl:text>Terminals which are not used
</xsl:text>
85 <xsl:for-each select=
"terminal">
86 <xsl:text> </xsl:text>
87 <xsl:value-of select=
"."/>
88 <xsl:text> </xsl:text>
90 <xsl:text> </xsl:text>
94 <xsl:template match=
"conflicts">
95 <xsl:if test=
"conflict">
96 <xsl:apply-templates select=
"conflict"/>
97 <xsl:text> </xsl:text>
101 <xsl:template match=
"conflict">
102 <xsl:text>State
</xsl:text>
103 <xsl:value-of select=
"@state"/>
104 <xsl:text> conflicts:
</xsl:text>
105 <xsl:value-of select=
"@num"/>
106 <xsl:text> </xsl:text>
107 <xsl:value-of select=
"@type"/>
108 <xsl:text> </xsl:text>
111 <xsl:template match=
"grammar">
112 <xsl:text>Grammar
</xsl:text>
113 <xsl:apply-templates select=
"rules/rule">
114 <xsl:with-param name=
"pad" select=
"'3'"/>
115 </xsl:apply-templates>
116 <xsl:text> </xsl:text>
117 <xsl:apply-templates select=
"terminals"/>
118 <xsl:apply-templates select=
"nonterminals"/>
121 <xsl:template match=
"grammar/terminals">
122 <xsl:text>Terminals, with rules where they appear
</xsl:text>
123 <xsl:apply-templates select=
"terminal"/>
124 <xsl:text> </xsl:text>
127 <xsl:template match=
"grammar/nonterminals">
128 <xsl:text>Nonterminals, with rules where they appear
</xsl:text>
129 <xsl:apply-templates select=
"nonterminal"/>
132 <xsl:template match=
"terminal">
133 <xsl:value-of select=
"@symbol"/>
134 <xsl:value-of select=
"concat(' (', @type, ')')"/>
135 <xsl:apply-templates select=
"rule"/>
136 <xsl:text> </xsl:text>
139 <xsl:template match=
"terminal/rule">
140 <xsl:text> </xsl:text>
141 <xsl:value-of select=
"."/>
144 <xsl:template match=
"nonterminal">
145 <xsl:value-of select=
"@symbol"/>
146 <xsl:value-of select=
"concat(' (', @type, ')')"/>
147 <xsl:text> </xsl:text>
148 <xsl:if test=
"left/rule">
149 <xsl:text>on left:
</xsl:text>
151 <xsl:apply-templates select=
"left/rule"/>
152 <xsl:if test=
"left/rule and right/rule">
153 <xsl:text>,
</xsl:text>
155 <xsl:if test=
"right/rule">
156 <xsl:text>on right:
</xsl:text>
158 <xsl:apply-templates select=
"right/rule"/>
159 <xsl:text> </xsl:text>
162 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
163 <xsl:text> </xsl:text>
164 <xsl:value-of select=
"."/>
167 <xsl:template match=
"automaton">
168 <xsl:apply-templates select=
"state">
169 <xsl:with-param name=
"pad" select=
"'3'"/>
170 </xsl:apply-templates>
173 <xsl:template match=
"automaton/state">
174 <xsl:param name=
"pad"/>
175 <xsl:text> </xsl:text>
176 <xsl:text>state
</xsl:text>
177 <xsl:value-of select=
"@number"/>
178 <xsl:text> </xsl:text>
179 <xsl:apply-templates select=
"itemset/rule">
180 <xsl:with-param name=
"pad" select=
"$pad"/>
181 </xsl:apply-templates>
182 <xsl:apply-templates select=
"actions/transitions">
183 <xsl:with-param name=
"type" select=
"'shift'"/>
184 </xsl:apply-templates>
185 <xsl:apply-templates select=
"actions/errors"/>
186 <xsl:apply-templates select=
"actions/reductions"/>
187 <xsl:apply-templates select=
"actions/transitions">
188 <xsl:with-param name=
"type" select=
"'goto'"/>
189 </xsl:apply-templates>
190 <xsl:apply-templates select=
"solved-conflicts"/>
193 <xsl:template match=
"actions/transitions">
194 <xsl:param name=
"type"/>
195 <xsl:if test=
"transition[@type = $type]">
196 <xsl:text> </xsl:text>
197 <xsl:apply-templates select=
"transition[@type = $type]">
198 <xsl:with-param name=
"pad">
199 <xsl:call-template name=
"max-width-symbol">
200 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
203 </xsl:apply-templates>
207 <xsl:template match=
"actions/errors">
208 <xsl:if test=
"error">
209 <xsl:text> </xsl:text>
210 <xsl:apply-templates select=
"error">
211 <xsl:with-param name=
"pad">
212 <xsl:call-template name=
"max-width-symbol">
213 <xsl:with-param name=
"node" select=
"error"/>
216 </xsl:apply-templates>
220 <xsl:template match=
"actions/reductions">
221 <xsl:if test=
"reduction">
222 <xsl:text> </xsl:text>
223 <xsl:apply-templates select=
"reduction">
224 <xsl:with-param name=
"pad">
225 <xsl:call-template name=
"max-width-symbol">
226 <xsl:with-param name=
"node" select=
"reduction"/>
229 </xsl:apply-templates>
233 <xsl:template match=
"rule">
234 <xsl:param name=
"pad"/>
235 <xsl:if test=
"not(name(..) = 'itemset') and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
236 <xsl:text> </xsl:text>
238 <xsl:text> </xsl:text>
239 <xsl:call-template name=
"lpad">
240 <xsl:with-param name=
"str" select=
"string(@number)"/>
241 <xsl:with-param name=
"pad" select=
"number($pad)"/>
243 <xsl:text> </xsl:text>
245 <xsl:when test=
"preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
246 <xsl:call-template name=
"lpad">
247 <xsl:with-param name=
"str" select=
"'|'"/>
248 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 1"/>
252 <xsl:value-of select=
"lhs"/>
253 <xsl:text>:
</xsl:text>
256 <xsl:apply-templates select=
"rhs/symbol|rhs/point|rhs/empty"/>
257 <xsl:apply-templates select=
"lookaheads"/>
258 <xsl:text> </xsl:text>
261 <xsl:template match=
"symbol">
262 <xsl:text> </xsl:text>
263 <xsl:value-of select=
"."/>
266 <xsl:template match=
"point">
267 <xsl:text> .
</xsl:text>
270 <xsl:template match=
"empty">
271 <xsl:text> /* empty */
</xsl:text>
274 <xsl:template match=
"lookaheads">
275 <xsl:text> [
</xsl:text>
276 <xsl:apply-templates select=
"symbol"/>
277 <xsl:text>]
</xsl:text>
280 <xsl:template match=
"lookaheads/symbol">
281 <xsl:value-of select=
"."/>
282 <xsl:if test=
"position() != last()">
283 <xsl:text>,
</xsl:text>
287 <xsl:template match=
"transition">
288 <xsl:param name=
"pad"/>
289 <xsl:text> </xsl:text>
290 <xsl:call-template name=
"rpad">
291 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
292 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
295 <xsl:when test=
"@type = 'shift'">
296 <xsl:text>shift, and go to state
</xsl:text>
297 <xsl:value-of select=
"@state"/>
299 <xsl:when test=
"@type = 'goto'">
300 <xsl:text>go to state
</xsl:text>
301 <xsl:value-of select=
"@state"/>
304 <xsl:text> </xsl:text>
307 <xsl:template match=
"error">
308 <xsl:param name=
"pad"/>
309 <xsl:text> </xsl:text>
310 <xsl:call-template name=
"rpad">
311 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
312 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
314 <xsl:text>error
</xsl:text>
315 <xsl:text> (
</xsl:text>
316 <xsl:value-of select=
"text()"/>
317 <xsl:text>)
</xsl:text>
318 <xsl:text> </xsl:text>
321 <xsl:template match=
"reduction">
322 <xsl:param name=
"pad"/>
323 <xsl:text> </xsl:text>
324 <xsl:call-template name=
"rpad">
325 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
326 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
328 <xsl:if test=
"@enabled = 'false'">
329 <xsl:text>[
</xsl:text>
332 <xsl:when test=
"@rule = 'accept'">
333 <xsl:text>accept
</xsl:text>
336 <xsl:text>reduce using rule
</xsl:text>
337 <xsl:value-of select=
"@rule"/>
338 <xsl:text> (
</xsl:text>
340 select=
"/bison-xml-report/grammar/rules/rule[@number = current()/@rule]/lhs[text()]"/>
341 <xsl:text>)
</xsl:text>
344 <xsl:if test=
"@enabled = 'false'">
345 <xsl:text>]
</xsl:text>
347 <xsl:text> </xsl:text>
350 <xsl:template match=
"solved-conflicts">
351 <xsl:if test=
"resolution">
352 <xsl:text> </xsl:text>
353 <xsl:apply-templates select=
"resolution"/>
357 <xsl:template match=
"resolution">
358 <xsl:text> Conflict between rule
</xsl:text>
359 <xsl:value-of select=
"@rule"/>
360 <xsl:text> and token
</xsl:text>
361 <xsl:value-of select=
"@symbol"/>
362 <xsl:text> resolved as
</xsl:text>
363 <xsl:if test=
"@type = 'error'">
364 <xsl:text>an
</xsl:text>
366 <xsl:value-of select=
"@type"/>
367 <xsl:text> (
</xsl:text>
368 <xsl:value-of select=
"."/>
369 <xsl:text>).
</xsl:text>
372 <xsl:template name=
"max-width-symbol">
373 <xsl:param name=
"node"/>
374 <xsl:variable name=
"longest">
375 <xsl:for-each select=
"$node">
376 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
378 <xsl:if test=
"position() = 1">
379 <xsl:value-of select=
"string-length(@symbol)"/>
383 <xsl:value-of select=
"$longest"/>
386 <xsl:template name=
"lpad">
387 <xsl:param name=
"str" select=
"''"/>
388 <xsl:param name=
"pad" select=
"0"/>
389 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
391 <xsl:when test=
"$diff < 0">
392 <xsl:value-of select=
"$str"/>
395 <xsl:call-template name=
"space">
396 <xsl:with-param name=
"repeat" select=
"$diff"/>
398 <xsl:value-of select=
"$str"/>
403 <xsl:template name=
"rpad">
404 <xsl:param name=
"str" select=
"''"/>
405 <xsl:param name=
"pad" select=
"0"/>
406 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
408 <xsl:when test=
"$diff < 0">
409 <xsl:value-of select=
"$str"/>
412 <xsl:value-of select=
"$str"/>
413 <xsl:call-template name=
"space">
414 <xsl:with-param name=
"repeat" select=
"$diff"/>
420 <xsl:template name=
"space">
421 <xsl:param name=
"repeat">0</xsl:param>
422 <xsl:param name=
"fill" select=
"' '"/>
423 <xsl:if test=
"number($repeat) >= 1">
424 <xsl:call-template name=
"space">
425 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
426 <xsl:with-param name=
"fill" select=
"$fill"/>
428 <xsl:value-of select=
"$fill"/>