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"
29 xmlns:
bison=
"http://www.gnu.org/software/bison/">
31 <xsl:import href=
"bison.xsl"/>
32 <xsl:output method=
"text" encoding=
"UTF-8" indent=
"no"/>
34 <xsl:template match=
"/">
35 <xsl:apply-templates select=
"bison-xml-report"/>
38 <xsl:template match=
"bison-xml-report">
39 <xsl:apply-templates select=
"reductions"/>
40 <xsl:apply-templates select=
"rules-never-reduced"/>
41 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
42 <xsl:apply-templates select=
"grammar"/>
43 <xsl:apply-templates select=
"automaton"/>
46 <xsl:template match=
"rules-never-reduced">
48 <xsl:text>Rules never reduced
</xsl:text>
49 <xsl:apply-templates select=
"rule">
50 <xsl:with-param name=
"pad" select=
"'3'"/>
51 </xsl:apply-templates>
52 <xsl:text> </xsl:text>
56 <xsl:template match=
"reductions">
57 <xsl:apply-templates select=
"useless/nonterminals"/>
58 <xsl:apply-templates select=
"unused/terminals"/>
59 <xsl:apply-templates select=
"useless/rules"/>
62 <xsl:template match=
"useless/nonterminals">
63 <xsl:if test=
"nonterminal">
64 <xsl:text>Useless nonterminals
</xsl:text>
65 <xsl:for-each select=
"nonterminal">
66 <xsl:text> </xsl:text>
67 <xsl:value-of select=
"."/>
68 <xsl:text> </xsl:text>
70 <xsl:text> </xsl:text>
74 <xsl:template match=
"useless/rules">
76 <xsl:text>Useless rules
</xsl:text>
77 <xsl:apply-templates select=
"rule">
78 <xsl:with-param name=
"pad" select=
"'3'"/>
79 </xsl:apply-templates>
80 <xsl:text> </xsl:text>
84 <xsl:template match=
"unused/terminals">
85 <xsl:if test=
"terminal">
86 <xsl:text>Terminals which are not used
</xsl:text>
87 <xsl:for-each select=
"terminal">
88 <xsl:text> </xsl:text>
89 <xsl:value-of select=
"."/>
90 <xsl:text> </xsl:text>
92 <xsl:text> </xsl:text>
96 <xsl:template match=
"grammar">
97 <xsl:text>Grammar
</xsl:text>
98 <xsl:apply-templates select=
"rules/rule">
99 <xsl:with-param name=
"pad" select=
"'3'"/>
100 </xsl:apply-templates>
101 <xsl:text> </xsl:text>
102 <xsl:apply-templates select=
"terminals"/>
103 <xsl:apply-templates select=
"nonterminals"/>
106 <xsl:template match=
"grammar/terminals">
107 <xsl:text>Terminals, with rules where they appear
</xsl:text>
108 <xsl:apply-templates select=
"terminal"/>
109 <xsl:text> </xsl:text>
112 <xsl:template match=
"grammar/nonterminals">
113 <xsl:text>Nonterminals, with rules where they appear
</xsl:text>
114 <xsl:apply-templates select=
"nonterminal"/>
117 <xsl:template match=
"terminal">
118 <xsl:value-of select=
"@name"/>
119 <xsl:call-template name=
"line-wrap">
120 <xsl:with-param name=
"first-line-length">
122 <xsl:when test=
"string-length(@name) > 66">0</xsl:when>
124 <xsl:value-of select=
"66 - string-length(@name)" />
128 <xsl:with-param name=
"line-length" select=
"66" />
129 <xsl:with-param name=
"text">
130 <xsl:value-of select=
"concat(' (', @number, ')')"/>
131 <xsl:apply-templates select=
"rule" />
136 <xsl:template match=
"terminal/rule">
137 <xsl:text> </xsl:text>
138 <xsl:value-of select=
"."/>
141 <xsl:template match=
"nonterminal">
142 <xsl:value-of select=
"@name"/>
143 <xsl:value-of select=
"concat(' (', @number, ')')"/>
144 <xsl:text> </xsl:text>
145 <xsl:variable name=
"output">
146 <xsl:call-template name=
"line-wrap">
147 <xsl:with-param name=
"line-length" select=
"66" />
148 <xsl:with-param name=
"text">
149 <xsl:text> </xsl:text>
150 <xsl:if test=
"left/rule">
151 <xsl:text>on@left:
</xsl:text>
153 <xsl:apply-templates select=
"left/rule"/>
154 <xsl:if test=
"left/rule and right/rule">
155 <xsl:text>,
</xsl:text>
157 <xsl:if test=
"right/rule">
158 <xsl:text>on@right:
</xsl:text>
160 <xsl:apply-templates select=
"right/rule"/>
164 <xsl:value-of select=
"translate($output, '@', ' ')" />
167 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
168 <xsl:text> </xsl:text>
169 <xsl:value-of select=
"."/>
172 <xsl:template match=
"automaton" mode=
"conflicts">
173 <xsl:variable name=
"conflict-report">
174 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
176 <xsl:if test=
"string-length($conflict-report) != 0">
177 <xsl:value-of select=
"$conflict-report"/>
178 <xsl:text> </xsl:text>
182 <xsl:template match=
"state" mode=
"conflicts">
183 <xsl:variable name=
"conflict-counts">
184 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
187 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
190 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
192 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
193 <xsl:value-of select=
"concat('State ', @number, ' conflicts:')"/>
194 <xsl:if test=
"$sr-count > 0">
195 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
196 <xsl:if test=
"$rr-count > 0">
197 <xsl:value-of select=
"(',')"/>
200 <xsl:if test=
"$rr-count > 0">
201 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
203 <xsl:value-of select=
"' '"/>
207 <xsl:template match=
"automaton">
208 <xsl:apply-templates select=
"state">
209 <xsl:with-param name=
"pad" select=
"'3'"/>
210 </xsl:apply-templates>
213 <xsl:template match=
"automaton/state">
214 <xsl:param name=
"pad"/>
215 <xsl:text> </xsl:text>
216 <xsl:text>state
</xsl:text>
217 <xsl:value-of select=
"@number"/>
218 <xsl:text> </xsl:text>
219 <xsl:apply-templates select=
"itemset/item">
220 <xsl:with-param name=
"pad" select=
"$pad"/>
221 </xsl:apply-templates>
222 <xsl:apply-templates select=
"actions/transitions">
223 <xsl:with-param name=
"type" select=
"'shift'"/>
224 </xsl:apply-templates>
225 <xsl:apply-templates select=
"actions/errors"/>
226 <xsl:apply-templates select=
"actions/reductions"/>
227 <xsl:apply-templates select=
"actions/transitions">
228 <xsl:with-param name=
"type" select=
"'goto'"/>
229 </xsl:apply-templates>
230 <xsl:apply-templates select=
"solved-conflicts"/>
233 <xsl:template match=
"actions/transitions">
234 <xsl:param name=
"type"/>
235 <xsl:if test=
"transition[@type = $type]">
236 <xsl:text> </xsl:text>
237 <xsl:apply-templates select=
"transition[@type = $type]">
238 <xsl:with-param name=
"pad">
239 <xsl:call-template name=
"max-width-symbol">
240 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
243 </xsl:apply-templates>
247 <xsl:template match=
"actions/errors">
248 <xsl:if test=
"error">
249 <xsl:text> </xsl:text>
250 <xsl:apply-templates select=
"error">
251 <xsl:with-param name=
"pad">
252 <xsl:call-template name=
"max-width-symbol">
253 <xsl:with-param name=
"node" select=
"error"/>
256 </xsl:apply-templates>
260 <xsl:template match=
"actions/reductions">
261 <xsl:if test=
"reduction">
262 <xsl:text> </xsl:text>
263 <xsl:apply-templates select=
"reduction">
264 <xsl:with-param name=
"pad">
265 <xsl:call-template name=
"max-width-symbol">
266 <xsl:with-param name=
"node" select=
"reduction"/>
269 </xsl:apply-templates>
273 <xsl:template match=
"item">
274 <xsl:param name=
"pad"/>
275 <xsl:param name=
"prev-rule-number"
276 select=
"preceding-sibling::item[1]/@rule-number"/>
277 <xsl:apply-templates select=
"key('bison:ruleNumber', current()/@rule-number)">
278 <xsl:with-param name=
"itemset" select=
"'true'"/>
279 <xsl:with-param name=
"pad" select=
"$pad"/>
280 <xsl:with-param name=
"prev-lhs"
281 select=
"key('bison:ruleNumber', $prev-rule-number)/lhs[text()]"/>
282 <xsl:with-param name=
"point" select=
"@point"/>
283 <xsl:with-param name=
"lookaheads">
284 <xsl:apply-templates select=
"lookaheads"/>
286 </xsl:apply-templates>
289 <xsl:template match=
"rule">
290 <xsl:param name=
"itemset"/>
291 <xsl:param name=
"pad"/>
292 <xsl:param name=
"prev-lhs"/>
293 <xsl:param name=
"point"/>
294 <xsl:param name=
"lookaheads"/>
296 <xsl:if test=
"$itemset != 'true'
297 and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
298 <xsl:text> </xsl:text>
301 <xsl:text> </xsl:text>
302 <xsl:call-template name=
"lpad">
303 <xsl:with-param name=
"str" select=
"string(@number)"/>
304 <xsl:with-param name=
"pad" select=
"number($pad)"/>
306 <xsl:text> </xsl:text>
310 <xsl:when test=
"$itemset != 'true'
311 and preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
312 <xsl:call-template name=
"lpad">
313 <xsl:with-param name=
"str" select=
"'|'"/>
314 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 1"/>
317 <xsl:when test=
"$itemset = 'true' and $prev-lhs = lhs[text()]">
318 <xsl:call-template name=
"lpad">
319 <xsl:with-param name=
"str" select=
"'|'"/>
320 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 1"/>
324 <xsl:value-of select=
"lhs"/>
325 <xsl:text>:
</xsl:text>
330 <xsl:for-each select=
"rhs/*">
331 <xsl:if test=
"position() = $point + 1">
332 <xsl:text> .
</xsl:text>
334 <xsl:if test=
"$itemset = 'true' and name(.) != 'empty'">
335 <xsl:apply-templates select=
"."/>
337 <xsl:if test=
"$itemset != 'true'">
338 <xsl:apply-templates select=
"."/>
340 <xsl:if test=
"position() = last() and position() = $point">
341 <xsl:text> .
</xsl:text>
344 <xsl:if test=
"$lookaheads">
345 <xsl:value-of select=
"$lookaheads"/>
348 <xsl:text> </xsl:text>
351 <xsl:template match=
"symbol">
352 <xsl:text> </xsl:text>
353 <xsl:value-of select=
"."/>
356 <xsl:template match=
"empty">
357 <xsl:text> /* empty */
</xsl:text>
360 <xsl:template match=
"lookaheads">
361 <xsl:text> [
</xsl:text>
362 <xsl:apply-templates select=
"symbol"/>
363 <xsl:text>]
</xsl:text>
366 <xsl:template match=
"lookaheads/symbol">
367 <xsl:value-of select=
"."/>
368 <xsl:if test=
"position() != last()">
369 <xsl:text>,
</xsl:text>
373 <xsl:template match=
"transition">
374 <xsl:param name=
"pad"/>
375 <xsl:text> </xsl:text>
376 <xsl:call-template name=
"rpad">
377 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
378 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
381 <xsl:when test=
"@type = 'shift'">
382 <xsl:text>shift, and go to state
</xsl:text>
383 <xsl:value-of select=
"@state"/>
385 <xsl:when test=
"@type = 'goto'">
386 <xsl:text>go to state
</xsl:text>
387 <xsl:value-of select=
"@state"/>
390 <xsl:text> </xsl:text>
393 <xsl:template match=
"error">
394 <xsl:param name=
"pad"/>
395 <xsl:text> </xsl:text>
396 <xsl:call-template name=
"rpad">
397 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
398 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
400 <xsl:text>error
</xsl:text>
401 <xsl:text> (
</xsl:text>
402 <xsl:value-of select=
"text()"/>
403 <xsl:text>)
</xsl:text>
404 <xsl:text> </xsl:text>
407 <xsl:template match=
"reduction">
408 <xsl:param name=
"pad"/>
409 <xsl:text> </xsl:text>
410 <xsl:call-template name=
"rpad">
411 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
412 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
414 <xsl:if test=
"@enabled = 'false'">
415 <xsl:text>[
</xsl:text>
418 <xsl:when test=
"@rule = 'accept'">
419 <xsl:text>accept
</xsl:text>
422 <xsl:text>reduce using rule
</xsl:text>
423 <xsl:value-of select=
"@rule"/>
424 <xsl:text> (
</xsl:text>
426 select=
"key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
427 <xsl:text>)
</xsl:text>
430 <xsl:if test=
"@enabled = 'false'">
431 <xsl:text>]
</xsl:text>
433 <xsl:text> </xsl:text>
436 <xsl:template match=
"solved-conflicts">
437 <xsl:if test=
"resolution">
438 <xsl:text> </xsl:text>
439 <xsl:apply-templates select=
"resolution"/>
443 <xsl:template match=
"resolution">
444 <xsl:text> Conflict between rule
</xsl:text>
445 <xsl:value-of select=
"@rule"/>
446 <xsl:text> and token
</xsl:text>
447 <xsl:value-of select=
"@symbol"/>
448 <xsl:text> resolved as
</xsl:text>
449 <xsl:if test=
"@type = 'error'">
450 <xsl:text>an
</xsl:text>
452 <xsl:value-of select=
"@type"/>
453 <xsl:text> (
</xsl:text>
454 <xsl:value-of select=
"."/>
455 <xsl:text>).
</xsl:text>
458 <xsl:template name=
"max-width-symbol">
459 <xsl:param name=
"node"/>
460 <xsl:variable name=
"longest">
461 <xsl:for-each select=
"$node">
462 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
464 <xsl:if test=
"position() = 1">
465 <xsl:value-of select=
"string-length(@symbol)"/>
469 <xsl:value-of select=
"$longest"/>
472 <xsl:template name=
"lpad">
473 <xsl:param name=
"str" select=
"''"/>
474 <xsl:param name=
"pad" select=
"0"/>
475 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
477 <xsl:when test=
"$diff < 0">
478 <xsl:value-of select=
"$str"/>
481 <xsl:call-template name=
"space">
482 <xsl:with-param name=
"repeat" select=
"$diff"/>
484 <xsl:value-of select=
"$str"/>
489 <xsl:template name=
"rpad">
490 <xsl:param name=
"str" select=
"''"/>
491 <xsl:param name=
"pad" select=
"0"/>
492 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
494 <xsl:when test=
"$diff < 0">
495 <xsl:value-of select=
"$str"/>
498 <xsl:value-of select=
"$str"/>
499 <xsl:call-template name=
"space">
500 <xsl:with-param name=
"repeat" select=
"$diff"/>
506 <xsl:template name=
"space">
507 <xsl:param name=
"repeat">0</xsl:param>
508 <xsl:param name=
"fill" select=
"' '"/>
509 <xsl:if test=
"number($repeat) >= 1">
510 <xsl:call-template name=
"space">
511 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
512 <xsl:with-param name=
"fill" select=
"$fill"/>
514 <xsl:value-of select=
"$fill"/>
518 <xsl:template name=
"line-wrap">
519 <xsl:param name=
"line-length"/> <!-- required -->
520 <xsl:param name=
"first-line-length" select=
"$line-length"/>
521 <xsl:param name=
"text"/> <!-- required -->
523 <xsl:when test=
"normalize-space($text) = ''" />
524 <xsl:when test=
"string-length($text) <= $first-line-length">
525 <xsl:value-of select=
"concat($text, ' ')" />
528 <xsl:variable name=
"break-pos">
529 <xsl:call-template name=
"ws-search">
530 <xsl:with-param name=
"text" select=
"$text" />
531 <xsl:with-param name=
"start" select=
"$first-line-length+1" />
534 <xsl:value-of select=
"substring($text, 1, $break-pos - 1)" />
535 <xsl:text> </xsl:text>
536 <xsl:call-template name=
"line-wrap">
537 <xsl:with-param name=
"line-length" select=
"$line-length" />
539 name=
"text" select=
"concat(' ', substring($text, $break-pos+1))"
546 <xsl:template name=
"ws-search">
547 <xsl:param name=
"text"/> <!-- required -->
548 <xsl:param name=
"start"/> <!-- required -->
549 <xsl:variable name=
"search-text" select=
"substring($text, $start)" />
551 <xsl:when test=
"not(contains($search-text, ' '))">
552 <xsl:value-of select=
"string-length($text)+1" />
556 select=
"$start + string-length(substring-before($search-text, ' '))"