]> git.saurik.com Git - bison.git/blame - data/xslt/xml2xhtml.xsl
* data/xslt/bison.xsl (bison:ruleNumber): Rename to...
[bison.git] / data / xslt / xml2xhtml.xsl
CommitLineData
bbeff196
WP
1<?xml version="1.0" encoding="UTF-8"?>
2
3<!--
4 xml2html.xsl - transform Bison XML Report into XHTML.
5 $Id$
6
7 Copyright (C) 2007 Free Software Foundation, Inc.
8
9 This file is part of Bison, the GNU Compiler Compiler.
10
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.
15
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.
20
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/>.
23
24 Written by Wojciech Polak <polak@gnu.org>.
25 -->
26
27<xsl:stylesheet version="1.0"
28 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21f1b063
JD
29 xmlns="http://www.w3.org/1999/xhtml"
30 xmlns:bison="http://www.gnu.org/software/bison/">
31
32<xsl:import href="bison.xsl"/>
bbeff196
WP
33
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"
37 indent="yes"/>
38
39<xsl:template match="/">
40 <html>
41 <head>
42 <title>GNU Bison XML Automaton Report</title>
43 <style type="text/css"><![CDATA[
44 body {
45 font-family: "Nimbus Sans L", Arial, sans-serif;
46 font-size: 9pt;
47 }
48 a:link {
49 color: #1f00ff;
50 text-decoration: none;
51 }
52 a:visited {
53 color: #1f00ff;
54 text-decoration: none;
55 }
56 a:hover {
57 color: red;
58 }
59 #menu a {
60 text-decoration: underline;
61 }
62 .i {
63 font-style: italic;
64 }
65 .pre {
66 font-family: monospace;
67 white-space: pre;
68 }
69 ol.decimal {
70 list-style-type: decimal;
71 }
72 ol.lower-alpha {
73 list-style-type: lower-alpha;
74 }
75 .point {
76 color: #cc0000;
77 }
78 #footer {
79 margin-top: 3.5em;
80 font-size: 7pt;
81 }
82 ]]></style>
83 </head>
84 <body>
85 <xsl:apply-templates select="bison-xml-report"/>
86 <xsl:text>&#10;&#10;</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>
95 </body>
96 </html>
97</xsl:template>
98
99<xsl:template match="bison-xml-report">
100 <h1>GNU Bison XML Automaton Report</h1>
101 <p>
102 input grammar: <span class="i"><xsl:value-of select="filename"/></span>
103 </p>
104
105 <xsl:text>&#10;&#10;</xsl:text>
106 <h3>Table of Contents</h3>
107 <ul id="menu">
108 <li>
109 <a href="#reductions">Reductions</a>
110 <ul class="lower-alpha">
cff03fb2 111 <li><a href="#nonterminals_useless_in_grammar">Nonterminals useless in grammar</a></li>
d80fb37a 112 <li><a href="#terminals_unused_in_grammar">Terminals unused in grammar</a></li>
cff03fb2 113 <li><a href="#rules_useless_in_grammar">Rules useless in grammar</a></li>
d80fb37a 114 <xsl:if test="grammar/rules/rule[@usefulness='useless-in-parser']">
cff03fb2
JD
115 <li><a href="#rules_useless_in_parser">Rules useless in parser due to conflicts</a></li>
116 </xsl:if>
bbeff196
WP
117 </ul>
118 </li>
119 <li><a href="#conflicts">Conflicts</a></li>
120 <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>
126 </ul>
127 </li>
128 <li><a href="#automaton">Automaton</a></li>
129 </ul>
d80fb37a
JD
130 <xsl:apply-templates select="grammar" mode="reductions"/>
131 <xsl:apply-templates select="grammar" mode="useless-in-parser"/>
21f1b063 132 <xsl:apply-templates select="automaton" mode="conflicts"/>
bbeff196
WP
133 <xsl:apply-templates select="grammar"/>
134 <xsl:apply-templates select="automaton"/>
135</xsl:template>
136
d80fb37a 137<xsl:template match="grammar" mode="reductions">
bbeff196
WP
138 <h2>
139 <a name="reductions"/>
140 <xsl:text> Reductions</xsl:text>
141 </h2>
d80fb37a
JD
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"/>
bbeff196
WP
145</xsl:template>
146
d80fb37a 147<xsl:template match="nonterminals" mode="useless-in-grammar">
bbeff196 148 <h3>
cff03fb2
JD
149 <a name="nonterminals_useless_in_grammar"/>
150 <xsl:text> Nonterminals useless in grammar</xsl:text>
bbeff196
WP
151 </h3>
152 <xsl:text>&#10;&#10;</xsl:text>
d80fb37a 153 <xsl:if test="nonterminal[@usefulness='useless-in-grammar']">
bbeff196 154 <p class="pre">
d80fb37a 155 <xsl:for-each select="nonterminal[@usefulness='useless-in-grammar']">
bbeff196 156 <xsl:text> </xsl:text>
d80fb37a 157 <xsl:value-of select="@name"/>
bbeff196
WP
158 <xsl:text>&#10;</xsl:text>
159 </xsl:for-each>
160 <xsl:text>&#10;&#10;</xsl:text>
161 </p>
162 </xsl:if>
163</xsl:template>
164
d80fb37a 165<xsl:template match="terminals" mode="unused-in-grammar">
bbeff196 166 <h3>
d80fb37a
JD
167 <a name="terminals_unused_in_grammar"/>
168 <xsl:text> Terminals unused in grammar</xsl:text>
bbeff196 169 </h3>
d80fb37a
JD
170 <xsl:text>&#10;&#10;</xsl:text>
171 <xsl:if test="terminal[@usefulness='unused-in-grammar']">
bbeff196 172 <p class="pre">
d80fb37a
JD
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>&#10;</xsl:text>
178 </xsl:for-each>
bbeff196
WP
179 <xsl:text>&#10;&#10;</xsl:text>
180 </p>
181 </xsl:if>
182</xsl:template>
183
d80fb37a 184<xsl:template match="rules" mode="useless-in-grammar">
bbeff196 185 <h3>
d80fb37a
JD
186 <a name="rules_useless_in_grammar"/>
187 <xsl:text> Rules useless in grammar</xsl:text>
bbeff196 188 </h3>
d80fb37a
JD
189 <xsl:text>&#10;</xsl:text>
190 <xsl:variable name="set" select="rule[@usefulness='useless-in-grammar']"/>
191 <xsl:if test="$set">
bbeff196 192 <p class="pre">
d80fb37a
JD
193 <xsl:call-template name="style-rule-set">
194 <xsl:with-param name="rule-set" select="$set"/>
195 </xsl:call-template>
bbeff196
WP
196 <xsl:text>&#10;&#10;</xsl:text>
197 </p>
198 </xsl:if>
199</xsl:template>
200
d80fb37a
JD
201<xsl:template match="grammar" mode="useless-in-parser">
202 <xsl:variable
203 name="set" select="rules/rule[@usefulness='useless-in-parser']"
204 />
205 <xsl:if test="$set">
206 <h2>
207 <a name="rules_useless_in_parser"/>
208 <xsl:text> Rules useless in parser due to conflicts</xsl:text>
209 </h2>
210 <xsl:text>&#10;</xsl:text>
211 <p class="pre">
212 <xsl:call-template name="style-rule-set">
213 <xsl:with-param name="rule-set" select="$set"/>
214 </xsl:call-template>
215 </p>
216 <xsl:text>&#10;&#10;</xsl:text>
217 </xsl:if>
218</xsl:template>
219
220<xsl:template match="grammar">
221 <h2>
222 <a name="grammar"/>
223 <xsl:text> Grammar</xsl:text>
224 </h2>
225 <xsl:text>&#10;</xsl:text>
226 <p class="pre">
227 <xsl:call-template name="style-rule-set">
228 <xsl:with-param
229 name="rule-set" select="rules/rule[@usefulness!='useless-in-grammar']"
230 />
231 </xsl:call-template>
232 </p>
233 <xsl:text>&#10;&#10;</xsl:text>
234 <xsl:apply-templates select="terminals"/>
235 <xsl:apply-templates select="nonterminals"/>
236</xsl:template>
237
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"/>
247 </xsl:if>
248 </xsl:with-param>
249 </xsl:apply-templates>
250 </xsl:for-each>
251</xsl:template>
252
21f1b063 253<xsl:template match="automaton" mode="conflicts">
bbeff196
WP
254 <h2>
255 <a name="conflicts"/>
256 <xsl:text> Conflicts</xsl:text>
257 </h2>
258 <xsl:text>&#10;&#10;</xsl:text>
21f1b063
JD
259 <xsl:variable name="conflict-report">
260 <xsl:apply-templates select="state" mode="conflicts"/>
261 </xsl:variable>
262 <xsl:if test="string-length($conflict-report) != 0">
bbeff196 263 <p class="pre">
21f1b063 264 <xsl:copy-of select="$conflict-report"/>
bbeff196
WP
265 <xsl:text>&#10;&#10;</xsl:text>
266 </p>
267 </xsl:if>
268</xsl:template>
269
21f1b063
JD
270<xsl:template match="state" mode="conflicts">
271 <xsl:variable name="conflict-counts">
272 <xsl:apply-templates select="." mode="bison:count-conflicts" />
273 </xsl:variable>
274 <xsl:variable
275 name="sr-count" select="substring-before($conflict-counts, ',')"
276 />
277 <xsl:variable
278 name="rr-count" select="substring-after($conflict-counts, ',')"
279 />
280 <xsl:if test="$sr-count > 0 or $rr-count > 0">
281 <a>
282 <xsl:attribute name="href">
283 <xsl:value-of select="concat('#state_', @number)"/>
284 </xsl:attribute>
285 <xsl:value-of select="concat('State ', @number)"/>
286 </a>
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="(',')"/>
292 </xsl:if>
293 </xsl:if>
294 <xsl:if test="$rr-count > 0">
295 <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
296 </xsl:if>
297 <xsl:value-of select="'&#10;'"/>
298 </xsl:if>
bbeff196
WP
299</xsl:template>
300
bbeff196
WP
301<xsl:template match="grammar/terminals">
302 <h3>
303 <a name="terminals"/>
304 <xsl:text> Terminals, with rules where they appear</xsl:text>
305 </h3>
306 <xsl:text>&#10;&#10;</xsl:text>
307 <p class="pre">
308 <xsl:apply-templates select="terminal"/>
309 </p>
310 <xsl:text>&#10;&#10;</xsl:text>
311</xsl:template>
312
313<xsl:template match="grammar/nonterminals">
314 <h3>
315 <a name="nonterminals"/>
316 <xsl:text> Nonterminals, with rules where they appear</xsl:text>
317 </h3>
318 <xsl:text>&#10;&#10;</xsl:text>
319 <p class="pre">
d80fb37a
JD
320 <xsl:apply-templates
321 select="nonterminal[@usefulness!='useless-in-grammar']"
322 />
bbeff196
WP
323 </p>
324</xsl:template>
325
326<xsl:template match="terminal">
36c48187 327 <b><xsl:value-of select="@name"/></b>
32f19b6b 328 <xsl:value-of select="concat(' (', @token-number, ')')"/>
d4a26c48
JD
329 <xsl:for-each select="key('bison:ruleByRhs', @name)">
330 <xsl:apply-templates select="." mode="number-link"/>
331 </xsl:for-each>
bbeff196
WP
332 <xsl:text>&#10;</xsl:text>
333</xsl:template>
334
bbeff196 335<xsl:template match="nonterminal">
36c48187 336 <b><xsl:value-of select="@name"/></b>
32f19b6b 337 <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
bbeff196 338 <xsl:text>&#10; </xsl:text>
d4a26c48 339 <xsl:if test="key('bison:ruleByLhs', @name)">
bbeff196 340 <xsl:text>on left:</xsl:text>
d4a26c48
JD
341 <xsl:for-each select="key('bison:ruleByLhs', @name)">
342 <xsl:apply-templates select="." mode="number-link"/>
343 </xsl:for-each>
bbeff196 344 </xsl:if>
d4a26c48
JD
345 <xsl:if test="key('bison:ruleByRhs', @name)">
346 <xsl:if test="key('bison:ruleByLhs', @name)">
347 <xsl:text>&#10; </xsl:text>
348 </xsl:if>
bbeff196 349 <xsl:text>on right:</xsl:text>
d4a26c48
JD
350 <xsl:for-each select="key('bison:ruleByRhs', @name)">
351 <xsl:apply-templates select="." mode="number-link"/>
352 </xsl:for-each>
bbeff196 353 </xsl:if>
bbeff196
WP
354 <xsl:text>&#10;</xsl:text>
355</xsl:template>
356
d4a26c48 357<xsl:template match="rule" mode="number-link">
bbeff196
WP
358 <xsl:text> </xsl:text>
359 <a>
360 <xsl:attribute name="href">
d4a26c48 361 <xsl:value-of select="concat('#rule_', @number)"/>
bbeff196 362 </xsl:attribute>
d4a26c48 363 <xsl:value-of select="@number"/>
bbeff196
WP
364 </a>
365</xsl:template>
366
367<xsl:template match="automaton">
368 <h2>
369 <a name="automaton"/>
370 <xsl:text> Automaton</xsl:text>
371 </h2>
372 <xsl:apply-templates select="state">
373 <xsl:with-param name="pad" select="'3'"/>
374 </xsl:apply-templates>
375</xsl:template>
376
377<xsl:template match="automaton/state">
378 <xsl:param name="pad"/>
379 <xsl:text>&#10;&#10;</xsl:text>
380 <h3>
381 <a>
382 <xsl:attribute name="name">
383 <xsl:value-of select="concat('state_', @number)"/>
384 </xsl:attribute>
385 </a>
386 <xsl:text>state </xsl:text>
387 <xsl:value-of select="@number"/>
388 </h3>
389 <xsl:text>&#10;&#10;</xsl:text>
390 <p class="pre">
95134bc1 391 <xsl:apply-templates select="itemset/item">
bbeff196
WP
392 <xsl:with-param name="pad" select="$pad"/>
393 </xsl:apply-templates>
394 <xsl:apply-templates select="actions/transitions">
395 <xsl:with-param name="type" select="'shift'"/>
396 </xsl:apply-templates>
397 <xsl:apply-templates select="actions/errors"/>
398 <xsl:apply-templates select="actions/reductions"/>
399 <xsl:apply-templates select="actions/transitions">
400 <xsl:with-param name="type" select="'goto'"/>
401 </xsl:apply-templates>
402 <xsl:apply-templates select="solved-conflicts"/>
403 </p>
404</xsl:template>
405
406<xsl:template match="actions/transitions">
407 <xsl:param name="type"/>
408 <xsl:if test="transition[@type = $type]">
409 <xsl:text>&#10;</xsl:text>
410 <xsl:apply-templates select="transition[@type = $type]">
411 <xsl:with-param name="pad">
412 <xsl:call-template name="max-width-symbol">
413 <xsl:with-param name="node" select="transition[@type = $type]"/>
414 </xsl:call-template>
415 </xsl:with-param>
416 </xsl:apply-templates>
417 </xsl:if>
418</xsl:template>
419
420<xsl:template match="actions/errors">
421 <xsl:if test="error">
422 <xsl:text>&#10;</xsl:text>
423 <xsl:apply-templates select="error">
424 <xsl:with-param name="pad">
425 <xsl:call-template name="max-width-symbol">
426 <xsl:with-param name="node" select="error"/>
427 </xsl:call-template>
428 </xsl:with-param>
429 </xsl:apply-templates>
430 </xsl:if>
431</xsl:template>
432
433<xsl:template match="actions/reductions">
434 <xsl:if test="reduction">
435 <xsl:text>&#10;</xsl:text>
436 <xsl:apply-templates select="reduction">
437 <xsl:with-param name="pad">
438 <xsl:call-template name="max-width-symbol">
439 <xsl:with-param name="node" select="reduction"/>
440 </xsl:call-template>
441 </xsl:with-param>
442 </xsl:apply-templates>
443 </xsl:if>
444</xsl:template>
445
95134bc1
WP
446<xsl:template match="item">
447 <xsl:param name="pad"/>
448 <xsl:param name="prev-rule-number"
449 select="preceding-sibling::item[1]/@rule-number"/>
d4a26c48
JD
450 <xsl:apply-templates
451 select="key('bison:ruleByNumber', current()/@rule-number)"
452 >
95134bc1
WP
453 <xsl:with-param name="itemset" select="'true'"/>
454 <xsl:with-param name="pad" select="$pad"/>
455 <xsl:with-param name="prev-lhs"
d4a26c48
JD
456 select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
457 />
95134bc1
WP
458 <xsl:with-param name="point" select="@point"/>
459 <xsl:with-param name="lookaheads">
460 <xsl:apply-templates select="lookaheads"/>
461 </xsl:with-param>
462 </xsl:apply-templates>
463</xsl:template>
464
bbeff196 465<xsl:template match="rule">
95134bc1 466 <xsl:param name="itemset"/>
bbeff196 467 <xsl:param name="pad"/>
95134bc1
WP
468 <xsl:param name="prev-lhs"/>
469 <xsl:param name="point"/>
470 <xsl:param name="lookaheads"/>
471
d80fb37a 472 <xsl:if test="$itemset != 'true' and not($prev-lhs = lhs[text()])">
bbeff196
WP
473 <xsl:text>&#10;</xsl:text>
474 </xsl:if>
95134bc1
WP
475
476 <xsl:if test="$itemset != 'true'">
bbeff196
WP
477 <a>
478 <xsl:attribute name="name">
479 <xsl:value-of select="concat('rule_', @number)"/>
480 </xsl:attribute>
481 </a>
482 </xsl:if>
483 <xsl:text> </xsl:text>
95134bc1 484
bbeff196 485 <xsl:choose>
95134bc1 486 <xsl:when test="$itemset = 'true'">
bbeff196
WP
487 <a>
488 <xsl:attribute name="href">
489 <xsl:value-of select="concat('#rule_', @number)"/>
490 </xsl:attribute>
491 <xsl:call-template name="lpad">
492 <xsl:with-param name="str" select="string(@number)"/>
493 <xsl:with-param name="pad" select="number($pad)"/>
494 </xsl:call-template>
495 </a>
496 </xsl:when>
497 <xsl:otherwise>
498 <xsl:call-template name="lpad">
499 <xsl:with-param name="str" select="string(@number)"/>
500 <xsl:with-param name="pad" select="number($pad)"/>
501 </xsl:call-template>
502 </xsl:otherwise>
503 </xsl:choose>
504 <xsl:text> </xsl:text>
95134bc1
WP
505
506 <!-- LHS -->
bbeff196 507 <xsl:choose>
d80fb37a 508 <xsl:when test="$itemset != 'true' and $prev-lhs = lhs[text()]">
95134bc1
WP
509 <xsl:call-template name="lpad">
510 <xsl:with-param name="str" select="'|'"/>
511 <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
512 </xsl:call-template>
513 </xsl:when>
514 <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
bbeff196
WP
515 <xsl:call-template name="lpad">
516 <xsl:with-param name="str" select="'|'"/>
517 <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
518 </xsl:call-template>
519 </xsl:when>
520 <xsl:otherwise>
521 <span class="i">
522 <xsl:value-of select="lhs"/>
523 </span>
524 <xsl:text> &#8594;</xsl:text>
525 </xsl:otherwise>
526 </xsl:choose>
95134bc1
WP
527
528 <!-- RHS -->
529 <xsl:for-each select="rhs/*">
530 <xsl:if test="position() = $point + 1">
531 <xsl:text> </xsl:text>
532 <span class="point">.</span>
533 </xsl:if>
534 <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
535 <xsl:apply-templates select="."/>
536 </xsl:if>
537 <xsl:if test="$itemset != 'true'">
538 <xsl:apply-templates select="."/>
539 </xsl:if>
540 <xsl:if test="position() = last() and position() = $point">
541 <xsl:text> </xsl:text>
542 <span class="point">.</span>
543 </xsl:if>
544 </xsl:for-each>
545 <xsl:if test="$lookaheads">
546 <xsl:value-of select="$lookaheads"/>
547 </xsl:if>
548
bbeff196
WP
549 <xsl:text>&#10;</xsl:text>
550</xsl:template>
551
552<xsl:template match="symbol">
553 <xsl:text> </xsl:text>
554 <xsl:choose>
555 <xsl:when test="@class = 'nonterminal'">
556 <span class="i"><xsl:value-of select="."/></span>
557 </xsl:when>
558 <xsl:otherwise>
559 <b><xsl:value-of select="."/></b>
560 </xsl:otherwise>
561 </xsl:choose>
562</xsl:template>
563
bbeff196
WP
564<xsl:template match="empty">
565 <xsl:text> &#949;</xsl:text>
566</xsl:template>
567
568<xsl:template match="lookaheads">
569 <xsl:text> [</xsl:text>
570 <xsl:apply-templates select="symbol"/>
571 <xsl:text>]</xsl:text>
572</xsl:template>
573
574<xsl:template match="lookaheads/symbol">
575 <xsl:value-of select="."/>
576 <xsl:if test="position() != last()">
577 <xsl:text>, </xsl:text>
578 </xsl:if>
579</xsl:template>
580
581<xsl:template match="transition">
582 <xsl:param name="pad"/>
583 <xsl:text> </xsl:text>
584 <xsl:call-template name="rpad">
585 <xsl:with-param name="str" select="string(@symbol)"/>
586 <xsl:with-param name="pad" select="number($pad) + 2"/>
587 </xsl:call-template>
588 <xsl:choose>
589 <xsl:when test="@type = 'shift'">
590 <a>
591 <xsl:attribute name="href">
592 <xsl:value-of select="concat('#state_', @state)"/>
593 </xsl:attribute>
594 <xsl:value-of select="concat('shift, and go to state ', @state)"/>
595 </a>
596 </xsl:when>
597 <xsl:when test="@type = 'goto'">
598 <a>
599 <xsl:attribute name="href">
600 <xsl:value-of select="concat('#state_', @state)"/>
601 </xsl:attribute>
602 <xsl:value-of select="concat('go to state ', @state)"/>
603 </a>
604 </xsl:when>
605 </xsl:choose>
606 <xsl:text>&#10;</xsl:text>
607</xsl:template>
608
609<xsl:template match="error">
610 <xsl:param name="pad"/>
611 <xsl:text> </xsl:text>
612 <xsl:call-template name="rpad">
613 <xsl:with-param name="str" select="string(@symbol)"/>
614 <xsl:with-param name="pad" select="number($pad) + 2"/>
615 </xsl:call-template>
616 <xsl:text>error</xsl:text>
617 <xsl:text> (</xsl:text>
618 <xsl:value-of select="text()"/>
619 <xsl:text>)</xsl:text>
620 <xsl:text>&#10;</xsl:text>
621</xsl:template>
622
623<xsl:template match="reduction">
624 <xsl:param name="pad"/>
625 <xsl:text> </xsl:text>
626 <xsl:call-template name="rpad">
627 <xsl:with-param name="str" select="string(@symbol)"/>
628 <xsl:with-param name="pad" select="number($pad) + 2"/>
629 </xsl:call-template>
630 <xsl:if test="@enabled = 'false'">
631 <xsl:text>[</xsl:text>
632 </xsl:if>
633 <xsl:choose>
634 <xsl:when test="@rule = 'accept'">
635 <xsl:text>accept</xsl:text>
636 </xsl:when>
637 <xsl:otherwise>
638 <a>
639 <xsl:attribute name="href">
640 <xsl:value-of select="concat('#rule_', @rule)"/>
641 </xsl:attribute>
642 <xsl:value-of select="concat('reduce using rule ', @rule)"/>
643 </a>
644 <xsl:text> (</xsl:text>
645 <xsl:value-of
d4a26c48
JD
646 select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
647 />
bbeff196
WP
648 <xsl:text>)</xsl:text>
649 </xsl:otherwise>
650 </xsl:choose>
651 <xsl:if test="@enabled = 'false'">
652 <xsl:text>]</xsl:text>
653 </xsl:if>
654 <xsl:text>&#10;</xsl:text>
655</xsl:template>
656
657<xsl:template match="solved-conflicts">
658 <xsl:if test="resolution">
659 <xsl:text>&#10;</xsl:text>
660 <xsl:apply-templates select="resolution"/>
661 </xsl:if>
662</xsl:template>
663
664<xsl:template match="resolution">
665 <xsl:text> Conflict between </xsl:text>
666 <a>
667 <xsl:attribute name="href">
668 <xsl:value-of select="concat('#rule_', @rule)"/>
669 </xsl:attribute>
670 <xsl:value-of select="concat('rule ',@rule)"/>
671 </a>
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>
677 </xsl:if>
678 <xsl:value-of select="@type"/>
679 <xsl:text> (</xsl:text>
680 <xsl:value-of select="."/>
681 <xsl:text>).&#10;</xsl:text>
682</xsl:template>
683
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)"
689 order="descending"/>
690 <xsl:if test="position() = 1">
691 <xsl:value-of select="string-length(@symbol)"/>
692 </xsl:if>
693 </xsl:for-each>
694 </xsl:variable>
695 <xsl:value-of select="$longest"/>
696</xsl:template>
697
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)" />
702 <xsl:choose>
703 <xsl:when test="$diff &lt; 0">
704 <xsl:value-of select="$str"/>
705 </xsl:when>
706 <xsl:otherwise>
707 <xsl:call-template name="space">
708 <xsl:with-param name="repeat" select="$diff"/>
709 </xsl:call-template>
710 <xsl:value-of select="$str"/>
711 </xsl:otherwise>
712 </xsl:choose>
713</xsl:template>
714
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)"/>
719 <xsl:choose>
720 <xsl:when test="$diff &lt; 0">
721 <xsl:value-of select="$str"/>
722 </xsl:when>
723 <xsl:otherwise>
724 <xsl:value-of select="$str"/>
725 <xsl:call-template name="space">
726 <xsl:with-param name="repeat" select="$diff"/>
727 </xsl:call-template>
728 </xsl:otherwise>
729 </xsl:choose>
730</xsl:template>
731
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) &gt;= 1">
736 <xsl:call-template name="space">
737 <xsl:with-param name="repeat" select="$repeat - 1"/>
738 <xsl:with-param name="fill" select="$fill"/>
739 </xsl:call-template>
740 <xsl:value-of select="$fill"/>
741 </xsl:if>
742</xsl:template>
743
744</xsl:stylesheet>