Sfoglia il codice sorgente

pattern finder broken

Will 4 mesi fa
parent
commit
04794f3b7d
4 ha cambiato i file con 27 aggiunte e 34 eliminazioni
  1. 3 3
      SS.csv
  2. 16 27
      SS.k
  3. 7 4
      excelpm.k
  4. 1 0
      utils.k

+ 3 - 3
SS.csv

@@ -1,3 +1,3 @@
-price,coin1,+/self[;1],"""balance"""
-,coin2,self[2;0]-self[0;0],"""Remaining after purchase"""
-,coin3,self[2;2]>=0,"""Anything to return?"""
+price, coin1, +/B:B
+stock, coin2, C1:C1-A1:A1
+     , coin3, A2:A2-1

+ 16 - 27
SS.k

@@ -1,12 +1,16 @@
-// import as re.*
-\d re
-\l ngnk-libs/regex/re.k
+\d u
+\l utils.k
+
+\d pat
+\l excelpm.k
+
+\l ngnk-libs/csv/csv.k
 
 \d .
 
 /helpers
 / e exclusive
-slice: {[l;s;e] s_(e-1)#l};
+slice: {[l;s;e] s_(e)#l};
 listize: {1_(,/(";",)'{"(",x,")"}'x)};
 split: {[l;di] idx: (-1,&(di~'l)),(#l); {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))};
 s2n: {[s] `i$s;}; // string to number
@@ -20,28 +24,13 @@ cstkey: "Events"; / key indicating start of events condition section
 astkey: "Actions"; / key indicating start of actions section
 sectionkeys: (tstkey;cstkey;astkey);
 
-lines: 0: "SS.csv";
-
-/csv parser
-parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
-csv: parsel'lines;
-
-kw:: "self";
-rep:: "t";
-
-deps:: (#csv;#csv[0])#0;
+lines: {x,"\n",y}/(0: "SS.csv");
+table: csv.csv[lines];
 
-fnr:{[l;k;rp] e:(#l)-(#k); r:!e; idx: &({y~x}[;k]'({slice[y;x;x+(#z)+1]}[;l;k]'r)); l{[last;x;y;z;r]left:x#last; right:(x+(#z))_last; (left,r,right;right)}[;;l;k;rp]/(|idx)};
-rd: {[r] deps[0;0]::1; r[0]}; // register dep
-dd: {[r] $[r[1;0]~"[";rd[r];r[0]]}; // detect dep
-/ :{[l;kw;rep] r: fnr[l;kw;rep]; $[(@r)=`C;r;dd[r]]}[;kw;rep]''csv;
-/ :deps;
+/ excel patterns
+pats: *''|''(pat.run''table);
 
-/ initialize data
-/ f:<`"compiled_ss.k";
-/ f 0: kcode;
-para:`0:
-testcases:{para"search ",z;`0:$x z;para"match ",z;`0:$y z}
-test:{para"---";para"regex: ", x;testcases[re.match[re.scmp@x];re.match[re.cmp@x]]'y;};
-cases:("abc";"xxxabbc";"abbbcyyy";"xxxabbbbcyyy");
-test["ab+c";cases]
+:pats {
+ u.ppr (x;y);
+ u.ppr $[x[0]>4;slice[y;x[1];x[2]];'$'];
+}''table;

+ 7 - 4
excelpm.k

@@ -22,12 +22,13 @@ states:: (s0;s1;s2;s3;s4;s5;s7);
 i: 1;
 
 run: {[str]
- str,:"$";
-
  // go over each char and run cur statoe
  // cur state; start of pattern; length of pattern    <- args
  idx::0;
- o:(0;-1;-1) {[a;c] // TODO, add support for multiple active states
+ o:(0;(0;0);1) {[a;c]
+  activeidx: (*|a);
+  indices: a[activeidx];
+
   s: a[0];
   r:{
    :$[x[0][y];x[1];0]
@@ -36,7 +37,9 @@ run: {[str]
   r: *($[(+/r)>0;r^0;0]);
 
   idx +: 1;
-  :(r;$[(s=0)&(r>0);idx-1;a[1]];$[r=5;idx;a[2]])
+  a0: $[s>4;s;r];
+
+  :(a0;($[(s=0)&(r>0);idx-1;indices[0]];$[r=5;idx;indices[1]]);activeidx)
  }\str;
 
  :o

+ 1 - 0
utils.k

@@ -0,0 +1 @@
+ppr: `0:`k@;