]> git.saurik.com Git - bison.git/blob - data/xslt/xml2text.xsl
Improve C++ namespace support. Discussed starting at
[bison.git] / data / xslt / xml2text.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!--
4 xml2text.xsl - transform Bison XML Report into plain text.
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">
29
30 <xsl:output method="text" encoding="UTF-8" indent="no"/>
31
32 <xsl:template match="/">
33 <xsl:apply-templates select="bison-xml-report"/>
34 </xsl:template>
35
36 <xsl:template match="bison-xml-report">
37 <xsl:apply-templates select="reductions"/>
38 <xsl:apply-templates select="rules-never-reduced"/>
39 <xsl:apply-templates select="conflicts"/>
40 <xsl:apply-templates select="grammar"/>
41 <xsl:apply-templates select="automaton"/>
42 </xsl:template>
43
44 <xsl:template match="rules-never-reduced">
45 <xsl:if test="rule">
46 <xsl:text>Rules never reduced&#10;</xsl:text>
47 <xsl:apply-templates select="rule">
48 <xsl:with-param name="pad" select="'3'"/>
49 </xsl:apply-templates>
50 <xsl:text>&#10;&#10;</xsl:text>
51 </xsl:if>
52 </xsl:template>
53
54 <xsl:template match="reductions">
55 <xsl:apply-templates select="useless/nonterminals"/>
56 <xsl:apply-templates select="unused/terminals"/>
57 <xsl:apply-templates select="useless/rules"/>
58 </xsl:template>
59
60 <xsl:template match="useless/nonterminals">
61 <xsl:if test="nonterminal">
62 <xsl:text>Useless nonterminals&#10;&#10;</xsl:text>
63 <xsl:for-each select="nonterminal">
64 <xsl:text> </xsl:text>
65 <xsl:value-of select="."/>
66 <xsl:text>&#10;</xsl:text>
67 </xsl:for-each>
68 <xsl:text>&#10;&#10;</xsl:text>
69 </xsl:if>
70 </xsl:template>
71
72 <xsl:template match="useless/rules">
73 <xsl:if test="rule">
74 <xsl:text>Useless rules&#10;</xsl:text>
75 <xsl:apply-templates select="rule">
76 <xsl:with-param name="pad" select="'3'"/>
77 </xsl:apply-templates>
78 <xsl:text>&#10;&#10;</xsl:text>
79 </xsl:if>
80 </xsl:template>
81
82 <xsl:template match="unused/terminals">
83 <xsl:if test="terminal">
84 <xsl:text>Terminals which are not used&#10;&#10;</xsl:text>
85 <xsl:for-each select="terminal">
86 <xsl:text> </xsl:text>
87 <xsl:value-of select="."/>
88 <xsl:text>&#10;</xsl:text>
89 </xsl:for-each>
90 <xsl:text>&#10;&#10;</xsl:text>
91 </xsl:if>
92 </xsl:template>
93
94 <xsl:template match="conflicts">
95 <xsl:if test="conflict">
96 <xsl:apply-templates select="conflict"/>
97 <xsl:text>&#10;&#10;</xsl:text>
98 </xsl:if>
99 </xsl:template>
100
101 <xsl:template match="conflict">
102 <xsl:text>State </xsl:text>
103 <xsl:value-of select="@state"/>
104 <xsl:text> conflicts: </xsl:text>
105 <xsl:value-of select="@num"/>
106 <xsl:text> </xsl:text>
107 <xsl:value-of select="@type"/>
108 <xsl:text>&#10;</xsl:text>
109 </xsl:template>
110
111 <xsl:template match="grammar">
112 <xsl:text>Grammar&#10;</xsl:text>
113 <xsl:apply-templates select="rules/rule">
114 <xsl:with-param name="pad" select="'3'"/>
115 </xsl:apply-templates>
116 <xsl:text>&#10;&#10;</xsl:text>
117 <xsl:apply-templates select="terminals"/>
118 <xsl:apply-templates select="nonterminals"/>
119 </xsl:template>
120
121 <xsl:template match="grammar/terminals">
122 <xsl:text>Terminals, with rules where they appear&#10;&#10;</xsl:text>
123 <xsl:apply-templates select="terminal"/>
124 <xsl:text>&#10;&#10;</xsl:text>
125 </xsl:template>
126
127 <xsl:template match="grammar/nonterminals">
128 <xsl:text>Nonterminals, with rules where they appear&#10;&#10;</xsl:text>
129 <xsl:apply-templates select="nonterminal"/>
130 </xsl:template>
131
132 <xsl:template match="terminal">
133 <xsl:value-of select="@symbol"/>
134 <xsl:value-of select="concat(' (', @type, ')')"/>
135 <xsl:apply-templates select="rule"/>
136 <xsl:text>&#10;</xsl:text>
137 </xsl:template>
138
139 <xsl:template match="terminal/rule">
140 <xsl:text> </xsl:text>
141 <xsl:value-of select="."/>
142 </xsl:template>
143
144 <xsl:template match="nonterminal">
145 <xsl:value-of select="@symbol"/>
146 <xsl:value-of select="concat(' (', @type, ')')"/>
147 <xsl:text>&#10; </xsl:text>
148 <xsl:if test="left/rule">
149 <xsl:text>on left:</xsl:text>
150 </xsl:if>
151 <xsl:apply-templates select="left/rule"/>
152 <xsl:if test="left/rule and right/rule">
153 <xsl:text>, </xsl:text>
154 </xsl:if>
155 <xsl:if test="right/rule">
156 <xsl:text>on right:</xsl:text>
157 </xsl:if>
158 <xsl:apply-templates select="right/rule"/>
159 <xsl:text>&#10;</xsl:text>
160 </xsl:template>
161
162 <xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
163 <xsl:text> </xsl:text>
164 <xsl:value-of select="."/>
165 </xsl:template>
166
167 <xsl:template match="automaton">
168 <xsl:apply-templates select="state">
169 <xsl:with-param name="pad" select="'3'"/>
170 </xsl:apply-templates>
171 </xsl:template>
172
173 <xsl:template match="automaton/state">
174 <xsl:param name="pad"/>
175 <xsl:text>&#10;&#10;</xsl:text>
176 <xsl:text>state </xsl:text>
177 <xsl:value-of select="@number"/>
178 <xsl:text>&#10;&#10;</xsl:text>
179 <xsl:apply-templates select="itemset/rule">
180 <xsl:with-param name="pad" select="$pad"/>
181 </xsl:apply-templates>
182 <xsl:apply-templates select="actions/transitions">
183 <xsl:with-param name="type" select="'shift'"/>
184 </xsl:apply-templates>
185 <xsl:apply-templates select="actions/errors"/>
186 <xsl:apply-templates select="actions/reductions"/>
187 <xsl:apply-templates select="actions/transitions">
188 <xsl:with-param name="type" select="'goto'"/>
189 </xsl:apply-templates>
190 <xsl:apply-templates select="solved-conflicts"/>
191 </xsl:template>
192
193 <xsl:template match="actions/transitions">
194 <xsl:param name="type"/>
195 <xsl:if test="transition[@type = $type]">
196 <xsl:text>&#10;</xsl:text>
197 <xsl:apply-templates select="transition[@type = $type]">
198 <xsl:with-param name="pad">
199 <xsl:call-template name="max-width-symbol">
200 <xsl:with-param name="node" select="transition[@type = $type]"/>
201 </xsl:call-template>
202 </xsl:with-param>
203 </xsl:apply-templates>
204 </xsl:if>
205 </xsl:template>
206
207 <xsl:template match="actions/errors">
208 <xsl:if test="error">
209 <xsl:text>&#10;</xsl:text>
210 <xsl:apply-templates select="error">
211 <xsl:with-param name="pad">
212 <xsl:call-template name="max-width-symbol">
213 <xsl:with-param name="node" select="error"/>
214 </xsl:call-template>
215 </xsl:with-param>
216 </xsl:apply-templates>
217 </xsl:if>
218 </xsl:template>
219
220 <xsl:template match="actions/reductions">
221 <xsl:if test="reduction">
222 <xsl:text>&#10;</xsl:text>
223 <xsl:apply-templates select="reduction">
224 <xsl:with-param name="pad">
225 <xsl:call-template name="max-width-symbol">
226 <xsl:with-param name="node" select="reduction"/>
227 </xsl:call-template>
228 </xsl:with-param>
229 </xsl:apply-templates>
230 </xsl:if>
231 </xsl:template>
232
233 <xsl:template match="rule">
234 <xsl:param name="pad"/>
235 <xsl:if test="not(name(..) = 'itemset') and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
236 <xsl:text>&#10;</xsl:text>
237 </xsl:if>
238 <xsl:text> </xsl:text>
239 <xsl:call-template name="lpad">
240 <xsl:with-param name="str" select="string(@number)"/>
241 <xsl:with-param name="pad" select="number($pad)"/>
242 </xsl:call-template>
243 <xsl:text> </xsl:text>
244 <xsl:choose>
245 <xsl:when test="preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
246 <xsl:call-template name="lpad">
247 <xsl:with-param name="str" select="'|'"/>
248 <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 1"/>
249 </xsl:call-template>
250 </xsl:when>
251 <xsl:otherwise>
252 <xsl:value-of select="lhs"/>
253 <xsl:text>:</xsl:text>
254 </xsl:otherwise>
255 </xsl:choose>
256 <xsl:apply-templates select="rhs/symbol|rhs/point|rhs/empty"/>
257 <xsl:apply-templates select="lookaheads"/>
258 <xsl:text>&#10;</xsl:text>
259 </xsl:template>
260
261 <xsl:template match="symbol">
262 <xsl:text> </xsl:text>
263 <xsl:value-of select="."/>
264 </xsl:template>
265
266 <xsl:template match="point">
267 <xsl:text> .</xsl:text>
268 </xsl:template>
269
270 <xsl:template match="empty">
271 <xsl:text> /* empty */</xsl:text>
272 </xsl:template>
273
274 <xsl:template match="lookaheads">
275 <xsl:text> [</xsl:text>
276 <xsl:apply-templates select="symbol"/>
277 <xsl:text>]</xsl:text>
278 </xsl:template>
279
280 <xsl:template match="lookaheads/symbol">
281 <xsl:value-of select="."/>
282 <xsl:if test="position() != last()">
283 <xsl:text>, </xsl:text>
284 </xsl:if>
285 </xsl:template>
286
287 <xsl:template match="transition">
288 <xsl:param name="pad"/>
289 <xsl:text> </xsl:text>
290 <xsl:call-template name="rpad">
291 <xsl:with-param name="str" select="string(@symbol)"/>
292 <xsl:with-param name="pad" select="number($pad) + 2"/>
293 </xsl:call-template>
294 <xsl:choose>
295 <xsl:when test="@type = 'shift'">
296 <xsl:text>shift, and go to state </xsl:text>
297 <xsl:value-of select="@state"/>
298 </xsl:when>
299 <xsl:when test="@type = 'goto'">
300 <xsl:text>go to state </xsl:text>
301 <xsl:value-of select="@state"/>
302 </xsl:when>
303 </xsl:choose>
304 <xsl:text>&#10;</xsl:text>
305 </xsl:template>
306
307 <xsl:template match="error">
308 <xsl:param name="pad"/>
309 <xsl:text> </xsl:text>
310 <xsl:call-template name="rpad">
311 <xsl:with-param name="str" select="string(@symbol)"/>
312 <xsl:with-param name="pad" select="number($pad) + 2"/>
313 </xsl:call-template>
314 <xsl:text>error</xsl:text>
315 <xsl:text> (</xsl:text>
316 <xsl:value-of select="text()"/>
317 <xsl:text>)</xsl:text>
318 <xsl:text>&#10;</xsl:text>
319 </xsl:template>
320
321 <xsl:template match="reduction">
322 <xsl:param name="pad"/>
323 <xsl:text> </xsl:text>
324 <xsl:call-template name="rpad">
325 <xsl:with-param name="str" select="string(@symbol)"/>
326 <xsl:with-param name="pad" select="number($pad) + 2"/>
327 </xsl:call-template>
328 <xsl:if test="@enabled = 'false'">
329 <xsl:text>[</xsl:text>
330 </xsl:if>
331 <xsl:choose>
332 <xsl:when test="@rule = 'accept'">
333 <xsl:text>accept</xsl:text>
334 </xsl:when>
335 <xsl:otherwise>
336 <xsl:text>reduce using rule </xsl:text>
337 <xsl:value-of select="@rule"/>
338 <xsl:text> (</xsl:text>
339 <xsl:value-of
340 select="/bison-xml-report/grammar/rules/rule[@number = current()/@rule]/lhs[text()]"/>
341 <xsl:text>)</xsl:text>
342 </xsl:otherwise>
343 </xsl:choose>
344 <xsl:if test="@enabled = 'false'">
345 <xsl:text>]</xsl:text>
346 </xsl:if>
347 <xsl:text>&#10;</xsl:text>
348 </xsl:template>
349
350 <xsl:template match="solved-conflicts">
351 <xsl:if test="resolution">
352 <xsl:text>&#10;</xsl:text>
353 <xsl:apply-templates select="resolution"/>
354 </xsl:if>
355 </xsl:template>
356
357 <xsl:template match="resolution">
358 <xsl:text> Conflict between rule </xsl:text>
359 <xsl:value-of select="@rule"/>
360 <xsl:text> and token </xsl:text>
361 <xsl:value-of select="@symbol"/>
362 <xsl:text> resolved as </xsl:text>
363 <xsl:if test="@type = 'error'">
364 <xsl:text>an </xsl:text>
365 </xsl:if>
366 <xsl:value-of select="@type"/>
367 <xsl:text> (</xsl:text>
368 <xsl:value-of select="."/>
369 <xsl:text>).&#10;</xsl:text>
370 </xsl:template>
371
372 <xsl:template name="max-width-symbol">
373 <xsl:param name="node"/>
374 <xsl:variable name="longest">
375 <xsl:for-each select="$node">
376 <xsl:sort data-type="number" select="string-length(@symbol)"
377 order="descending"/>
378 <xsl:if test="position() = 1">
379 <xsl:value-of select="string-length(@symbol)"/>
380 </xsl:if>
381 </xsl:for-each>
382 </xsl:variable>
383 <xsl:value-of select="$longest"/>
384 </xsl:template>
385
386 <xsl:template name="lpad">
387 <xsl:param name="str" select="''"/>
388 <xsl:param name="pad" select="0"/>
389 <xsl:variable name="diff" select="$pad - string-length($str)" />
390 <xsl:choose>
391 <xsl:when test="$diff &lt; 0">
392 <xsl:value-of select="$str"/>
393 </xsl:when>
394 <xsl:otherwise>
395 <xsl:call-template name="space">
396 <xsl:with-param name="repeat" select="$diff"/>
397 </xsl:call-template>
398 <xsl:value-of select="$str"/>
399 </xsl:otherwise>
400 </xsl:choose>
401 </xsl:template>
402
403 <xsl:template name="rpad">
404 <xsl:param name="str" select="''"/>
405 <xsl:param name="pad" select="0"/>
406 <xsl:variable name="diff" select="$pad - string-length($str)"/>
407 <xsl:choose>
408 <xsl:when test="$diff &lt; 0">
409 <xsl:value-of select="$str"/>
410 </xsl:when>
411 <xsl:otherwise>
412 <xsl:value-of select="$str"/>
413 <xsl:call-template name="space">
414 <xsl:with-param name="repeat" select="$diff"/>
415 </xsl:call-template>
416 </xsl:otherwise>
417 </xsl:choose>
418 </xsl:template>
419
420 <xsl:template name="space">
421 <xsl:param name="repeat">0</xsl:param>
422 <xsl:param name="fill" select="' '"/>
423 <xsl:if test="number($repeat) &gt;= 1">
424 <xsl:call-template name="space">
425 <xsl:with-param name="repeat" select="$repeat - 1"/>
426 <xsl:with-param name="fill" select="$fill"/>
427 </xsl:call-template>
428 <xsl:value-of select="$fill"/>
429 </xsl:if>
430 </xsl:template>
431
432 </xsl:stylesheet>