|
@@ -1,54 +1,68 @@
|
|
|
|
+/ utils (ppr -> pretty print)
|
|
\d u
|
|
\d u
|
|
\l utils.k
|
|
\l utils.k
|
|
|
|
|
|
|
|
+/ csv parser
|
|
\d csv
|
|
\d csv
|
|
\l ngnk-libs/csv/csv.k
|
|
\l ngnk-libs/csv/csv.k
|
|
\d .
|
|
\d .
|
|
|
|
|
|
|
|
+/ excel pattern finder
|
|
\l excelpm.k
|
|
\l excelpm.k
|
|
\d .
|
|
\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]
|
|
|
|
|
|
+/ ====================================================================================
|
|
|
|
+/ helpers ============================================================================
|
|
|
|
+/ ====================================================================================
|
|
|
|
+slice: {[l;s;e] s_(e)#l}; / slice a list (l) from start (s) til end (e)
|
|
|
|
+listize: {1_(,/(";",)'{"(",x,")"}'x)}; / turn a list(l) of strings into a string representation of a k list
|
|
|
|
+split: {[l;di] idx: (-1,&(di~'l)),(#l); {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))}; / split a list(l) by delimiter (di)
|
|
|
|
+s2n: {[s] `i$s;}; / string to number
|
|
|
|
+parseidx: {core: slice[x;1;#x]; split[core;";"]}; / parse a string containing k index
|
|
|
|
+str: `k@;
|
|
|
|
+gi: {[r;c;rb;cb] / generate indices of a rowxcol table starting from row=rb and col=cb
|
|
i: r#(,!c)
|
|
i: r#(,!c)
|
|
i: ((!r)+rb) {x,'y}'(i+cb);
|
|
i: ((!r)+rb) {x,'y}'(i+cb);
|
|
:i
|
|
:i
|
|
};
|
|
};
|
|
|
|
+hasloops: {deps:&'x; d:deps; #,/((#deps)(,/'deps@)/d)>0}; / determine if dependency table contains loops
|
|
|
|
+order: { / come up with a order of calculations for a dependency graph
|
|
|
|
+ deps: {$[+/x>0;&x;()]}'x;
|
|
|
|
+ d: ?,/deps;
|
|
|
|
+ all: !(#deps);
|
|
|
|
+ :d,(all^d)
|
|
|
|
+};
|
|
|
|
|
|
-// decode excel formula
|
|
|
|
-mc: {[c;i]
|
|
|
|
|
|
+/ ====================================================================================
|
|
|
|
+/ excel formula handler ==============================================================
|
|
|
|
+/ ====================================================================================
|
|
|
|
+mc: {[c;i] / generate indices for column-based indexing
|
|
i: gi[(#table);i+1;0;c];
|
|
i: gi[(#table);i+1;0;c];
|
|
:i
|
|
:i
|
|
};
|
|
};
|
|
|
|
|
|
-mr: {[r;i]
|
|
|
|
|
|
+mr: {[r;i] / generate indices for row-based indexing
|
|
i: gi[i+1;(#table[0]);r;0];
|
|
i: gi[i+1;(#table[0]);r;0];
|
|
:i
|
|
:i
|
|
};
|
|
};
|
|
|
|
|
|
-drr: {[s;e]
|
|
|
|
|
|
+drr: {[s;e] / decode range of indices from start(s) to end(e) with one indicator missing (full rows or full column selection)
|
|
r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]];
|
|
r: $[s[0]<0;mc[s[1];(e[1]-s[1])];mr[s[0];(e[0]-s[0])]];
|
|
:r
|
|
:r
|
|
};
|
|
};
|
|
|
|
|
|
-dre: {[s;e]
|
|
|
|
|
|
+dre: {[s;e] / decode range of indices from start(s) to end(e) with both indices present
|
|
:gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]]
|
|
:gi[(e[0]-s[0])+1;(e[1]-s[1])+1;s[0];s[1]]
|
|
};
|
|
};
|
|
|
|
|
|
-dr: {[s;e] // decode range
|
|
|
|
|
|
+dr: {[s;e] / decode range from start(s) to end(e)
|
|
ln: (s[0]<0) | (s[1]<0);
|
|
ln: (s[0]<0) | (s[1]<0);
|
|
rn: (e[0]<0) | (e[1]<0);
|
|
rn: (e[0]<0) | (e[1]<0);
|
|
|
|
|
|
:$[ln|rn;drr[s;e];dre[s;e]]
|
|
:$[ln|rn;drr[s;e];dre[s;e]]
|
|
};
|
|
};
|
|
|
|
|
|
-dbit: {[b]
|
|
|
|
|
|
+dbit: {[b] / decode bit - refering to A3 or C5 part of A3:C5
|
|
ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index
|
|
ci: (`i$(b@&(pat.testAtZ'b)))-65; // col index
|
|
ri: (`i$(b@&(pat.test0t9'b)))-49; // row index
|
|
ri: (`i$(b@&(pat.test0t9'b)))-49; // row index
|
|
|
|
|
|
@@ -58,7 +72,7 @@ dbit: {[b]
|
|
:(ri;ci)
|
|
:(ri;ci)
|
|
};
|
|
};
|
|
|
|
|
|
-lr: {[f]
|
|
|
|
|
|
+lr: {[f] / turn A3:C5 into left and right bits
|
|
ci: *&(":"~'f);
|
|
ci: *&(":"~'f);
|
|
l: slice[f;0;ci];
|
|
l: slice[f;0;ci];
|
|
r: slice[f;ci+1;#f];
|
|
r: slice[f;ci+1;#f];
|
|
@@ -69,7 +83,7 @@ lr: {[f]
|
|
:(lb;rb);
|
|
:(lb;rb);
|
|
};
|
|
};
|
|
|
|
|
|
-de:{[idx;cell]
|
|
|
|
|
|
+de:{[idx;cell] / decode excel string in a cell
|
|
ci: cell[0];
|
|
ci: cell[0];
|
|
cell: cell[1];
|
|
cell: cell[1];
|
|
idx: (*idx);
|
|
idx: (*idx);
|
|
@@ -77,38 +91,42 @@ de:{[idx;cell]
|
|
f: slice[cell;idx[0];idx[1]];
|
|
f: slice[cell;idx[0];idx[1]];
|
|
l: slice[cell;0;idx[0]];
|
|
l: slice[cell;0;idx[0]];
|
|
r: slice[cell;idx[1];#cell];
|
|
r: slice[cell;idx[1];#cell];
|
|
- u.ppr (l;r);
|
|
|
|
- u.ppr table[ci[0];ci[1]];
|
|
|
|
|
|
|
|
(fl;fr): lr[f];
|
|
(fl;fr): lr[f];
|
|
- r: dr[fl;fr];
|
|
|
|
|
|
+ range: dr[fl;fr];
|
|
|
|
|
|
i: (ci[0]*3) + ci[1];
|
|
i: (ci[0]*3) + ci[1];
|
|
{
|
|
{
|
|
i:(*y);
|
|
i:(*y);
|
|
i: (i[0]*3)+i[1];
|
|
i: (i[0]*3)+i[1];
|
|
deps[x;i]: 1;
|
|
deps[x;i]: 1;
|
|
- }[(ci[0]*3)+ci[1];]'r;
|
|
|
|
|
|
+ }[(ci[0]*3)+ci[1];]'range;
|
|
|
|
+
|
|
|
|
+ / compiled list
|
|
|
|
+ cl: {i:(*x); "self[",(`k@x[0;0]),";",(`k@x[0;1]),"]"}'range;
|
|
|
|
+ cl: l,"(",({x,";",y}/cl),")",r;
|
|
|
|
+ table[ci[0];ci[1];1]:: cl;
|
|
};
|
|
};
|
|
|
|
|
|
-/:parseidx["[1;2]"];
|
|
|
|
-/:split["1;2;3";";"];
|
|
|
|
|
|
+/ ====================================================================================
|
|
|
|
+/ Compiler ===========================================================================
|
|
|
|
+/ ====================================================================================
|
|
|
|
|
|
tstkey: "States/Events"; / key indicating start of transition section
|
|
tstkey: "States/Events"; / key indicating start of transition section
|
|
cstkey: "Events"; / key indicating start of events condition section
|
|
cstkey: "Events"; / key indicating start of events condition section
|
|
astkey: "Actions"; / key indicating start of actions section
|
|
astkey: "Actions"; / key indicating start of actions section
|
|
sectionkeys: (tstkey;cstkey;astkey);
|
|
sectionkeys: (tstkey;cstkey;astkey);
|
|
|
|
|
|
-lines: {x,"\n",y}/(0: "SS.csv");
|
|
|
|
|
|
+fname: "SS.csv";
|
|
|
|
+tname: "SS";
|
|
|
|
+lines: {x,"\n",y}/(0: fname);
|
|
table:: csv.csv[lines];
|
|
table:: csv.csv[lines];
|
|
d: (#table)*(#table[0]);
|
|
d: (#table)*(#table[0]);
|
|
deps:: (d;d)#0;
|
|
deps:: (d;d)#0;
|
|
|
|
|
|
/ excel patterns
|
|
/ excel patterns
|
|
:pats: pat.run''table;
|
|
:pats: pat.run''table;
|
|
-
|
|
|
|
u.ppr'table;
|
|
u.ppr'table;
|
|
-/ u.ppr'pats;
|
|
|
|
|
|
|
|
// start with last to maintain prior index accuracy
|
|
// start with last to maintain prior index accuracy
|
|
lasts:{:((#x[0])-1)_x[0]}''pats;
|
|
lasts:{:((#x[0])-1)_x[0]}''pats;
|
|
@@ -119,6 +137,7 @@ f: pats {
|
|
}''lasts;
|
|
}''lasts;
|
|
|
|
|
|
ti: gi[#table;#table[0];0;0];
|
|
ti: gi[#table;#table[0];0;0];
|
|
|
|
+ptable:: table;
|
|
table::ti {(,x),,y}''table;
|
|
table::ti {(,x),,y}''table;
|
|
|
|
|
|
table {
|
|
table {
|
|
@@ -129,4 +148,25 @@ table {
|
|
:$[y~0;0;de[y;x]]
|
|
:$[y~0;0;de[y;x]]
|
|
}''firsts;
|
|
}''firsts;
|
|
|
|
|
|
-:deps
|
|
|
|
|
|
+ord:order[deps];
|
|
|
|
+
|
|
|
|
+/ ====================================================================================
|
|
|
|
+/ Generator ==========================================================================
|
|
|
|
+/ ====================================================================================
|
|
|
|
+compstr:: "/ compiled ",fname,"\n\n";
|
|
|
|
+al: {[l;indt] tab: "" {[x;y] x,"\t"}/(indt#0); compstr:: compstr,tab,l,"\n"}; // add line with indentation
|
|
|
|
+
|
|
|
|
+al[(tname,":{[]");0];
|
|
|
|
+al["self:(", (str (#table)),";", (str (#table[0])), ")#0;\n";1];
|
|
|
|
+
|
|
|
|
+{
|
|
|
|
+ d: #table;
|
|
|
|
+ i0: `i$(_(x%d));
|
|
|
|
+ i1: x-(i0*d);
|
|
|
|
+ al["self[",(str(i0)),";",(str(i1)),"]: ", table[i0;i1;1], ";";1];
|
|
|
|
+}'ord;
|
|
|
|
+
|
|
|
|
+al[":self";1];
|
|
|
|
+al[("};");0];
|
|
|
|
+
|
|
|
|
+`0: compstr;
|