changeset 52:9bb415e0adc9

try to fix error processin odd REUTER|IDN\!'.SPX' external ref
author Henry S. Thompson <ht@markup.co.uk>
date Tue, 16 May 2017 17:28:52 +0100
parents 793496d2d165
children 8000dbed09df
files n2a.xsl notes.txt tokenise.xsl
diffstat 3 files changed, 57 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/n2a.xsl	Tue May 16 17:27:19 2017 +0100
+++ b/n2a.xsl	Tue May 16 17:28:52 2017 +0100
@@ -43,7 +43,7 @@
                                             e:crnf($r))
                                  else if (local-name($b)='v')
                                   then $b/text()
-                                 else e:shouldnt()"/>
+                                 else e:shouldnt('rnf',concat(local-name($b),' ',string($b)))"/>
  </xsl:function>
  
  <xsl:function name="e:fnf" as="xs:string">
@@ -91,7 +91,7 @@
   <xsl:value-of select="if (local-name($c)='a') then xs:integer($c/text())
                           else if (local-name($c)='r')
                             then xs:integer($c/@d)+$h
-                          else e:shouldnt()"/>
+                          else e:shouldnt('delta',local-name($c))"/>
  </xsl:function>
  
  <xsl:template match="e:*|@*" mode="shift">
@@ -106,6 +106,8 @@
  </xsl:template>
  
  <xsl:function name="e:shouldnt">
-  <xsl:message terminate="yes">shouldn't happen</xsl:message>
+  <xsl:param name="where" as="xs:string"/>  
+  <xsl:param name="what" as="xs:string"/>
+  <xsl:message terminate="yes">shouldn't happen in <xsl:value-of select="$where"/>: <xsl:value-of select="$what"/></xsl:message>
  </xsl:function>
 </xsl:stylesheet>
--- a/notes.txt	Tue May 16 17:27:19 2017 +0100
+++ b/notes.txt	Tue May 16 17:28:52 2017 +0100
@@ -224,3 +224,14 @@
 ------------
 @@ string identify, to say nothing of actual value, is lost -- fix?
 @@ row/column/both spans
+------
+enron/kenneth_lay__19506 contains this formula:
+
+  <f>[1]!'.SPX'</f>
+
+which crashes tokenise/rnf
+
+Changes intended to fix this fixed a bug (?) which wasn't properly
+merging e.g. +3 -- no examples of larger numbers available to check
+with...
+
--- a/tokenise.xsl	Tue May 16 17:27:19 2017 +0100
+++ b/tokenise.xsl	Tue May 16 17:28:52 2017 +0100
@@ -1,7 +1,6 @@
 <?xml version='1.0'?>
 <!DOCTYPE xsl:stylesheet SYSTEM "../../../lib/xml/xsl.dtd" >
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s e xf" xmlns="http://markup.co.uk/excel" xmlns:xf="http://www.w3.org/2005/xpath-functions">
- <xsl:param name="sheet-number"/>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0" xmlns:s="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:e="http://markup.co.uk/excel" exclude-result-prefixes="xs s e xf" xmlns="http://markup.co.uk/excel" xmlns:xf="http://www.w3.org/2005/xpath-functions"> <xsl:param name="sheet-number"/>
  <xsl:param name="xlDir"/>
 
   <xsl:variable name="pat1">("[^"]*")|(\{[^}]+})|(,)|([^=\-+*/();:,.$&lt;>^!]+(?:\.[^=\-+*/();:,.$&lt;>^!]+)*\()|([)])|(^=|\()|((?:(?:'[^']+')|(?:\[[0-9]+\][^!]*)|(?:[a-zA-Z_][a-zA-Z0-9._]*)!))|(\$?[A-Z]+\$?[0-9]+)|([a-zA-Z_\\][a-zA-Z0-9._]*)|(.)</xsl:variable>
@@ -50,7 +49,8 @@
   <xsl:param name="col" required="yes" as="xs:integer"/>
   <xsl:param name="soFar" as="element(*)*"/>
   <xsl:variable name="last" select="$soFar[count($soFar)]"></xsl:variable>
-  <xsl:if test="false()"><xsl:message>tok1: <xsl:value-of select="$n"/>|<xsl:value-of select="$i"/>|<xsl:value-of select="if ($last instance of element()) then name($last) else 'bogus'"/>|<xsl:value-of select="string($last)"/></xsl:message></xsl:if>
+  <xsl:if test="$row=5 and $col=1"><xsl:message>tok1: <xsl:value-of select="$n"/>|<xsl:value-of select="$i"/>|<xsl:value-of select="if ($i=1) then string-join($tokens,'\') else $tokens[$i]"/>|<xsl:value-of select="if ($last instance of element()) then name($last) else 'bogus'"/>|<xsl:value-of select="string($last)"/></xsl:message></xsl:if>
+  <!-- Tail-recursion incrementing index $i into $tokens -->
   <xsl:sequence select="
     if ($i gt $n)
           then $soFar
@@ -67,6 +67,7 @@
   <xsl:param name="local" required="yes" as="xs:boolean"/>
   <xsl:param name="row" required="yes" as="xs:integer"/>
   <xsl:param name="col" required="yes" as="xs:integer"/>
+  <!-- Consume one or more tokens, returns new index and an element -->
   <xsl:if test="false()"><xsl:message>exp: <xsl:value-of select="$tokens[$i]/@nr"/>:<xsl:value-of select="$tokens[$i]"/>,<xsl:value-of select="$tokens[$i+1]"/></xsl:message></xsl:if>
   <xsl:sequence select="
     let $t := $tokens[$i],
@@ -82,9 +83,13 @@
               if ($xref=('[0]',$sheet-name))
               then (: it's a local reference after all :)
                e:expand($tokens,$i+1,true(),$row,$col)
-              else let $ext := e:expand($tokens,$i+1,false(),$row,$col) return
+              else let $ext := if ($tokens[$i+1]=&quot;'&quot;)
+                           then (: odd case, see notes wrt enron/kenneth_lay :)
+                            e:oddx($tokens,$i+2,$tokens[$i+1])                  
+                           else
+                            e:expand($tokens,$i+1,false(),$row,$col) return
                     [$ext?1,e:external($xref,$ext?2)]
-     else if ($t/@nr=10) then e:amalgamate($tokens,$i+1,string($t))
+     else if ($t/@nr=10) then e:misc($tokens,$i+1,string($t))
      else if ($r[@nr=10 and .=':'])
        then (: a range, takes priority :)
           [$i+3,e:range($tokens,$i,$local,$row,$col)]
@@ -99,24 +104,46 @@
      else (: shouldn't ever get here :) ()"/>
  </xsl:function>
  
+ <xsl:function name="e:misc">
+  <xsl:param name="tokens" as="element(xf:group)*"/>
+  <xsl:param name="i" as="xs:integer"/>
+  <xsl:param name="soFar" as="xs:string"/>
+  <!-- Amalgamate bits of type 10 and wrap in <x> -->
+  <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,'')"/>
+  <xsl:variable name="x"><x><xsl:value-of select="$content?2"/></x></xsl:variable>
+  <xsl:sequence select="[$content?1,$x/*]"/>
+ </xsl:function>
+
+ <xsl:function name="e:oddx">
+  <xsl:param name="tokens" as="element(xf:group)*"/>
+  <xsl:param name="i" as="xs:integer"/>
+  <xsl:param name="soFar" as="xs:string"/><!-- Will always be a lonely ' -->
+  <!-- Amalgamate bits of type 9 and 10 as <v> for wrapping in <e> -->
+  <xsl:variable name="content" select="e:amalgamate($tokens,$i,$soFar,10,$soFar)"/>
+  <xsl:variable name="x"><v><xsl:value-of select="
+    if ($tokens[$content?1]=$soFar)
+    then $content?2
+    else e:shouldnt('oddx',$tokens[$content?1])"/></v></xsl:variable>
+  <xsl:sequence select="[$content?1+1,$x/*]"/>
+ </xsl:function>
+ 
  <xsl:function name="e:amalgamate" as="array(*)">
   <xsl:param name="tokens" as="element(xf:group)*"/>
   <xsl:param name="i" as="xs:integer"/>
   <xsl:param name="soFar" as="xs:string"/>
+  <xsl:param name="nrs" as="xs:integer*"/>
+  <xsl:param name="stop" as="xs:string"/>
   <xsl:choose>
-   <xsl:when test="$tokens[i]/@nr=10">
+   <xsl:when test="$tokens[$i]/@nr=$nrs and $tokens[$i]!=$stop">
     <xsl:sequence select="e:amalgamate($tokens,$i+1,concat($soFar,
-                                                       string($tokens[$i])))"/>
+                                                       string($tokens[$i])),
+                                       $nrs,$stop)"/>
    </xsl:when>
    <xsl:otherwise>
-    <xsl:variable name="res">
-     <x><xsl:value-of select="$soFar"/></x>
-    </xsl:variable>
-    <xsl:if test="false()"><xsl:message>amal: <xsl:value-of select="$res/."/></xsl:message></xsl:if>
-    <xsl:sequence select="[$i,$res/*]"/>
+    <xsl:if test="false()"><xsl:message>amal <xsl:value-of select="$nrs"/>: <xsl:value-of select="$soFar"/></xsl:message></xsl:if>
+    <xsl:sequence select="[$i,$soFar]"/>
    </xsl:otherwise>
-  </xsl:choose>
-  
+  </xsl:choose>  
  </xsl:function>
  
  <xsl:function name="e:exp1" as="array(*)">