* 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.
This commit is contained in:
Joel E. Denny
2007-12-08 16:05:38 +00:00
parent ef1b427325
commit d4a26c4832
6 changed files with 98 additions and 109 deletions

View File

@@ -1,3 +1,35 @@
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> 2007-12-01 Joel E. Denny <jdenny@ces.clemson.edu>
Don't let --report affect XML output; always print all information. Don't let --report affect XML output; always print all information.

View File

@@ -26,9 +26,23 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/"> xmlns:bison="http://www.gnu.org/software/bison/">
<xsl:key name="bison:ruleNumber" <xsl:key
match="/bison-xml-report/grammar/rules/rule" name="bison:ruleByNumber"
use="@number"/> 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 --> <!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
<xsl:template match="state" mode="bison:count-conflicts"> <xsl:template match="state" mode="bison:count-conflicts">

View File

@@ -61,7 +61,7 @@
</xsl:template> </xsl:template>
<xsl:template match="item"> <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:with-param name="point" select="@point"/>
</xsl:apply-templates> </xsl:apply-templates>
<xsl:apply-templates select="lookaheads"/> <xsl:apply-templates select="lookaheads"/>

View File

@@ -150,16 +150,13 @@
<xsl:with-param name="line-length" select="66" /> <xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text"> <xsl:with-param name="text">
<xsl:value-of select="concat(' (', @token-number, ')')"/> <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:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:template> </xsl:template>
<xsl:template match="terminal/rule">
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="nonterminal"> <xsl:template match="nonterminal">
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/> <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
@@ -169,28 +166,27 @@
<xsl:with-param name="line-length" select="66" /> <xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text"> <xsl:with-param name="text">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<xsl:if test="left/rule"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on@left:</xsl:text> <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:if>
<xsl:apply-templates select="left/rule"/> <xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:if test="left/rule and right/rule"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>, </xsl:text> <xsl:text>, </xsl:text>
</xsl:if> </xsl:if>
<xsl:if test="right/rule">
<xsl:text>on@right:</xsl:text> <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:if>
<xsl:apply-templates select="right/rule"/>
</xsl:with-param> </xsl:with-param>
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:value-of select="translate($output, '@', ' ')" /> <xsl:value-of select="translate($output, '@', ' ')" />
</xsl:template> </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:template match="automaton" mode="conflicts">
<xsl:variable name="conflict-report"> <xsl:variable name="conflict-report">
<xsl:apply-templates select="state" mode="conflicts"/> <xsl:apply-templates select="state" mode="conflicts"/>
@@ -296,11 +292,15 @@
<xsl:param name="pad"/> <xsl:param name="pad"/>
<xsl:param name="prev-rule-number" <xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@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="itemset" select="'true'"/>
<xsl:with-param name="pad" select="$pad"/> <xsl:with-param name="pad" select="$pad"/>
<xsl:with-param name="prev-lhs" <xsl:with-param
select="key('bison:ruleNumber', $prev-rule-number)/lhs[text()]"/> name="prev-lhs"
select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
/>
<xsl:with-param name="point" select="@point"/> <xsl:with-param name="point" select="@point"/>
<xsl:with-param name="lookaheads"> <xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/> <xsl:apply-templates select="lookaheads"/>
@@ -443,7 +443,7 @@
<xsl:value-of select="@rule"/> <xsl:value-of select="@rule"/>
<xsl:text> (</xsl:text> <xsl:text> (</xsl:text>
<xsl:value-of <xsl:value-of
select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/> select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
<xsl:text>)</xsl:text> <xsl:text>)</xsl:text>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>

View File

@@ -326,45 +326,41 @@
<xsl:template match="terminal"> <xsl:template match="terminal">
<b><xsl:value-of select="@name"/></b> <b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @token-number, ')')"/> <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>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:template> </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"> <xsl:template match="nonterminal">
<b><xsl:value-of select="@name"/></b> <b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/> <xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text>&#10; </xsl:text> <xsl:text>&#10; </xsl:text>
<xsl:if test="left/rule"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on left:</xsl:text> <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:if>
<xsl:apply-templates select="left/rule"/> <xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:if test="left/rule and right/rule"> <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>&#10; </xsl:text> <xsl:text>&#10; </xsl:text>
</xsl:if> </xsl:if>
<xsl:if test="right/rule">
<xsl:text>on right:</xsl:text> <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:if>
<xsl:apply-templates select="right/rule"/>
<xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
</xsl:template> </xsl:template>
<xsl:template match="nonterminal/left/rule|nonterminal/right/rule"> <xsl:template match="rule" mode="number-link">
<xsl:text> </xsl:text> <xsl:text> </xsl:text>
<a> <a>
<xsl:attribute name="href"> <xsl:attribute name="href">
<xsl:value-of select="concat('#rule_', .)"/> <xsl:value-of select="concat('#rule_', @number)"/>
</xsl:attribute> </xsl:attribute>
<xsl:value-of select="."/> <xsl:value-of select="@number"/>
</a> </a>
</xsl:template> </xsl:template>
@@ -451,11 +447,14 @@
<xsl:param name="pad"/> <xsl:param name="pad"/>
<xsl:param name="prev-rule-number" <xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@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="itemset" select="'true'"/>
<xsl:with-param name="pad" select="$pad"/> <xsl:with-param name="pad" select="$pad"/>
<xsl:with-param name="prev-lhs" <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="point" select="@point"/>
<xsl:with-param name="lookaheads"> <xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/> <xsl:apply-templates select="lookaheads"/>
@@ -644,7 +643,8 @@
</a> </a>
<xsl:text> (</xsl:text> <xsl:text> (</xsl:text>
<xsl:value-of <xsl:value-of
select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/> select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
/>
<xsl:text>)</xsl:text> <xsl:text>)</xsl:text>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>

View File

@@ -392,24 +392,12 @@ print_grammar (FILE *out, int level)
if (token_translations[i] != undeftoken->number) if (token_translations[i] != undeftoken->number)
{ {
char const *tag = symbols[token_translations[i]]->tag; char const *tag = symbols[token_translations[i]]->tag;
rule_number r;
item_number *rhsp;
xml_printf (out, level + 2, xml_printf (out, level + 2,
"<terminal symbol-number=\"%d\" token-number=\"%d\"" "<terminal symbol-number=\"%d\" token-number=\"%d\""
" name=\"%s\" usefulness=\"%s\">", " name=\"%s\" usefulness=\"%s\"/>",
token_translations[i], i, xml_escape (tag), token_translations[i], i, xml_escape (tag),
reduce_token_unused_in_grammar (token_translations[i]) reduce_token_unused_in_grammar (token_translations[i])
? "unused-in-grammar" : "useful"); ? "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, "</terminals>");
@@ -417,58 +405,13 @@ print_grammar (FILE *out, int level)
xml_puts (out, level + 1, "<nonterminals>"); xml_puts (out, level + 1, "<nonterminals>");
for (i = ntokens; i < nsyms + nuseless_nonterminals; i++) for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
{ {
int left_count = 0, right_count = 0;
rule_number r;
char const *tag = symbols[i]->tag; 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, xml_printf (out, level + 2,
"<nonterminal symbol-number=\"%d\" name=\"%s\"" "<nonterminal symbol-number=\"%d\" name=\"%s\""
" usefulness=\"%s\">", " usefulness=\"%s\"/>",
i, xml_escape (tag), i, xml_escape (tag),
reduce_nonterminal_useless_in_grammar (i) reduce_nonterminal_useless_in_grammar (i)
? "useless-in-grammar" : "useful"); ? "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 + 1, "</nonterminals>");
xml_puts (out, level, "</grammar>"); xml_puts (out, level, "</grammar>");