xml2xhtml.xsl 23 KB

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