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