bison.xsl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. bison.xsl - common templates for Bison XSLT.
  4. Copyright (C) 2007-2015 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 <http://www.gnu.org/licenses/>.
  16. -->
  17. <xsl:stylesheet version="1.0"
  18. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  19. xmlns:bison="http://www.gnu.org/software/bison/">
  20. <xsl:key
  21. name="bison:symbolByName"
  22. match="/bison-xml-report/grammar/nonterminals/nonterminal"
  23. use="@name"
  24. />
  25. <xsl:key
  26. name="bison:symbolByName"
  27. match="/bison-xml-report/grammar/terminals/terminal"
  28. use="@name"
  29. />
  30. <xsl:key
  31. name="bison:ruleByNumber"
  32. match="/bison-xml-report/grammar/rules/rule"
  33. use="@number"
  34. />
  35. <xsl:key
  36. name="bison:ruleByLhs"
  37. match="/bison-xml-report/grammar/rules/rule[
  38. @usefulness != 'useless-in-grammar']"
  39. use="lhs"
  40. />
  41. <xsl:key
  42. name="bison:ruleByRhs"
  43. match="/bison-xml-report/grammar/rules/rule[
  44. @usefulness != 'useless-in-grammar']"
  45. use="rhs/symbol"
  46. />
  47. <!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
  48. <xsl:template match="state" mode="bison:count-conflicts">
  49. <xsl:variable name="transitions" select="actions/transitions"/>
  50. <xsl:variable name="reductions" select="actions/reductions"/>
  51. <xsl:variable
  52. name="terminals"
  53. select="
  54. $transitions/transition[@type='shift']/@symbol
  55. | $reductions/reduction/@symbol
  56. "
  57. />
  58. <xsl:variable name="conflict-data">
  59. <xsl:for-each select="$terminals">
  60. <xsl:variable name="name" select="."/>
  61. <xsl:if test="generate-id($terminals[. = $name][1]) = generate-id(.)">
  62. <xsl:variable
  63. name="shift-count"
  64. select="count($transitions/transition[@symbol=$name])"
  65. />
  66. <xsl:variable
  67. name="reduce-count"
  68. select="count($reductions/reduction[@symbol=$name])"
  69. />
  70. <xsl:if test="$shift-count > 0 and $reduce-count > 0">
  71. <xsl:text>s</xsl:text>
  72. </xsl:if>
  73. <xsl:if test="$reduce-count > 1">
  74. <xsl:text>r</xsl:text>
  75. </xsl:if>
  76. </xsl:if>
  77. </xsl:for-each>
  78. </xsl:variable>
  79. <xsl:value-of select="string-length(translate($conflict-data, 'r', ''))"/>
  80. <xsl:text>,</xsl:text>
  81. <xsl:value-of select="string-length(translate($conflict-data, 's', ''))"/>
  82. </xsl:template>
  83. <xsl:template name="space">
  84. <xsl:param name="repeat">0</xsl:param>
  85. <xsl:param name="fill" select="' '"/>
  86. <xsl:if test="number($repeat) &gt;= 1">
  87. <xsl:call-template name="space">
  88. <xsl:with-param name="repeat" select="$repeat - 1"/>
  89. <xsl:with-param name="fill" select="$fill"/>
  90. </xsl:call-template>
  91. <xsl:value-of select="$fill"/>
  92. </xsl:if>
  93. </xsl:template>
  94. </xsl:stylesheet>