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">
31 <xsl:output method=
"xml" encoding=
"UTF-8"
32 doctype-public=
"-//W3C//DTD XHTML 1.0 Strict//EN"
33 doctype-system=
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
36 <xsl:template match=
"/">
39 <title>GNU Bison XML Automaton Report
</title>
40 <style type=
"text/css"><![CDATA[
42 font-family: "Nimbus Sans L", Arial, sans-serif;
47 text-decoration: none;
51 text-decoration: none;
57 text-decoration: underline;
63 font-family: monospace;
67 list-style-type: decimal;
70 list-style-type: lower-alpha;
82 <xsl:apply-templates select=
"bison-xml-report"/>
83 <xsl:text> </xsl:text>
84 <div id=
"footer"><hr />
85 <a href=
"http://www.gnu.org/software/bison/" title=
"GNU Bison">
86 GNU Bison
<xsl:value-of select=
"/bison-xml-report/@version"/></a>
87 XML Automaton Report, written by
88 <a href=
"http://www.gnu.org.ua/~polak/" title=
"Wojciech Polak">Wojciech Polak
</a>.
89 Copyright (C)
2007 Free Software Foundation, Inc.
<br />
90 Verbatim copying and distribution of this entire page is permitted
91 in any medium, provided this notice is preserved.
</div>
96 <xsl:template match=
"bison-xml-report">
97 <h1>GNU Bison XML Automaton Report
</h1>
99 input grammar:
<span class=
"i"><xsl:value-of select=
"filename"/></span>
102 <xsl:text> </xsl:text>
103 <h3>Table of Contents
</h3>
106 <a href=
"#reductions">Reductions
</a>
107 <ul class=
"lower-alpha">
108 <li><a href=
"#useless_nonterminals">Useless nonterminal symbols
</a></li>
109 <li><a href=
"#unused_terminals">Unused terminal symbols
</a></li>
110 <li><a href=
"#useless_rules">Useless rules
</a></li>
113 <li><a href=
"#conflicts">Conflicts
</a></li>
115 <a href=
"#grammar">Grammar
</a>
116 <ul class=
"lower-alpha">
117 <li><a href=
"#grammar">Itemset
</a></li>
118 <li><a href=
"#terminals">Terminal symbols
</a></li>
119 <li><a href=
"#nonterminals">Nonterminal symbols
</a></li>
122 <li><a href=
"#automaton">Automaton
</a></li>
124 <xsl:apply-templates select=
"reductions"/>
125 <xsl:apply-templates select=
"rules-never-reduced"/>
126 <xsl:apply-templates select=
"conflicts"/>
127 <xsl:apply-templates select=
"grammar"/>
128 <xsl:apply-templates select=
"automaton"/>
131 <xsl:template match=
"rules-never-reduced">
134 <a name=
"rules_never_reduced"/>
135 <xsl:text> Rules never reduced
</xsl:text>
137 <xsl:text> </xsl:text>
139 <xsl:apply-templates select=
"rule">
140 <xsl:with-param name=
"pad" select=
"'3'"/>
141 </xsl:apply-templates>
143 <xsl:text> </xsl:text>
147 <xsl:template match=
"reductions">
149 <a name=
"reductions"/>
150 <xsl:text> Reductions
</xsl:text>
152 <xsl:apply-templates select=
"useless/nonterminals"/>
153 <xsl:apply-templates select=
"unused/terminals"/>
154 <xsl:apply-templates select=
"useless/rules"/>
157 <xsl:template match=
"useless/nonterminals">
159 <a name=
"useless_nonterminals"/>
160 <xsl:text> Useless nonterminals
</xsl:text>
162 <xsl:text> </xsl:text>
163 <xsl:if test=
"nonterminal">
165 <xsl:for-each select=
"nonterminal">
166 <xsl:text> </xsl:text>
167 <xsl:value-of select=
"."/>
168 <xsl:text> </xsl:text>
170 <xsl:text> </xsl:text>
175 <xsl:template match=
"useless/rules">
177 <a name=
"useless_rules"/>
178 <xsl:text> Useless rules
</xsl:text>
180 <xsl:text> </xsl:text>
183 <xsl:apply-templates select=
"rule">
184 <xsl:with-param name=
"pad" select=
"'3'"/>
185 </xsl:apply-templates>
186 <xsl:text> </xsl:text>
191 <xsl:template match=
"unused/terminals">
193 <a name=
"unused_terminals"/>
194 <xsl:text> Terminals which are not used
</xsl:text>
196 <xsl:text> </xsl:text>
197 <xsl:if test=
"terminal">
199 <xsl:for-each select=
"terminal">
200 <xsl:text> </xsl:text>
201 <xsl:value-of select=
"."/>
202 <xsl:text> </xsl:text>
204 <xsl:text> </xsl:text>
209 <xsl:template match=
"conflicts">
211 <a name=
"conflicts"/>
212 <xsl:text> Conflicts
</xsl:text>
214 <xsl:text> </xsl:text>
215 <xsl:if test=
"conflict">
217 <xsl:apply-templates select=
"conflict"/>
218 <xsl:text> </xsl:text>
223 <xsl:template match=
"conflict">
225 <xsl:attribute name=
"href">
226 <xsl:value-of select=
"concat('#state_', @state)"/>
228 <xsl:value-of select=
"concat('State ', @state)"/>
230 <xsl:text> conflicts:
</xsl:text>
231 <xsl:value-of select=
"@num"/>
232 <xsl:text> </xsl:text>
233 <xsl:value-of select=
"@type"/>
234 <xsl:text> </xsl:text>
237 <xsl:template match=
"grammar">
240 <xsl:text> Grammar
</xsl:text>
242 <xsl:text> </xsl:text>
244 <xsl:apply-templates select=
"rules/rule">
245 <xsl:with-param name=
"pad" select=
"'3'"/>
246 </xsl:apply-templates>
248 <xsl:text> </xsl:text>
249 <xsl:apply-templates select=
"terminals"/>
250 <xsl:apply-templates select=
"nonterminals"/>
253 <xsl:template match=
"grammar/terminals">
255 <a name=
"terminals"/>
256 <xsl:text> Terminals, with rules where they appear
</xsl:text>
258 <xsl:text> </xsl:text>
260 <xsl:apply-templates select=
"terminal"/>
262 <xsl:text> </xsl:text>
265 <xsl:template match=
"grammar/nonterminals">
267 <a name=
"nonterminals"/>
268 <xsl:text> Nonterminals, with rules where they appear
</xsl:text>
270 <xsl:text> </xsl:text>
272 <xsl:apply-templates select=
"nonterminal"/>
276 <xsl:template match=
"terminal">
277 <b><xsl:value-of select=
"@symbol"/></b>
278 <xsl:value-of select=
"concat(' (', @type, ')')"/>
279 <xsl:apply-templates select=
"rule"/>
280 <xsl:text> </xsl:text>
283 <xsl:template match=
"terminal/rule">
284 <xsl:text> </xsl:text>
286 <xsl:attribute name=
"href">
287 <xsl:value-of select=
"concat('#rule_', .)"/>
289 <xsl:value-of select=
"."/>
293 <xsl:template match=
"nonterminal">
294 <b><xsl:value-of select=
"@symbol"/></b>
295 <xsl:value-of select=
"concat(' (', @type, ')')"/>
296 <xsl:text> </xsl:text>
297 <xsl:if test=
"left/rule">
298 <xsl:text>on left:
</xsl:text>
300 <xsl:apply-templates select=
"left/rule"/>
301 <xsl:if test=
"left/rule and right/rule">
302 <xsl:text> </xsl:text>
304 <xsl:if test=
"right/rule">
305 <xsl:text>on right:
</xsl:text>
307 <xsl:apply-templates select=
"right/rule"/>
308 <xsl:text> </xsl:text>
311 <xsl:template match=
"nonterminal/left/rule|nonterminal/right/rule">
312 <xsl:text> </xsl:text>
314 <xsl:attribute name=
"href">
315 <xsl:value-of select=
"concat('#rule_', .)"/>
317 <xsl:value-of select=
"."/>
321 <xsl:template match=
"automaton">
323 <a name=
"automaton"/>
324 <xsl:text> Automaton
</xsl:text>
326 <xsl:apply-templates select=
"state">
327 <xsl:with-param name=
"pad" select=
"'3'"/>
328 </xsl:apply-templates>
331 <xsl:template match=
"automaton/state">
332 <xsl:param name=
"pad"/>
333 <xsl:text> </xsl:text>
336 <xsl:attribute name=
"name">
337 <xsl:value-of select=
"concat('state_', @number)"/>
340 <xsl:text>state
</xsl:text>
341 <xsl:value-of select=
"@number"/>
343 <xsl:text> </xsl:text>
345 <xsl:apply-templates select=
"itemset/rule">
346 <xsl:with-param name=
"pad" select=
"$pad"/>
347 </xsl:apply-templates>
348 <xsl:apply-templates select=
"actions/transitions">
349 <xsl:with-param name=
"type" select=
"'shift'"/>
350 </xsl:apply-templates>
351 <xsl:apply-templates select=
"actions/errors"/>
352 <xsl:apply-templates select=
"actions/reductions"/>
353 <xsl:apply-templates select=
"actions/transitions">
354 <xsl:with-param name=
"type" select=
"'goto'"/>
355 </xsl:apply-templates>
356 <xsl:apply-templates select=
"solved-conflicts"/>
360 <xsl:template match=
"actions/transitions">
361 <xsl:param name=
"type"/>
362 <xsl:if test=
"transition[@type = $type]">
363 <xsl:text> </xsl:text>
364 <xsl:apply-templates select=
"transition[@type = $type]">
365 <xsl:with-param name=
"pad">
366 <xsl:call-template name=
"max-width-symbol">
367 <xsl:with-param name=
"node" select=
"transition[@type = $type]"/>
370 </xsl:apply-templates>
374 <xsl:template match=
"actions/errors">
375 <xsl:if test=
"error">
376 <xsl:text> </xsl:text>
377 <xsl:apply-templates select=
"error">
378 <xsl:with-param name=
"pad">
379 <xsl:call-template name=
"max-width-symbol">
380 <xsl:with-param name=
"node" select=
"error"/>
383 </xsl:apply-templates>
387 <xsl:template match=
"actions/reductions">
388 <xsl:if test=
"reduction">
389 <xsl:text> </xsl:text>
390 <xsl:apply-templates select=
"reduction">
391 <xsl:with-param name=
"pad">
392 <xsl:call-template name=
"max-width-symbol">
393 <xsl:with-param name=
"node" select=
"reduction"/>
396 </xsl:apply-templates>
400 <xsl:template match=
"rule">
401 <xsl:param name=
"pad"/>
402 <xsl:if test=
"not(name(..) = 'itemset') and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
403 <xsl:text> </xsl:text>
405 <xsl:if test=
"not(name(..) = 'itemset')">
407 <xsl:attribute name=
"name">
408 <xsl:value-of select=
"concat('rule_', @number)"/>
412 <xsl:text> </xsl:text>
414 <xsl:when test=
"name(..) = 'itemset'">
416 <xsl:attribute name=
"href">
417 <xsl:value-of select=
"concat('#rule_', @number)"/>
419 <xsl:call-template name=
"lpad">
420 <xsl:with-param name=
"str" select=
"string(@number)"/>
421 <xsl:with-param name=
"pad" select=
"number($pad)"/>
426 <xsl:call-template name=
"lpad">
427 <xsl:with-param name=
"str" select=
"string(@number)"/>
428 <xsl:with-param name=
"pad" select=
"number($pad)"/>
432 <xsl:text> </xsl:text>
434 <xsl:when test=
"preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
435 <xsl:call-template name=
"lpad">
436 <xsl:with-param name=
"str" select=
"'|'"/>
437 <xsl:with-param name=
"pad" select=
"number(string-length(lhs[text()])) + 2"/>
442 <xsl:value-of select=
"lhs"/>
444 <xsl:text> →</xsl:text>
447 <xsl:apply-templates select=
"rhs/symbol|rhs/point|rhs/empty"/>
448 <xsl:apply-templates select=
"lookaheads"/>
449 <xsl:text> </xsl:text>
452 <xsl:template match=
"symbol">
453 <xsl:text> </xsl:text>
455 <xsl:when test=
"@class = 'nonterminal'">
456 <span class=
"i"><xsl:value-of select=
"."/></span>
459 <b><xsl:value-of select=
"."/></b>
464 <xsl:template match=
"point">
465 <xsl:text> </xsl:text>
466 <span class=
"point">.
</span>
469 <xsl:template match=
"empty">
470 <xsl:text> ε</xsl:text>
473 <xsl:template match=
"lookaheads">
474 <xsl:text> [
</xsl:text>
475 <xsl:apply-templates select=
"symbol"/>
476 <xsl:text>]
</xsl:text>
479 <xsl:template match=
"lookaheads/symbol">
480 <xsl:value-of select=
"."/>
481 <xsl:if test=
"position() != last()">
482 <xsl:text>,
</xsl:text>
486 <xsl:template match=
"transition">
487 <xsl:param name=
"pad"/>
488 <xsl:text> </xsl:text>
489 <xsl:call-template name=
"rpad">
490 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
491 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
494 <xsl:when test=
"@type = 'shift'">
496 <xsl:attribute name=
"href">
497 <xsl:value-of select=
"concat('#state_', @state)"/>
499 <xsl:value-of select=
"concat('shift, and go to state ', @state)"/>
502 <xsl:when test=
"@type = 'goto'">
504 <xsl:attribute name=
"href">
505 <xsl:value-of select=
"concat('#state_', @state)"/>
507 <xsl:value-of select=
"concat('go to state ', @state)"/>
511 <xsl:text> </xsl:text>
514 <xsl:template match=
"error">
515 <xsl:param name=
"pad"/>
516 <xsl:text> </xsl:text>
517 <xsl:call-template name=
"rpad">
518 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
519 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
521 <xsl:text>error
</xsl:text>
522 <xsl:text> (
</xsl:text>
523 <xsl:value-of select=
"text()"/>
524 <xsl:text>)
</xsl:text>
525 <xsl:text> </xsl:text>
528 <xsl:template match=
"reduction">
529 <xsl:param name=
"pad"/>
530 <xsl:text> </xsl:text>
531 <xsl:call-template name=
"rpad">
532 <xsl:with-param name=
"str" select=
"string(@symbol)"/>
533 <xsl:with-param name=
"pad" select=
"number($pad) + 2"/>
535 <xsl:if test=
"@enabled = 'false'">
536 <xsl:text>[
</xsl:text>
539 <xsl:when test=
"@rule = 'accept'">
540 <xsl:text>accept
</xsl:text>
544 <xsl:attribute name=
"href">
545 <xsl:value-of select=
"concat('#rule_', @rule)"/>
547 <xsl:value-of select=
"concat('reduce using rule ', @rule)"/>
549 <xsl:text> (
</xsl:text>
551 select=
"/bison-xml-report/grammar/rules/rule[@number = current()/@rule]/lhs[text()]"/>
552 <xsl:text>)
</xsl:text>
555 <xsl:if test=
"@enabled = 'false'">
556 <xsl:text>]
</xsl:text>
558 <xsl:text> </xsl:text>
561 <xsl:template match=
"solved-conflicts">
562 <xsl:if test=
"resolution">
563 <xsl:text> </xsl:text>
564 <xsl:apply-templates select=
"resolution"/>
568 <xsl:template match=
"resolution">
569 <xsl:text> Conflict between
</xsl:text>
571 <xsl:attribute name=
"href">
572 <xsl:value-of select=
"concat('#rule_', @rule)"/>
574 <xsl:value-of select=
"concat('rule ',@rule)"/>
576 <xsl:text> and token
</xsl:text>
577 <xsl:value-of select=
"@symbol"/>
578 <xsl:text> resolved as
</xsl:text>
579 <xsl:if test=
"@type = 'error'">
580 <xsl:text>an
</xsl:text>
582 <xsl:value-of select=
"@type"/>
583 <xsl:text> (
</xsl:text>
584 <xsl:value-of select=
"."/>
585 <xsl:text>).
</xsl:text>
588 <xsl:template name=
"max-width-symbol">
589 <xsl:param name=
"node"/>
590 <xsl:variable name=
"longest">
591 <xsl:for-each select=
"$node">
592 <xsl:sort data-type=
"number" select=
"string-length(@symbol)"
594 <xsl:if test=
"position() = 1">
595 <xsl:value-of select=
"string-length(@symbol)"/>
599 <xsl:value-of select=
"$longest"/>
602 <xsl:template name=
"lpad">
603 <xsl:param name=
"str" select=
"''"/>
604 <xsl:param name=
"pad" select=
"0"/>
605 <xsl:variable name=
"diff" select=
"$pad - string-length($str)" />
607 <xsl:when test=
"$diff < 0">
608 <xsl:value-of select=
"$str"/>
611 <xsl:call-template name=
"space">
612 <xsl:with-param name=
"repeat" select=
"$diff"/>
614 <xsl:value-of select=
"$str"/>
619 <xsl:template name=
"rpad">
620 <xsl:param name=
"str" select=
"''"/>
621 <xsl:param name=
"pad" select=
"0"/>
622 <xsl:variable name=
"diff" select=
"$pad - string-length($str)"/>
624 <xsl:when test=
"$diff < 0">
625 <xsl:value-of select=
"$str"/>
628 <xsl:value-of select=
"$str"/>
629 <xsl:call-template name=
"space">
630 <xsl:with-param name=
"repeat" select=
"$diff"/>
636 <xsl:template name=
"space">
637 <xsl:param name=
"repeat">0</xsl:param>
638 <xsl:param name=
"fill" select=
"' '"/>
639 <xsl:if test=
"number($repeat) >= 1">
640 <xsl:call-template name=
"space">
641 <xsl:with-param name=
"repeat" select=
"$repeat - 1"/>
642 <xsl:with-param name=
"fill" select=
"$fill"/>
644 <xsl:value-of select=
"$fill"/>