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=
"#useless_nonterminals">Useless nonterminal symbols
</a></li>
112 <li><a href=
"#unused_terminals">Unused terminal symbols
</a></li>
113 <li><a href=
"#useless_rules">Useless rules
</a></li>
116 <li><a href=
"#conflicts">Conflicts
</a></li>
118 <a href=
"#grammar">Grammar
</a>
119 <ul class=
"lower-alpha">
120 <li><a href=
"#grammar">Itemset
</a></li>
121 <li><a href=
"#terminals">Terminal symbols
</a></li>
122 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
125 <li><a href=
"#automaton">Automaton
</a></li>
127 <xsl:apply-templates select=
"reductions"/>
128 <xsl:apply-templates select=
"rules-never-reduced"/>
129 <xsl:apply-templates select=
"automaton" mode=
"conflicts"/>
130 <xsl:apply-templates select=
"grammar"/>
131 <xsl:apply-templates select=
"automaton"/>
134 <xsl:template match=
"rules-never-reduced">
137 <a name=
"rules_never_reduced"/>
138 <xsl:text> Rules never reduced
</xsl:text>
140 <xsl:text> </xsl:text>
142 <xsl:apply-templates select=
"rule">
143 <xsl:with-param name=
"pad" select=
"'3'"/>
144 </xsl:apply-templates>
146 <xsl:text> </xsl:text>
150 <xsl:template match=
"reductions">
152 <a name=
"reductions"/>
153 <xsl:text> Reductions
</xsl:text>
155 <xsl:apply-templates select=
"useless/nonterminals"/>
156 <xsl:apply-templates select=
"unused/terminals"/>
157 <xsl:apply-templates select=
"useless/rules"/>
160 <xsl:template match=
"useless/nonterminals">
162 <a name=
"useless_nonterminals"/>
163 <xsl:text> Useless nonterminals
</xsl:text>
165 <xsl:text> </xsl:text>
166 <xsl:if test=
"nonterminal">
168 <xsl:for-each select=
"nonterminal">
169 <xsl:text> </xsl:text>
170 <xsl:value-of select=
"."/>
171 <xsl:text> </xsl:text>
173 <xsl:text> </xsl:text>
178 <xsl:template match=
"useless/rules">
180 <a name=
"useless_rules"/>
181 <xsl:text> Useless rules
</xsl:text>
183 <xsl:text> </xsl:text>
186 <xsl:apply-templates select=
"rule">
187 <xsl:with-param name=
"pad" select=
"'3'"/>
188 </xsl:apply-templates>
189 <xsl:text> </xsl:text>
194 <xsl:template match=
"unused/terminals">
196 <a name=
"unused_terminals"/>
197 <xsl:text> Terminals which are not used
</xsl:text>
199 <xsl:text> </xsl:text>
200 <xsl:if test=
"terminal">
202 <xsl:for-each select=
"terminal">
203 <xsl:text> </xsl:text>
204 <xsl:value-of select=
"."/>
205 <xsl:text> </xsl:text>
207 <xsl:text> </xsl:text>
212 <xsl:template match=
"automaton" mode=
"conflicts">
214 <a name=
"conflicts"/>
215 <xsl:text> Conflicts
</xsl:text>
217 <xsl:text> </xsl:text>
218 <xsl:variable name=
"conflict-report">
219 <xsl:apply-templates select=
"state" mode=
"conflicts"/>
221 <xsl:if test=
"string-length($conflict-report) != 0">
223 <xsl:copy-of select=
"$conflict-report"/>
224 <xsl:text> </xsl:text>
229 <xsl:template match=
"state" mode=
"conflicts">
230 <xsl:variable name=
"conflict-counts">
231 <xsl:apply-templates select=
"." mode=
"bison:count-conflicts" />
234 name=
"sr-count" select=
"substring-before($conflict-counts, ',')"
237 name=
"rr-count" select=
"substring-after($conflict-counts, ',')"
239 <xsl:if test=
"$sr-count > 0 or $rr-count > 0">
241 <xsl:attribute name=
"href">
242 <xsl:value-of select=
"concat('#state_', @number)"/>
244 <xsl:value-of select=
"concat('State ', @number)"/>
246 <xsl:text> conflicts:
</xsl:text>
247 <xsl:if test=
"$sr-count > 0">
248 <xsl:value-of select=
"concat(' ', $sr-count, ' shift/reduce')"/>
249 <xsl:if test=
"$rr-count > 0">
250 <xsl:value-of select=
"(',')"/>
253 <xsl:if test=
"$rr-count > 0">
254 <xsl:value-of select=
"concat(' ', $rr-count, ' reduce/reduce')"/>
256 <xsl:value-of select=
"' '"/>
260 <xsl:template match=
"grammar">
263 <xsl:text> Grammar
</xsl:text>
265 <xsl:text> </xsl:text>
267 <xsl:apply-templates select=
"rules/rule">
268 <xsl:with-param name=
"pad" select=
"'3'"/>
269 </xsl:apply-templates>
271 <xsl:text> </xsl:text>
272 <xsl:apply-templates select=
"terminals"/>
273 <xsl:apply-templates select=
"nonterminals"/>
276 <xsl:template match=
"grammar/terminals">
278 <a name=
"terminals"/>
279 <xsl:text> Terminals, with rules where they appear
</xsl:text>
281 <xsl:text> </xsl:text>
283 <xsl:apply-templates select=
"terminal"/>
285 <xsl:text> </xsl:text>
288 <xsl:template match=
"grammar/nonterminals">
290 <a name=
"nonterminals"/>
291 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
293 <xsl:text> </xsl:text>
295 <xsl:apply-templates select=
"nonterminal"/>
299 <xsl:template match=
"terminal">
300 <b><xsl:value-of select=
"@symbol"/></b>
301 <xsl:value-of select=
"concat(' (', @type, ')')"/>
302 <xsl:apply-templates select=
"rule"/>
303 <xsl:text> </xsl:text>
306 <xsl:template match=
"terminal/rule">
307 <xsl:text> </xsl:text>
309 <xsl:attribute name=
"href">
310 <xsl:value-of select=
"concat('#rule_', .)"/>
312 <xsl:value-of select=
"."/>
316 <xsl:template match=
"nonterminal">
317 <b><xsl:value-of select=
"@symbol"/></b>
318 <xsl:value-of select=
"concat(' (', @type, ')')"/>
319 <xsl:text> </xsl:text>
320 <xsl:if test=
"left/rule">
321 <xsl:text>on left:
</xsl:text>
323 <xsl:apply-templates select=
"left/rule"/>
324 <xsl:if test=
"left/rule and right/rule">
325 <xsl:text> </xsl:text>
327 <xsl:if test=
"right/rule">
328 <xsl:text>on right:
</xsl:text>
330 <xsl:apply-templates select=
"right/rule"/>
331 <xsl:text> </xsl:text>
334 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
335 <xsl:text> </xsl:text>
337 <xsl:attribute name=
"href">
338 <xsl:value-of select=
"concat('#rule_', .)"/>
340 <xsl:value-of select=
"."/>
344 <xsl:template match=
"automaton">
346 <a name=
"automaton"/>
347 <xsl:text> Automaton
</xsl:text>
349 <xsl:apply-templates select=
"state">
350 <xsl:with-param name=
"pad" select=
"'3'"/>
351 </xsl:apply-templates>
354 <xsl:template match=
"automaton/state">
355 <xsl:param name=
"pad"/>
356 <xsl:text> </xsl:text>
359 <xsl:attribute name=
"name">
360 <xsl:value-of select=
"concat('state_', @number)"/>
363 <xsl:text>state
</xsl:text>
364 <xsl:value-of select=
"@number"/>
366 <xsl:text> </xsl:text>
368 <xsl:apply-templates select=
"itemset/rule">
369 <xsl:with-param name=
"pad" select=
"$pad"/>
370 </xsl:apply-templates>
371 <xsl:apply-templates select=
"actions/transitions">
372 <xsl:with-param name=
"type" select=
"'shift'"/>
373 </xsl:apply-templates>
374 <xsl:apply-templates select=
"actions/errors"/>
375 <xsl:apply-templates select=
"actions/reductions"/>
376 <xsl:apply-templates select=
"actions/transitions">
377 <xsl:with-param name=
"type" select=
"'goto'"/>
378 </xsl:apply-templates>
379 <xsl:apply-templates select=
"solved-conflicts"/>
383 <xsl:template match=
"actions/transitions">
384 <xsl:param name=
"type"/>
385 <xsl:if test=
"transition[@type = $type]">
386 <xsl:text> </xsl:text>
387 <xsl:apply-templates select=
"transition[@type = $type]">
388 <xsl:with-param name=
"pad">
389 <xsl:call-template name=
"max-width-symbol">
390 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
393 </xsl:apply-templates>
397 <xsl:template match=
"actions/errors">
398 <xsl:if test=
"error">
399 <xsl:text> </xsl:text>
400 <xsl:apply-templates select=
"error">
401 <xsl:with-param name=
"pad">
402 <xsl:call-template name=
"max-width-symbol">
403 <xsl:with-param name=
"node" select=
"error"/>
406 </xsl:apply-templates>
410 <xsl:template match=
"actions/reductions">
411 <xsl:if test=
"reduction">
412 <xsl:text> </xsl:text>
413 <xsl:apply-templates select=
"reduction">
414 <xsl:with-param name=
"pad">
415 <xsl:call-template name=
"max-width-symbol">
416 <xsl:with-param name=
"node" select=
"reduction"/>
419 </xsl:apply-templates>
423 <xsl:template match=
"rule">
424 <xsl:param name=
"pad"/>
425 <xsl:if test=
"not(name(..) = 'itemset') and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
426 <xsl:text> </xsl:text>
428 <xsl:if test=
"not(name(..) = 'itemset')">
430 <xsl:attribute name=
"name">
431 <xsl:value-of select=
"concat('rule_', @number)"/>
435 <xsl:text> </xsl:text>
437 <xsl:when test=
"name(..) = 'itemset'">
439 <xsl:attribute name=
"href">
440 <xsl:value-of select=
"concat('#rule_', @number)"/>
442 <xsl:call-template name=
"lpad">
443 <xsl:with-param name=
"str" select=
"string(@number)"/>
444 <xsl:with-param name=
"pad" select=
"number($pad)"/>
449 <xsl:call-template name=
"lpad">
450 <xsl:with-param name=
"str" select=
"string(@number)"/>
451 <xsl:with-param name=
"pad" select=
"number($pad)"/>
455 <xsl:text> </xsl:text>
457 <xsl:when test=
"preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
458 <xsl:call-template name=
"lpad">
459 <xsl:with-param name=
"str" select=
"'|'"/>
460 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
465 <xsl:value-of select=
"lhs"/>
467 <xsl:text> →</xsl:text>
470 <xsl:apply-templates select=
"rhs/symbol|rhs/point|rhs/empty"/>
471 <xsl:apply-templates select=
"lookaheads"/>
472 <xsl:text> </xsl:text>
475 <xsl:template match=
"symbol">
476 <xsl:text> </xsl:text>
478 <xsl:when test=
"@class = 'nonterminal'">
479 <span class=
"i"><xsl:value-of select=
"."/></span>
482 <b><xsl:value-of select=
"."/></b>
487 <xsl:template match=
"point">
488 <xsl:text> </xsl:text>
489 <span class=
"point">.
</span>
492 <xsl:template match=
"empty">
493 <xsl:text> ε</xsl:text>
496 <xsl:template match=
"lookaheads">
497 <xsl:text> [
</xsl:text>
498 <xsl:apply-templates select=
"symbol"/>
499 <xsl:text>]
</xsl:text>
502 <xsl:template match=
"lookaheads/symbol">
503 <xsl:value-of select=
"."/>
504 <xsl:if test=
"position() != last()">
505 <xsl:text>,
</xsl:text>
509 <xsl:template match=
"transition">
510 <xsl:param name=
"pad"/>
511 <xsl:text> </xsl:text>
512 <xsl:call-template name=
"rpad">
513 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
514 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
517 <xsl:when test=
"@type = 'shift'">
519 <xsl:attribute name=
"href">
520 <xsl:value-of select=
"concat('#state_', @state)"/>
522 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
525 <xsl:when test=
"@type = 'goto'">
527 <xsl:attribute name=
"href">
528 <xsl:value-of select=
"concat('#state_', @state)"/>
530 <xsl:value-of select=
"concat('go to state ', @state)"/>
534 <xsl:text> </xsl:text>
537 <xsl:template match=
"error">
538 <xsl:param name=
"pad"/>
539 <xsl:text> </xsl:text>
540 <xsl:call-template name=
"rpad">
541 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
542 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
544 <xsl:text>error
</xsl:text>
545 <xsl:text> (
</xsl:text>
546 <xsl:value-of select=
"text()"/>
547 <xsl:text>)
</xsl:text>
548 <xsl:text> </xsl:text>
551 <xsl:template match=
"reduction">
552 <xsl:param name=
"pad"/>
553 <xsl:text> </xsl:text>
554 <xsl:call-template name=
"rpad">
555 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
556 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
558 <xsl:if test=
"@enabled = 'false'">
559 <xsl:text>[
</xsl:text>
562 <xsl:when test=
"@rule = 'accept'">
563 <xsl:text>accept
</xsl:text>
567 <xsl:attribute name=
"href">
568 <xsl:value-of select=
"concat('#rule_', @rule)"/>
570 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
572 <xsl:text> (
</xsl:text>
574 select=
"/bison-xml-report/grammar/rules/rule[@number = current()/@rule]/lhs[text()]"/>
575 <xsl:text>)
</xsl:text>
578 <xsl:if test=
"@enabled = 'false'">
579 <xsl:text>]
</xsl:text>
581 <xsl:text> </xsl:text>
584 <xsl:template match=
"solved-conflicts">
585 <xsl:if test=
"resolution">
586 <xsl:text> </xsl:text>
587 <xsl:apply-templates select=
"resolution"/>
591 <xsl:template match=
"resolution">
592 <xsl:text> Conflict between
</xsl:text>
594 <xsl:attribute name=
"href">
595 <xsl:value-of select=
"concat('#rule_', @rule)"/>
597 <xsl:value-of select=
"concat('rule ',@rule)"/>
599 <xsl:text> and token
</xsl:text>
600 <xsl:value-of select=
"@symbol"/>
601 <xsl:text> resolved as
</xsl:text>
602 <xsl:if test=
"@type = 'error'">
603 <xsl:text>an
</xsl:text>
605 <xsl:value-of select=
"@type"/>
606 <xsl:text> (
</xsl:text>
607 <xsl:value-of select=
"."/>
608 <xsl:text>).
</xsl:text>
611 <xsl:template name=
"max-width-symbol">
612 <xsl:param name=
"node"/>
613 <xsl:variable name=
"longest">
614 <xsl:for-each select=
"$node">
615 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
617 <xsl:if test=
"position() = 1">
618 <xsl:value-of select=
"string-length(@symbol)"/>
622 <xsl:value-of select=
"$longest"/>
625 <xsl:template name=
"lpad">
626 <xsl:param name=
"str" select=
"''"/>
627 <xsl:param name=
"pad" select=
"0"/>
628 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
630 <xsl:when test=
"$diff < 0">
631 <xsl:value-of select=
"$str"/>
634 <xsl:call-template name=
"space">
635 <xsl:with-param name=
"repeat" select=
"$diff"/>
637 <xsl:value-of select=
"$str"/>
642 <xsl:template name=
"rpad">
643 <xsl:param name=
"str" select=
"''"/>
644 <xsl:param name=
"pad" select=
"0"/>
645 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
647 <xsl:when test=
"$diff < 0">
648 <xsl:value-of select=
"$str"/>
651 <xsl:value-of select=
"$str"/>
652 <xsl:call-template name=
"space">
653 <xsl:with-param name=
"repeat" select=
"$diff"/>
659 <xsl:template name=
"space">
660 <xsl:param name=
"repeat">0</xsl:param>
661 <xsl:param name=
"fill" select=
"' '"/>
662 <xsl:if test=
"number($repeat) >= 1">
663 <xsl:call-template name=
"space">
664 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
665 <xsl:with-param name=
"fill" select=
"$fill"/>
667 <xsl:value-of select=
"$fill"/>