bison-patches
[Top][All Lists]
Advanced

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

XML and --graph fixes


From: Joel E. Denny
Subject: XML and --graph fixes
Date: Sun, 21 Oct 2007 02:09:22 -0400 (EDT)

It seems we haven't been testing xml2dot.xsl.  I'd like to commit the 
following.  Is this ok with you, Wojciech?

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1741
diff -p -u -r1.1741 ChangeLog
--- ChangeLog   19 Oct 2007 06:14:43 -0000      1.1741
+++ ChangeLog   21 Oct 2007 05:54:28 -0000
@@ -1,3 +1,21 @@
+2007-10-21  Joel E. Denny  <address@hidden>
+
+       * data/xslt/xml2dot.xsl (xsl:template match="automaton/state"): After
+       2007-10-11 change, the child elements here are items not rules.
+       (<xsl:template match="item"): New.
+       (xsl:template match="rule"): Update for new reduced itemset.
+       (xsl:template match="point"): Remove.
+       (xsl:template match="empty"): For consistency with --graph, don't
+       output "/* empty */".
+       * data/xslt/xml2text.xsl (xsl:template match="terminal"): When invoking
+       line-wrap, don't pass a negative value as first-line-length since this
+       won't work with the following changes.
+       (xsl:template name="line-wrap"): Simplify slightly.
+       (xsl:template name="ws-search"): Eliminate recursion.
+       * src/print_graph.c (print_core): Don't print a reduction's lookahead
+       set next to an item whose dot is not at the end of the RHS even if it
+       happens to be associated with the same rule.
+
 2007-10-19  Joel E. Denny  <address@hidden>
 
        Add %define lr.keep_unreachable_states.
Index: data/xslt/xml2dot.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2dot.xsl,v
retrieving revision 1.3
diff -p -u -r1.3 xml2dot.xsl
--- data/xslt/xml2dot.xsl       11 Oct 2007 16:37:59 -0000      1.3
+++ data/xslt/xml2dot.xsl       21 Oct 2007 05:54:29 -0000
@@ -25,8 +25,10 @@
   -->
 
 <xsl:stylesheet version="1.0"
-  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/";>
+
+<xsl:import href="bison.xsl"/>
 <xsl:output method="text" encoding="UTF-8" indent="no"/>
 
 <xsl:template match="/">
@@ -48,7 +50,7 @@
     <xsl:with-param name="number" select="@number"/>
     <xsl:with-param name="label">
       <xsl:value-of select="@number"/>
-      <xsl:apply-templates select="itemset/rule"/>
+      <xsl:apply-templates select="itemset/item"/>
     </xsl:with-param>
   </xsl:call-template>
   <xsl:apply-templates select="actions/transitions"/>
@@ -58,12 +60,27 @@
   <xsl:apply-templates select="transition"/>
 </xsl:template>
 
+<xsl:template match="item">
+  <xsl:apply-templates select="key('bison:ruleNumber', @rule-number)">
+    <xsl:with-param name="point" select="@point"/>
+  </xsl:apply-templates>
+  <xsl:apply-templates select="lookaheads"/>
+</xsl:template>
+
 <xsl:template match="rule">
+  <xsl:param name="point"/>
   <xsl:text>&#10;</xsl:text>
   <xsl:value-of select="lhs"/>
   <xsl:text> -&gt;</xsl:text>
-  <xsl:apply-templates select="rhs/symbol|rhs/point|rhs/empty"/>
-  <xsl:apply-templates select="lookaheads"/>
+  <xsl:if test="$point = 0">
+    <xsl:text> .</xsl:text>
+  </xsl:if>
+  <xsl:for-each select="rhs/symbol|rhs/empty">
+    <xsl:apply-templates select="."/>
+    <xsl:if test="$point = position()">
+      <xsl:text> .</xsl:text>
+    </xsl:if>
+  </xsl:for-each>
 </xsl:template>
 
 <xsl:template match="symbol">
@@ -71,13 +88,7 @@
   <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>
+<xsl:template match="empty"/>
 
 <xsl:template match="lookaheads">
   <xsl:text>[</xsl:text>
Index: data/xslt/xml2text.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2text.xsl,v
retrieving revision 1.4
diff -p -u -r1.4 xml2text.xsl
--- data/xslt/xml2text.xsl      17 Oct 2007 18:12:20 -0000      1.4
+++ data/xslt/xml2text.xsl      21 Oct 2007 05:54:29 -0000
@@ -117,9 +117,14 @@
 <xsl:template match="terminal">
   <xsl:value-of select="@name"/>
   <xsl:call-template name="line-wrap">
-    <xsl:with-param
-      name="first-line-length" select="66 - string-length(@name)"
-    />
+    <xsl:with-param name="first-line-length">
+      <xsl:choose>
+        <xsl:when test="string-length(@name) &gt; 66">0</xsl:when>
+        <xsl:otherwise>
+          <xsl:value-of select="66 - string-length(@name)" />
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:with-param>
     <xsl:with-param name="line-length" select="66" />
     <xsl:with-param name="text">
       <xsl:value-of select="concat(' (', @number, ')')"/>
@@ -515,7 +520,7 @@
   <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="normalize-space($text) = ''" />
     <xsl:when test="string-length($text) &lt;= $first-line-length">
       <xsl:value-of select="concat($text, '&#10;')" />
     </xsl:when>
@@ -523,7 +528,7 @@
       <xsl:variable name="break-pos">
         <xsl:call-template name="ws-search">
           <xsl:with-param name="text" select="$text" />
-          <xsl:with-param name="pos" select="$first-line-length+1" />
+          <xsl:with-param name="start" select="$first-line-length+1" />
         </xsl:call-template>
       </xsl:variable>
       <xsl:value-of select="substring($text, 1, $break-pos - 1)" />
@@ -540,18 +545,16 @@
 
 <xsl:template name="ws-search">
   <xsl:param name="text"/> <!-- required -->
-  <xsl:param name="pos"/> <!-- required -->
+  <xsl:param name="start"/> <!-- required -->
+  <xsl:variable name="search-text" select="substring($text, $start)" />
   <xsl:choose>
-    <xsl:when
-      test="$pos &gt; string-length($text) or substring($text, $pos, 1) = ' '"
-    >
-      <xsl:value-of select="$pos" />
+    <xsl:when test="not(contains($search-text, ' '))">
+      <xsl:value-of select="string-length($text)+1" />
     </xsl:when>
     <xsl:otherwise>
-      <xsl:call-template name="ws-search">
-        <xsl:with-param name="text" select="$text" />
-        <xsl:with-param name="pos" select="$pos+1" />
-      </xsl:call-template>
+      <xsl:value-of
+        select="$start + string-length(substring-before($search-text, ' '))"
+      />
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
Index: src/print_graph.c
===================================================================
RCS file: /sources/bison/bison/src/print_graph.c,v
retrieving revision 1.65
diff -p -u -r1.65 print_graph.c
--- src/print_graph.c   15 Aug 2007 20:21:31 -0000      1.65
+++ src/print_graph.c   21 Oct 2007 05:54:29 -0000
@@ -82,7 +82,8 @@ print_core (struct obstack *oout, state 
        obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
 
       /* Experimental feature: display the lookahead tokens. */
-      if (report_flag & report_lookahead_tokens)
+      if (report_flag & report_lookahead_tokens
+          && item_number_is_rule_number (*sp1))
        {
          /* Find the reduction we are handling.  */
          reductions *reds = s->reductions;




reply via email to

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