1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2html.xsl - transform Bison XML Report into XHTML.
6 Copyright (C) 2007, 2008 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:if test=
"$itemset = 'true' and name(.) != 'empty'">
536 <xsl:apply-templates select=
"."/>
538 <xsl:if test=
"$itemset != 'true'">
539 <xsl:apply-templates select=
"."/>
541 <xsl:if test=
"position() = last() and position() = $point">
542 <xsl:text> </xsl:text>
543 <span class=
"point">.
</span>
546 <xsl:if test=
"$lookaheads">
547 <xsl:value-of select=
"$lookaheads"/>
550 <xsl:text> </xsl:text>
553 <xsl:template match=
"symbol">
554 <xsl:text> </xsl:text>
556 <xsl:when test=
"name(key('bison:symbolByName', .)) = 'nonterminal'">
557 <span class=
"i"><xsl:value-of select=
"."/></span>
560 <b><xsl:value-of select=
"."/></b>
565 <xsl:template match=
"empty">
566 <xsl:text> ε</xsl:text>
569 <xsl:template match=
"lookaheads">
570 <xsl:text> [
</xsl:text>
571 <xsl:apply-templates select=
"symbol"/>
572 <xsl:text>]
</xsl:text>
575 <xsl:template match=
"lookaheads/symbol">
576 <xsl:value-of select=
"."/>
577 <xsl:if test=
"position() != last()">
578 <xsl:text>,
</xsl:text>
582 <xsl:template match=
"transition">
583 <xsl:param name=
"pad"/>
584 <xsl:text> </xsl:text>
585 <xsl:call-template name=
"rpad">
586 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
587 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
590 <xsl:when test=
"@type = 'shift'">
592 <xsl:attribute name=
"href">
593 <xsl:value-of select=
"concat('#state_', @state)"/>
595 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
598 <xsl:when test=
"@type = 'goto'">
600 <xsl:attribute name=
"href">
601 <xsl:value-of select=
"concat('#state_', @state)"/>
603 <xsl:value-of select=
"concat('go to state ', @state)"/>
607 <xsl:text> </xsl:text>
610 <xsl:template match=
"error">
611 <xsl:param name=
"pad"/>
612 <xsl:text> </xsl:text>
613 <xsl:call-template name=
"rpad">
614 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
615 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
617 <xsl:text>error
</xsl:text>
618 <xsl:text> (
</xsl:text>
619 <xsl:value-of select=
"text()"/>
620 <xsl:text>)
</xsl:text>
621 <xsl:text> </xsl:text>
624 <xsl:template match=
"reduction">
625 <xsl:param name=
"pad"/>
626 <xsl:text> </xsl:text>
627 <xsl:call-template name=
"rpad">
628 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
629 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
631 <xsl:if test=
"@enabled = 'false'">
632 <xsl:text>[
</xsl:text>
635 <xsl:when test=
"@rule = 'accept'">
636 <xsl:text>accept
</xsl:text>
640 <xsl:attribute name=
"href">
641 <xsl:value-of select=
"concat('#rule_', @rule)"/>
643 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
645 <xsl:text> (
</xsl:text>
647 select=
"key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
649 <xsl:text>)
</xsl:text>
652 <xsl:if test=
"@enabled = 'false'">
653 <xsl:text>]
</xsl:text>
655 <xsl:text> </xsl:text>
658 <xsl:template match=
"solved-conflicts">
659 <xsl:if test=
"resolution">
660 <xsl:text> </xsl:text>
661 <xsl:apply-templates select=
"resolution"/>
665 <xsl:template match=
"resolution">
666 <xsl:text> Conflict between
</xsl:text>
668 <xsl:attribute name=
"href">
669 <xsl:value-of select=
"concat('#rule_', @rule)"/>
671 <xsl:value-of select=
"concat('rule ',@rule)"/>
673 <xsl:text> and token
</xsl:text>
674 <xsl:value-of select=
"@symbol"/>
675 <xsl:text> resolved as
</xsl:text>
676 <xsl:if test=
"@type = 'error'">
677 <xsl:text>an
</xsl:text>
679 <xsl:value-of select=
"@type"/>
680 <xsl:text> (
</xsl:text>
681 <xsl:value-of select=
"."/>
682 <xsl:text>).
</xsl:text>
685 <xsl:template name=
"max-width-symbol">
686 <xsl:param name=
"node"/>
687 <xsl:variable name=
"longest">
688 <xsl:for-each select=
"$node">
689 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
691 <xsl:if test=
"position() = 1">
692 <xsl:value-of select=
"string-length(@symbol)"/>
696 <xsl:value-of select=
"$longest"/>
699 <xsl:template name=
"lpad">
700 <xsl:param name=
"str" select=
"''"/>
701 <xsl:param name=
"pad" select=
"0"/>
702 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
704 <xsl:when test=
"$diff < 0">
705 <xsl:value-of select=
"$str"/>
708 <xsl:call-template name=
"space">
709 <xsl:with-param name=
"repeat" select=
"$diff"/>
711 <xsl:value-of select=
"$str"/>
716 <xsl:template name=
"rpad">
717 <xsl:param name=
"str" select=
"''"/>
718 <xsl:param name=
"pad" select=
"0"/>
719 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
721 <xsl:when test=
"$diff < 0">
722 <xsl:value-of select=
"$str"/>
725 <xsl:value-of select=
"$str"/>
726 <xsl:call-template name=
"space">
727 <xsl:with-param name=
"repeat" select=
"$diff"/>
733 <xsl:template name=
"space">
734 <xsl:param name=
"repeat">0</xsl:param>
735 <xsl:param name=
"fill" select=
"' '"/>
736 <xsl:if test=
"number($repeat) >= 1">
737 <xsl:call-template name=
"space">
738 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
739 <xsl:with-param name=
"fill" select=
"$fill"/>
741 <xsl:value-of select=
"$fill"/>