SS.k 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /helpers
  2. / e exclusive
  3. slice: {[l;s;e] s_(e-1)#l};
  4. listize: {1_(,/(";",)'{"(",x,")"}'x)};
  5. split: {[l;di] idx: (-1,&(di~'l)),(#l); {slice[x;y[0]+1;y[1]+1]}[l]'(idx@(2':!#idx))};
  6. s2n: {[s] `i$s;}; // string to number
  7. parseidx: {core: slice[x;1;#x]; split[core;";"]};
  8. :parseidx["[1;2]"];
  9. /:split["1;2;3";";"];
  10. tstkey: "States/Events"; / key indicating start of transition section
  11. cstkey: "Events"; / key indicating start of events condition section
  12. astkey: "Actions"; / key indicating start of actions section
  13. sectionkeys: (tstkey;cstkey;astkey);
  14. lines: 0: "SS.csv";
  15. /csv parser
  16. parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
  17. csv: parsel'lines;
  18. kw:: "self";
  19. rep:: "t";
  20. deps:: (#csv;#csv[0])#0;
  21. 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)};
  22. rd: {[r] deps[0;0]::1; r[0]}; // register dep
  23. dd: {[r] $[r[1;0]~"[";rd[r];r[0]]}; // detect dep
  24. / :{[l;kw;rep] r: fnr[l;kw;rep]; $[(@r)=`C;r;dd[r]]}[;kw;rep]''csv;
  25. / :deps;
  26. / initialize data
  27. / f:<`"compiled_ss.k";
  28. / f 0: kcode;