\d u \l utils.k \d csv \l ngnk-libs/csv/csv.k \d . \l excelpm.k \d . /helpers / e exclusive 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 parseidx: {core: slice[x;1;#x]; split[core;";"]}; gi: {[r;c;rb;cb] i: r#(,!c) i: ((!r)+rb) {x,'y}'(i+cb); :i }; // decode excel formula // fill these ========== mc: {[c;i] i: gi[(#table);i+1;0;c]; :i }; mr: {[r;i] i: gi[i+1;(#table[0]);r;0]; :i }; // ===================== drr: {[s;e] r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]]; :r }; dre: {[s;e] :gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]] }; dr: {[s;e] // decode range ln: (s[0]<0) | (s[1]<0); rn: (e[0]<0) | (e[1]<0); :$[ln|rn;drr[s;e];dre[s;e]] }; dbit: {[b] ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index ri: (`i$(b@&(pat.test0t9'b)))-49; // row index ci: $[(#ci)>0;*ci;-1]; ri: $[(#ri)>0;*ri;-1]; :(ri;ci) }; lr: {[f] ci: *&(":"~'f); l: slice[f;0;ci]; r: slice[f;ci+1;#f]; lb: dbit[l]; rb: dbit[r]; :(lb;rb); }; de:{[idx;cell] ci: cell[0]; cell: cell[1]; idx: (*idx); f: slice[cell;idx[0];idx[1]]; l: slice[cell;0;idx[0]]; r: slice[cell;idx[1];#cell]; (fl;fr): lr[f]; deps[ci[0];ci[1]]:: (1;1); u.ppr "de: ", f; u.ppr (fl;fr); u.ppr'deps; }; /:parseidx["[1;2]"]; /:split["1;2;3";";"]; tstkey: "States/Events"; / key indicating start of transition section cstkey: "Events"; / key indicating start of events condition section astkey: "Actions"; / key indicating start of actions section sectionkeys: (tstkey;cstkey;astkey); lines: {x,"\n",y}/(0: "SS.csv"); table:: csv.csv[lines]; deps:: (#table;#table[0])#0; / excel patterns pats: pat.run''table; u.ppr'table; / u.ppr'pats; // start with last to maintain prior index accuracy lasts:{:((#x[0])-1)_x[0]}''pats; f: pats { :$[x[2]=5;y;0] }''lasts; ti: gi[#table;#table[0];0;0]; table :ti {(,x),,y}''table; / table { / :$[y~0;0;de[y;x]] / }''f