@fraczak/k 1.2.1 → 1.2.2
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/README.md +1 -1
- package/package.json +5 -1
- package/repl.coffee +25 -1
- package/repl.js +32 -3
- package/repl.sh +32 -3
- package/run.coffee +1 -1
- package/run.js +1 -1
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ There are three predefined value encodings: `int`, `string`, and
|
|
|
102
102
|
|
|
103
103
|
One can define recursive codes. E.g.:
|
|
104
104
|
|
|
105
|
-
tree = <string leaf, {tree left, tree right} tree>;
|
|
105
|
+
$ tree = <string leaf, {tree left, tree right} tree>;
|
|
106
106
|
|
|
107
107
|
Each _code_ definition starts with a `$`.
|
|
108
108
|
The above example defines new code called _tree_.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "k-language for JSON-like data transformation",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"all": "coffee -c *.coffee; npm run prepare; npm run prepublishOnly",
|
|
10
10
|
"test": "coffee -c symbol-table.coffee; jison parser.jison; coffee test.coffee"
|
|
11
11
|
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/fraczak/k.git"
|
|
15
|
+
},
|
|
12
16
|
"author": "Wojciech Fraczak",
|
|
13
17
|
"license": "ISC",
|
|
14
18
|
"bin": {
|
package/repl.coffee
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env coffee
|
|
2
2
|
k = require "./"
|
|
3
|
+
run = require "./run"
|
|
4
|
+
|
|
5
|
+
console.log "Very! experimental repl shell for 'k-language'..."
|
|
6
|
+
|
|
7
|
+
help = ->
|
|
8
|
+
console.log " --h print help"
|
|
9
|
+
console.log " --a print codes and relations"
|
|
10
|
+
console.log " --c print codes"
|
|
11
|
+
console.log " --l file.k load 'file.k'"
|
|
12
|
+
|
|
13
|
+
help()
|
|
14
|
+
|
|
15
|
+
re = /^[ \n\t]*(?:--l[ ]+)(.+[^ ])[ ]*?$/
|
|
3
16
|
|
|
4
17
|
do (val = {}, buffer = []) ->
|
|
5
18
|
process.stdin.on 'data', (data) ->
|
|
@@ -13,7 +26,18 @@ do (val = {}, buffer = []) ->
|
|
|
13
26
|
for line in todo
|
|
14
27
|
if val is undefined
|
|
15
28
|
val = {}
|
|
16
|
-
if
|
|
29
|
+
if line.match /^[ \n\t]*(?:--h)?$/
|
|
30
|
+
help()
|
|
31
|
+
else if line.match re
|
|
32
|
+
file = line.match(re)[1]
|
|
33
|
+
console.log "-- loading file: #{file} ..."
|
|
34
|
+
val = k.compile_file(file) val
|
|
35
|
+
console.log "=> #{JSON.stringify val}"
|
|
36
|
+
else if line.match /^[ \n\t]*(?:--a)?$/
|
|
37
|
+
console.log JSON.stringify run.defs, " ", 2
|
|
38
|
+
else if line.match /^[ \n\t]*(?:--c)?$/
|
|
39
|
+
console.log JSON.stringify {codes: run.defs?.codes, reps: run.defs?.representatives}, " ", 2
|
|
40
|
+
else if not line.match /^[ \n\t]*(?:#.*)?$/
|
|
17
41
|
try
|
|
18
42
|
val = k.run "#{line} ()", val
|
|
19
43
|
console.log "=> #{JSON.stringify val}"
|
package/repl.js
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
2
|
(function() {
|
|
3
3
|
//!/usr/bin/env coffee
|
|
4
|
-
var k,
|
|
4
|
+
var help, k, re, run,
|
|
5
5
|
splice = [].splice;
|
|
6
6
|
|
|
7
7
|
k = require("./");
|
|
8
8
|
|
|
9
|
+
run = require("./run");
|
|
10
|
+
|
|
11
|
+
console.log("Very! experimental repl shell for 'k-language'...");
|
|
12
|
+
|
|
13
|
+
help = function() {
|
|
14
|
+
console.log(" --h print help");
|
|
15
|
+
console.log(" --a print codes and relations");
|
|
16
|
+
console.log(" --c print codes");
|
|
17
|
+
return console.log(" --l file.k load 'file.k'");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
help();
|
|
21
|
+
|
|
22
|
+
re = /^[ \n\t]*(?:--l[ ]+)(.+[^ ])[ ]*?$/;
|
|
23
|
+
|
|
9
24
|
(function(val, buffer) {
|
|
10
25
|
return process.stdin.on('data', function(data) {
|
|
11
|
-
var e, first, i, last, len, line, ref, rest, results, todo;
|
|
26
|
+
var e, file, first, i, last, len, line, ref, ref1, ref2, rest, results, todo;
|
|
12
27
|
[first, ...rest] = data.toString("utf8").split("\n");
|
|
13
28
|
buffer.push(first);
|
|
14
29
|
if (rest.length > 0) {
|
|
@@ -22,7 +37,21 @@
|
|
|
22
37
|
if (val === void 0) {
|
|
23
38
|
val = {};
|
|
24
39
|
}
|
|
25
|
-
if (
|
|
40
|
+
if (line.match(/^[ \n\t]*(?:--h)?$/)) {
|
|
41
|
+
results.push(help());
|
|
42
|
+
} else if (line.match(re)) {
|
|
43
|
+
file = line.match(re)[1];
|
|
44
|
+
console.log(`-- loading file: ${file} ...`);
|
|
45
|
+
val = k.compile_file(file)(val);
|
|
46
|
+
results.push(console.log(`=> ${JSON.stringify(val)}`));
|
|
47
|
+
} else if (line.match(/^[ \n\t]*(?:--a)?$/)) {
|
|
48
|
+
results.push(console.log(JSON.stringify(run.defs, " ", 2)));
|
|
49
|
+
} else if (line.match(/^[ \n\t]*(?:--c)?$/)) {
|
|
50
|
+
results.push(console.log(JSON.stringify({
|
|
51
|
+
codes: (ref1 = run.defs) != null ? ref1.codes : void 0,
|
|
52
|
+
reps: (ref2 = run.defs) != null ? ref2.representatives : void 0
|
|
53
|
+
}, " ", 2)));
|
|
54
|
+
} else if (!line.match(/^[ \n\t]*(?:#.*)?$/)) {
|
|
26
55
|
try {
|
|
27
56
|
val = k.run(`${line} ()`, val);
|
|
28
57
|
results.push(console.log(`=> ${JSON.stringify(val)}`));
|
package/repl.sh
CHANGED
|
@@ -2,14 +2,29 @@
|
|
|
2
2
|
// Generated by CoffeeScript 2.7.0
|
|
3
3
|
(function() {
|
|
4
4
|
//!/usr/bin/env coffee
|
|
5
|
-
var k,
|
|
5
|
+
var help, k, re, run,
|
|
6
6
|
splice = [].splice;
|
|
7
7
|
|
|
8
8
|
k = require("./");
|
|
9
9
|
|
|
10
|
+
run = require("./run");
|
|
11
|
+
|
|
12
|
+
console.log("Very! experimental repl shell for 'k-language'...");
|
|
13
|
+
|
|
14
|
+
help = function() {
|
|
15
|
+
console.log(" --h print help");
|
|
16
|
+
console.log(" --a print codes and relations");
|
|
17
|
+
console.log(" --c print codes");
|
|
18
|
+
return console.log(" --l file.k load 'file.k'");
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
help();
|
|
22
|
+
|
|
23
|
+
re = /^[ \n\t]*(?:--l[ ]+)(.+[^ ])[ ]*?$/;
|
|
24
|
+
|
|
10
25
|
(function(val, buffer) {
|
|
11
26
|
return process.stdin.on('data', function(data) {
|
|
12
|
-
var e, first, i, last, len, line, ref, rest, results, todo;
|
|
27
|
+
var e, file, first, i, last, len, line, ref, ref1, ref2, rest, results, todo;
|
|
13
28
|
[first, ...rest] = data.toString("utf8").split("\n");
|
|
14
29
|
buffer.push(first);
|
|
15
30
|
if (rest.length > 0) {
|
|
@@ -23,7 +38,21 @@
|
|
|
23
38
|
if (val === void 0) {
|
|
24
39
|
val = {};
|
|
25
40
|
}
|
|
26
|
-
if (
|
|
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
|
+
val = k.compile_file(file)(val);
|
|
47
|
+
results.push(console.log(`=> ${JSON.stringify(val)}`));
|
|
48
|
+
} else if (line.match(/^[ \n\t]*(?:--a)?$/)) {
|
|
49
|
+
results.push(console.log(JSON.stringify(run.defs, " ", 2)));
|
|
50
|
+
} else if (line.match(/^[ \n\t]*(?:--c)?$/)) {
|
|
51
|
+
results.push(console.log(JSON.stringify({
|
|
52
|
+
codes: (ref1 = run.defs) != null ? ref1.codes : void 0,
|
|
53
|
+
reps: (ref2 = run.defs) != null ? ref2.representatives : void 0
|
|
54
|
+
}, " ", 2)));
|
|
55
|
+
} else if (!line.match(/^[ \n\t]*(?:#.*)?$/)) {
|
|
27
56
|
try {
|
|
28
57
|
val = k.run(`${line} ()`, val);
|
|
29
58
|
results.push(console.log(`=> ${JSON.stringify(val)}`));
|
package/run.coffee
CHANGED