@fraczak/k 1.3.0 → 1.3.1
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/index.coffee +1 -6
- package/index.js +2 -11
- package/package.json +1 -1
- package/pretty.coffee +3 -3
- package/pretty.js +3 -3
- package/run.coffee +0 -2
- package/run.js +1 -3
package/index.coffee
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
fs = require "fs"
|
|
2
1
|
{parse} = require "./parser.js"
|
|
3
2
|
run = require "./run"
|
|
4
3
|
t = require "./codes"
|
|
@@ -22,12 +21,8 @@ compile = (script) ->
|
|
|
22
21
|
|
|
23
22
|
compile.doc = "Transforms k-script (string) into a function"
|
|
24
23
|
|
|
25
|
-
compile_file = (fileName) ->
|
|
26
|
-
compile fs.readFileSync(fileName).toString "utf8"
|
|
27
|
-
compile_file.doc = "Transforms k-script (from file) into a function"
|
|
28
|
-
|
|
29
24
|
runScriptOnData = (script, data) ->
|
|
30
25
|
compile(script) data
|
|
31
26
|
runScriptOnData.doc = "Run 'script' (string) on 'data': (script,data) -> data"
|
|
32
27
|
|
|
33
|
-
module.exports = {compile,
|
|
28
|
+
module.exports = {compile, run: runScriptOnData, parse}
|
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
2
|
(function() {
|
|
3
|
-
var compile,
|
|
4
|
-
|
|
5
|
-
fs = require("fs");
|
|
3
|
+
var compile, finalize, parse, run, runScriptOnData, t;
|
|
6
4
|
|
|
7
5
|
({parse} = require("./parser.js"));
|
|
8
6
|
|
|
@@ -36,12 +34,6 @@
|
|
|
36
34
|
|
|
37
35
|
compile.doc = "Transforms k-script (string) into a function";
|
|
38
36
|
|
|
39
|
-
compile_file = function(fileName) {
|
|
40
|
-
return compile(fs.readFileSync(fileName).toString("utf8"));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
compile_file.doc = "Transforms k-script (from file) into a function";
|
|
44
|
-
|
|
45
37
|
runScriptOnData = function(script, data) {
|
|
46
38
|
return compile(script)(data);
|
|
47
39
|
};
|
|
@@ -50,9 +42,8 @@
|
|
|
50
42
|
|
|
51
43
|
module.exports = {
|
|
52
44
|
compile,
|
|
53
|
-
compile_file,
|
|
54
45
|
run: runScriptOnData,
|
|
55
|
-
parse
|
|
46
|
+
parse
|
|
56
47
|
};
|
|
57
48
|
|
|
58
49
|
}).call(this);
|
package/package.json
CHANGED
package/pretty.coffee
CHANGED
|
@@ -6,12 +6,12 @@ compareAs = (fn) ->
|
|
|
6
6
|
return 1 if a > b
|
|
7
7
|
0
|
|
8
8
|
|
|
9
|
-
nameRE = /^[a-zA-
|
|
9
|
+
nameRE = /^[a-zA-Z0-9_][a-zA-Z0-9_?!]*$/
|
|
10
10
|
prettyCode_labels = ( codes, representatives, label_ref_map) ->
|
|
11
11
|
labels = Object.keys(label_ref_map)
|
|
12
12
|
.sort compareAs (x) -> x
|
|
13
13
|
.map (label) ->
|
|
14
|
-
plabel = if
|
|
14
|
+
plabel = if nameRE.test label
|
|
15
15
|
label
|
|
16
16
|
else
|
|
17
17
|
"'#{label}'"
|
|
@@ -64,7 +64,7 @@ prettyRel = (prettyCode, exp) ->
|
|
|
64
64
|
"$#{prettyCode {code:"ref",ref:exp.code}}"
|
|
65
65
|
when 'product'
|
|
66
66
|
do (labelled = exp.product.map ({label,exp}) ->
|
|
67
|
-
if
|
|
67
|
+
if nameRE.test label
|
|
68
68
|
"#{pretty exp} #{label}"
|
|
69
69
|
else
|
|
70
70
|
"#{pretty exp} '#{label}'") ->
|
package/pretty.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
nameRE = /^[a-zA-
|
|
18
|
+
nameRE = /^[a-zA-Z0-9_][a-zA-Z0-9_?!]*$/;
|
|
19
19
|
|
|
20
20
|
prettyCode_labels = function(codes, representatives, label_ref_map) {
|
|
21
21
|
var labels;
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
return x;
|
|
24
24
|
})).map(function(label) {
|
|
25
25
|
var plabel;
|
|
26
|
-
plabel =
|
|
26
|
+
plabel = nameRE.test(label) ? label : `'${label}'`;
|
|
27
27
|
return `${prettyCode(codes, representatives, {
|
|
28
28
|
code: "ref",
|
|
29
29
|
ref: label_ref_map[label]
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
return (function(labelled) {
|
|
91
91
|
return `{${labelled.join(", ")}}`;
|
|
92
92
|
})(exp.product.map(function({label, exp}) {
|
|
93
|
-
if (
|
|
93
|
+
if (nameRE.test(label)) {
|
|
94
94
|
return `${pretty(exp)} ${label}`;
|
|
95
95
|
} else {
|
|
96
96
|
return `${pretty(exp)} '${label}'`;
|
package/run.coffee
CHANGED
package/run.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
|
2
2
|
(function() {
|
|
3
|
-
var builtin, codes,
|
|
3
|
+
var builtin, codes, run, valid, verify,
|
|
4
4
|
modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
|
|
5
5
|
|
|
6
|
-
fs = require("fs");
|
|
7
|
-
|
|
8
6
|
valid = function(x) {
|
|
9
7
|
if (isNaN(x)) {
|
|
10
8
|
return void 0;
|