1 <?xml version=
"1.0" encoding=
"UTF-8"?>
4 xml2html.xsl - transform Bison XML Report into XHTML.
7 Copyright (C) 2007, 2008 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=
"/">
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=
"http://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">
231 name=
"rule-set" select=
"rules/rule[@usefulness!='useless-in-grammar']"
235 <xsl:text> </xsl:text>
236 <xsl:apply-templates select=
"terminals"/>
237 <xsl:apply-templates select=
"nonterminals"/>
240 <xsl:template name=
"style-rule-set">
241 <xsl:param name=
"rule-set"/>
242 <xsl:for-each select=
"$rule-set">
243 <xsl:apply-templates select=
".">
244 <xsl:with-param name=
"pad" select=
"'3'"/>
245 <xsl:with-param name=
"prev-lhs">
246 <xsl:if test=
"position()>1">
247 <xsl:variable name=
"position" select=
"position()"/>
248 <xsl:value-of select=
"$rule-set[$position - 1]/lhs"/>
251 </xsl:apply-templates>
255 <xsl:template match=
"automaton" mode=
"conflicts">
257 <a name=
"conflicts"/>
258 <xsl:text> Conflicts
</xsl:text>
260 <xsl:text> </xsl:text>
261 <xsl:variable name=
"conflict-report">
262 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
264 <xsl:if test=
"string-length($conflict-report) != 0">
266 <xsl:copy-of select=
"$conflict-report"/>
267 <xsl:text> </xsl:text>
272 <xsl:template match=
"state" mode=
"conflicts">
273 <xsl:variable name=
"conflict-counts">
274 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
277 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
280 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
282 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
284 <xsl:attribute name=
"href">
285 <xsl:value-of select=
"concat('#state_', @number)"/>
287 <xsl:value-of select=
"concat('State ', @number)"/>
289 <xsl:text> conflicts:
</xsl:text>
290 <xsl:if test=
"$sr-count > 0">
291 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
292 <xsl:if test=
"$rr-count > 0">
293 <xsl:value-of select=
"(',')"/>
296 <xsl:if test=
"$rr-count > 0">
297 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
299 <xsl:value-of select=
"' '"/>
303 <xsl:template match=
"grammar/terminals">
305 <a name=
"terminals"/>
306 <xsl:text> Terminals, with rules where they appear
</xsl:text>
308 <xsl:text> </xsl:text>
310 <xsl:apply-templates select=
"terminal"/>
312 <xsl:text> </xsl:text>
315 <xsl:template match=
"grammar/nonterminals">
317 <a name=
"nonterminals"/>
318 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
320 <xsl:text> </xsl:text>
323 select=
"nonterminal[@usefulness!='useless-in-grammar']"
328 <xsl:template match=
"terminal">
329 <b><xsl:value-of select=
"@name"/></b>
330 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
331 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
332 <xsl:apply-templates select=
"." mode=
"number-link"/>
334 <xsl:text> </xsl:text>
337 <xsl:template match=
"nonterminal">
338 <b><xsl:value-of select=
"@name"/></b>
339 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
340 <xsl:text> </xsl:text>
341 <xsl:if test=
"key('bison:ruleByLhs', @name)">
342 <xsl:text>on left:
</xsl:text>
343 <xsl:for-each select=
"key('bison:ruleByLhs', @name)">
344 <xsl:apply-templates select=
"." mode=
"number-link"/>
347 <xsl:if test=
"key('bison:ruleByRhs', @name)">
348 <xsl:if test=
"key('bison:ruleByLhs', @name)">
349 <xsl:text> </xsl:text>
351 <xsl:text>on right:
</xsl:text>
352 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
353 <xsl:apply-templates select=
"." mode=
"number-link"/>
356 <xsl:text> </xsl:text>
359 <xsl:template match=
"rule" mode=
"number-link">
360 <xsl:text> </xsl:text>
362 <xsl:attribute name=
"href">
363 <xsl:value-of select=
"concat('#rule_', @number)"/>
365 <xsl:value-of select=
"@number"/>
369 <xsl:template match=
"automaton">
371 <a name=
"automaton"/>
372 <xsl:text> Automaton
</xsl:text>
374 <xsl:apply-templates select=
"state">
375 <xsl:with-param name=
"pad" select=
"'3'"/>
376 </xsl:apply-templates>
379 <xsl:template match=
"automaton/state">
380 <xsl:param name=
"pad"/>
381 <xsl:text> </xsl:text>
384 <xsl:attribute name=
"name">
385 <xsl:value-of select=
"concat('state_', @number)"/>
388 <xsl:text>state
</xsl:text>
389 <xsl:value-of select=
"@number"/>
391 <xsl:text> </xsl:text>
393 <xsl:apply-templates select=
"itemset/item">
394 <xsl:with-param name=
"pad" select=
"$pad"/>
395 </xsl:apply-templates>
396 <xsl:apply-templates select=
"actions/transitions">
397 <xsl:with-param name=
"type" select=
"'shift'"/>
398 </xsl:apply-templates>
399 <xsl:apply-templates select=
"actions/errors"/>
400 <xsl:apply-templates select=
"actions/reductions"/>
401 <xsl:apply-templates select=
"actions/transitions">
402 <xsl:with-param name=
"type" select=
"'goto'"/>
403 </xsl:apply-templates>
404 <xsl:apply-templates select=
"solved-conflicts"/>
408 <xsl:template match=
"actions/transitions">
409 <xsl:param name=
"type"/>
410 <xsl:if test=
"transition[@type = $type]">
411 <xsl:text> </xsl:text>
412 <xsl:apply-templates select=
"transition[@type = $type]">
413 <xsl:with-param name=
"pad">
414 <xsl:call-template name=
"max-width-symbol">
415 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
418 </xsl:apply-templates>
422 <xsl:template match=
"actions/errors">
423 <xsl:if test=
"error">
424 <xsl:text> </xsl:text>
425 <xsl:apply-templates select=
"error">
426 <xsl:with-param name=
"pad">
427 <xsl:call-template name=
"max-width-symbol">
428 <xsl:with-param name=
"node" select=
"error"/>
431 </xsl:apply-templates>
435 <xsl:template match=
"actions/reductions">
436 <xsl:if test=
"reduction">
437 <xsl:text> </xsl:text>
438 <xsl:apply-templates select=
"reduction">
439 <xsl:with-param name=
"pad">
440 <xsl:call-template name=
"max-width-symbol">
441 <xsl:with-param name=
"node" select=
"reduction"/>
444 </xsl:apply-templates>
448 <xsl:template match=
"item">
449 <xsl:param name=
"pad"/>
450 <xsl:param name=
"prev-rule-number"
451 select=
"preceding-sibling::item[1]/@rule-number"/>
453 select=
"key('bison:ruleByNumber', current()/@rule-number)"
455 <xsl:with-param name=
"itemset" select=
"'true'"/>
456 <xsl:with-param name=
"pad" select=
"$pad"/>
457 <xsl:with-param name=
"prev-lhs"
458 select=
"key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
460 <xsl:with-param name=
"point" select=
"@point"/>
461 <xsl:with-param name=
"lookaheads">
462 <xsl:apply-templates select=
"lookaheads"/>
464 </xsl:apply-templates>
467 <xsl:template match=
"rule">
468 <xsl:param name=
"itemset"/>
469 <xsl:param name=
"pad"/>
470 <xsl:param name=
"prev-lhs"/>
471 <xsl:param name=
"point"/>
472 <xsl:param name=
"lookaheads"/>
474 <xsl:if test=
"$itemset != 'true' and not($prev-lhs = lhs[text()])">
475 <xsl:text> </xsl:text>
478 <xsl:if test=
"$itemset != 'true'">
480 <xsl:attribute name=
"name">
481 <xsl:value-of select=
"concat('rule_', @number)"/>
485 <xsl:text> </xsl:text>
488 <xsl:when test=
"$itemset = 'true'">
490 <xsl:attribute name=
"href">
491 <xsl:value-of select=
"concat('#rule_', @number)"/>
493 <xsl:call-template name=
"lpad">
494 <xsl:with-param name=
"str" select=
"string(@number)"/>
495 <xsl:with-param name=
"pad" select=
"number($pad)"/>
500 <xsl:call-template name=
"lpad">
501 <xsl:with-param name=
"str" select=
"string(@number)"/>
502 <xsl:with-param name=
"pad" select=
"number($pad)"/>
506 <xsl:text> </xsl:text>
510 <xsl:when test=
"$itemset != 'true' and $prev-lhs = lhs[text()]">
511 <xsl:call-template name=
"lpad">
512 <xsl:with-param name=
"str" select=
"'|'"/>
513 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
516 <xsl:when test=
"$itemset = 'true' and $prev-lhs = lhs[text()]">
517 <xsl:call-template name=
"lpad">
518 <xsl:with-param name=
"str" select=
"'|'"/>
519 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
524 <xsl:value-of select=
"lhs"/>
526 <xsl:text> →</xsl:text>
531 <xsl:for-each select=
"rhs/*">
532 <xsl:if test=
"position() = $point + 1">
533 <xsl:text> </xsl:text>
534 <span class=
"point">.
</span>
536 <xsl:if test=
"$itemset = 'true' and name(.) != 'empty'">
537 <xsl:apply-templates select=
"."/>
539 <xsl:if test=
"$itemset != 'true'">
540 <xsl:apply-templates select=
"."/>
542 <xsl:if test=
"position() = last() and position() = $point">
543 <xsl:text> </xsl:text>
544 <span class=
"point">.
</span>
547 <xsl:if test=
"$lookaheads">
548 <xsl:value-of select=
"$lookaheads"/>
551 <xsl:text> </xsl:text>
554 <xsl:template match=
"symbol">
555 <xsl:text> </xsl:text>
557 <xsl:when test=
"name(key('bison:symbolByName', .)) = 'nonterminal'">
558 <span class=
"i"><xsl:value-of select=
"."/></span>
561 <b><xsl:value-of select=
"."/></b>
566 <xsl:template match=
"empty">
567 <xsl:text> ε</xsl:text>
570 <xsl:template match=
"lookaheads">
571 <xsl:text> [
</xsl:text>
572 <xsl:apply-templates select=
"symbol"/>
573 <xsl:text>]
</xsl:text>
576 <xsl:template match=
"lookaheads/symbol">
577 <xsl:value-of select=
"."/>
578 <xsl:if test=
"position() != last()">
579 <xsl:text>,
</xsl:text>
583 <xsl:template match=
"transition">
584 <xsl:param name=
"pad"/>
585 <xsl:text> </xsl:text>
586 <xsl:call-template name=
"rpad">
587 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
588 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
591 <xsl:when test=
"@type = 'shift'">
593 <xsl:attribute name=
"href">
594 <xsl:value-of select=
"concat('#state_', @state)"/>
596 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
599 <xsl:when test=
"@type = 'goto'">
601 <xsl:attribute name=
"href">
602 <xsl:value-of select=
"concat('#state_', @state)"/>
604 <xsl:value-of select=
"concat('go to state ', @state)"/>
608 <xsl:text> </xsl:text>
611 <xsl:template match=
"error">
612 <xsl:param name=
"pad"/>
613 <xsl:text> </xsl:text>
614 <xsl:call-template name=
"rpad">
615 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
616 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
618 <xsl:text>error
</xsl:text>
619 <xsl:text> (
</xsl:text>
620 <xsl:value-of select=
"text()"/>
621 <xsl:text>)
</xsl:text>
622 <xsl:text> </xsl:text>
625 <xsl:template match=
"reduction">
626 <xsl:param name=
"pad"/>
627 <xsl:text> </xsl:text>
628 <xsl:call-template name=
"rpad">
629 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
630 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
632 <xsl:if test=
"@enabled = 'false'">
633 <xsl:text>[
</xsl:text>
636 <xsl:when test=
"@rule = 'accept'">
637 <xsl:text>accept
</xsl:text>
641 <xsl:attribute name=
"href">
642 <xsl:value-of select=
"concat('#rule_', @rule)"/>
644 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
646 <xsl:text> (
</xsl:text>
648 select=
"key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
650 <xsl:text>)
</xsl:text>
653 <xsl:if test=
"@enabled = 'false'">
654 <xsl:text>]
</xsl:text>
656 <xsl:text> </xsl:text>
659 <xsl:template match=
"solved-conflicts">
660 <xsl:if test=
"resolution">
661 <xsl:text> </xsl:text>
662 <xsl:apply-templates select=
"resolution"/>
666 <xsl:template match=
"resolution">
667 <xsl:text> Conflict between
</xsl:text>
669 <xsl:attribute name=
"href">
670 <xsl:value-of select=
"concat('#rule_', @rule)"/>
672 <xsl:value-of select=
"concat('rule ',@rule)"/>
674 <xsl:text> and token
</xsl:text>
675 <xsl:value-of select=
"@symbol"/>
676 <xsl:text> resolved as
</xsl:text>
677 <xsl:if test=
"@type = 'error'">
678 <xsl:text>an
</xsl:text>
680 <xsl:value-of select=
"@type"/>
681 <xsl:text> (
</xsl:text>
682 <xsl:value-of select=
"."/>
683 <xsl:text>).
</xsl:text>
686 <xsl:template name=
"max-width-symbol">
687 <xsl:param name=
"node"/>
688 <xsl:variable name=
"longest">
689 <xsl:for-each select=
"$node">
690 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
692 <xsl:if test=
"position() = 1">
693 <xsl:value-of select=
"string-length(@symbol)"/>
697 <xsl:value-of select=
"$longest"/>
700 <xsl:template name=
"lpad">
701 <xsl:param name=
"str" select=
"''"/>
702 <xsl:param name=
"pad" select=
"0"/>
703 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
705 <xsl:when test=
"$diff < 0">
706 <xsl:value-of select=
"$str"/>
709 <xsl:call-template name=
"space">
710 <xsl:with-param name=
"repeat" select=
"$diff"/>
712 <xsl:value-of select=
"$str"/>
717 <xsl:template name=
"rpad">
718 <xsl:param name=
"str" select=
"''"/>
719 <xsl:param name=
"pad" select=
"0"/>
720 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
722 <xsl:when test=
"$diff < 0">
723 <xsl:value-of select=
"$str"/>
726 <xsl:value-of select=
"$str"/>
727 <xsl:call-template name=
"space">
728 <xsl:with-param name=
"repeat" select=
"$diff"/>
734 <xsl:template name=
"space">
735 <xsl:param name=
"repeat">0</xsl:param>
736 <xsl:param name=
"fill" select=
"' '"/>
737 <xsl:if test=
"number($repeat) >= 1">
738 <xsl:call-template name=
"space">
739 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
740 <xsl:with-param name=
"fill" select=
"$fill"/>
742 <xsl:value-of select=
"$fill"/>