1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2html.xsl - transform Bison XML Report into XHTML.
6 Copyright (C) 2007-2013 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 <http://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=
"http://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=
"/">
42 <xsl:value-of select=
"bison-xml-report/filename"/>
43 <xsl:text> - GNU Bison XML Automaton Report
</xsl:text>
45 <style type=
"text/css"><![CDATA[
47 font-family: "Nimbus Sans L", Arial, sans-serif;
52 text-decoration: none;
56 text-decoration: none;
62 text-decoration: underline;
68 font-family: monospace;
72 list-style-type: decimal;
75 list-style-type: lower-alpha;
87 <xsl:apply-templates select=
"bison-xml-report"/>
88 <xsl:text> </xsl:text>
89 <div id=
"footer"><hr />This document was generated using
90 <a href=
"http://www.gnu.org/software/bison/" title=
"GNU Bison">
91 GNU Bison
<xsl:value-of select=
"/bison-xml-report/@version"/></a>
92 XML Automaton Report.
<br />
93 <!-- default copying notice -->
94 Verbatim copying and distribution of this entire page is
95 permitted in any medium, provided this notice is preserved.
</div>
100 <xsl:template match=
"bison-xml-report">
101 <h1>GNU Bison XML Automaton Report
</h1>
103 input grammar:
<span class=
"i"><xsl:value-of select=
"filename"/></span>
106 <xsl:text> </xsl:text>
107 <h3>Table of Contents
</h3>
110 <a href=
"#reductions">Reductions
</a>
111 <ul class=
"lower-alpha">
112 <li><a href=
"#nonterminals_useless_in_grammar">Nonterminals useless in grammar
</a></li>
113 <li><a href=
"#terminals_unused_in_grammar">Terminals unused in grammar
</a></li>
114 <li><a href=
"#rules_useless_in_grammar">Rules useless in grammar
</a></li>
115 <xsl:if test=
"grammar/rules/rule[@usefulness='useless-in-parser']">
116 <li><a href=
"#rules_useless_in_parser">Rules useless in parser due to conflicts
</a></li>
120 <li><a href=
"#conflicts">Conflicts
</a></li>
122 <a href=
"#grammar">Grammar
</a>
123 <ul class=
"lower-alpha">
124 <li><a href=
"#grammar">Itemset
</a></li>
125 <li><a href=
"#terminals">Terminal symbols
</a></li>
126 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
129 <li><a href=
"#automaton">Automaton
</a></li>
131 <xsl:apply-templates select=
"grammar" mode=
"reductions"/>
132 <xsl:apply-templates select=
"grammar" mode=
"useless-in-parser"/>
133 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
134 <xsl:apply-templates select=
"grammar"/>
135 <xsl:apply-templates select=
"automaton"/>
138 <xsl:template match=
"grammar" mode=
"reductions">
140 <a name=
"reductions"/>
141 <xsl:text> Reductions
</xsl:text>
143 <xsl:apply-templates select=
"nonterminals" mode=
"useless-in-grammar"/>
144 <xsl:apply-templates select=
"terminals" mode=
"unused-in-grammar"/>
145 <xsl:apply-templates select=
"rules" mode=
"useless-in-grammar"/>
148 <xsl:template match=
"nonterminals" mode=
"useless-in-grammar">
150 <a name=
"nonterminals_useless_in_grammar"/>
151 <xsl:text> Nonterminals useless in grammar
</xsl:text>
153 <xsl:text> </xsl:text>
154 <xsl:if test=
"nonterminal[@usefulness='useless-in-grammar']">
156 <xsl:for-each select=
"nonterminal[@usefulness='useless-in-grammar']">
157 <xsl:text> </xsl:text>
158 <xsl:value-of select=
"@name"/>
159 <xsl:text> </xsl:text>
161 <xsl:text> </xsl:text>
166 <xsl:template match=
"terminals" mode=
"unused-in-grammar">
168 <a name=
"terminals_unused_in_grammar"/>
169 <xsl:text> Terminals unused in grammar
</xsl:text>
171 <xsl:text> </xsl:text>
172 <xsl:if test=
"terminal[@usefulness='unused-in-grammar']">
174 <xsl:for-each select=
"terminal[@usefulness='unused-in-grammar']">
175 <xsl:sort select=
"@symbol-number" data-type=
"number"/>
176 <xsl:text> </xsl:text>
177 <xsl:value-of select=
"@name"/>
178 <xsl:text> </xsl:text>
180 <xsl:text> </xsl:text>
185 <xsl:template match=
"rules" mode=
"useless-in-grammar">
187 <a name=
"rules_useless_in_grammar"/>
188 <xsl:text> Rules useless in grammar
</xsl:text>
190 <xsl:text> </xsl:text>
191 <xsl:variable name=
"set" select=
"rule[@usefulness='useless-in-grammar']"/>
194 <xsl:call-template name=
"style-rule-set">
195 <xsl:with-param name=
"rule-set" select=
"$set"/>
197 <xsl:text> </xsl:text>
202 <xsl:template match=
"grammar" mode=
"useless-in-parser">
204 name=
"set" select=
"rules/rule[@usefulness='useless-in-parser']"
208 <a name=
"rules_useless_in_parser"/>
209 <xsl:text> Rules useless in parser due to conflicts
</xsl:text>
211 <xsl:text> </xsl:text>
213 <xsl:call-template name=
"style-rule-set">
214 <xsl:with-param name=
"rule-set" select=
"$set"/>
217 <xsl:text> </xsl:text>
221 <xsl:template match=
"grammar">
224 <xsl:text> Grammar
</xsl:text>
226 <xsl:text> </xsl:text>
228 <xsl:call-template name=
"style-rule-set">
230 name=
"rule-set" select=
"rules/rule[@usefulness!='useless-in-grammar']"
234 <xsl:text> </xsl:text>
235 <xsl:apply-templates select=
"terminals"/>
236 <xsl:apply-templates select=
"nonterminals"/>
239 <xsl:template name=
"style-rule-set">
240 <xsl:param name=
"rule-set"/>
241 <xsl:for-each select=
"$rule-set">
242 <xsl:apply-templates select=
".">
243 <xsl:with-param name=
"pad" select=
"'3'"/>
244 <xsl:with-param name=
"prev-lhs">
245 <xsl:if test=
"position()>1">
246 <xsl:variable name=
"position" select=
"position()"/>
247 <xsl:value-of select=
"$rule-set[$position - 1]/lhs"/>
250 </xsl:apply-templates>
254 <xsl:template match=
"automaton" mode=
"conflicts">
256 <a name=
"conflicts"/>
257 <xsl:text> Conflicts
</xsl:text>
259 <xsl:text> </xsl:text>
260 <xsl:variable name=
"conflict-report">
261 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
263 <xsl:if test=
"string-length($conflict-report) != 0">
265 <xsl:copy-of select=
"$conflict-report"/>
266 <xsl:text> </xsl:text>
271 <xsl:template match=
"state" mode=
"conflicts">
272 <xsl:variable name=
"conflict-counts">
273 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
276 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
279 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
281 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
283 <xsl:attribute name=
"href">
284 <xsl:value-of select=
"concat('#state_', @number)"/>
286 <xsl:value-of select=
"concat('State ', @number)"/>
288 <xsl:text> conflicts:
</xsl:text>
289 <xsl:if test=
"$sr-count > 0">
290 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
291 <xsl:if test=
"$rr-count > 0">
292 <xsl:value-of select=
"(',')"/>
295 <xsl:if test=
"$rr-count > 0">
296 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
298 <xsl:value-of select=
"' '"/>
302 <xsl:template match=
"grammar/terminals">
304 <a name=
"terminals"/>
305 <xsl:text> Terminals, with rules where they appear
</xsl:text>
307 <xsl:text> </xsl:text>
309 <xsl:apply-templates select=
"terminal"/>
311 <xsl:text> </xsl:text>
314 <xsl:template match=
"grammar/nonterminals">
316 <a name=
"nonterminals"/>
317 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
319 <xsl:text> </xsl:text>
322 select=
"nonterminal[@usefulness!='useless-in-grammar']"
327 <xsl:template match=
"terminal">
328 <b><xsl:value-of select=
"@name"/></b>
329 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
330 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
331 <xsl:apply-templates select=
"." mode=
"number-link"/>
333 <xsl:text> </xsl:text>
336 <xsl:template match=
"nonterminal">
337 <b><xsl:value-of select=
"@name"/></b>
338 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
339 <xsl:text> </xsl:text>
340 <xsl:if test=
"key('bison:ruleByLhs', @name)">
341 <xsl:text>on left:
</xsl:text>
342 <xsl:for-each select=
"key('bison:ruleByLhs', @name)">
343 <xsl:apply-templates select=
"." mode=
"number-link"/>
346 <xsl:if test=
"key('bison:ruleByRhs', @name)">
347 <xsl:if test=
"key('bison:ruleByLhs', @name)">
348 <xsl:text> </xsl:text>
350 <xsl:text>on right:
</xsl:text>
351 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
352 <xsl:apply-templates select=
"." mode=
"number-link"/>
355 <xsl:text> </xsl:text>
358 <xsl:template match=
"rule" mode=
"number-link">
359 <xsl:text> </xsl:text>
361 <xsl:attribute name=
"href">
362 <xsl:value-of select=
"concat('#rule_', @number)"/>
364 <xsl:value-of select=
"@number"/>
368 <xsl:template match=
"automaton">
370 <a name=
"automaton"/>
371 <xsl:text> Automaton
</xsl:text>
373 <xsl:apply-templates select=
"state">
374 <xsl:with-param name=
"pad" select=
"'3'"/>
375 </xsl:apply-templates>
378 <xsl:template match=
"automaton/state">
379 <xsl:param name=
"pad"/>
380 <xsl:text> </xsl:text>
383 <xsl:attribute name=
"name">
384 <xsl:value-of select=
"concat('state_', @number)"/>
387 <xsl:text>state
</xsl:text>
388 <xsl:value-of select=
"@number"/>
390 <xsl:text> </xsl:text>
392 <xsl:apply-templates select=
"itemset/item">
393 <xsl:with-param name=
"pad" select=
"$pad"/>
394 </xsl:apply-templates>
395 <xsl:apply-templates select=
"actions/transitions">
396 <xsl:with-param name=
"type" select=
"'shift'"/>
397 </xsl:apply-templates>
398 <xsl:apply-templates select=
"actions/errors"/>
399 <xsl:apply-templates select=
"actions/reductions"/>
400 <xsl:apply-templates select=
"actions/transitions">
401 <xsl:with-param name=
"type" select=
"'goto'"/>
402 </xsl:apply-templates>
403 <xsl:apply-templates select=
"solved-conflicts"/>
407 <xsl:template match=
"actions/transitions">
408 <xsl:param name=
"type"/>
409 <xsl:if test=
"transition[@type = $type]">
410 <xsl:text> </xsl:text>
411 <xsl:apply-templates select=
"transition[@type = $type]">
412 <xsl:with-param name=
"pad">
413 <xsl:call-template name=
"max-width-symbol">
414 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
417 </xsl:apply-templates>
421 <xsl:template match=
"actions/errors">
422 <xsl:if test=
"error">
423 <xsl:text> </xsl:text>
424 <xsl:apply-templates select=
"error">
425 <xsl:with-param name=
"pad">
426 <xsl:call-template name=
"max-width-symbol">
427 <xsl:with-param name=
"node" select=
"error"/>
430 </xsl:apply-templates>
434 <xsl:template match=
"actions/reductions">
435 <xsl:if test=
"reduction">
436 <xsl:text> </xsl:text>
437 <xsl:apply-templates select=
"reduction">
438 <xsl:with-param name=
"pad">
439 <xsl:call-template name=
"max-width-symbol">
440 <xsl:with-param name=
"node" select=
"reduction"/>
443 </xsl:apply-templates>
447 <xsl:template match=
"item">
448 <xsl:param name=
"pad"/>
449 <xsl:param name=
"prev-rule-number"
450 select=
"preceding-sibling::item[1]/@rule-number"/>
452 select=
"key('bison:ruleByNumber', current()/@rule-number)"
454 <xsl:with-param name=
"itemset" select=
"'true'"/>
455 <xsl:with-param name=
"pad" select=
"$pad"/>
456 <xsl:with-param name=
"prev-lhs"
457 select=
"key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
459 <xsl:with-param name=
"point" select=
"@point"/>
460 <xsl:with-param name=
"lookaheads">
461 <xsl:apply-templates select=
"lookaheads"/>
463 </xsl:apply-templates>
466 <xsl:template match=
"rule">
467 <xsl:param name=
"itemset"/>
468 <xsl:param name=
"pad"/>
469 <xsl:param name=
"prev-lhs"/>
470 <xsl:param name=
"point"/>
471 <xsl:param name=
"lookaheads"/>
473 <xsl:if test=
"$itemset != 'true' and not($prev-lhs = lhs[text()])">
474 <xsl:text> </xsl:text>
477 <xsl:if test=
"$itemset != 'true'">
479 <xsl:attribute name=
"name">
480 <xsl:value-of select=
"concat('rule_', @number)"/>
484 <xsl:text> </xsl:text>
487 <xsl:when test=
"$itemset = 'true'">
489 <xsl:attribute name=
"href">
490 <xsl:value-of select=
"concat('#rule_', @number)"/>
492 <xsl:call-template name=
"lpad">
493 <xsl:with-param name=
"str" select=
"string(@number)"/>
494 <xsl:with-param name=
"pad" select=
"number($pad)"/>
499 <xsl:call-template name=
"lpad">
500 <xsl:with-param name=
"str" select=
"string(@number)"/>
501 <xsl:with-param name=
"pad" select=
"number($pad)"/>
505 <xsl:text> </xsl:text>
509 <xsl:when test=
"$itemset != 'true' and $prev-lhs = lhs[text()]">
510 <xsl:call-template name=
"lpad">
511 <xsl:with-param name=
"str" select=
"'|'"/>
512 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
515 <xsl:when test=
"$itemset = 'true' and $prev-lhs = lhs[text()]">
516 <xsl:call-template name=
"lpad">
517 <xsl:with-param name=
"str" select=
"'|'"/>
518 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
523 <xsl:value-of select=
"lhs"/>
525 <xsl:text> →</xsl:text>
530 <xsl:for-each select=
"rhs/*">
531 <xsl:if test=
"position() = $point + 1">
532 <xsl:text> </xsl:text>
533 <span class=
"point">.
</span>
535 <xsl:apply-templates select=
"."/>
536 <xsl:if test=
"position() = last() and position() = $point">
537 <xsl:text> </xsl:text>
538 <span class=
"point">.
</span>
541 <xsl:if test=
"$lookaheads">
542 <xsl:value-of select=
"$lookaheads"/>
545 <xsl:text> </xsl:text>
548 <xsl:template match=
"symbol">
549 <xsl:text> </xsl:text>
551 <xsl:when test=
"name(key('bison:symbolByName', .)) = 'nonterminal'">
552 <span class=
"i"><xsl:value-of select=
"."/></span>
555 <b><xsl:value-of select=
"."/></b>
560 <xsl:template match=
"empty">
561 <xsl:text> %empty
</xsl:text>
564 <xsl:template match=
"lookaheads">
565 <xsl:text> [
</xsl:text>
566 <xsl:apply-templates select=
"symbol"/>
567 <xsl:text>]
</xsl:text>
570 <xsl:template match=
"lookaheads/symbol">
571 <xsl:value-of select=
"."/>
572 <xsl:if test=
"position() != last()">
573 <xsl:text>,
</xsl:text>
577 <xsl:template match=
"transition">
578 <xsl:param name=
"pad"/>
579 <xsl:text> </xsl:text>
580 <xsl:call-template name=
"rpad">
581 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
582 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
585 <xsl:when test=
"@type = 'shift'">
587 <xsl:attribute name=
"href">
588 <xsl:value-of select=
"concat('#state_', @state)"/>
590 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
593 <xsl:when test=
"@type = 'goto'">
595 <xsl:attribute name=
"href">
596 <xsl:value-of select=
"concat('#state_', @state)"/>
598 <xsl:value-of select=
"concat('go to state ', @state)"/>
602 <xsl:text> </xsl:text>
605 <xsl:template match=
"error">
606 <xsl:param name=
"pad"/>
607 <xsl:text> </xsl:text>
608 <xsl:call-template name=
"rpad">
609 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
610 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
612 <xsl:text>error
</xsl:text>
613 <xsl:text> (
</xsl:text>
614 <xsl:value-of select=
"text()"/>
615 <xsl:text>)
</xsl:text>
616 <xsl:text> </xsl:text>
619 <xsl:template match=
"reduction">
620 <xsl:param name=
"pad"/>
621 <xsl:text> </xsl:text>
622 <xsl:call-template name=
"rpad">
623 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
624 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
626 <xsl:if test=
"@enabled = 'false'">
627 <xsl:text>[
</xsl:text>
630 <xsl:when test=
"@rule = 'accept'">
631 <xsl:text>accept
</xsl:text>
635 <xsl:attribute name=
"href">
636 <xsl:value-of select=
"concat('#rule_', @rule)"/>
638 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
640 <xsl:text> (
</xsl:text>
642 select=
"key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
644 <xsl:text>)
</xsl:text>
647 <xsl:if test=
"@enabled = 'false'">
648 <xsl:text>]
</xsl:text>
650 <xsl:text> </xsl:text>
653 <xsl:template match=
"solved-conflicts">
654 <xsl:if test=
"resolution">
655 <xsl:text> </xsl:text>
656 <xsl:apply-templates select=
"resolution"/>
660 <xsl:template match=
"resolution">
661 <xsl:text> Conflict between
</xsl:text>
663 <xsl:attribute name=
"href">
664 <xsl:value-of select=
"concat('#rule_', @rule)"/>
666 <xsl:value-of select=
"concat('rule ',@rule)"/>
668 <xsl:text> and token
</xsl:text>
669 <xsl:value-of select=
"@symbol"/>
670 <xsl:text> resolved as
</xsl:text>
671 <xsl:if test=
"@type = 'error'">
672 <xsl:text>an
</xsl:text>
674 <xsl:value-of select=
"@type"/>
675 <xsl:text> (
</xsl:text>
676 <xsl:value-of select=
"."/>
677 <xsl:text>).
</xsl:text>
680 <xsl:template name=
"max-width-symbol">
681 <xsl:param name=
"node"/>
682 <xsl:variable name=
"longest">
683 <xsl:for-each select=
"$node">
684 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
686 <xsl:if test=
"position() = 1">
687 <xsl:value-of select=
"string-length(@symbol)"/>
691 <xsl:value-of select=
"$longest"/>
694 <xsl:template name=
"lpad">
695 <xsl:param name=
"str" select=
"''"/>
696 <xsl:param name=
"pad" select=
"0"/>
697 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
699 <xsl:when test=
"$diff < 0">
700 <xsl:value-of select=
"$str"/>
703 <xsl:call-template name=
"space">
704 <xsl:with-param name=
"repeat" select=
"$diff"/>
706 <xsl:value-of select=
"$str"/>
711 <xsl:template name=
"rpad">
712 <xsl:param name=
"str" select=
"''"/>
713 <xsl:param name=
"pad" select=
"0"/>
714 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
716 <xsl:when test=
"$diff < 0">
717 <xsl:value-of select=
"$str"/>
720 <xsl:value-of select=
"$str"/>
721 <xsl:call-template name=
"space">
722 <xsl:with-param name=
"repeat" select=
"$diff"/>
728 <xsl:template name=
"space">
729 <xsl:param name=
"repeat">0</xsl:param>
730 <xsl:param name=
"fill" select=
"' '"/>
731 <xsl:if test=
"number($repeat) >= 1">
732 <xsl:call-template name=
"space">
733 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
734 <xsl:with-param name=
"fill" select=
"$fill"/>
736 <xsl:value-of select=
"$fill"/>