@fraczak/k 1.3.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/INTRO.md CHANGED
@@ -129,7 +129,7 @@ names are integers starting from zero. E.g., `{.toto "0", .titi "1",
129
129
  zero? = [(),0] EQ 0;
130
130
  factorial = <
131
131
  zero? 1,
132
- [(dec factorial), ()] TIMES
132
+ [dec factorial, ()] TIMES
133
133
  >;
134
134
  { () x, factorial "x!" }
135
135
 
@@ -137,10 +137,24 @@ names are integers starting from zero. E.g., `{.toto "0", .titi "1",
137
137
 
138
138
  _Codes_ (prefixed by `$`) can be defined by taged union and product. E.g.:
139
139
 
140
- $nat = <nat 1, {} 0>; -- e.g., {{{{} 0} 1} 1}
141
- $pair = {nat x, nat y}; -- e.g., {{{} 0} x, {{{{} 0} 1} 1} y}
140
+ $nat = <nat 1, {} 0>;
141
+ $pair = {nat x, nat y};
142
142
 
143
- suc = $nat {() 1} $nat;
144
- add = $pair <{.x.1 x, .y suc y} add, .y> $nat;
143
+ suc = {$nat 1};
144
+ add = $pair <{.x.1 x, .y suc y} add, .y>;
145
+
146
+ ### Basic extension codes
147
+
148
+ Since _basic extension_ introduces integers, booleans, and strings, there are three
149
+ predefined types: `int`, `bool`, and `string`. A vector product code can also be defined
150
+ by `[ codeExp ]`. All members of the vector are the same code. E.g.,
151
+
152
+ $intVector = [ int ];
153
+ $boolVector = [ bool ];
154
+ $tree = [ tree ];
155
+
156
+ emptyList? = $intVector $[ string ]; -- as only an empty vector can be a vector
157
+ -- of integers and a vector of strings
158
+
145
159
 
146
160
 
package/README.md CHANGED
@@ -4,8 +4,9 @@
4
4
 
5
5
  From javascript:
6
6
 
7
- var k = require("@fraczak/k"),
8
- fn = k.compile("<.name,.nom,'?'>");
7
+ import k from "@fraczak/k";
8
+
9
+ const fn = k.compile("<.name,.nom,'?'>");
9
10
  console.log([{name:"x"},{nom:"y"},{}].map(fn));
10
11
  // returns: [ "x", "y", "?" ]
11
12
 
package/codes.mjs ADDED
@@ -0,0 +1,104 @@
1
+ function are_different(classes, representatives, name1, name2, codes) {
2
+ if (name1 === name2) return false;
3
+ const code1 = codes[name1];
4
+ const code2 = codes[name2];
5
+ if (code1.code !== code2.code) return true;
6
+ switch (code1.code) {
7
+ case "union":
8
+ case "product":
9
+ const [fields1, fields2] = [code1, code2].map((code) => {
10
+ const arg = code[code.code];
11
+ return Object.keys(arg).reduce((fields, label) => {
12
+ const ref = representatives[arg[label]];
13
+ fields[label] = ref != null ? ref : arg[label];
14
+ return fields;
15
+ }, {});
16
+ });
17
+ if (Object.keys(fields1).length !== Object.keys(fields2).length)
18
+ return true;
19
+
20
+ for (const field in fields1) {
21
+ if (fields2[field] !== fields1[field]) return true;
22
+ }
23
+ break;
24
+ case "vector":
25
+ const [arg1, arg2] = [code1, code2].map(
26
+ ({ vector }) => representatives[vector] || vector
27
+ );
28
+ if (arg1 !== arg2) return true;
29
+ }
30
+ return false;
31
+ }
32
+
33
+ function minimize(codes) {
34
+ const names = Object.keys(codes);
35
+ const classes = {};
36
+ classes["{}"] = names;
37
+ const representatives = names.reduce((representatives, name) => {
38
+ representatives[name] = "{}";
39
+ return representatives;
40
+ }, {});
41
+ let changed = true;
42
+ while (changed) {
43
+ changed = false;
44
+ for (const name1 in classes) {
45
+ const [eq_names, dif_names] = classes[name1].reduce(
46
+ ([eq_names, dif_names], name2) => {
47
+ if (are_different(classes, representatives, name1, name2, codes)) {
48
+ dif_names.push(name2);
49
+ } else {
50
+ eq_names.push(name2);
51
+ }
52
+ return [eq_names, dif_names];
53
+ },
54
+ [[], []]
55
+ );
56
+ classes[name1] = eq_names;
57
+
58
+ if (dif_names.length > 0) {
59
+ const new_rep = dif_names[0];
60
+ changed = true;
61
+ classes[new_rep] = dif_names;
62
+ dif_names.forEach((name) => (representatives[name] = new_rep));
63
+ }
64
+ }
65
+ }
66
+ return { classes, representatives };
67
+ }
68
+
69
+ function normalize(label_ref_map, representatives) {
70
+ return Object.keys(label_ref_map).reduce((result, label) => {
71
+ const name = label_ref_map[label];
72
+ result[label] = representatives[name] || name;
73
+ return result;
74
+ }, {});
75
+ }
76
+
77
+ function normalizeAll(codes, representatives) {
78
+ return Object.keys(codes).reduce(function (normalized, name) {
79
+ if (name === representatives[name]) {
80
+ const code = codes[name];
81
+
82
+ switch (code.code) {
83
+ case "union":
84
+ case "product":
85
+ normalized[name] = { code: code.code };
86
+ normalized[name][code.code] = normalize(
87
+ code[code.code],
88
+ representatives
89
+ );
90
+ break;
91
+ case "vector":
92
+ normalized[name] = {
93
+ code: "vector",
94
+ vector: representatives[code.vector] || code.vector,
95
+ };
96
+ }
97
+ }
98
+
99
+ return normalized;
100
+ }, {});
101
+ }
102
+
103
+ export default { minimize, normalize, normalizeAll };
104
+ export { minimize, normalize, normalizeAll };
package/index.mjs ADDED
@@ -0,0 +1,35 @@
1
+ import { parse } from "./parser.mjs";
2
+
3
+ import run from "./run.mjs";
4
+
5
+ import t from "./codes.mjs";
6
+
7
+ function finalize(codes) {
8
+ const representatives = t.minimize(codes).representatives;
9
+ return {
10
+ codes: t.normalizeAll(codes, representatives),
11
+ representatives,
12
+ };
13
+ }
14
+
15
+ function compile(script) {
16
+ const { defs, exp } = parse(script);
17
+ const { codes, representatives } = finalize(defs.codes);
18
+ run.defs = {
19
+ codes,
20
+ representatives,
21
+ rels: defs.rels,
22
+ };
23
+ return run.bind(null, exp);
24
+ }
25
+
26
+ compile.doc = "Transforms k-script (string) into a function";
27
+
28
+ function runScriptOnData(script, data) {
29
+ return compile(script)(data);
30
+ }
31
+ runScriptOnData.doc = "Run 'script' (string) on 'data': (script,data) -> data";
32
+
33
+ export default { compile, run: runScriptOnData, parse };
34
+
35
+ export { compile, runScriptOnData as run, parse };
package/k.mjs ADDED
@@ -0,0 +1,92 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import k from "./index.mjs";
5
+
6
+ const splice = [].splice;
7
+
8
+ const prog = process.argv[1];
9
+
10
+ let kScript, jsonStream, oneJson;
11
+
12
+ ({ kScript, jsonStream, oneJson } = (function (oneJson, args) {
13
+ let e;
14
+ try {
15
+ kScript = (function (arg) {
16
+ if (arg == null) {
17
+ throw new Error();
18
+ }
19
+ if (arg === "-k") {
20
+ return fs.readFileSync(args.shift()).toString("utf8");
21
+ } else {
22
+ return arg;
23
+ }
24
+ })(args.shift());
25
+ kScript = k.compile(kScript);
26
+ jsonStream = (function (arg) {
27
+ if (arg === "-1") {
28
+ oneJson = true;
29
+ arg = args.shift();
30
+ }
31
+ if (arg == null) {
32
+ return process.stdin;
33
+ }
34
+ return fs.createReadStream(arg);
35
+ })(args.shift());
36
+ return { kScript, jsonStream, oneJson };
37
+ } catch (error) {
38
+ e = error;
39
+ console.error(e);
40
+ console.error(`Usage: ${prog} ( k-expr | -k k-file ) [ -1 ] [ json-file ]`);
41
+ console.error(` E.g., echo '{\"a\": 12}' | ${prog} '[(),()]'`);
42
+ return process.exit(-1);
43
+ }
44
+ })(false, process.argv.slice(2)));
45
+
46
+ if (oneJson) {
47
+ (function (buffer) {
48
+ jsonStream.on("data", function (data) {
49
+ return buffer.push(data);
50
+ });
51
+ return jsonStream.on("end", function () {
52
+ var e;
53
+ try {
54
+ return console.log(
55
+ JSON.stringify(kScript(JSON.parse(buffer.join(""))))
56
+ );
57
+ } catch (error) {
58
+ e = error;
59
+ return console.error(e);
60
+ }
61
+ });
62
+ })([]);
63
+ } else {
64
+ (function (buffer, line) {
65
+ return jsonStream.on("data", function (data) {
66
+ var e, first, i, json, last, len, ref, rest, results, todo;
67
+ [first, ...rest] = data.toString("utf8").split("\n");
68
+ buffer.push(first);
69
+ if (rest.length > 0) {
70
+ todo = buffer.join("");
71
+ (ref = rest), ([...rest] = ref), ([last] = splice.call(rest, -1));
72
+ buffer = [last];
73
+ todo = [todo, ...rest];
74
+ results = [];
75
+ for (i = 0, len = todo.length; i < len; i++) {
76
+ json = todo[i];
77
+ if (!json.match(/^[ \n\t]*(?:#.*)?$/)) {
78
+ try {
79
+ console.log(JSON.stringify(kScript(JSON.parse(json))));
80
+ } catch (error) {
81
+ e = error;
82
+ console.error(`Problem [line ${line}]: '${json}'`);
83
+ console.error(e);
84
+ }
85
+ }
86
+ results.push((line = line + 1));
87
+ }
88
+ return results;
89
+ }
90
+ });
91
+ })([], 0);
92
+ }
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "1.3.3",
3
+ "version": "2.0.0",
4
4
  "description": "k-language for JSON-like data transformation",
5
- "main": "index.js",
5
+ "main": "index.mjs",
6
6
  "scripts": {
7
- "prepare": "coffee -c symbol-table.coffee; jiwson parser.jison",
8
- "prepublishOnly": "coffee -c *.coffee; echo '#!/usr/bin/env node' | cat - k.js > k.sh; echo '#!/usr/bin/env node' | cat - repl.js > repl.sh;",
9
- "all": "coffee -c *.coffee; npm run prepare; npm run prepublishOnly",
10
- "test": "coffee -c symbol-table.coffee; jiwson parser.jison; coffee test.coffee"
7
+ "prepare": "jiwson -m es6 parser.jison -o parser.mjs",
8
+ "test": "node test.mjs"
11
9
  },
12
10
  "repository": {
13
11
  "type": "git",
@@ -16,11 +14,10 @@
16
14
  "author": "Wojciech Fraczak",
17
15
  "license": "ISC",
18
16
  "bin": {
19
- "k": "./k.sh",
20
- "k-repl": "./repl.sh"
17
+ "k": "./k.mjs",
18
+ "k-repl": "./repl.mjs"
21
19
  },
22
20
  "devDependencies": {
23
- "coffeescript": "^2.7.0",
24
21
  "jiwson": "^0.1.1"
25
22
  }
26
23
  }
package/parser.jison CHANGED
@@ -1,6 +1,26 @@
1
1
  %{
2
2
 
3
- var s = require("./symbol-table");
3
+ import s from "./symbol-table.mjs";
4
+
5
+ function fromEscString(escString) {
6
+ const isSingleQuoted = escString.startsWith("'");
7
+ let str = escString.substring(1, escString.length - 1);
8
+ if (isSingleQuoted) {
9
+ str = str.replace(/\\'/g, "'");
10
+ } else {
11
+ str = str.replace(/\\"/g, '"');
12
+ }
13
+ str = str.replace(/\\\\/g, '\\');
14
+ str = str.replace(/\\\//g, '/');
15
+ str = str.replace(/\\b/g, '\b');
16
+ str = str.replace(/\\f/g, '\f');
17
+ str = str.replace(/\\n/g, '\n');
18
+ str = str.replace(/\\r/g, '\r');
19
+ str = str.replace(/\\t/g, '\t');
20
+ str = str.replace(/\\u([\dA-F]{4})/gi, (match, p1) => String.fromCharCode(parseInt(p1, 16)));
21
+
22
+ return str;
23
+ }
4
24
 
5
25
  %}
6
26
 
@@ -24,7 +44,7 @@ var s = require("./symbol-table");
24
44
  ";" return 'SC';
25
45
  ":" return 'COL';
26
46
  "$" return 'DOLLAR';
27
- \"[^\"\n]*\"|\'[^\'\n]*\' return 'STRING'
47
+ \"([^"\\]|\\(.|\n))*\"|\'([^'\\]|\\(.|\n))*\' return 'STRING';
28
48
  [a-zA-Z_][a-zA-Z0-9_?!]* return 'NAME';
29
49
  0|[-]?[1-9][0-9]* return 'INT';
30
50
  <<EOF>> return 'EOF';
@@ -40,11 +60,11 @@ var s = require("./symbol-table");
40
60
  %%
41
61
 
42
62
  name: NAME { $$ = String(yytext); };
43
- str: STRING { $$ = String(yytext).slice(1,-1); };
63
+ str: STRING { $$ = fromEscString(String(yytext)); };
44
64
  int: INT { $$ = parseInt(String(yytext)); };
45
65
 
46
66
  input_with_eof: defs comp EOF {
47
- result = {defs: {rels: s.rels, codes: s.codes}, exp: $2};
67
+ const result = {defs: {rels: s.rels, codes: s.codes}, exp: $2};
48
68
  // console.log(JSON.stringify(result, "", 2));
49
69
  return result;
50
70
  };
@@ -1,3 +1,4 @@
1
+
1
2
  /* parser generated by jison 0.1.1 */
2
3
  /*
3
4
  Returns a Parser object of the following structure:
@@ -74,7 +75,27 @@
74
75
 
75
76
 
76
77
 
77
- var s = require("./symbol-table");
78
+ import s from "./symbol-table.mjs";
79
+
80
+ function fromEscString(escString) {
81
+ const isSingleQuoted = escString.startsWith("'");
82
+ let str = escString.substring(1, escString.length - 1);
83
+ if (isSingleQuoted) {
84
+ str = str.replace(/\\'/g, "'");
85
+ } else {
86
+ str = str.replace(/\\"/g, '"');
87
+ }
88
+ str = str.replace(/\\\\/g, '\\');
89
+ str = str.replace(/\\\//g, '/');
90
+ str = str.replace(/\\b/g, '\b');
91
+ str = str.replace(/\\f/g, '\f');
92
+ str = str.replace(/\\n/g, '\n');
93
+ str = str.replace(/\\r/g, '\r');
94
+ str = str.replace(/\\t/g, '\t');
95
+ str = str.replace(/\\u([\dA-F]{4})/gi, (match, p1) => String.fromCharCode(parseInt(p1, 16)));
96
+
97
+ return str;
98
+ }
78
99
 
79
100
 
80
101
 
@@ -94,14 +115,14 @@ case 1:
94
115
  this.$ = String(yytext);
95
116
  break;
96
117
  case 2:
97
- this.$ = String(yytext).slice(1,-1);
118
+ this.$ = fromEscString(String(yytext));
98
119
  break;
99
120
  case 3:
100
121
  this.$ = parseInt(String(yytext));
101
122
  break;
102
123
  case 4:
103
124
 
104
- result = {defs: {rels: s.rels, codes: s.codes}, exp: $$[$0-1]};
125
+ const result = {defs: {rels: s.rels, codes: s.codes}, exp: $$[$0-1]};
105
126
  // console.log(JSON.stringify(result, "", 2));
106
127
  return result;
107
128
 
@@ -713,7 +734,7 @@ case 15:return 28;
713
734
  break;
714
735
  case 16:return 15;
715
736
  break;
716
- case 17:return 6
737
+ case 17:return 6;
717
738
  break;
718
739
  case 18:return 4;
719
740
  break;
@@ -723,7 +744,7 @@ case 20:return 12;
723
744
  break;
724
745
  }
725
746
  },
726
- rules: [/^(?:[/][*]([*][^/]|[^*])*[*][/])/,/^(?:(\/\/|#|%|--)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\[)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\])/,/^(?:\))/,/^(?:=)/,/^(?:\.)/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\$)/,/^(?:"[^\"\n]*"|'[^\'\n]*')/,/^(?:[a-zA-Z_][a-zA-Z0-9_?!]*)/,/^(?:0|[-]?[1-9][0-9]*)/,/^(?:$)/],
747
+ rules: [/^(?:[/][*]([*][^/]|[^*])*[*][/])/,/^(?:(\/\/|#|%|--)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\[)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\])/,/^(?:\))/,/^(?:=)/,/^(?:\.)/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\$)/,/^(?:"([^"\\]|\\(.|\n))*"|'([^'\\]|\\(.|\n))*')/,/^(?:[a-zA-Z_][a-zA-Z0-9_?!]*)/,/^(?:0|[-]?[1-9][0-9]*)/,/^(?:$)/],
727
748
  conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],"inclusive":true}}
728
749
  });
729
750
  return lexer;
@@ -736,20 +757,11 @@ Parser.prototype = parser;parser.Parser = Parser;
736
757
  return new Parser;
737
758
  })();
738
759
 
739
-
740
- if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
741
- exports.parser = parser;
742
- exports.Parser = parser.Parser;
743
- exports.parse = function () { return parser.parse.apply(parser, arguments); };
744
- exports.main = function commonjsMain (args) {
745
- if (!args[1]) {
746
- console.log('Usage: '+args[0]+' FILE');
747
- process.exit(1);
748
- }
749
- var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8");
750
- return exports.parser.parse(source);
751
- };
752
- if (typeof module !== 'undefined' && require.main === module) {
753
- exports.main(process.argv.slice(1));
760
+ const ___parser = parser;
761
+ const ___Parser = parser.Parser;
762
+ const ___parse = parser.parse.bind(parser);
763
+ export {
764
+ ___parser as parser,
765
+ ___Parser as Parser,
766
+ ___parse as parse
754
767
  }
755
- }
package/pretty.mjs ADDED
@@ -0,0 +1,95 @@
1
+ function compareAs(fn) {
2
+ return function (a, b) {
3
+ [a, b] = [a, b].map(fn);
4
+ if (a < b) return -1;
5
+ if (a > b) return 1;
6
+ return 0;
7
+ };
8
+ }
9
+
10
+ const nameRE = /^[a-zA-Z0-9_][a-zA-Z0-9_?!]*$/;
11
+
12
+ function prettyCode_labels (codes, representatives, label_ref_map) {
13
+ return Object.keys(label_ref_map)
14
+ .sort( compareAs((x) => x) )
15
+ .map( (label) => {
16
+ const plabel = nameRE.test(label) ? label : `'${label}'`;
17
+ return `${prettyCode(codes, representatives, {
18
+ code: "ref",
19
+ ref: label_ref_map[label],
20
+ })} ${plabel}`;
21
+ })
22
+ .join(", ");
23
+ };
24
+
25
+ function prettyCode (codes, representatives, codeExp) {
26
+ switch (codeExp.code) {
27
+ case "ref":
28
+ const name = representatives[codeExp.ref] || codeExp.ref;
29
+ if (name.startsWith(":")) {
30
+ return prettyCode(codes, representatives, codes[name]);
31
+ } else {
32
+ return name;
33
+ }
34
+ case "product":
35
+ return `{${prettyCode_labels(codes, representatives, codeExp.product)}}`;
36
+ case "union":
37
+ return `<${prettyCode_labels(codes, representatives, codeExp.union)}>`;
38
+ case "vector":
39
+ return `[${representatives[codeExp.vector] || codeExp.vector}]`;
40
+ default:
41
+ return ":error";
42
+ }
43
+ };
44
+
45
+ function prettyRel (prettyCode, exp) {
46
+ "use strict";
47
+ const pretty = (exp) => {
48
+ switch (exp.op) {
49
+ case "vector":
50
+ return `[${exp.vector.map(pretty).join(", ")}]`;
51
+ case "union":
52
+ return `<${exp.union.map(pretty).join(", ")}>`;
53
+ case "ref":
54
+ return exp.ref;
55
+ case "identity":
56
+ return "()";
57
+ case "comp":
58
+ return exp.comp.map(pretty).join(" ");
59
+ case "str":
60
+ return `'${exp.str}'`;
61
+ case "int":
62
+ return exp.int;
63
+ case "dot":
64
+ if ("number" === typeof exp.dot) {
65
+ return `.${exp.dot}`;
66
+ } else if (nameRE.test(exp.dot)) {
67
+ return `.${exp.dot}`;
68
+ } else {
69
+ return `'${exp.dot}'`;
70
+ }
71
+ break;
72
+ case "code":
73
+ return `$${prettyCode({
74
+ code: "ref",
75
+ ref: exp.code,
76
+ })}`;
77
+ case "product":
78
+ return (function (labelled) {
79
+ return `{${labelled.join(", ")}}`;
80
+ })(
81
+ exp.product.map(function ({ label, exp }) {
82
+ if (nameRE.test(label)) {
83
+ return `${pretty(exp)} ${label}`;
84
+ } else {
85
+ return `${pretty(exp)} '${label}'`;
86
+ }
87
+ })
88
+ );
89
+ }
90
+ };
91
+ return pretty(exp);
92
+ };
93
+
94
+ export default { prettyCode, prettyRel };
95
+ export { prettyCode, prettyRel };
package/repl.mjs ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ import k from "./index.mjs";
4
+ import run from "./run.mjs";
5
+ import { prettyCode, prettyRel } from "./pretty.mjs";
6
+
7
+ import fs from "node:fs";
8
+
9
+ const splice = [].splice;
10
+
11
+ console.log("Very! experimental repl shell for 'k-language'...");
12
+
13
+ const help = function () {
14
+ console.log(" --h print help");
15
+ console.log(" --a print codes and relations");
16
+ console.log(" --c print codes");
17
+ console.log(" --r print rels");
18
+ return console.log(" --l file.k load 'file.k'");
19
+ };
20
+
21
+ help();
22
+
23
+ const re = /^[ \n\t]*(?:--l[ ]+)(.+[^ ])[ ]*?$/;
24
+
25
+ (function (val, buffer) {
26
+ return process.stdin.on("data", function (data) {
27
+ var e, file, first, i, kScript, last, len, line, ref, rest, results, todo;
28
+ [first, ...rest] = data.toString("utf8").split("\n");
29
+ buffer.push(first);
30
+ if (rest.length > 0) {
31
+ todo = buffer.join("");
32
+ (ref = rest), ([...rest] = ref), ([last] = splice.call(rest, -1));
33
+ buffer = [last];
34
+ todo = [todo, ...rest];
35
+ results = [];
36
+ for (i = 0, len = todo.length; i < len; i++) {
37
+ line = todo[i];
38
+ if (val === void 0) {
39
+ val = {};
40
+ }
41
+ if (line.match(/^[ \n\t]*(?:--h)?$/)) {
42
+ results.push(help());
43
+ } else if (line.match(re)) {
44
+ file = line.match(re)[1];
45
+ console.log(`-- loading file: ${file} ...`);
46
+ kScript = fs.readFileSync(file).toString();
47
+ val = k.compile(kScript)(val);
48
+ results.push(console.log(`=> ${JSON.stringify(val)}`));
49
+ } else if (line.match(/^[ \n\t]*(?:--a)?$/)) {
50
+ results.push(console.log(JSON.stringify(run.defs, " ", 2)));
51
+ } else if (line.match(/^[ \n\t]*(?:--r)?$/)) {
52
+ results.push(
53
+ console.log(
54
+ (function (defs, result) {
55
+ if (defs == null) {
56
+ return result;
57
+ }
58
+ return (function (prettyRel) {
59
+ var ref1, relExps, relName;
60
+ ref1 = defs.rels;
61
+ for (relName in ref1) {
62
+ relExps = ref1[relName];
63
+ result[relName] = relExps.map(prettyRel);
64
+ }
65
+ return result;
66
+ })(
67
+ prettyRel.bind(
68
+ null,
69
+ prettyCode.bind(null, defs.codes, defs.representatives)
70
+ )
71
+ );
72
+ })(run.defs, {})
73
+ )
74
+ );
75
+ } else if (line.match(/^[ \n\t]*(?:--c)?$/)) {
76
+ results.push(
77
+ console.log(
78
+ (function (defs, result) {
79
+ var codeExp, codeName, ref1;
80
+ if (defs == null) {
81
+ return result;
82
+ }
83
+ ref1 = defs.codes;
84
+ for (codeName in ref1) {
85
+ codeExp = ref1[codeName];
86
+ result[codeName] = prettyCode(
87
+ defs.codes,
88
+ defs.representatives,
89
+ codeExp
90
+ );
91
+ }
92
+ return result;
93
+ })(run.defs, {})
94
+ )
95
+ );
96
+ } else if (!line.match(/^[ \n\t]*(?:#.*)?$/)) {
97
+ try {
98
+ val = k.run(`${line} ()`, val);
99
+ results.push(console.log(`=> ${JSON.stringify(val)}`));
100
+ } catch (error) {
101
+ e = error;
102
+ console.error("ERROR:");
103
+ results.push(console.error(e));
104
+ }
105
+ } else {
106
+ results.push(void 0);
107
+ }
108
+ }
109
+ return results;
110
+ }
111
+ });
112
+ })({}, []);