(bison:ruleByNumber): ... this for clarity.
* data/xslt/xml2dot.xsl (xsl:template match="item"): Update.
* data/xslt/xml2text.xsl (xsl:template match="item"): Update.
(xsl:template match="reduction"): Update.
(xsl:template match="item"): Update.
(xsl:template match="reduction"): Update.
In the XML output, don't print the list of rules where symbols appear.
Compute it in XSLT instead. Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2007-09/msg00024.html>.
* data/xslt/bison.xsl (bison:ruleByLhs): New.
(bison:ruleByRhs): New.
* data/xslt/xml2text.xsl (xsl:template match="terminal"): Use
bison:ruleByRhs.
(xsl:template match="terminal/rule"): Remove.
(xsl:template match="nonterminal"): Use bison:ruleByLhs and
bison:ruleByRhs.
(xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
Remove.
* data/xslt/xml2xhtml.xsl (xsl:template match="terminal"): Use
bison:ruleByRhs and mode="number-link" for rule template.
(xsl:template match="terminal/rule"): Remove.
(xsl:template match="nonterminal"): Use bison:ruleByLhs and
bison:ruleByRhs and mode="number-link" for rule template.
(xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
Rewrite as...
(xsl:template match="rule" mode="number-link"): ... this.
* src/print-xml.c (print_grammar): Don't print the list of rules.
+2007-12-08 Joel E. Denny <jdenny@ces.clemson.edu>
+
+ * data/xslt/bison.xsl (bison:ruleNumber): Rename to...
+ (bison:ruleByNumber): ... this for clarity.
+ * data/xslt/xml2dot.xsl (xsl:template match="item"): Update.
+ * data/xslt/xml2text.xsl (xsl:template match="item"): Update.
+ (xsl:template match="reduction"): Update.
+ (xsl:template match="item"): Update.
+ (xsl:template match="reduction"): Update.
+
+ In the XML output, don't print the list of rules where symbols appear.
+ Compute it in XSLT instead. Discussed at
+ <http://lists.gnu.org/archive/html/bison-patches/2007-09/msg00024.html>.
+ * data/xslt/bison.xsl (bison:ruleByLhs): New.
+ (bison:ruleByRhs): New.
+ * data/xslt/xml2text.xsl (xsl:template match="terminal"): Use
+ bison:ruleByRhs.
+ (xsl:template match="terminal/rule"): Remove.
+ (xsl:template match="nonterminal"): Use bison:ruleByLhs and
+ bison:ruleByRhs.
+ (xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
+ Remove.
+ * data/xslt/xml2xhtml.xsl (xsl:template match="terminal"): Use
+ bison:ruleByRhs and mode="number-link" for rule template.
+ (xsl:template match="terminal/rule"): Remove.
+ (xsl:template match="nonterminal"): Use bison:ruleByLhs and
+ bison:ruleByRhs and mode="number-link" for rule template.
+ (xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
+ Rewrite as...
+ (xsl:template match="rule" mode="number-link"): ... this.
+ * src/print-xml.c (print_grammar): Don't print the list of rules.
+
2007-12-01 Joel E. Denny <jdenny@ces.clemson.edu>
Don't let --report affect XML output; always print all information.
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/">
-<xsl:key name="bison:ruleNumber"
- match="/bison-xml-report/grammar/rules/rule"
- use="@number"/>
+<xsl:key
+ name="bison:ruleByNumber"
+ match="/bison-xml-report/grammar/rules/rule"
+ use="@number"
+/>
+<xsl:key
+ name="bison:ruleByLhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="lhs"
+/>
+<xsl:key
+ name="bison:ruleByRhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="rhs/symbol"
+/>
<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
<xsl:template match="state" mode="bison:count-conflicts">
</xsl:template>
<xsl:template match="item">
- <xsl:apply-templates select="key('bison:ruleNumber', @rule-number)">
+ <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
<xsl:with-param name="point" select="@point"/>
</xsl:apply-templates>
<xsl:apply-templates select="lookaheads"/>
<xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text">
<xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:apply-templates select="rule" />
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
-<xsl:template match="terminal/rule">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
<xsl:template match="nonterminal">
<xsl:value-of select="@name"/>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text">
<xsl:text> </xsl:text>
- <xsl:if test="left/rule">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on@left:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="left/rule"/>
- <xsl:if test="left/rule and right/rule">
- <xsl:text>, </xsl:text>
- </xsl:if>
- <xsl:if test="right/rule">
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
<xsl:text>on@right:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="right/rule"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="translate($output, '@', ' ')" />
</xsl:template>
-<xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
<xsl:template match="automaton" mode="conflicts">
<xsl:variable name="conflict-report">
<xsl:apply-templates select="state" mode="conflicts"/>
<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:apply-templates
+ select="key('bison:ruleByNumber', 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="prev-lhs"
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
<xsl:value-of select="@rule"/>
<xsl:text> (</xsl:text>
<xsl:value-of
- select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
<xsl:text>)</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:template match="terminal">
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:apply-templates select="rule"/>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>
-<xsl:template match="terminal/rule">
- <xsl:text> </xsl:text>
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', .)"/>
- </xsl:attribute>
- <xsl:value-of select="."/>
- </a>
-</xsl:template>
-
<xsl:template match="nonterminal">
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text> </xsl:text>
- <xsl:if test="left/rule">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on left:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="left/rule"/>
- <xsl:if test="left/rule and right/rule">
- <xsl:text> </xsl:text>
- </xsl:if>
- <xsl:if test="right/rule">
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text> </xsl:text>
+ </xsl:if>
<xsl:text>on right:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="right/rule"/>
<xsl:text> </xsl:text>
</xsl:template>
-<xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
+<xsl:template match="rule" mode="number-link">
<xsl:text> </xsl:text>
<a>
<xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', .)"/>
+ <xsl:value-of select="concat('#rule_', @number)"/>
</xsl:attribute>
- <xsl:value-of select="."/>
+ <xsl:value-of select="@number"/>
</a>
</xsl:template>
<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:apply-templates
+ select="key('bison:ruleByNumber', 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()]"/>
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
</a>
<xsl:text> (</xsl:text>
<xsl:value-of
- select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
+ />
<xsl:text>)</xsl:text>
</xsl:otherwise>
</xsl:choose>
if (token_translations[i] != undeftoken->number)
{
char const *tag = symbols[token_translations[i]]->tag;
- rule_number r;
- item_number *rhsp;
-
xml_printf (out, level + 2,
"<terminal symbol-number=\"%d\" token-number=\"%d\""
- " name=\"%s\" usefulness=\"%s\">",
+ " name=\"%s\" usefulness=\"%s\"/>",
token_translations[i], i, xml_escape (tag),
reduce_token_unused_in_grammar (token_translations[i])
? "unused-in-grammar" : "useful");
-
- for (r = 0; r < nrules; r++)
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == token_translations[i])
- {
- xml_printf (out, level + 3, "<rule>%d</rule>", r);
- break;
- }
- xml_puts (out, level + 2, "</terminal>");
}
xml_puts (out, level + 1, "</terminals>");
xml_puts (out, level + 1, "<nonterminals>");
for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
{
- int left_count = 0, right_count = 0;
- rule_number r;
char const *tag = symbols[i]->tag;
-
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- if (rules[r].lhs->number == i)
- left_count++;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- right_count++;
- break;
- }
- }
-
xml_printf (out, level + 2,
"<nonterminal symbol-number=\"%d\" name=\"%s\""
- " usefulness=\"%s\">",
+ " usefulness=\"%s\"/>",
i, xml_escape (tag),
reduce_nonterminal_useless_in_grammar (i)
? "useless-in-grammar" : "useful");
-
- if (left_count > 0)
- {
- xml_puts (out, level + 3, "<left>");
- for (r = 0; r < nrules; r++)
- {
- if (rules[r].lhs->number == i)
- xml_printf (out, level + 4, "<rule>%d</rule>", r);
- }
- xml_puts (out, level + 3, "</left>");
- }
-
- if (right_count > 0)
- {
- xml_puts (out, level + 3, "<right>");
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- xml_printf (out, level + 4, "<rule>%d</rule>", r);
- break;
- }
- }
- xml_puts (out, level + 3, "</right>");
- }
-
- xml_puts (out, level + 2, "</nonterminal>");
}
xml_puts (out, level + 1, "</nonterminals>");
xml_puts (out, level, "</grammar>");