<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns="http://www.w3.org/1999/xhtml">
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:bison="http://www.gnu.org/software/bison/">
+
+<xsl:import href="bison.xsl"/>
<xsl:output method="xml" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
</ul>
<xsl:apply-templates select="reductions"/>
<xsl:apply-templates select="rules-never-reduced"/>
- <xsl:apply-templates select="conflicts"/>
+ <xsl:apply-templates select="automaton" mode="conflicts"/>
<xsl:apply-templates select="grammar"/>
<xsl:apply-templates select="automaton"/>
</xsl:template>
</xsl:if>
</xsl:template>
-<xsl:template match="conflicts">
+<xsl:template match="automaton" mode="conflicts">
<h2>
<a name="conflicts"/>
<xsl:text> Conflicts</xsl:text>
</h2>
<xsl:text> </xsl:text>
- <xsl:if test="conflict">
+ <xsl:variable name="conflict-report">
+ <xsl:apply-templates select="state" mode="conflicts"/>
+ </xsl:variable>
+ <xsl:if test="string-length($conflict-report) != 0">
<p class="pre">
- <xsl:apply-templates select="conflict"/>
+ <xsl:copy-of select="$conflict-report"/>
<xsl:text> </xsl:text>
</p>
</xsl:if>
</xsl:template>
-<xsl:template match="conflict">
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#state_', @state)"/>
- </xsl:attribute>
- <xsl:value-of select="concat('State ', @state)"/>
- </a>
- <xsl:text> conflicts: </xsl:text>
- <xsl:value-of select="@num"/>
- <xsl:text> </xsl:text>
- <xsl:value-of select="@type"/>
- <xsl:text> </xsl:text>
+<xsl:template match="state" mode="conflicts">
+ <xsl:variable name="conflict-counts">
+ <xsl:apply-templates select="." mode="bison:count-conflicts" />
+ </xsl:variable>
+ <xsl:variable
+ name="sr-count" select="substring-before($conflict-counts, ',')"
+ />
+ <xsl:variable
+ name="rr-count" select="substring-after($conflict-counts, ',')"
+ />
+ <xsl:if test="$sr-count > 0 or $rr-count > 0">
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#state_', @number)"/>
+ </xsl:attribute>
+ <xsl:value-of select="concat('State ', @number)"/>
+ </a>
+ <xsl:text> conflicts:</xsl:text>
+ <xsl:if test="$sr-count > 0">
+ <xsl:value-of select="concat(' ', $sr-count, ' shift/reduce')"/>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="(',')"/>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="$rr-count > 0">
+ <xsl:value-of select="concat(' ', $rr-count, ' reduce/reduce')"/>
+ </xsl:if>
+ <xsl:value-of select="' '"/>
+ </xsl:if>
</xsl:template>
<xsl:template match="grammar">
</xsl:template>
<xsl:template match="terminal">
- <b><xsl:value-of select="@symbol"/></b>
- <xsl:value-of select="concat(' (', @type, ')')"/>
+ <b><xsl:value-of select="@name"/></b>
+ <xsl:value-of select="concat(' (', @number, ')')"/>
<xsl:apply-templates select="rule"/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:template>
<xsl:template match="nonterminal">
- <b><xsl:value-of select="@symbol"/></b>
- <xsl:value-of select="concat(' (', @type, ')')"/>
+ <b><xsl:value-of select="@name"/></b>
+ <xsl:value-of select="concat(' (', @number, ')')"/>
<xsl:text> </xsl:text>
<xsl:if test="left/rule">
<xsl:text>on left:</xsl:text>
</h3>
<xsl:text> </xsl:text>
<p class="pre">
- <xsl:apply-templates select="itemset/rule">
+ <xsl:apply-templates select="itemset/item">
<xsl:with-param name="pad" select="$pad"/>
</xsl:apply-templates>
<xsl:apply-templates select="actions/transitions">
</xsl:if>
</xsl:template>
+<xsl:template match="item">
+ <xsl:param name="pad"/>
+ <xsl:param name="prev-rule-number"
+ select="preceding-sibling::item[1]/@rule-number"/>
+ <xsl:apply-templates select="key('bison:ruleNumber', current()/@rule-number)">
+ <xsl:with-param name="itemset" select="'true'"/>
+ <xsl:with-param name="pad" select="$pad"/>
+ <xsl:with-param name="prev-lhs"
+ select="key('bison:ruleNumber', $prev-rule-number)/lhs[text()]"/>
+ <xsl:with-param name="point" select="@point"/>
+ <xsl:with-param name="lookaheads">
+ <xsl:apply-templates select="lookaheads"/>
+ </xsl:with-param>
+ </xsl:apply-templates>
+</xsl:template>
+
<xsl:template match="rule">
+ <xsl:param name="itemset"/>
<xsl:param name="pad"/>
- <xsl:if test="not(name(..) = 'itemset') and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
+ <xsl:param name="prev-lhs"/>
+ <xsl:param name="point"/>
+ <xsl:param name="lookaheads"/>
+
+ <xsl:if test="$itemset != 'true'
+ and not(preceding-sibling::rule[1]/lhs[text()] = lhs[text()])">
<xsl:text> </xsl:text>
</xsl:if>
- <xsl:if test="not(name(..) = 'itemset')">
+
+ <xsl:if test="$itemset != 'true'">
<a>
<xsl:attribute name="name">
<xsl:value-of select="concat('rule_', @number)"/>
</a>
</xsl:if>
<xsl:text> </xsl:text>
+
<xsl:choose>
- <xsl:when test="name(..) = 'itemset'">
+ <xsl:when test="$itemset = 'true'">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat('#rule_', @number)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
+
+ <!-- LHS -->
<xsl:choose>
- <xsl:when test="preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
+ <xsl:when test="$itemset != 'true'
+ and preceding-sibling::rule[1]/lhs[text()] = lhs[text()]">
+ <xsl:call-template name="lpad">
+ <xsl:with-param name="str" select="'|'"/>
+ <xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="$itemset = 'true' and $prev-lhs = lhs[text()]">
<xsl:call-template name="lpad">
<xsl:with-param name="str" select="'|'"/>
<xsl:with-param name="pad" select="number(string-length(lhs[text()])) + 2"/>
<xsl:text> →</xsl:text>
</xsl:otherwise>
</xsl:choose>
- <xsl:apply-templates select="rhs/symbol|rhs/point|rhs/empty"/>
- <xsl:apply-templates select="lookaheads"/>
+
+ <!-- RHS -->
+ <xsl:for-each select="rhs/*">
+ <xsl:if test="position() = $point + 1">
+ <xsl:text> </xsl:text>
+ <span class="point">.</span>
+ </xsl:if>
+ <xsl:if test="$itemset = 'true' and name(.) != 'empty'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="$itemset != 'true'">
+ <xsl:apply-templates select="."/>
+ </xsl:if>
+ <xsl:if test="position() = last() and position() = $point">
+ <xsl:text> </xsl:text>
+ <span class="point">.</span>
+ </xsl:if>
+ </xsl:for-each>
+ <xsl:if test="$lookaheads">
+ <xsl:value-of select="$lookaheads"/>
+ </xsl:if>
+
<xsl:text> </xsl:text>
</xsl:template>
</xsl:choose>
</xsl:template>
-<xsl:template match="point">
- <xsl:text> </xsl:text>
- <span class="point">.</span>
-</xsl:template>
-
<xsl:template match="empty">
<xsl:text> ε</xsl:text>
</xsl:template>
</a>
<xsl:text> (</xsl:text>
<xsl:value-of
- select="/bison-xml-report/grammar/rules/rule[@number = current()/@rule]/lhs[text()]"/>
+ select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
<xsl:text>)</xsl:text>
</xsl:otherwise>
</xsl:choose>