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 />
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, written by
94 <a href=
"http://www.gnu.org.ua/~polak/" title=
"Wojciech Polak">Wojciech Polak
</a>.
95 Copyright (C)
2007,
2008 Free Software Foundation, Inc.
<br />
96 Verbatim copying and distribution of this entire page is permitted
97 in any medium, provided this notice is preserved.
</div>
102 <xsl:template match=
"bison-xml-report">
103 <h1>GNU Bison XML Automaton Report
</h1>
105 input grammar:
<span class=
"i"><xsl:value-of select=
"filename"/></span>
108 <xsl:text> </xsl:text>
109 <h3>Table of Contents
</h3>
112 <a href=
"#reductions">Reductions
</a>
113 <ul class=
"lower-alpha">
114 <li><a href=
"#nonterminals_useless_in_grammar">Nonterminals useless in grammar
</a></li>
115 <li><a href=
"#terminals_unused_in_grammar">Terminals unused in grammar
</a></li>
116 <li><a href=
"#rules_useless_in_grammar">Rules useless in grammar
</a></li>
117 <xsl:if test=
"grammar/rules/rule[@usefulness='useless-in-parser']">
118 <li><a href=
"#rules_useless_in_parser">Rules useless in parser due to conflicts
</a></li>
122 <li><a href=
"#conflicts">Conflicts
</a></li>
124 <a href=
"#grammar">Grammar
</a>
125 <ul class=
"lower-alpha">
126 <li><a href=
"#grammar">Itemset
</a></li>
127 <li><a href=
"#terminals">Terminal symbols
</a></li>
128 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
131 <li><a href=
"#automaton">Automaton
</a></li>
133 <xsl:apply-templates select=
"grammar" mode=
"reductions"/>
134 <xsl:apply-templates select=
"grammar" mode=
"useless-in-parser"/>
135 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
136 <xsl:apply-templates select=
"grammar"/>
137 <xsl:apply-templates select=
"automaton"/>
140 <xsl:template match=
"grammar" mode=
"reductions">
142 <a name=
"reductions"/>
143 <xsl:text> Reductions
</xsl:text>
145 <xsl:apply-templates select=
"nonterminals" mode=
"useless-in-grammar"/>
146 <xsl:apply-templates select=
"terminals" mode=
"unused-in-grammar"/>
147 <xsl:apply-templates select=
"rules" mode=
"useless-in-grammar"/>
150 <xsl:template match=
"nonterminals" mode=
"useless-in-grammar">
152 <a name=
"nonterminals_useless_in_grammar"/>
153 <xsl:text> Nonterminals useless in grammar
</xsl:text>
155 <xsl:text> </xsl:text>
156 <xsl:if test=
"nonterminal[@usefulness='useless-in-grammar']">
158 <xsl:for-each select=
"nonterminal[@usefulness='useless-in-grammar']">
159 <xsl:text> </xsl:text>
160 <xsl:value-of select=
"@name"/>
161 <xsl:text> </xsl:text>
163 <xsl:text> </xsl:text>
168 <xsl:template match=
"terminals" mode=
"unused-in-grammar">
170 <a name=
"terminals_unused_in_grammar"/>
171 <xsl:text> Terminals unused in grammar
</xsl:text>
173 <xsl:text> </xsl:text>
174 <xsl:if test=
"terminal[@usefulness='unused-in-grammar']">
176 <xsl:for-each select=
"terminal[@usefulness='unused-in-grammar']">
177 <xsl:sort select=
"@symbol-number" data-type=
"number"/>
178 <xsl:text> </xsl:text>
179 <xsl:value-of select=
"@name"/>
180 <xsl:text> </xsl:text>
182 <xsl:text> </xsl:text>
187 <xsl:template match=
"rules" mode=
"useless-in-grammar">
189 <a name=
"rules_useless_in_grammar"/>
190 <xsl:text> Rules useless in grammar
</xsl:text>
192 <xsl:text> </xsl:text>
193 <xsl:variable name=
"set" select=
"rule[@usefulness='useless-in-grammar']"/>
196 <xsl:call-template name=
"style-rule-set">
197 <xsl:with-param name=
"rule-set" select=
"$set"/>
199 <xsl:text> </xsl:text>
204 <xsl:template match=
"grammar" mode=
"useless-in-parser">
206 name=
"set" select=
"rules/rule[@usefulness='useless-in-parser']"
210 <a name=
"rules_useless_in_parser"/>
211 <xsl:text> Rules useless in parser due to conflicts
</xsl:text>
213 <xsl:text> </xsl:text>
215 <xsl:call-template name=
"style-rule-set">
216 <xsl:with-param name=
"rule-set" select=
"$set"/>
219 <xsl:text> </xsl:text>
223 <xsl:template match=
"grammar">
226 <xsl:text> Grammar
</xsl:text>
228 <xsl:text> </xsl:text>
230 <xsl:call-template name=
"style-rule-set">
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=
"rule-set"/>
243 <xsl:for-each select=
"$rule-set">
244 <xsl:apply-templates select=
".">
245 <xsl:with-param name=
"pad" select=
"'3'"/>
246 <xsl:with-param name=
"prev-lhs">
247 <xsl:if test=
"position()>1">
248 <xsl:variable name=
"position" select=
"position()"/>
249 <xsl:value-of select=
"$rule-set[$position - 1]/lhs"/>
252 </xsl:apply-templates>
256 <xsl:template match=
"automaton" mode=
"conflicts">
258 <a name=
"conflicts"/>
259 <xsl:text> Conflicts
</xsl:text>
261 <xsl:text> </xsl:text>
262 <xsl:variable name=
"conflict-report">
263 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
265 <xsl:if test=
"string-length($conflict-report) != 0">
267 <xsl:copy-of select=
"$conflict-report"/>
268 <xsl:text> </xsl:text>
273 <xsl:template match=
"state" mode=
"conflicts">
274 <xsl:variable name=
"conflict-counts">
275 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
278 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
281 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
283 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
285 <xsl:attribute name=
"href">
286 <xsl:value-of select=
"concat('#state_', @number)"/>
288 <xsl:value-of select=
"concat('State ', @number)"/>
290 <xsl:text> conflicts:
</xsl:text>
291 <xsl:if test=
"$sr-count > 0">
292 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
293 <xsl:if test=
"$rr-count > 0">
294 <xsl:value-of select=
"(',')"/>
297 <xsl:if test=
"$rr-count > 0">
298 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
300 <xsl:value-of select=
"' '"/>
304 <xsl:template match=
"grammar/terminals">
306 <a name=
"terminals"/>
307 <xsl:text> Terminals, with rules where they appear
</xsl:text>
309 <xsl:text> </xsl:text>
311 <xsl:apply-templates select=
"terminal"/>
313 <xsl:text> </xsl:text>
316 <xsl:template match=
"grammar/nonterminals">
318 <a name=
"nonterminals"/>
319 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
321 <xsl:text> </xsl:text>
324 select=
"nonterminal[@usefulness!='useless-in-grammar']"
329 <xsl:template match=
"terminal">
330 <b><xsl:value-of select=
"@name"/></b>
331 <xsl:value-of select=
"concat(' (', @token-number, ')')"/>
332 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
333 <xsl:apply-templates select=
"." mode=
"number-link"/>
335 <xsl:text> </xsl:text>
338 <xsl:template match=
"nonterminal">
339 <b><xsl:value-of select=
"@name"/></b>
340 <xsl:value-of select=
"concat(' (', @symbol-number, ')')"/>
341 <xsl:text> </xsl:text>
342 <xsl:if test=
"key('bison:ruleByLhs', @name)">
343 <xsl:text>on left:
</xsl:text>
344 <xsl:for-each select=
"key('bison:ruleByLhs', @name)">
345 <xsl:apply-templates select=
"." mode=
"number-link"/>
348 <xsl:if test=
"key('bison:ruleByRhs', @name)">
349 <xsl:if test=
"key('bison:ruleByLhs', @name)">
350 <xsl:text> </xsl:text>
352 <xsl:text>on right:
</xsl:text>
353 <xsl:for-each select=
"key('bison:ruleByRhs', @name)">
354 <xsl:apply-templates select=
"." mode=
"number-link"/>
357 <xsl:text> </xsl:text>
360 <xsl:template match=
"rule" mode=
"number-link">
361 <xsl:text> </xsl:text>
363 <xsl:attribute name=
"href">
364 <xsl:value-of select=
"concat('#rule_', @number)"/>
366 <xsl:value-of select=
"@number"/>
370 <xsl:template match=
"automaton">
372 <a name=
"automaton"/>
373 <xsl:text> Automaton
</xsl:text>
375 <xsl:apply-templates select=
"state">
376 <xsl:with-param name=
"pad" select=
"'3'"/>
377 </xsl:apply-templates>
380 <xsl:template match=
"automaton/state">
381 <xsl:param name=
"pad"/>
382 <xsl:text> </xsl:text>
385 <xsl:attribute name=
"name">
386 <xsl:value-of select=
"concat('state_', @number)"/>
389 <xsl:text>state
</xsl:text>
390 <xsl:value-of select=
"@number"/>
392 <xsl:text> </xsl:text>
394 <xsl:apply-templates select=
"itemset/item">
395 <xsl:with-param name=
"pad" select=
"$pad"/>
396 </xsl:apply-templates>
397 <xsl:apply-templates select=
"actions/transitions">
398 <xsl:with-param name=
"type" select=
"'shift'"/>
399 </xsl:apply-templates>
400 <xsl:apply-templates select=
"actions/errors"/>
401 <xsl:apply-templates select=
"actions/reductions"/>
402 <xsl:apply-templates select=
"actions/transitions">
403 <xsl:with-param name=
"type" select=
"'goto'"/>
404 </xsl:apply-templates>
405 <xsl:apply-templates select=
"solved-conflicts"/>
409 <xsl:template match=
"actions/transitions">
410 <xsl:param name=
"type"/>
411 <xsl:if test=
"transition[@type = $type]">
412 <xsl:text> </xsl:text>
413 <xsl:apply-templates select=
"transition[@type = $type]">
414 <xsl:with-param name=
"pad">
415 <xsl:call-template name=
"max-width-symbol">
416 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
419 </xsl:apply-templates>
423 <xsl:template match=
"actions/errors">
424 <xsl:if test=
"error">
425 <xsl:text> </xsl:text>
426 <xsl:apply-templates select=
"error">
427 <xsl:with-param name=
"pad">
428 <xsl:call-template name=
"max-width-symbol">
429 <xsl:with-param name=
"node" select=
"error"/>
432 </xsl:apply-templates>
436 <xsl:template match=
"actions/reductions">
437 <xsl:if test=
"reduction">
438 <xsl:text> </xsl:text>
439 <xsl:apply-templates select=
"reduction">
440 <xsl:with-param name=
"pad">
441 <xsl:call-template name=
"max-width-symbol">
442 <xsl:with-param name=
"node" select=
"reduction"/>
445 </xsl:apply-templates>
449 <xsl:template match=
"item">
450 <xsl:param name=
"pad"/>
451 <xsl:param name=
"prev-rule-number"
452 select=
"preceding-sibling::item[1]/@rule-number"/>
454 select=
"key('bison:ruleByNumber', current()/@rule-number)"
456 <xsl:with-param name=
"itemset" select=
"'true'"/>
457 <xsl:with-param name=
"pad" select=
"$pad"/>
458 <xsl:with-param name=
"prev-lhs"
459 select=
"key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
461 <xsl:with-param name=
"point" select=
"@point"/>
462 <xsl:with-param name=
"lookaheads">
463 <xsl:apply-templates select=
"lookaheads"/>
465 </xsl:apply-templates>
468 <xsl:template match=
"rule">
469 <xsl:param name=
"itemset"/>
470 <xsl:param name=
"pad"/>
471 <xsl:param name=
"prev-lhs"/>
472 <xsl:param name=
"point"/>
473 <xsl:param name=
"lookaheads"/>
475 <xsl:if test=
"$itemset != 'true' and not($prev-lhs = lhs[text()])">
476 <xsl:text> </xsl:text>
479 <xsl:if test=
"$itemset != 'true'">
481 <xsl:attribute name=
"name">
482 <xsl:value-of select=
"concat('rule_', @number)"/>
486 <xsl:text> </xsl:text>
489 <xsl:when test=
"$itemset = 'true'">
491 <xsl:attribute name=
"href">
492 <xsl:value-of select=
"concat('#rule_', @number)"/>
494 <xsl:call-template name=
"lpad">
495 <xsl:with-param name=
"str" select=
"string(@number)"/>
496 <xsl:with-param name=
"pad" select=
"number($pad)"/>
501 <xsl:call-template name=
"lpad">
502 <xsl:with-param name=
"str" select=
"string(@number)"/>
503 <xsl:with-param name=
"pad" select=
"number($pad)"/>
507 <xsl:text> </xsl:text>
511 <xsl:when test=
"$itemset != 'true' and $prev-lhs = lhs[text()]">
512 <xsl:call-template name=
"lpad">
513 <xsl:with-param name=
"str" select=
"'|'"/>
514 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
517 <xsl:when test=
"$itemset = 'true' and $prev-lhs = lhs[text()]">
518 <xsl:call-template name=
"lpad">
519 <xsl:with-param name=
"str" select=
"'|'"/>
520 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
525 <xsl:value-of select=
"lhs"/>
527 <xsl:text> →</xsl:text>
532 <xsl:for-each select=
"rhs/*">
533 <xsl:if test=
"position() = $point + 1">
534 <xsl:text> </xsl:text>
535 <span class=
"point">.
</span>
537 <xsl:if test=
"$itemset = 'true' and name(.) != 'empty'">
538 <xsl:apply-templates select=
"."/>
540 <xsl:if test=
"$itemset != 'true'">
541 <xsl:apply-templates select=
"."/>
543 <xsl:if test=
"position() = last() and position() = $point">
544 <xsl:text> </xsl:text>
545 <span class=
"point">.
</span>
548 <xsl:if test=
"$lookaheads">
549 <xsl:value-of select=
"$lookaheads"/>
552 <xsl:text> </xsl:text>
555 <xsl:template match=
"symbol">
556 <xsl:text> </xsl:text>
558 <xsl:when test=
"name(key('bison:symbolByName', .)) = 'nonterminal'">
559 <span class=
"i"><xsl:value-of select=
"."/></span>
562 <b><xsl:value-of select=
"."/></b>
567 <xsl:template match=
"empty">
568 <xsl:text> ε</xsl:text>
571 <xsl:template match=
"lookaheads">
572 <xsl:text> [
</xsl:text>
573 <xsl:apply-templates select=
"symbol"/>
574 <xsl:text>]
</xsl:text>
577 <xsl:template match=
"lookaheads/symbol">
578 <xsl:value-of select=
"."/>
579 <xsl:if test=
"position() != last()">
580 <xsl:text>,
</xsl:text>
584 <xsl:template match=
"transition">
585 <xsl:param name=
"pad"/>
586 <xsl:text> </xsl:text>
587 <xsl:call-template name=
"rpad">
588 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
589 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
592 <xsl:when test=
"@type = 'shift'">
594 <xsl:attribute name=
"href">
595 <xsl:value-of select=
"concat('#state_', @state)"/>
597 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
600 <xsl:when test=
"@type = 'goto'">
602 <xsl:attribute name=
"href">
603 <xsl:value-of select=
"concat('#state_', @state)"/>
605 <xsl:value-of select=
"concat('go to state ', @state)"/>
609 <xsl:text> </xsl:text>
612 <xsl:template match=
"error">
613 <xsl:param name=
"pad"/>
614 <xsl:text> </xsl:text>
615 <xsl:call-template name=
"rpad">
616 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
617 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
619 <xsl:text>error
</xsl:text>
620 <xsl:text> (
</xsl:text>
621 <xsl:value-of select=
"text()"/>
622 <xsl:text>)
</xsl:text>
623 <xsl:text> </xsl:text>
626 <xsl:template match=
"reduction">
627 <xsl:param name=
"pad"/>
628 <xsl:text> </xsl:text>
629 <xsl:call-template name=
"rpad">
630 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
631 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
633 <xsl:if test=
"@enabled = 'false'">
634 <xsl:text>[
</xsl:text>
637 <xsl:when test=
"@rule = 'accept'">
638 <xsl:text>accept
</xsl:text>
642 <xsl:attribute name=
"href">
643 <xsl:value-of select=
"concat('#rule_', @rule)"/>
645 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
647 <xsl:text> (
</xsl:text>
649 select=
"key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
651 <xsl:text>)
</xsl:text>
654 <xsl:if test=
"@enabled = 'false'">
655 <xsl:text>]
</xsl:text>
657 <xsl:text> </xsl:text>
660 <xsl:template match=
"solved-conflicts">
661 <xsl:if test=
"resolution">
662 <xsl:text> </xsl:text>
663 <xsl:apply-templates select=
"resolution"/>
667 <xsl:template match=
"resolution">
668 <xsl:text> Conflict between
</xsl:text>
670 <xsl:attribute name=
"href">
671 <xsl:value-of select=
"concat('#rule_', @rule)"/>
673 <xsl:value-of select=
"concat('rule ',@rule)"/>
675 <xsl:text> and token
</xsl:text>
676 <xsl:value-of select=
"@symbol"/>
677 <xsl:text> resolved as
</xsl:text>
678 <xsl:if test=
"@type = 'error'">
679 <xsl:text>an
</xsl:text>
681 <xsl:value-of select=
"@type"/>
682 <xsl:text> (
</xsl:text>
683 <xsl:value-of select=
"."/>
684 <xsl:text>).
</xsl:text>
687 <xsl:template name=
"max-width-symbol">
688 <xsl:param name=
"node"/>
689 <xsl:variable name=
"longest">
690 <xsl:for-each select=
"$node">
691 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
693 <xsl:if test=
"position() = 1">
694 <xsl:value-of select=
"string-length(@symbol)"/>
698 <xsl:value-of select=
"$longest"/>
701 <xsl:template name=
"lpad">
702 <xsl:param name=
"str" select=
"''"/>
703 <xsl:param name=
"pad" select=
"0"/>
704 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
706 <xsl:when test=
"$diff < 0">
707 <xsl:value-of select=
"$str"/>
710 <xsl:call-template name=
"space">
711 <xsl:with-param name=
"repeat" select=
"$diff"/>
713 <xsl:value-of select=
"$str"/>
718 <xsl:template name=
"rpad">
719 <xsl:param name=
"str" select=
"''"/>
720 <xsl:param name=
"pad" select=
"0"/>
721 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
723 <xsl:when test=
"$diff < 0">
724 <xsl:value-of select=
"$str"/>
727 <xsl:value-of select=
"$str"/>
728 <xsl:call-template name=
"space">
729 <xsl:with-param name=
"repeat" select=
"$diff"/>
735 <xsl:template name=
"space">
736 <xsl:param name=
"repeat">0</xsl:param>
737 <xsl:param name=
"fill" select=
"' '"/>
738 <xsl:if test=
"number($repeat) >= 1">
739 <xsl:call-template name=
"space">
740 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
741 <xsl:with-param name=
"fill" select=
"$fill"/>
743 <xsl:value-of select=
"$fill"/>