|
@@ -1,12 +1,74 @@
|
|
-/ csv parser - e exclusive
|
|
|
|
-getrange: {[str;s;e] s_(e-1)#str};
|
|
|
|
|
|
+/helpers
|
|
|
|
+/ e exclusive
|
|
|
|
+slice: {[l;s;e] s_(e-1)#l};
|
|
|
|
+listize: {1_(,/(";",)'{"(",x,")"}'x)};
|
|
|
|
+
|
|
|
|
+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: 0: "tempST.csv";
|
|
lines: 0: "tempST.csv";
|
|
|
|
|
|
/csv parser
|
|
/csv parser
|
|
-parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;getrange[l].'r}
|
|
|
|
-parsel'lines
|
|
|
|
|
|
+parsel: {[l] comi: &l=",";comi+:1;r: 2':!#comi;r: comi@r;r: (1 2#(0;r[0;0])),r;slice[l].'r};
|
|
|
|
+tempST: parsel'lines;
|
|
|
|
+tname: tempST[0;0];
|
|
|
|
+
|
|
|
|
+/ st compile
|
|
|
|
+/ separate sections
|
|
|
|
+si: (*'&'{(y~)'x}[*'tempST]'sectionkeys),(#tempST-1); / sections line numbers
|
|
|
|
+slices: si@(2':!#si);
|
|
|
|
+(t;c;a):1_'slice[tempST;] .'slices;
|
|
|
|
+
|
|
|
|
+/ postprocess sections
|
|
|
|
+s:*'t;
|
|
|
|
+t:2_'t;
|
|
|
|
+a:*'a;
|
|
|
|
+c:*'c;
|
|
|
|
+
|
|
|
|
+/ TODO: make dynamic
|
|
|
|
+args: `isOff `T ! `i `i;
|
|
|
|
+
|
|
|
|
+fname: tname,".k";
|
|
|
|
+kcode: "/ ",fname,".csv compiled\n\n";
|
|
|
|
+tstr: "";
|
|
|
|
+
|
|
|
|
+/a TODO: make dynamic
|
|
|
|
+avars: ("A",'$((!#a)+1))
|
|
|
|
+a:,[;"\"};\n"]'((,[;":{\""]'avars),'a);
|
|
|
|
+a: ,/a;
|
|
|
|
+avars: 1_,/(";",'avars);
|
|
|
|
+
|
|
|
|
+/c
|
|
|
|
+vars: {x,":args["}'$'!args;
|
|
|
|
+cargs:,[;"];"]'(vars,'($!#vars));
|
|
|
|
+cargs: ,/cargs;
|
|
|
|
+c:"{[args]",cargs,"(",listize[c],")}";
|
|
|
|
+
|
|
|
|
+/s
|
|
|
|
+s:,[;"\""]'("\"",'s);
|
|
|
|
+s:listize[s];
|
|
|
|
+
|
|
|
|
+/at
|
|
|
|
+at: ,/("`",'$:args@!args);
|
|
|
|
+
|
|
|
|
+/ t
|
|
|
|
+t:listize[listize't];
|
|
|
|
+
|
|
|
|
+kcode ,: a;
|
|
|
|
+kcode ,: ("a:(",avars,");\n");
|
|
|
|
+kcode ,: ("c:",c,";\n");
|
|
|
|
+kcode ,: ("s:(",s,");\n");
|
|
|
|
+kcode ,: ("t:(",t,");\n");
|
|
|
|
+kcode ,: ("at:",at,";\n");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/ initialize data
|
|
|
|
+f:<`"tempST.k";
|
|
|
|
+f 0: kcode;
|
|
|
|
|
|
|
|
+/ -======== notes ========-
|
|
/ / how the parser works
|
|
/ / how the parser works
|
|
/ t: lines[0];
|
|
/ t: lines[0];
|
|
/ comi: &t=","; / commas idx
|
|
/ comi: &t=","; / commas idx
|
|
@@ -15,4 +77,4 @@ parsel'lines
|
|
/ r: 2':!#comi; / ranges of comma separated parts
|
|
/ r: 2':!#comi; / ranges of comma separated parts
|
|
/ r: comi@r; / apply ranges to comma idx
|
|
/ r: comi@r; / apply ranges to comma idx
|
|
/ r: (1 2#(0;r[0;0])),r; / add 0-first comma range
|
|
/ r: (1 2#(0;r[0;0])),r; / add 0-first comma range
|
|
-/ getrange[t].'r
|
|
|
|
|
|
+/ slice[t].'r
|