1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2html.xsl - transform Bison XML Report into XHTML.
6 Copyright (C) 2007-2015, 2018-2022 Free Software Foundation, Inc.
8 This file is part of Bison, the GNU Compiler Compiler.
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.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <https://www.gnu.org/licenses/>.
23 Written by Wojciech Polak <polak@gnu.org>.
26 <xsl:stylesheet version=
"1.0"
27 xmlns:
xsl=
"http://www.w3.org/1999/XSL/Transform"
28 xmlns=
"http://www.w3.org/1999/xhtml"
29 xmlns:
bison=
"https://www.gnu.org/software/bison/">
31 <xsl:import href=
"bison.xsl"/>
33 <xsl:output method=
"xml" encoding=
"UTF-8"
34 doctype-public=
"-//W3C//DTD XHTML 1.0 Strict//EN"
35 doctype-system=
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
38 <xsl:template match=
"/">
41 <meta http-equiv=
"Content-Type" content=
"text/html;charset=UTF-8"/>
43 <xsl:value-of select=
"bison-xml-report/filename"/>
44 <xsl:text> - GNU Bison XML Automaton Report
</xsl:text>
46 <style type=
"text/css"><![CDATA[
48 font-family:
"Nimbus Sans L", Arial, sans-serif;
53 text-decoration: none;
57 text-decoration: none;
63 text-decoration: underline;
69 font-family: monospace;
73 list-style-type: decimal;
76 list-style-type: lower-alpha;
88 <xsl:apply-templates select=
"bison-xml-report"/>
89 <xsl:text> </xsl:text>
90 <div id=
"footer"><hr />This document was generated using
91 <a href=
"https://www.gnu.org/software/bison/" title=
"GNU Bison">
92 GNU Bison
<xsl:value-of select=
"/bison-xml-report/@version"/></a>
93 XML Automaton Report.
<br />
94 <!-- default copying notice -->
95 Verbatim copying and distribution of this entire page is
96 permitted in any medium, provided this notice is preserved.
</div>
101 <xsl:template match=
"bison-xml-report">
102 <h1>GNU Bison XML Automaton Report
</h1>
104 input grammar:
<span class=
"i"><xsl:value-of select=
"filename"/></span>
107 <xsl:text> </xsl:text>
108 <h3>Table of Contents
</h3>
111 <a href=
"#reductions">Reductions
</a>
112 <ul class=
"lower-alpha">
113 <li><a href=
"#nonterminals_useless_in_grammar">Nonterminals useless in grammar
</a></li>
114 <li><a href=
"#terminals_unused_in_grammar">Terminals unused in grammar
</a></li>
115 <li><a href=
"#rules_useless_in_grammar">Rules useless in grammar
</a></li>
116 <xsl:if test=
"grammar/rules/rule[@usefulness='useless-in-parser']">
117 <li><a href=
"#rules_useless_in_parser">Rules useless in parser due to conflicts
</a></li>
121 <li><a href=
"#conflicts">Conflicts
</a></li>
123 <a href=
"#grammar">Grammar
</a>
124 <ul class=
"lower-alpha">
125 <li><a href=
"#grammar">Itemset
</a></li>
126 <li><a href=
"#terminals">Terminal symbols
</a></li>
127 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
130 <li><a href=
"#automaton">Automaton
</a></li>
132 <xsl:apply-templates select=
"grammar" mode=
"reductions"/>
133 <xsl:apply-templates select=
"grammar" mode=
"useless-in-parser"/>
134 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
135 <xsl:apply-templates select=
"grammar"/>
136 <xsl:apply-templates select=
"automaton"/>
139 <xsl:template match=
"grammar" mode=
"reductions">
141 <a name=
"reductions"/>
142 <xsl:text> Reductions
</xsl:text>
144 <xsl:apply-templates select=
"nonterminals" mode=
"useless-in-grammar"/>
145 <xsl:apply-templates select=
"terminals" mode=
"unused-in-grammar"/>
146 <xsl:apply-templates select=
"rules" mode=
"useless-in-grammar"/>
149 <xsl:template match=
"nonterminals" mode=
"useless-in-grammar">
151 <a name=
"nonterminals_useless_in_grammar"/>
152 <xsl:text> Nonterminals useless in grammar
</xsl:text>
154 <xsl:text> </xsl:text>
155 <xsl:if test=
"nonterminal[@usefulness='useless-in-grammar']">
157 <xsl:for-each select=
"nonterminal[@usefulness='useless-in-grammar']">
158 <xsl:text> </xsl:text>
159 <xsl:value-of select=
"@name"/>
160 <xsl:text> </xsl:text>
162 <xsl:text> </xsl:text>
167 <xsl:template match=
"terminals" mode=
"unused-in-grammar">
169 <a name=
"terminals_unused_in_grammar"/>
170 <xsl:text> Terminals unused in grammar
</xsl:text>
172 <xsl:text> </xsl:text>
173 <xsl:if test=
"terminal[@usefulness='unused-in-grammar']">
175 <xsl:for-each select=
"terminal[@usefulness='unused-in-grammar']">
176 <xsl:sort select=
"@symbol-number" data-type=
"number"/>
177 <xsl:text> </xsl:text>
178 <xsl:value-of select=
"@name"/>
179 <xsl:text> </xsl:text>
181 <xsl:text> </xsl:text>
186 <xsl:template match=
"rules" mode=
"useless-in-grammar">
188 <a name=
"rules_useless_in_grammar"/>
189 <xsl:text> Rules useless in grammar
</xsl:text>
191 <xsl:text> </xsl:text>
192 <xsl:variable name=
"set" select=
"rule[@usefulness='useless-in-grammar']"/>
195 <xsl:call-template name=
"style-rule-set">
196 <xsl:with-param name=
"rule-set" select=
"$set"/>
198 <xsl:text> </xsl:text>
203 <xsl:template match=
"grammar" mode=
"useless-in-parser">
205 name=
"set" select=
"rules/rule[@usefulness='useless-in-parser']"
209 <a name=
"rules_useless_in_parser"/>
210 <xsl:text> Rules useless in parser due to conflicts
</xsl:text>
212 <xsl:text> </xsl:text>
214 <xsl:call-template name=
"style-rule-set">
215 <xsl:with-param name=
"rule-set" select=
"$set"/>
218 <xsl:text> </xsl:text>
222 <xsl:template match=
"grammar">
225 <xsl:text> Grammar
</xsl:text>
227 <xsl:text> </xsl:text>
229 <xsl:call-template name=
"style-rule-set">
230 <xsl:with-param name=
"anchor" select=
"'true'" />
232 name=
"rule-set" select=
"rules/rule[@usefulness!='useless-in-grammar']"
236 <xsl:text> </xsl:text>
237 <xsl:apply-templates select=
"terminals"/>
238 <xsl:apply-templates select=
"nonterminals"/>
241 <xsl:template name=
"style-rule-set">
242 <xsl:param name=
"anchor"/>
243 <xsl:param name=
"rule-set"/>
244 <xsl:for-each select=
"$rule-set">
245 <xsl:apply-templates select=
".">
246 <xsl:with-param name=
"anchor" select=
"$anchor"/>
247 <xsl:with-param name=
"pad" select=
"'3'"/>
248 <xsl:with-param name=
"prev-lhs">
249 <xsl:if test=
"position()>1">
250 <xsl:variable name=
"position" select=
"position()"/>
251 <xsl:value-of select=
"$rule-set[$position - 1]/lhs"/>
254 </xsl:apply-templates>
258 <xsl:template match=
"automaton" mode=
"conflicts">
260 <a name=
"conflicts"/>
261 <xsl:text> Conflicts
</xsl:text>
263 <xsl:text> </xsl:text>
264 <xsl:variable name=
"conflict-report">
265 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
267 <xsl:if test=
"string-length($conflict-report) != 0">
269 <xsl:copy-of select=
"$conflict-report"/>
270 <xsl:text> </xsl:text>
275 <xsl:template match=
"state" mode=
"conflicts">
276 <xsl:variable name=
"conflict-counts">
277 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
280 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
283 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
285 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
287 <xsl:attribute name=
"href">
288 <xsl:value-of select=
"concat('#state_', @number)"/>
290 <xsl:value-of select=
"concat('State ', @number)"/>
292 <xsl:text> conflicts:
</xsl:text>
293 <xsl:if test=
"$sr-count > 0">
294 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
295 <xsl:if test=
"$rr-count > 0">
296 <xsl:value-of select=
"(',')"/>
299 <xsl:if test=
"$rr-count > 0">
300 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
302 <xsl:value-of select=
"' '"/>
306 <xsl:template match=
"grammar/terminals">
308 <a name=
"terminals"/>
309 <xsl:text> Terminals, with rules where they appear
</xsl:text>
311 <xsl:text> </xsl:text>
313 <xsl:text> </xsl:text>
314 <xsl:apply-templates select=
"terminal"/>
316 <xsl:text> </xsl:text>
319 <xsl:template match=
"grammar/nonterminals">
321 <a name=
"nonterminals"/>
322 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
324 <xsl:text> </xsl:text>
326 <xsl:text> </xsl:text>
328 select=
"nonterminal[@usefulness!='useless-in-grammar']"
333 <xsl:template match=
"terminal">
334 <xsl:text> </xsl:text>
336 <b><xsl:value-of select=
"@name"/></b>
337 <xsl:if test=
"string-length(@type) != 0">
338 <xsl:value-of select=
"concat(' <', @type, '>')"/>
340 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
341 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
342 <xsl:apply-templates select=
"." mode=
"number-link"/>
345 <xsl:text> </xsl:text>
348 <xsl:template match=
"nonterminal">
349 <xsl:text> </xsl:text>
351 <b><xsl:value-of select=
"@name"/></b>
352 <xsl:if test=
"string-length(@type) != 0">
353 <xsl:value-of select=
"concat(' <', @type, '>')"/>
355 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
356 <xsl:text> </xsl:text>
358 <xsl:text> </xsl:text>
359 <xsl:if test=
"key('bison:ruleByLhs', @name)">
360 <xsl:text> </xsl:text>
362 <xsl:text>on left:
</xsl:text>
363 <xsl:for-each select=
"key('bison:ruleByLhs', @name)">
364 <xsl:apply-templates select=
"." mode=
"number-link"/>
367 <xsl:text> </xsl:text>
369 <xsl:if test=
"key('bison:ruleByRhs', @name)">
370 <xsl:text> </xsl:text>
372 <xsl:text>on right:
</xsl:text>
373 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
374 <xsl:apply-templates select=
"." mode=
"number-link"/>
377 <xsl:text> </xsl:text>
379 <xsl:text> </xsl:text>
381 <xsl:text> </xsl:text>
383 <xsl:text> </xsl:text>
386 <xsl:template match=
"rule" mode=
"number-link">
387 <xsl:text> </xsl:text>
389 <xsl:attribute name=
"href">
390 <xsl:value-of select=
"concat('#rule_', @number)"/>
392 <xsl:value-of select=
"@number"/>
396 <xsl:template match=
"automaton">
398 <a name=
"automaton"/>
399 <xsl:text> Automaton
</xsl:text>
401 <xsl:apply-templates select=
"state">
402 <xsl:with-param name=
"pad" select=
"'3'"/>
403 </xsl:apply-templates>
406 <xsl:template match=
"automaton/state">
407 <xsl:param name=
"pad"/>
408 <xsl:text> </xsl:text>
411 <xsl:attribute name=
"name">
412 <xsl:value-of select=
"concat('state_', @number)"/>
415 <xsl:text>State
</xsl:text>
416 <xsl:value-of select=
"@number"/>
418 <xsl:text> </xsl:text>
420 <xsl:apply-templates select=
"itemset/item">
421 <xsl:with-param name=
"pad" select=
"$pad"/>
422 </xsl:apply-templates>
423 <xsl:apply-templates select=
"actions/transitions">
424 <xsl:with-param name=
"type" select=
"'shift'"/>
425 </xsl:apply-templates>
426 <xsl:apply-templates select=
"actions/errors"/>
427 <xsl:apply-templates select=
"actions/reductions"/>
428 <xsl:apply-templates select=
"actions/transitions">
429 <xsl:with-param name=
"type" select=
"'goto'"/>
430 </xsl:apply-templates>
431 <xsl:apply-templates select=
"solved-conflicts"/>
435 <xsl:template match=
"actions/transitions">
436 <xsl:param name=
"type"/>
437 <xsl:if test=
"transition[@type = $type]">
438 <xsl:text> </xsl:text>
439 <xsl:apply-templates select=
"transition[@type = $type]">
440 <xsl:with-param name=
"pad">
441 <xsl:call-template name=
"max-width-symbol">
442 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
445 </xsl:apply-templates>
449 <xsl:template match=
"actions/errors">
450 <xsl:if test=
"error">
451 <xsl:text> </xsl:text>
452 <xsl:apply-templates select=
"error">
453 <xsl:with-param name=
"pad">
454 <xsl:call-template name=
"max-width-symbol">
455 <xsl:with-param name=
"node" select=
"error"/>
458 </xsl:apply-templates>
462 <xsl:template match=
"actions/reductions">
463 <xsl:if test=
"reduction">
464 <xsl:text> </xsl:text>
465 <xsl:apply-templates select=
"reduction">
466 <xsl:with-param name=
"pad">
467 <xsl:call-template name=
"max-width-symbol">
468 <xsl:with-param name=
"node" select=
"reduction"/>
471 </xsl:apply-templates>
475 <xsl:template match=
"item">
476 <xsl:param name=
"pad"/>
477 <xsl:param name=
"prev-rule-number"
478 select=
"preceding-sibling::item[1]/@rule-number"/>
480 select=
"key('bison:ruleByNumber', current()/@rule-number)"
482 <xsl:with-param name=
"itemset" select=
"'true'"/>
483 <xsl:with-param name=
"pad" select=
"$pad"/>
484 <xsl:with-param name=
"prev-lhs"
485 select=
"key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
487 <xsl:with-param name=
"dot" select=
"@dot"/>
488 <xsl:with-param name=
"lookaheads">
489 <xsl:apply-templates select=
"lookaheads"/>
491 </xsl:apply-templates>
495 anchor = 'true': define as an <a> anchor.
496 itemset = 'true': show the items.
498 <xsl:template match=
"rule">
499 <xsl:param name=
"anchor"/>
500 <xsl:param name=
"itemset"/>
501 <xsl:param name=
"pad"/>
502 <xsl:param name=
"prev-lhs"/>
503 <xsl:param name=
"dot"/>
504 <xsl:param name=
"lookaheads"/>
506 <xsl:if test=
"$itemset != 'true' and not($prev-lhs = lhs[text()])">
507 <xsl:text> </xsl:text>
510 <xsl:text> </xsl:text>
513 <xsl:when test=
"$anchor = 'true'">
515 <xsl:attribute name=
"name">
516 <xsl:value-of select=
"concat('rule_', @number)"/>
518 <xsl:call-template name=
"lpad">
519 <xsl:with-param name=
"str" select=
"string(@number)"/>
520 <xsl:with-param name=
"pad" select=
"number($pad)"/>
526 <xsl:attribute name=
"href">
527 <xsl:value-of select=
"concat('#rule_', @number)"/>
529 <xsl:call-template name=
"lpad">
530 <xsl:with-param name=
"str" select=
"string(@number)"/>
531 <xsl:with-param name=
"pad" select=
"number($pad)"/>
536 <xsl:text> </xsl:text>
540 <xsl:when test=
"$prev-lhs = lhs[text()]">
541 <xsl:call-template name=
"lpad">
542 <xsl:with-param name=
"str" select=
"'|'"/>
543 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
548 <xsl:value-of select=
"lhs"/>
550 <xsl:text> →</xsl:text>
555 <xsl:for-each select=
"rhs/*">
556 <xsl:if test=
"position() = $dot + 1">
557 <xsl:text> </xsl:text>
558 <span class=
"dot">•</span>
560 <xsl:apply-templates select=
"."/>
561 <xsl:if test=
"position() = last() and position() = $dot">
562 <xsl:text> </xsl:text>
563 <span class=
"dot">•</span>
566 <xsl:if test=
"$lookaheads">
567 <xsl:value-of select=
"$lookaheads"/>
570 <xsl:text> </xsl:text>
573 <xsl:template match=
"symbol">
574 <xsl:text> </xsl:text>
576 <xsl:when test=
"name(key('bison:symbolByName', .)) = 'nonterminal'">
577 <span class=
"i"><xsl:value-of select=
"."/></span>
580 <b><xsl:value-of select=
"."/></b>
585 <xsl:template match=
"empty">
586 <xsl:text> %empty
</xsl:text>
589 <xsl:template match=
"lookaheads">
590 <xsl:text> [
</xsl:text>
591 <xsl:apply-templates select=
"symbol"/>
592 <xsl:text>]
</xsl:text>
595 <xsl:template match=
"lookaheads/symbol">
596 <xsl:value-of select=
"."/>
597 <xsl:if test=
"position() != last()">
598 <xsl:text>,
</xsl:text>
602 <xsl:template match=
"transition">
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"/>
610 <xsl:when test=
"@type = 'shift'">
612 <xsl:attribute name=
"href">
613 <xsl:value-of select=
"concat('#state_', @state)"/>
615 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
618 <xsl:when test=
"@type = 'goto'">
620 <xsl:attribute name=
"href">
621 <xsl:value-of select=
"concat('#state_', @state)"/>
623 <xsl:value-of select=
"concat('go to state ', @state)"/>
627 <xsl:text> </xsl:text>
630 <xsl:template match=
"error">
631 <xsl:param name=
"pad"/>
632 <xsl:text> </xsl:text>
633 <xsl:call-template name=
"rpad">
634 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
635 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
637 <xsl:text>error
</xsl:text>
638 <xsl:text> (
</xsl:text>
639 <xsl:value-of select=
"text()"/>
640 <xsl:text>)
</xsl:text>
641 <xsl:text> </xsl:text>
644 <xsl:template match=
"reduction">
645 <xsl:param name=
"pad"/>
646 <xsl:text> </xsl:text>
647 <xsl:call-template name=
"rpad">
648 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
649 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
651 <xsl:if test=
"@enabled = 'false'">
652 <xsl:text>[
</xsl:text>
655 <xsl:when test=
"@rule = 'accept'">
656 <xsl:text>accept
</xsl:text>
660 <xsl:attribute name=
"href">
661 <xsl:value-of select=
"concat('#rule_', @rule)"/>
663 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
665 <xsl:text> (
</xsl:text>
667 select=
"key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
669 <xsl:text>)
</xsl:text>
672 <xsl:if test=
"@enabled = 'false'">
673 <xsl:text>]
</xsl:text>
675 <xsl:text> </xsl:text>
678 <xsl:template match=
"solved-conflicts">
679 <xsl:if test=
"resolution">
680 <xsl:text> </xsl:text>
681 <xsl:apply-templates select=
"resolution"/>
685 <xsl:template match=
"resolution">
686 <xsl:text> Conflict between
</xsl:text>
688 <xsl:attribute name=
"href">
689 <xsl:value-of select=
"concat('#rule_', @rule)"/>
691 <xsl:value-of select=
"concat('rule ',@rule)"/>
693 <xsl:text> and token
</xsl:text>
694 <xsl:value-of select=
"@symbol"/>
695 <xsl:text> resolved as
</xsl:text>
696 <xsl:if test=
"@type = 'error'">
697 <xsl:text>an
</xsl:text>
699 <xsl:value-of select=
"@type"/>
700 <xsl:text> (
</xsl:text>
701 <xsl:value-of select=
"."/>
702 <xsl:text>).
</xsl:text>
705 <xsl:template name=
"max-width-symbol">
706 <xsl:param name=
"node"/>
707 <xsl:variable name=
"longest">
708 <xsl:for-each select=
"$node">
709 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
711 <xsl:if test=
"position() = 1">
712 <xsl:value-of select=
"string-length(@symbol)"/>
716 <xsl:value-of select=
"$longest"/>
719 <xsl:template name=
"lpad">
720 <xsl:param name=
"str" select=
"''"/>
721 <xsl:param name=
"pad" select=
"0"/>
722 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
724 <xsl:when test=
"$diff < 0">
725 <xsl:value-of select=
"$str"/>
728 <xsl:call-template name=
"space">
729 <xsl:with-param name=
"repeat" select=
"$diff"/>
731 <xsl:value-of select=
"$str"/>
736 <xsl:template name=
"rpad">
737 <xsl:param name=
"str" select=
"''"/>
738 <xsl:param name=
"pad" select=
"0"/>
739 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
741 <xsl:when test=
"$diff < 0">
742 <xsl:value-of select=
"$str"/>
745 <xsl:value-of select=
"$str"/>
746 <xsl:call-template name=
"space">
747 <xsl:with-param name=
"repeat" select=
"$diff"/>
753 <xsl:template name=
"space">
754 <xsl:param name=
"repeat">0</xsl:param>
755 <xsl:param name=
"fill" select=
"' '"/>
756 <xsl:if test=
"number($repeat) >= 1">
757 <xsl:call-template name=
"space">
758 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
759 <xsl:with-param name=
"fill" select=
"$fill"/>
761 <xsl:value-of select=
"$fill"/>