]> git.saurik.com Git - bison.git/commitdiff
* data/xslt/bison.xsl (bison:ruleNumber): Rename to...
authorJoel E. Denny <jdenny@ces.clemson.edu>
Sat, 8 Dec 2007 16:05:38 +0000 (16:05 +0000)
committerJoel E. Denny <jdenny@ces.clemson.edu>
Sat, 8 Dec 2007 16:05:38 +0000 (16:05 +0000)
(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.

ChangeLog
data/xslt/bison.xsl
data/xslt/xml2dot.xsl
data/xslt/xml2text.xsl
data/xslt/xml2xhtml.xsl
src/print-xml.c

index a5b31366b2269e36c47e370fda51bfcefbfe3dff..b3db792b0a86cc27faf34821d982233c019a19ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        Don't let --report affect XML output; always print all information.
index ce3fe0f36ff3b3d63eb201254ef75e3083d7a2e3..dc0dd9c516dbe2560c6b87d9d5e00816ffe32f92 100644 (file)
   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">
index d1d2691ac908ea40c6ad0480aa7da9dde7f4d422..e106da1e123bcfe666fb26ad63e5fb0307285ff4 100644 (file)
@@ -61,7 +61,7 @@
 </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"/>
index c2568a44c879a98369ca5839ae22564347c4c525..0e4811d713cfb2e69ae15f77048d1d1a1723d7bd 100644 (file)
     <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>
index 15155e9d0409a55766b59a32c5d45b948b0dde5f..c1936dc69c77382fdd9d38859a415f4096c0b3ec 100644 (file)
 <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>&#10;</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>&#10;    </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>&#10;    </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>&#10;    </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>&#10;</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>
index 33ececa776a6b6ae1c885c4d4fcedff244c77a00..9b1891bdbe97e040a34f156711c129db978d37a7 100644 (file)
@@ -392,24 +392,12 @@ print_grammar (FILE *out, int level)
     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>");
 
@@ -417,58 +405,13 @@ print_grammar (FILE *out, int level)
   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>");