nv-constexpr-paren-exec 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +27 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,10 +7,9 @@ const {is_jsid_str} = require("nv-char-jsid2");
7
7
  const unesc = require("nv-string-unesc");
8
8
  const codify = require("nv-constexpr-simple-codify");
9
9
 
10
- // `name:= "a" +"b"` -> "ab"
11
- // `act:= path="./func.js" ` -> body of func.js
12
-
13
-
10
+ // `name := "a" +"b"` -> "ab"
11
+ // `act := path="./func.js" ` -> body of func.js
12
+ // `indent :=<depth> ... `
14
13
  const parse = (s)=>{
15
14
  var idx = s.indexOf(":=");
16
15
  if(idx >=0) {
@@ -58,8 +57,25 @@ const parse = (s)=>{
58
57
  } else {
59
58
  throw(`action content MUST be object`);
60
59
  }
60
+ } else if(type === "indent") {
61
+ var d = {type:"indent"};
62
+ var rgx = /^([0-9]+)(.*)$/;
63
+ var r = rgx.exec(ison_str);
64
+ var depth = parseInt(r[1]);
65
+ if(!Object.is(depth,NaN)) {
66
+ var code = r[2];
67
+ if(code.includes("`")) {throw('code can NOT includes "`"');} else {}
68
+ code = code.replace(/[\t ]+/g," ");
69
+ code = code.replace(/[\r\n]+/g,"\n");
70
+ var lns = code.splice("\n");
71
+ lns = lns.map(ln=>" ".repeat(depth)+ln);
72
+ d.code = "\n" +lns.join("\n") + "\n";
73
+ return d;
74
+ } else {
75
+ throw(`indent :=<int> ${depth} is MUST be int`)
76
+ }
61
77
  } else {
62
- throw(`type can ONLY be : name | action |nm | act`);
78
+ throw(`type can ONLY be : name | action |nm | act | indent`);
63
79
  }
64
80
  } else {
65
81
  throw(`MUST have type(name | action |nm | act): <type>:=... `)
@@ -96,15 +112,17 @@ class ParenExec {
96
112
  } else {
97
113
  return [false,reason]
98
114
  }
99
- } else {
100
- //d.type === "action"
115
+ } else if(d.type === "action"){
101
116
  var cmt = d.cmt;
102
117
  var code = d.code;
103
118
  if(cmt !== undefined) {
104
- return `${code}/*${cmt}*/`;
119
+ return [true,`${code}/*${cmt}*/`];
105
120
  } else {
106
- return `${code}`;
121
+ return [true,`${code}`];
107
122
  }
123
+ } else {
124
+ //d.type === "indent"
125
+ return [true, d.code];
108
126
  }
109
127
  } catch(e) {
110
128
  return [false,e.message]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nv-constexpr-paren-exec",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "nv-char-basic": "^1.0.3",