bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: <reductions>


From: Wojciech Polak
Subject: Re: <reductions>
Date: Thu, 11 Oct 2007 18:56:58 +0200

I committed this.

2007-10-11  Wojciech Polak  <address@hidden>

        * src/print-xml.c (print_core): Remove item set
        redundancy.
        * data/xslt/bison.xsl (bison:ruleNumber): New key.
        Improve processing time. Suggested by Joel E. Denny.
        * data/xslt/xml2dot.xsl (xsl:template name="escape"):
        Write xsl:param "required" attribute as comment.
        * data/xslt/xml2text.xsl (xsl:template match="item"): New.
        (xsl:template match="rule"): Support new reduced itemset.
        (xsl:template match="point"): Remove.
        * data/xslt/xml2xhtml.xsl: Likewise.

Index: data/xslt/bison.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/bison.xsl,v
retrieving revision 1.1
diff -p -u -r1.1 bison.xsl
--- data/xslt/bison.xsl 9 Oct 2007 08:48:43 -0000 1.1
+++ data/xslt/bison.xsl 11 Oct 2007 16:19:14 -0000
@@ -2,6 +2,8 @@

<!--
     bison.xsl - common templates for Bison XSLT.
+    $Id$
+
     Copyright (C) 2007 Free Software Foundation, Inc.

     This file is part of Bison, the GNU Compiler Compiler.
@@ -24,6 +26,10 @@
   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"/>
+
<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
<xsl:template match="state" mode="bison:count-conflicts">
   <xsl:variable name="transitions" select="actions/transitions"/>
Index: data/xslt/xml2dot.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2dot.xsl,v
retrieving revision 1.2
diff -p -u -r1.2 xml2dot.xsl
--- data/xslt/xml2dot.xsl 9 Oct 2007 08:48:43 -0000 1.2
+++ data/xslt/xml2dot.xsl 11 Oct 2007 16:19:14 -0000
@@ -151,7 +151,7 @@
</xsl:template>

<xsl:template name="escape">
-  <xsl:param name="subject" required="yes"/>
+  <xsl:param name="subject"/> <!-- required -->
   <xsl:call-template name="string-replace">
     <xsl:with-param name="subject">
       <xsl:call-template name="string-replace">
Index: data/xslt/xml2text.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2text.xsl,v
retrieving revision 1.2
diff -p -u -r1.2 xml2text.xsl
--- data/xslt/xml2text.xsl 9 Oct 2007 08:48:43 -0000 1.2
+++ data/xslt/xml2text.xsl 11 Oct 2007 16:19:14 -0000
@@ -211,7 +211,7 @@
   <xsl:text>state </xsl:text>
   <xsl:value-of select="@number"/>
   <xsl:text>&#10;&#10;</xsl:text>
-  <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">
@@ -265,19 +265,51 @@
   </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>&#10;</xsl:text>
   </xsl:if>
+
   <xsl:text>  </xsl:text>
   <xsl:call-template name="lpad">
     <xsl:with-param name="str" select="string(@number)"/>
     <xsl:with-param name="pad" select="number($pad)"/>
   </xsl:call-template>
   <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()]))
+ 1"/>
+      </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()])) +
1"/>
@@ -288,8 +320,26 @@
       <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>
+    </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>
+    </xsl:if>
+  </xsl:for-each>
+  <xsl:if test="$lookaheads">
+    <xsl:value-of select="$lookaheads"/>
+  </xsl:if>
+
   <xsl:text>&#10;</xsl:text>
</xsl:template>

@@ -298,10 +348,6 @@
   <xsl:value-of select="."/>
</xsl:template>

-<xsl:template match="point">
-  <xsl:text> .</xsl:text>
-</xsl:template>
-
<xsl:template match="empty">
   <xsl:text> /* empty */</xsl:text>
</xsl:template>
@@ -372,7 +418,7 @@
       <xsl:value-of select="@rule"/>
       <xsl:text> (</xsl:text>
       <xsl:value-of
-   select="/bison-xml-report/grammar/rules/address@hidden =
current()/@rule]/lhs[text()]"/>
+   select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
       <xsl:text>)</xsl:text>
     </xsl:otherwise>
   </xsl:choose>
@@ -465,9 +511,9 @@
</xsl:template>

<xsl:template name="line-wrap">
-  <xsl:param name="line-length" required="yes" />
-  <xsl:param name="first-line-length" select="$line-length" />
-  <xsl:param name="text" required="yes" />
+  <xsl:param name="line-length"/> <!-- required -->
+  <xsl:param name="first-line-length" select="$line-length"/>
+  <xsl:param name="text"/> <!-- required -->
   <xsl:choose>
     <xsl:when test="string-length($text) = 0 or normalize-space($text)
= ''" />
     <xsl:when test="string-length($text) &lt;= $first-line-length">
@@ -493,8 +539,8 @@
</xsl:template>

<xsl:template name="ws-search">
-  <xsl:param name="text" required="yes" />
-  <xsl:param name="pos" required="yes" />
+  <xsl:param name="text"/> <!-- required -->
+  <xsl:param name="pos"/> <!-- required -->
   <xsl:choose>
     <xsl:when
       test="$pos &gt; string-length($text) or substring($text, $pos, 1)
= ' '"
Index: data/xslt/xml2xhtml.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2xhtml.xsl,v
retrieving revision 1.2
diff -p -u -r1.2 xml2xhtml.xsl
--- data/xslt/xml2xhtml.xsl 9 Oct 2007 08:48:43 -0000 1.2
+++ data/xslt/xml2xhtml.xsl 11 Oct 2007 16:19:14 -0000
@@ -365,7 +365,7 @@
   </h3>
   <xsl:text>&#10;&#10;</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">
@@ -420,12 +420,35 @@
   </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>&#10;</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)"/>
@@ -433,8 +456,9 @@
     </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)"/>
@@ -453,8 +477,17 @@
     </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"/>
@@ -467,8 +500,28 @@
       <xsl:text> &#8594;</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>&#10;</xsl:text>
</xsl:template>

@@ -484,11 +537,6 @@
   </xsl:choose>
</xsl:template>

-<xsl:template match="point">
-  <xsl:text> </xsl:text>
-  <span class="point">.</span>
-</xsl:template>
-
<xsl:template match="empty">
   <xsl:text> &#949;</xsl:text>
</xsl:template>
@@ -571,7 +619,7 @@
       </a>
       <xsl:text> (</xsl:text>
       <xsl:value-of
-   select="/bison-xml-report/grammar/rules/address@hidden =
current()/@rule]/lhs[text()]"/>
+   select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
       <xsl:text>)</xsl:text>
     </xsl:otherwise>
   </xsl:choose>
Index: src/print-xml.c
===================================================================
RCS file: /sources/bison/bison/src/print-xml.c,v
retrieving revision 1.5
diff -p -u -r1.5 print-xml.c
--- src/print-xml.c 9 Oct 2007 08:48:43 -0000 1.5
+++ src/print-xml.c 11 Oct 2007 16:19:14 -0000
@@ -108,6 +108,7 @@ print_core (FILE *out, int level, state 

   for (i = 0; i < snritems; i++)
     {
+      bool printed = false;
       item_number *sp;
       item_number *sp1;
       rule_number r;
@@ -118,30 +119,33 @@ print_core (FILE *out, int level, state 
sp++;

       r = item_number_as_rule_number (*sp);
-
-      xml_printf (out, level + 1, "<rule number=\"%d\">",
-   rules[r].number);
-
-      rule_lhs_print_xml (&rules[r], out, level + 2);
-
-      xml_puts (out, level + 2, "<rhs>");
-      for (sp = rules[r].rhs; sp < sp1; sp++)
- xml_printf (out, level + 3, "<symbol class=\"%s\">%s</symbol>",
-     symbol_class_get_string (symbols[*sp]),
-     xml_escape (symbols[*sp]->tag));
-      xml_puts (out, level + 3, "<point/>");
-      for (/* Nothing */; *sp >= 0; ++sp)
- xml_printf (out, level + 3, "<symbol class=\"%s\">%s</symbol>",
-     symbol_class_get_string (symbols[*sp]),
-     xml_escape (symbols[*sp]->tag));
-
-      xml_puts (out, level + 2, "</rhs>");
+      sp = rules[r].rhs;

       /* Display the lookahead tokens?  */
       if (report_flag & report_lookahead_tokens)
- state_rule_lookahead_tokens_print_xml (s, &rules[r], out, level + 2);
+ {
+   reductions *reds = s->reductions;
+   int red = state_reduction_find (s, &rules[r]);
+   /* Print item with lookaheads if there are. */
+   if (reds->lookahead_tokens && red != -1)
+     {
+       xml_printf (out, level + 1,
+   "<item rule-number=\"%d\" point=\"%d\">",
+   rules[r].number, sp1 - sp);
+       state_rule_lookahead_tokens_print_xml (s, &rules[r],
+      out, level + 2);
+       xml_puts (out, level + 1, "</item>");
+       printed = true;
+     }
+ }

-      xml_puts (out, level + 1, "</rule>");
+      if (!printed)
+ {
+   xml_printf (out, level + 1,
+       "<item rule-number=\"%d\" point=\"%d\"/>",
+       rules[r].number,
+       sp1 - sp);
+ }
     }
   xml_puts (out, level, "</itemset>");
}






reply via email to

[Prev in Thread] Current Thread [Next in Thread]