1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2html.xsl - transform Bison XML Report into XHTML.
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=
"http://www.w3.org/1999/xhtml"
30 xmlns:
bison=
"http://www.gnu.org/software/bison/">
32 <xsl:import href=
"bison.xsl"/>
34 <xsl:output method=
"xml" encoding=
"UTF-8"
35 doctype-public=
"-//W3C//DTD XHTML 1.0 Strict//EN"
36 doctype-system=
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
39 <xsl:template match=
"/">
42 <title>GNU Bison XML Automaton Report
</title>
43 <style type=
"text/css"><![CDATA[
45 font-family: "Nimbus Sans L", Arial, sans-serif;
50 text-decoration: none;
54 text-decoration: none;
60 text-decoration: underline;
66 font-family: monospace;
70 list-style-type: decimal;
73 list-style-type: lower-alpha;
85 <xsl:apply-templates select=
"bison-xml-report"/>
86 <xsl:text> </xsl:text>
87 <div id=
"footer"><hr />
88 <a href=
"http://www.gnu.org/software/bison/" title=
"GNU Bison">
89 GNU Bison
<xsl:value-of select=
"/bison-xml-report/@version"/></a>
90 XML Automaton Report, written by
91 <a href=
"http://www.gnu.org.ua/~polak/" title=
"Wojciech Polak">Wojciech Polak
</a>.
92 Copyright (C)
2007 Free Software Foundation, Inc.
<br />
93 Verbatim copying and distribution of this entire page is permitted
94 in any medium, provided this notice is preserved.
</div>
99 <xsl:template match=
"bison-xml-report">
100 <h1>GNU Bison XML Automaton Report
</h1>
102 input grammar:
<span class=
"i"><xsl:value-of select=
"filename"/></span>
105 <xsl:text> </xsl:text>
106 <h3>Table of Contents
</h3>
109 <a href=
"#reductions">Reductions
</a>
110 <ul class=
"lower-alpha">
111 <li><a href=
"#nonterminals_useless_in_grammar">Nonterminals useless in grammar
</a></li>
112 <li><a href=
"#unused_terminals">Unused terminals
</a></li>
113 <li><a href=
"#rules_useless_in_grammar">Rules useless in grammar
</a></li>
114 <xsl:if test=
"rules-useless-in-parser/rule">
115 <li><a href=
"#rules_useless_in_parser">Rules useless in parser due to conflicts
</a></li>
119 <li><a href=
"#conflicts">Conflicts
</a></li>
121 <a href=
"#grammar">Grammar
</a>
122 <ul class=
"lower-alpha">
123 <li><a href=
"#grammar">Itemset
</a></li>
124 <li><a href=
"#terminals">Terminal symbols
</a></li>
125 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
128 <li><a href=
"#automaton">Automaton
</a></li>
130 <xsl:apply-templates select=
"reductions"/>
131 <xsl:apply-templates select=
"rules-useless-in-parser"/>
132 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
133 <xsl:apply-templates select=
"grammar"/>
134 <xsl:apply-templates select=
"automaton"/>
137 <xsl:template match=
"rules-useless-in-parser">
140 <a name=
"rules_useless_in_parser"/>
141 <xsl:text> Rules useless in parser due to conflicts
</xsl:text>
143 <xsl:text> </xsl:text>
145 <xsl:apply-templates select=
"rule">
146 <xsl:with-param name=
"pad" select=
"'3'"/>
147 </xsl:apply-templates>
149 <xsl:text> </xsl:text>
153 <xsl:template match=
"reductions">
155 <a name=
"reductions"/>
156 <xsl:text> Reductions
</xsl:text>
158 <xsl:apply-templates select=
"useless-in-grammar/nonterminals"/>
159 <xsl:apply-templates select=
"unused/terminals"/>
160 <xsl:apply-templates select=
"useless-in-grammar/rules"/>
163 <xsl:template match=
"useless-in-grammar/nonterminals">
165 <a name=
"nonterminals_useless_in_grammar"/>
166 <xsl:text> Nonterminals useless in grammar
</xsl:text>
168 <xsl:text> </xsl:text>
169 <xsl:if test=
"nonterminal">
171 <xsl:for-each select=
"nonterminal">
172 <xsl:text> </xsl:text>
173 <xsl:value-of select=
"."/>
174 <xsl:text> </xsl:text>
176 <xsl:text> </xsl:text>
181 <xsl:template match=
"useless-in-grammar/rules">
183 <a name=
"rules_useless_in_grammar"/>
184 <xsl:text> Rules useless in grammar
</xsl:text>
186 <xsl:text> </xsl:text>
189 <xsl:apply-templates select=
"rule">
190 <xsl:with-param name=
"pad" select=
"'3'"/>
191 </xsl:apply-templates>
192 <xsl:text> </xsl:text>
197 <xsl:template match=
"unused/terminals">
199 <a name=
"unused_terminals"/>
200 <xsl:text> Terminals which are not used
</xsl:text>
202 <xsl:text> </xsl:text>
203 <xsl:if test=
"terminal">
205 <xsl:for-each select=
"terminal">
206 <xsl:text> </xsl:text>
207 <xsl:value-of select=
"."/>
208 <xsl:text> </xsl:text>
210 <xsl:text> </xsl:text>
215 <xsl:template match=
"automaton" mode=
"conflicts">
217 <a name=
"conflicts"/>
218 <xsl:text> Conflicts
</xsl:text>
220 <xsl:text> </xsl:text>
221 <xsl:variable name=
"conflict-report">
222 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
224 <xsl:if test=
"string-length($conflict-report) != 0">
226 <xsl:copy-of select=
"$conflict-report"/>
227 <xsl:text> </xsl:text>
232 <xsl:template match=
"state" mode=
"conflicts">
233 <xsl:variable name=
"conflict-counts">
234 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
237 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
240 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
242 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
244 <xsl:attribute name=
"href">
245 <xsl:value-of select=
"concat('#state_', @number)"/>
247 <xsl:value-of select=
"concat('State ', @number)"/>
249 <xsl:text> conflicts:
</xsl:text>
250 <xsl:if test=
"$sr-count > 0">
251 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
252 <xsl:if test=
"$rr-count > 0">
253 <xsl:value-of select=
"(',')"/>
256 <xsl:if test=
"$rr-count > 0">
257 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
259 <xsl:value-of select=
"' '"/>
263 <xsl:template match=
"grammar">
266 <xsl:text> Grammar
</xsl:text>
268 <xsl:text> </xsl:text>
270 <xsl:apply-templates select=
"rules/rule">
271 <xsl:with-param name=
"pad" select=
"'3'"/>
272 </xsl:apply-templates>
274 <xsl:text> </xsl:text>
275 <xsl:apply-templates select=
"terminals"/>
276 <xsl:apply-templates select=
"nonterminals"/>
279 <xsl:template match=
"grammar/terminals">
281 <a name=
"terminals"/>
282 <xsl:text> Terminals, with rules where they appear
</xsl:text>
284 <xsl:text> </xsl:text>
286 <xsl:apply-templates select=
"terminal"/>
288 <xsl:text> </xsl:text>
291 <xsl:template match=
"grammar/nonterminals">
293 <a name=
"nonterminals"/>
294 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
296 <xsl:text> </xsl:text>
298 <xsl:apply-templates select=
"nonterminal"/>
302 <xsl:template match=
"terminal">
303 <b><xsl:value-of select=
"@name"/></b>
304 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
305 <xsl:apply-templates select=
"rule"/>
306 <xsl:text> </xsl:text>
309 <xsl:template match=
"terminal/rule">
310 <xsl:text> </xsl:text>
312 <xsl:attribute name=
"href">
313 <xsl:value-of select=
"concat('#rule_', .)"/>
315 <xsl:value-of select=
"."/>
319 <xsl:template match=
"nonterminal">
320 <b><xsl:value-of select=
"@name"/></b>
321 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
322 <xsl:text> </xsl:text>
323 <xsl:if test=
"left/rule">
324 <xsl:text>on left:
</xsl:text>
326 <xsl:apply-templates select=
"left/rule"/>
327 <xsl:if test=
"left/rule and right/rule">
328 <xsl:text> </xsl:text>
330 <xsl:if test=
"right/rule">
331 <xsl:text>on right:
</xsl:text>
333 <xsl:apply-templates select=
"right/rule"/>
334 <xsl:text> </xsl:text>
337 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
338 <xsl:text> </xsl:text>
340 <xsl:attribute name=
"href">
341 <xsl:value-of select=
"concat('#rule_', .)"/>
343 <xsl:value-of select=
"."/>
347 <xsl:template match=
"automaton">
349 <a name=
"automaton"/>
350 <xsl:text> Automaton
</xsl:text>
352 <xsl:apply-templates select=
"state">
353 <xsl:with-param name=
"pad" select=
"'3'"/>
354 </xsl:apply-templates>
357 <xsl:template match=
"automaton/state">
358 <xsl:param name=
"pad"/>
359 <xsl:text> </xsl:text>
362 <xsl:attribute name=
"name">
363 <xsl:value-of select=
"concat('state_', @number)"/>
366 <xsl:text>state
</xsl:text>
367 <xsl:value-of select=
"@number"/>
369 <xsl:text> </xsl:text>
371 <xsl:apply-templates select=
"itemset/item">
372 <xsl:with-param name=
"pad" select=
"$pad"/>
373 </xsl:apply-templates>
374 <xsl:apply-templates select=
"actions/transitions">
375 <xsl:with-param name=
"type" select=
"'shift'"/>
376 </xsl:apply-templates>
377 <xsl:apply-templates select=
"actions/errors"/>
378 <xsl:apply-templates select=
"actions/reductions"/>
379 <xsl:apply-templates select=
"actions/transitions">
380 <xsl:with-param name=
"type" select=
"'goto'"/>
381 </xsl:apply-templates>
382 <xsl:apply-templates select=
"solved-conflicts"/>
386 <xsl:template match=
"actions/transitions">
387 <xsl:param name=
"type"/>
388 <xsl:if test=
"transition[@type = $type]">
389 <xsl:text> </xsl:text>
390 <xsl:apply-templates select=
"transition[@type = $type]">
391 <xsl:with-param name=
"pad">
392 <xsl:call-template name=
"max-width-symbol">
393 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
396 </xsl:apply-templates>
400 <xsl:template match=
"actions/errors">
401 <xsl:if test=
"error">
402 <xsl:text> </xsl:text>
403 <xsl:apply-templates select=
"error">
404 <xsl:with-param name=
"pad">
405 <xsl:call-template name=
"max-width-symbol">
406 <xsl:with-param name=
"node" select=
"error"/>
409 </xsl:apply-templates>
413 <xsl:template match=
"actions/reductions">
414 <xsl:if test=
"reduction">
415 <xsl:text> </xsl:text>
416 <xsl:apply-templates select=
"reduction">
417 <xsl:with-param name=
"pad">
418 <xsl:call-template name=
"max-width-symbol">
419 <xsl:with-param name=
"node" select=
"reduction"/>
422 </xsl:apply-templates>
426 <xsl:template match=
"item">
427 <xsl:param name=
"pad"/>
428 <xsl:param name=
"prev-rule-number"
429 select=
"preceding-sibling::item[1]/@rule-number"/>
430 <xsl:apply-templates select=
"key('bison:ruleNumber', current()/@rule-number)">
431 <xsl:with-param name=
"itemset" select=
"'true'"/>
432 <xsl:with-param name=
"pad" select=
"$pad"/>
433 <xsl:with-param name=
"prev-lhs"
434 select=
"key('bison:ruleNumber', $prev-rule-number)/lhs[text()]"/>
435 <xsl:with-param name=
"point" select=
"@point"/>
436 <xsl:with-param name=
"lookaheads">
437 <xsl:apply-templates select=
"lookaheads"/>
439 </xsl:apply-templates>
442 <xsl:template match=
"rule">
443 <xsl:param name=
"itemset"/>
444 <xsl:param name=
"pad"/>
445 <xsl:param name=
"prev-lhs"/>
446 <xsl:param name=
"point"/>
447 <xsl:param name=
"lookaheads"/>
449 <xsl:if test=
"$itemset != 'true'
450 and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
451 <xsl:text> </xsl:text>
454 <xsl:if test=
"$itemset != 'true'">
456 <xsl:attribute name=
"name">
457 <xsl:value-of select=
"concat('rule_', @number)"/>
461 <xsl:text> </xsl:text>
464 <xsl:when test=
"$itemset = 'true'">
466 <xsl:attribute name=
"href">
467 <xsl:value-of select=
"concat('#rule_', @number)"/>
469 <xsl:call-template name=
"lpad">
470 <xsl:with-param name=
"str" select=
"string(@number)"/>
471 <xsl:with-param name=
"pad" select=
"number($pad)"/>
476 <xsl:call-template name=
"lpad">
477 <xsl:with-param name=
"str" select=
"string(@number)"/>
478 <xsl:with-param name=
"pad" select=
"number($pad)"/>
482 <xsl:text> </xsl:text>
486 <xsl:when test=
"$itemset != 'true'
487 and preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
488 <xsl:call-template name=
"lpad">
489 <xsl:with-param name=
"str" select=
"'|'"/>
490 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
493 <xsl:when test=
"$itemset = 'true' and $prev-lhs = lhs[text()]">
494 <xsl:call-template name=
"lpad">
495 <xsl:with-param name=
"str" select=
"'|'"/>
496 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
501 <xsl:value-of select=
"lhs"/>
503 <xsl:text> →</xsl:text>
508 <xsl:for-each select=
"rhs/*">
509 <xsl:if test=
"position() = $point + 1">
510 <xsl:text> </xsl:text>
511 <span class=
"point">.
</span>
513 <xsl:if test=
"$itemset = 'true' and name(.) != 'empty'">
514 <xsl:apply-templates select=
"."/>
516 <xsl:if test=
"$itemset != 'true'">
517 <xsl:apply-templates select=
"."/>
519 <xsl:if test=
"position() = last() and position() = $point">
520 <xsl:text> </xsl:text>
521 <span class=
"point">.
</span>
524 <xsl:if test=
"$lookaheads">
525 <xsl:value-of select=
"$lookaheads"/>
528 <xsl:text> </xsl:text>
531 <xsl:template match=
"symbol">
532 <xsl:text> </xsl:text>
534 <xsl:when test=
"@class = 'nonterminal'">
535 <span class=
"i"><xsl:value-of select=
"."/></span>
538 <b><xsl:value-of select=
"."/></b>
543 <xsl:template match=
"empty">
544 <xsl:text> ε</xsl:text>
547 <xsl:template match=
"lookaheads">
548 <xsl:text> [
</xsl:text>
549 <xsl:apply-templates select=
"symbol"/>
550 <xsl:text>]
</xsl:text>
553 <xsl:template match=
"lookaheads/symbol">
554 <xsl:value-of select=
"."/>
555 <xsl:if test=
"position() != last()">
556 <xsl:text>,
</xsl:text>
560 <xsl:template match=
"transition">
561 <xsl:param name=
"pad"/>
562 <xsl:text> </xsl:text>
563 <xsl:call-template name=
"rpad">
564 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
565 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
568 <xsl:when test=
"@type = 'shift'">
570 <xsl:attribute name=
"href">
571 <xsl:value-of select=
"concat('#state_', @state)"/>
573 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
576 <xsl:when test=
"@type = 'goto'">
578 <xsl:attribute name=
"href">
579 <xsl:value-of select=
"concat('#state_', @state)"/>
581 <xsl:value-of select=
"concat('go to state ', @state)"/>
585 <xsl:text> </xsl:text>
588 <xsl:template match=
"error">
589 <xsl:param name=
"pad"/>
590 <xsl:text> </xsl:text>
591 <xsl:call-template name=
"rpad">
592 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
593 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
595 <xsl:text>error
</xsl:text>
596 <xsl:text> (
</xsl:text>
597 <xsl:value-of select=
"text()"/>
598 <xsl:text>)
</xsl:text>
599 <xsl:text> </xsl:text>
602 <xsl:template match=
"reduction">
603 <xsl:param name=
"pad"/>
604 <xsl:text> </xsl:text>
605 <xsl:call-template name=
"rpad">
606 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
607 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
609 <xsl:if test=
"@enabled = 'false'">
610 <xsl:text>[
</xsl:text>
613 <xsl:when test=
"@rule = 'accept'">
614 <xsl:text>accept
</xsl:text>
618 <xsl:attribute name=
"href">
619 <xsl:value-of select=
"concat('#rule_', @rule)"/>
621 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
623 <xsl:text> (
</xsl:text>
625 select=
"key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
626 <xsl:text>)
</xsl:text>
629 <xsl:if test=
"@enabled = 'false'">
630 <xsl:text>]
</xsl:text>
632 <xsl:text> </xsl:text>
635 <xsl:template match=
"solved-conflicts">
636 <xsl:if test=
"resolution">
637 <xsl:text> </xsl:text>
638 <xsl:apply-templates select=
"resolution"/>
642 <xsl:template match=
"resolution">
643 <xsl:text> Conflict between
</xsl:text>
645 <xsl:attribute name=
"href">
646 <xsl:value-of select=
"concat('#rule_', @rule)"/>
648 <xsl:value-of select=
"concat('rule ',@rule)"/>
650 <xsl:text> and token
</xsl:text>
651 <xsl:value-of select=
"@symbol"/>
652 <xsl:text> resolved as
</xsl:text>
653 <xsl:if test=
"@type = 'error'">
654 <xsl:text>an
</xsl:text>
656 <xsl:value-of select=
"@type"/>
657 <xsl:text> (
</xsl:text>
658 <xsl:value-of select=
"."/>
659 <xsl:text>).
</xsl:text>
662 <xsl:template name=
"max-width-symbol">
663 <xsl:param name=
"node"/>
664 <xsl:variable name=
"longest">
665 <xsl:for-each select=
"$node">
666 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
668 <xsl:if test=
"position() = 1">
669 <xsl:value-of select=
"string-length(@symbol)"/>
673 <xsl:value-of select=
"$longest"/>
676 <xsl:template name=
"lpad">
677 <xsl:param name=
"str" select=
"''"/>
678 <xsl:param name=
"pad" select=
"0"/>
679 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
681 <xsl:when test=
"$diff < 0">
682 <xsl:value-of select=
"$str"/>
685 <xsl:call-template name=
"space">
686 <xsl:with-param name=
"repeat" select=
"$diff"/>
688 <xsl:value-of select=
"$str"/>
693 <xsl:template name=
"rpad">
694 <xsl:param name=
"str" select=
"''"/>
695 <xsl:param name=
"pad" select=
"0"/>
696 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
698 <xsl:when test=
"$diff < 0">
699 <xsl:value-of select=
"$str"/>
702 <xsl:value-of select=
"$str"/>
703 <xsl:call-template name=
"space">
704 <xsl:with-param name=
"repeat" select=
"$diff"/>
710 <xsl:template name=
"space">
711 <xsl:param name=
"repeat">0</xsl:param>
712 <xsl:param name=
"fill" select=
"' '"/>
713 <xsl:if test=
"number($repeat) >= 1">
714 <xsl:call-template name=
"space">
715 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
716 <xsl:with-param name=
"fill" select=
"$fill"/>
718 <xsl:value-of select=
"$fill"/>