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=
"#terminals_unused_in_grammar">Terminals unused in grammar
</a></li>
113 <li><a href=
"#rules_useless_in_grammar">Rules useless in grammar
</a></li>
114 <xsl:if test=
"grammar/rules/rule[@usefulness='useless-in-parser']">
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=
"grammar" mode=
"reductions"/>
131 <xsl:apply-templates select=
"grammar" mode=
"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=
"grammar" mode=
"reductions">
139 <a name=
"reductions"/>
140 <xsl:text> Reductions
</xsl:text>
142 <xsl:apply-templates select=
"nonterminals" mode=
"useless-in-grammar"/>
143 <xsl:apply-templates select=
"terminals" mode=
"unused-in-grammar"/>
144 <xsl:apply-templates select=
"rules" mode=
"useless-in-grammar"/>
147 <xsl:template match=
"nonterminals" mode=
"useless-in-grammar">
149 <a name=
"nonterminals_useless_in_grammar"/>
150 <xsl:text> Nonterminals useless in grammar
</xsl:text>
152 <xsl:text> </xsl:text>
153 <xsl:if test=
"nonterminal[@usefulness='useless-in-grammar']">
155 <xsl:for-each select=
"nonterminal[@usefulness='useless-in-grammar']">
156 <xsl:text> </xsl:text>
157 <xsl:value-of select=
"@name"/>
158 <xsl:text> </xsl:text>
160 <xsl:text> </xsl:text>
165 <xsl:template match=
"terminals" mode=
"unused-in-grammar">
167 <a name=
"terminals_unused_in_grammar"/>
168 <xsl:text> Terminals unused in grammar
</xsl:text>
170 <xsl:text> </xsl:text>
171 <xsl:if test=
"terminal[@usefulness='unused-in-grammar']">
173 <xsl:for-each select=
"terminal[@usefulness='unused-in-grammar']">
174 <xsl:sort select=
"@symbol-number" data-type=
"number"/>
175 <xsl:text> </xsl:text>
176 <xsl:value-of select=
"@name"/>
177 <xsl:text> </xsl:text>
179 <xsl:text> </xsl:text>
184 <xsl:template match=
"rules" mode=
"useless-in-grammar">
186 <a name=
"rules_useless_in_grammar"/>
187 <xsl:text> Rules useless in grammar
</xsl:text>
189 <xsl:text> </xsl:text>
190 <xsl:variable name=
"set" select=
"rule[@usefulness='useless-in-grammar']"/>
193 <xsl:call-template name=
"style-rule-set">
194 <xsl:with-param name=
"rule-set" select=
"$set"/>
196 <xsl:text> </xsl:text>
201 <xsl:template match=
"grammar" mode=
"useless-in-parser">
203 name=
"set" select=
"rules/rule[@usefulness='useless-in-parser']"
207 <a name=
"rules_useless_in_parser"/>
208 <xsl:text> Rules useless in parser due to conflicts
</xsl:text>
210 <xsl:text> </xsl:text>
212 <xsl:call-template name=
"style-rule-set">
213 <xsl:with-param name=
"rule-set" select=
"$set"/>
216 <xsl:text> </xsl:text>
220 <xsl:template match=
"grammar">
223 <xsl:text> Grammar
</xsl:text>
225 <xsl:text> </xsl:text>
227 <xsl:call-template name=
"style-rule-set">
229 name=
"rule-set" select=
"rules/rule[@usefulness!='useless-in-grammar']"
233 <xsl:text> </xsl:text>
234 <xsl:apply-templates select=
"terminals"/>
235 <xsl:apply-templates select=
"nonterminals"/>
238 <xsl:template name=
"style-rule-set">
239 <xsl:param name=
"rule-set"/>
240 <xsl:for-each select=
"$rule-set">
241 <xsl:apply-templates select=
".">
242 <xsl:with-param name=
"pad" select=
"'3'"/>
243 <xsl:with-param name=
"prev-lhs">
244 <xsl:if test=
"position()>1">
245 <xsl:variable name=
"position" select=
"position()"/>
246 <xsl:value-of select=
"$rule-set[$position - 1]/lhs"/>
249 </xsl:apply-templates>
253 <xsl:template match=
"automaton" mode=
"conflicts">
255 <a name=
"conflicts"/>
256 <xsl:text> Conflicts
</xsl:text>
258 <xsl:text> </xsl:text>
259 <xsl:variable name=
"conflict-report">
260 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
262 <xsl:if test=
"string-length($conflict-report) != 0">
264 <xsl:copy-of select=
"$conflict-report"/>
265 <xsl:text> </xsl:text>
270 <xsl:template match=
"state" mode=
"conflicts">
271 <xsl:variable name=
"conflict-counts">
272 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
275 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
278 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
280 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
282 <xsl:attribute name=
"href">
283 <xsl:value-of select=
"concat('#state_', @number)"/>
285 <xsl:value-of select=
"concat('State ', @number)"/>
287 <xsl:text> conflicts:
</xsl:text>
288 <xsl:if test=
"$sr-count > 0">
289 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
290 <xsl:if test=
"$rr-count > 0">
291 <xsl:value-of select=
"(',')"/>
294 <xsl:if test=
"$rr-count > 0">
295 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
297 <xsl:value-of select=
"' '"/>
301 <xsl:template match=
"grammar/terminals">
303 <a name=
"terminals"/>
304 <xsl:text> Terminals, with rules where they appear
</xsl:text>
306 <xsl:text> </xsl:text>
308 <xsl:apply-templates select=
"terminal"/>
310 <xsl:text> </xsl:text>
313 <xsl:template match=
"grammar/nonterminals">
315 <a name=
"nonterminals"/>
316 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
318 <xsl:text> </xsl:text>
321 select=
"nonterminal[@usefulness!='useless-in-grammar']"
326 <xsl:template match=
"terminal">
327 <b><xsl:value-of select=
"@name"/></b>
328 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
329 <xsl:apply-templates select=
"rule"/>
330 <xsl:text> </xsl:text>
333 <xsl:template match=
"terminal/rule">
334 <xsl:text> </xsl:text>
336 <xsl:attribute name=
"href">
337 <xsl:value-of select=
"concat('#rule_', .)"/>
339 <xsl:value-of select=
"."/>
343 <xsl:template match=
"nonterminal">
344 <b><xsl:value-of select=
"@name"/></b>
345 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
346 <xsl:text> </xsl:text>
347 <xsl:if test=
"left/rule">
348 <xsl:text>on left:
</xsl:text>
350 <xsl:apply-templates select=
"left/rule"/>
351 <xsl:if test=
"left/rule and right/rule">
352 <xsl:text> </xsl:text>
354 <xsl:if test=
"right/rule">
355 <xsl:text>on right:
</xsl:text>
357 <xsl:apply-templates select=
"right/rule"/>
358 <xsl:text> </xsl:text>
361 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
362 <xsl:text> </xsl:text>
364 <xsl:attribute name=
"href">
365 <xsl:value-of select=
"concat('#rule_', .)"/>
367 <xsl:value-of select=
"."/>
371 <xsl:template match=
"automaton">
373 <a name=
"automaton"/>
374 <xsl:text> Automaton
</xsl:text>
376 <xsl:apply-templates select=
"state">
377 <xsl:with-param name=
"pad" select=
"'3'"/>
378 </xsl:apply-templates>
381 <xsl:template match=
"automaton/state">
382 <xsl:param name=
"pad"/>
383 <xsl:text> </xsl:text>
386 <xsl:attribute name=
"name">
387 <xsl:value-of select=
"concat('state_', @number)"/>
390 <xsl:text>state
</xsl:text>
391 <xsl:value-of select=
"@number"/>
393 <xsl:text> </xsl:text>
395 <xsl:apply-templates select=
"itemset/item">
396 <xsl:with-param name=
"pad" select=
"$pad"/>
397 </xsl:apply-templates>
398 <xsl:apply-templates select=
"actions/transitions">
399 <xsl:with-param name=
"type" select=
"'shift'"/>
400 </xsl:apply-templates>
401 <xsl:apply-templates select=
"actions/errors"/>
402 <xsl:apply-templates select=
"actions/reductions"/>
403 <xsl:apply-templates select=
"actions/transitions">
404 <xsl:with-param name=
"type" select=
"'goto'"/>
405 </xsl:apply-templates>
406 <xsl:apply-templates select=
"solved-conflicts"/>
410 <xsl:template match=
"actions/transitions">
411 <xsl:param name=
"type"/>
412 <xsl:if test=
"transition[@type = $type]">
413 <xsl:text> </xsl:text>
414 <xsl:apply-templates select=
"transition[@type = $type]">
415 <xsl:with-param name=
"pad">
416 <xsl:call-template name=
"max-width-symbol">
417 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
420 </xsl:apply-templates>
424 <xsl:template match=
"actions/errors">
425 <xsl:if test=
"error">
426 <xsl:text> </xsl:text>
427 <xsl:apply-templates select=
"error">
428 <xsl:with-param name=
"pad">
429 <xsl:call-template name=
"max-width-symbol">
430 <xsl:with-param name=
"node" select=
"error"/>
433 </xsl:apply-templates>
437 <xsl:template match=
"actions/reductions">
438 <xsl:if test=
"reduction">
439 <xsl:text> </xsl:text>
440 <xsl:apply-templates select=
"reduction">
441 <xsl:with-param name=
"pad">
442 <xsl:call-template name=
"max-width-symbol">
443 <xsl:with-param name=
"node" select=
"reduction"/>
446 </xsl:apply-templates>
450 <xsl:template match=
"item">
451 <xsl:param name=
"pad"/>
452 <xsl:param name=
"prev-rule-number"
453 select=
"preceding-sibling::item[1]/@rule-number"/>
454 <xsl:apply-templates select=
"key('bison:ruleNumber', 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:ruleNumber', $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=
"@class = '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:ruleNumber', current()/@rule)/lhs[text()]"/>
648 <xsl:text>)
</xsl:text>
651 <xsl:if test=
"@enabled = 'false'">
652 <xsl:text>]
</xsl:text>
654 <xsl:text> </xsl:text>
657 <xsl:template match=
"solved-conflicts">
658 <xsl:if test=
"resolution">
659 <xsl:text> </xsl:text>
660 <xsl:apply-templates select=
"resolution"/>
664 <xsl:template match=
"resolution">
665 <xsl:text> Conflict between
</xsl:text>
667 <xsl:attribute name=
"href">
668 <xsl:value-of select=
"concat('#rule_', @rule)"/>
670 <xsl:value-of select=
"concat('rule ',@rule)"/>
672 <xsl:text> and token
</xsl:text>
673 <xsl:value-of select=
"@symbol"/>
674 <xsl:text> resolved as
</xsl:text>
675 <xsl:if test=
"@type = 'error'">
676 <xsl:text>an
</xsl:text>
678 <xsl:value-of select=
"@type"/>
679 <xsl:text> (
</xsl:text>
680 <xsl:value-of select=
"."/>
681 <xsl:text>).
</xsl:text>
684 <xsl:template name=
"max-width-symbol">
685 <xsl:param name=
"node"/>
686 <xsl:variable name=
"longest">
687 <xsl:for-each select=
"$node">
688 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
690 <xsl:if test=
"position() = 1">
691 <xsl:value-of select=
"string-length(@symbol)"/>
695 <xsl:value-of select=
"$longest"/>
698 <xsl:template name=
"lpad">
699 <xsl:param name=
"str" select=
"''"/>
700 <xsl:param name=
"pad" select=
"0"/>
701 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
703 <xsl:when test=
"$diff < 0">
704 <xsl:value-of select=
"$str"/>
707 <xsl:call-template name=
"space">
708 <xsl:with-param name=
"repeat" select=
"$diff"/>
710 <xsl:value-of select=
"$str"/>
715 <xsl:template name=
"rpad">
716 <xsl:param name=
"str" select=
"''"/>
717 <xsl:param name=
"pad" select=
"0"/>
718 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
720 <xsl:when test=
"$diff < 0">
721 <xsl:value-of select=
"$str"/>
724 <xsl:value-of select=
"$str"/>
725 <xsl:call-template name=
"space">
726 <xsl:with-param name=
"repeat" select=
"$diff"/>
732 <xsl:template name=
"space">
733 <xsl:param name=
"repeat">0</xsl:param>
734 <xsl:param name=
"fill" select=
"' '"/>
735 <xsl:if test=
"number($repeat) >= 1">
736 <xsl:call-template name=
"space">
737 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
738 <xsl:with-param name=
"fill" select=
"$fill"/>
740 <xsl:value-of select=
"$fill"/>