nv-constexpr-paren-exec 1.0.0 → 1.1.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/TEST/func.js +0 -2
- package/TEST/tst.js +4 -2
- package/index.js +44 -117
- package/package.json +1 -20
package/TEST/func.js
CHANGED
package/TEST/tst.js
CHANGED
package/index.js
CHANGED
|
@@ -1,125 +1,52 @@
|
|
|
1
|
-
const _fs
|
|
2
|
-
const _path
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var idx = s.indexOf(":=");
|
|
16
|
-
if(idx >=0) {
|
|
17
|
-
var type = s.slice(0,idx).trim().toLowerCase();
|
|
18
|
-
var ison_str = s.slice(idx+2).trim();
|
|
19
|
-
if(type === "name" || type === "nm") {
|
|
20
|
-
return {
|
|
21
|
-
type:"name",
|
|
22
|
-
expr:ison_str
|
|
23
|
-
}
|
|
24
|
-
} else if(type === "action" || type === "act") {
|
|
25
|
-
ison_str = `{${ison_str}}`;
|
|
26
|
-
var ison = parse_from_str(ison_str);
|
|
27
|
-
// .cmt Same As .desc
|
|
28
|
-
// .path
|
|
29
|
-
// .code
|
|
30
|
-
// .code 优先级高于 .path
|
|
31
|
-
if(!Array.isArray(ison) && ison !== null && typeof(ison) === "object") {
|
|
32
|
-
var d = {type:"action"}
|
|
33
|
-
if(ison.cmt !== undefined) {
|
|
34
|
-
d.cmt = String(ison.cmt);
|
|
35
|
-
} else if(ison.desc !== undefined) {
|
|
36
|
-
d.cmt = String(ison.desc)
|
|
37
|
-
} else {}
|
|
38
|
-
if(ison.code) {
|
|
39
|
-
d.code = String(ison.code)
|
|
40
|
-
} else if(ison.path) {
|
|
41
|
-
var code = _fs.readFileSync(_path.resolve(ison.path)).toString();
|
|
42
|
-
if(code.includes("`")) {throw('code can NOT includes "`"');} else {}
|
|
43
|
-
code = code.replace(/[\r\n\t ]+/g," ");
|
|
44
|
-
code = code.trim();
|
|
45
|
-
var rgx0 = /\{(.*)\}$/;
|
|
46
|
-
var r0 = rgx0.exec(code);
|
|
47
|
-
if(r0) {
|
|
48
|
-
d.code = r0[1].trim();
|
|
49
|
-
} else {
|
|
50
|
-
d.code = code;
|
|
51
|
-
}
|
|
52
|
-
} else {}
|
|
53
|
-
if(d.code) {
|
|
54
|
-
return d;
|
|
55
|
-
} else {
|
|
56
|
-
throw(`action content MUST have .path OR .code`);
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
throw(`action content MUST be object`);
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
throw(`type can ONLY be : name | action |nm | act`);
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
throw(`MUST have type(name | action |nm | act): <type>:=... `)
|
|
1
|
+
const _fs = require("fs");
|
|
2
|
+
const _path = require("path");
|
|
3
|
+
|
|
4
|
+
const topl = (p)=> {
|
|
5
|
+
p = _path.resolve(p);
|
|
6
|
+
var pl = [];
|
|
7
|
+
while(true) {
|
|
8
|
+
var desc = _path.parse(p);
|
|
9
|
+
if(desc.dir !== p) {
|
|
10
|
+
pl.push(desc.name);
|
|
11
|
+
p = desc.dir;
|
|
12
|
+
} else {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
66
15
|
}
|
|
16
|
+
return pl;
|
|
67
17
|
}
|
|
68
18
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return [false,reason]
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
//d.type === "action"
|
|
101
|
-
var cmt = d.cmt;
|
|
102
|
-
var code = d.code;
|
|
103
|
-
if(cmt !== undefined) {
|
|
104
|
-
return `${code}/*${cmt}*/`;
|
|
105
|
-
} else {
|
|
106
|
-
return `${code}`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
} catch(e) {
|
|
110
|
-
return [false,e.message]
|
|
111
|
-
}
|
|
19
|
+
const run = (path, fn_as_cmt_depth=1)=>{
|
|
20
|
+
path = _path.resolve(path);
|
|
21
|
+
if(_fs.existsSync(path)) {
|
|
22
|
+
var stat = _fs.lstatSync(path);
|
|
23
|
+
if(stat.isFile()) {
|
|
24
|
+
var code = _fs.readFileSync(path).toString();
|
|
25
|
+
if(code.includes("`")) {
|
|
26
|
+
return [false, "macro code can NOT includes '`' "];
|
|
27
|
+
} else {
|
|
28
|
+
code = code.trim();
|
|
29
|
+
code = code.replace(/[\t ]+/g, " ");
|
|
30
|
+
code = code.replace(/[\n\r]+/g, "\n");
|
|
31
|
+
var pl = topl(path);
|
|
32
|
+
var cnt = pl.length;
|
|
33
|
+
pl = pl.slice(0,fn_as_cmt_depth);
|
|
34
|
+
pl.reverse();
|
|
35
|
+
var cmt = pl.join("/");
|
|
36
|
+
if(cmt!== "") {
|
|
37
|
+
code = `${code}/*${cmt}*/`;
|
|
38
|
+
} else {
|
|
39
|
+
}
|
|
40
|
+
return [true,code];
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
return [false,`${path} NOT file`]
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
return [false,`${path} NOT exists`]
|
|
112
47
|
}
|
|
113
48
|
}
|
|
114
49
|
|
|
115
|
-
|
|
116
|
-
const run = (env,code,keep_cmt=true)=>{
|
|
117
|
-
var ctx = creat(env);
|
|
118
|
-
return ctx.run(code);
|
|
119
|
-
}
|
|
50
|
+
run.topl = topl;
|
|
120
51
|
module.exports = run;
|
|
121
|
-
module.exports.parse = parse;
|
|
122
|
-
module.exports.creat = creat;
|
|
123
|
-
module.exports.ParenExec = ParenExec;
|
|
124
|
-
|
|
125
52
|
|
package/package.json
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nv-constexpr-paren-exec",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"dependencies": {
|
|
6
|
-
"nv-char-basic": "^1.0.3",
|
|
7
|
-
"nv-char-jsid2": "^1.0.8",
|
|
8
|
-
"nv-char-whitespace": "^1.0.7",
|
|
9
|
-
"nv-constexpr-simple-codify": "^1.0.5",
|
|
10
|
-
"nv-facutil-csutil": "^1.0.21",
|
|
11
|
-
"nv-facutil-untf": "^1.0.2",
|
|
12
|
-
"nv-string-unesc": "^1.0.0",
|
|
13
|
-
"nvison-bw": "^1.0.0",
|
|
14
|
-
"nvison-cfg": "^1.1.0",
|
|
15
|
-
"nvison-obj-class": "^1.2.2",
|
|
16
|
-
"nvison-obj-typedef": "^1.1.0",
|
|
17
|
-
"nvison-parse-d": "^1.2.1",
|
|
18
|
-
"nvison-parse-engine": "^1.2.1",
|
|
19
|
-
"nvison-parse-internal-bw": "^1.2.2",
|
|
20
|
-
"nvison-parse-scope": "^1.1.1",
|
|
21
|
-
"nvison-parse-state": "^1.0.12"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {},
|
|
24
5
|
"scripts": {
|
|
25
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
26
7
|
},
|