sptc 0.0.32 → 0.0.34
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 +16 -15
- package/bin/sptc.js +4 -5
- package/bin/sptcd.js +10 -10
- package/engine/interpreter-macro.js +47 -1
- package/engine/interpreter.js +8 -44
- package/package.json +2 -3
- package/tests/test1/exp.s +11 -0
package/README.md
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
# Simple Pretreat Toolkit CLI
|
|
2
2
|
|
|
3
|
-
This project is developing..
|
|
4
|
-
|
|
5
3
|
---
|
|
6
4
|
|
|
7
5
|
### sptc
|
|
8
6
|
|
|
9
7
|
```
|
|
10
|
-
Usage: sptc [options]
|
|
8
|
+
Usage: sptc [options] <filename>
|
|
11
9
|
|
|
12
10
|
sptc
|
|
13
11
|
|
|
14
12
|
Options:
|
|
15
|
-
-V, --version
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
(default: "")
|
|
19
|
-
-h, --help display help for command
|
|
13
|
+
-V, --version output the version number
|
|
14
|
+
-d, --defines <string> Macro definition switches. Separate multiple switches with a comma. (default: "")
|
|
15
|
+
-h, --help display help for command
|
|
20
16
|
```
|
|
21
17
|
|
|
22
18
|
### sptcd
|
|
23
19
|
```
|
|
24
20
|
Usage: sptc http server [options]
|
|
25
21
|
|
|
26
|
-
A simple
|
|
22
|
+
A simple HTTP server
|
|
27
23
|
|
|
28
24
|
Options:
|
|
29
25
|
-V, --version output the version number
|
|
30
|
-
-p, --port <number>
|
|
26
|
+
-p, --port <number> The port to serve on. (default: 9090)
|
|
31
27
|
-l, --locally Only accepts local connections.
|
|
32
|
-
-w, --workdir <string>
|
|
33
|
-
-r, --router <string>
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
28
|
+
-w, --workdir <string> Specifies the working directory. (default: ".")
|
|
29
|
+
-r, --router <string> Specifies a file to use as a router entry. If specified, all requests will be routed to
|
|
30
|
+
this file.
|
|
31
|
+
-e, --exts <string> Specifies the valid extensions for executable SPTC files. (default: ".s, .sjs, .sptc")
|
|
32
|
+
-n, --workers <number> The number of worker processes. (default: 1)
|
|
33
|
+
-s, --silent Enables silent mode.
|
|
34
|
+
-t, --traverse If the pathname is a directory, executes the index file under the pathname directory if
|
|
35
|
+
one exists. If no index file is found, traverses the directory. This option is ignored
|
|
36
|
+
if a router file is specified.
|
|
37
|
+
-d, --debug Enables debug mode.
|
|
37
38
|
-h, --help display help for command
|
|
38
39
|
```
|
|
39
40
|
|
package/bin/sptc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const {executeSptcFile}=require('../engine')
|
|
4
4
|
const {Command}=require('commander')
|
|
@@ -7,10 +7,9 @@ const program=new Command()
|
|
|
7
7
|
.name(`sptc`)
|
|
8
8
|
.description(`sptc`)
|
|
9
9
|
.version(version)
|
|
10
|
-
.
|
|
11
|
-
.option('-d, --defines <string>', 'Macro definition switches.
|
|
12
|
-
.action(({
|
|
13
|
-
filename,
|
|
10
|
+
.arguments('<filename>', 'Sptc filename.')
|
|
11
|
+
.option('-d, --defines <string>', 'Macro definition switches. Separate multiple switches with a comma.', '')
|
|
12
|
+
.action((filename, {
|
|
14
13
|
defines,
|
|
15
14
|
})=>{
|
|
16
15
|
executeSptcFile(filename, {}, {
|
package/bin/sptcd.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const {FastCGI, FastCGI_FPM}=require('../dist/httpServer')
|
|
4
4
|
const {Command}=require('commander')
|
|
5
5
|
const version=require('../package.json').version
|
|
6
6
|
const program=new Command()
|
|
7
7
|
.name(`sptc http server`)
|
|
8
|
-
.description(`A simple
|
|
8
|
+
.description(`A simple HTTP server`)
|
|
9
9
|
.version(version)
|
|
10
|
-
.requiredOption('-p, --port <number>', '
|
|
10
|
+
.requiredOption('-p, --port <number>', 'The port to serve on.', 9090)
|
|
11
11
|
.option('-l, --locally', 'Only accepts local connections.')
|
|
12
|
-
.option('-w, --workdir <string>', '
|
|
13
|
-
.option('-r, --router <string>', '
|
|
14
|
-
.option('-e, --exts <string>', '
|
|
15
|
-
.option('-n, --workers <number>', '
|
|
16
|
-
.option('-s, --
|
|
17
|
-
.option('-t, --traverse', 'If pathname is a directory,
|
|
18
|
-
.option('-d, --debug', '
|
|
12
|
+
.option('-w, --workdir <string>', 'Specifies the working directory.', '.')
|
|
13
|
+
.option('-r, --router <string>', 'Specifies a file to use as a router entry. If specified, all requests will be routed to this file.')
|
|
14
|
+
.option('-e, --exts <string>', 'Specifies the valid extensions for executable SPTC files.', '.s, .sjs, .sptc')
|
|
15
|
+
.option('-n, --workers <number>', 'The number of worker processes.', 1)
|
|
16
|
+
.option('-s, --silent', 'Enables silent mode.')
|
|
17
|
+
.option('-t, --traverse', 'If the pathname is a directory, executes the index file under the pathname directory if one exists. If no index file is found, traverses the directory. This option is ignored if a router file is specified.')
|
|
18
|
+
.option('-d, --debug', 'Enables debug mode.')
|
|
19
19
|
.action(({
|
|
20
20
|
port,
|
|
21
21
|
locally,
|
|
@@ -29,13 +29,59 @@ function buildMacroContext({filename, ...inherits}) {
|
|
|
29
29
|
return ctx
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function evalExpression(exp, defs) {
|
|
33
|
+
let ret={
|
|
34
|
+
value: true,
|
|
35
|
+
symbol: 'and',
|
|
36
|
+
}
|
|
37
|
+
const stack=[]
|
|
38
|
+
for(let i=0; i<exp.length; i++) {
|
|
39
|
+
const c=exp[i]
|
|
40
|
+
if(c==='(') {
|
|
41
|
+
stack.push({...ret})
|
|
42
|
+
ret.value=true
|
|
43
|
+
ret.symbol='and'
|
|
44
|
+
}else if(c===')') {
|
|
45
|
+
const val=stack.pop()
|
|
46
|
+
if(val.symbol==='and') {
|
|
47
|
+
ret.value=val.value && ret.value
|
|
48
|
+
}else if(val.symbol==='or') {
|
|
49
|
+
ret.value=val.value || ret.value
|
|
50
|
+
}
|
|
51
|
+
ret.symbol=val.symbol
|
|
52
|
+
}else if(c===' ') {
|
|
53
|
+
while(exp[i+1]===' ') ++i;
|
|
54
|
+
}else{
|
|
55
|
+
let r=c
|
|
56
|
+
for(;;) {
|
|
57
|
+
const a=exp[i+1]
|
|
58
|
+
if(a && '() '.indexOf(a)===-1) {
|
|
59
|
+
r+=exp[++i]
|
|
60
|
+
}else{
|
|
61
|
+
break
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if(r==='and' || r==='or') {
|
|
65
|
+
ret.symbol=r
|
|
66
|
+
}else{
|
|
67
|
+
if(ret.symbol==='and') {
|
|
68
|
+
ret.value=ret.value && defs.has(r)
|
|
69
|
+
}else if(ret.symbol==='or') {
|
|
70
|
+
ret.value=ret.value || defs.has(r)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return ret.value
|
|
76
|
+
}
|
|
77
|
+
|
|
32
78
|
function execute(ctx, ast) {
|
|
33
79
|
let ret=''
|
|
34
80
|
for(let i=0; i<ast.length; i++) {
|
|
35
81
|
const p=ast[i]
|
|
36
82
|
if(p.type===O_IFDEF) {
|
|
37
83
|
const {match, consequent, alternate}=p
|
|
38
|
-
const sub_tree=ctx.defs
|
|
84
|
+
const sub_tree=evalExpression(match, ctx.defs)? consequent: alternate
|
|
39
85
|
ret+=execute(ctx, sub_tree)
|
|
40
86
|
}else if(p.type===O_STR) {
|
|
41
87
|
ret+=p.str
|
package/engine/interpreter.js
CHANGED
|
@@ -65,51 +65,15 @@ function _var_dump(x) {
|
|
|
65
65
|
|
|
66
66
|
function buildGlobal() {
|
|
67
67
|
const ctx={
|
|
68
|
-
// nodejs
|
|
69
|
-
setTimeout,
|
|
70
|
-
setInterval,
|
|
71
|
-
clearTimeout,
|
|
72
|
-
clearInterval,
|
|
73
|
-
queueMicrotask,
|
|
74
|
-
clearImmediate,
|
|
75
|
-
setImmediate,
|
|
76
|
-
|
|
77
68
|
console,
|
|
69
|
+
setTimeout, clearTimeout,
|
|
70
|
+
setInterval, clearInterval,
|
|
71
|
+
setImmediate, clearImmediate,
|
|
72
|
+
queueMicrotask,
|
|
78
73
|
Buffer,
|
|
79
74
|
process,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
TextEncoder,
|
|
83
|
-
URL,
|
|
84
|
-
URLSearchParams,
|
|
85
|
-
|
|
86
|
-
Promise,
|
|
87
|
-
// importESModule: x=>import(x),
|
|
88
|
-
// require
|
|
89
|
-
|
|
90
|
-
// v8
|
|
91
|
-
JSON,
|
|
92
|
-
RegExp,
|
|
93
|
-
Object,
|
|
94
|
-
Array,
|
|
95
|
-
String,
|
|
96
|
-
Number,
|
|
97
|
-
Boolean,
|
|
98
|
-
Date,
|
|
99
|
-
Math,
|
|
100
|
-
Set, WeakSet,
|
|
101
|
-
Map, WeakMap,
|
|
102
|
-
Proxy,
|
|
103
|
-
Symbol,
|
|
104
|
-
Error,
|
|
105
|
-
Function,
|
|
106
|
-
// eval,
|
|
107
|
-
|
|
108
|
-
escape, unescape,
|
|
109
|
-
encodeURI, decodeURI,
|
|
110
|
-
encodeURIComponent, decodeURIComponent,
|
|
111
|
-
isNaN, isFinite,
|
|
112
|
-
parseInt, parseFloat,
|
|
75
|
+
TextEncoder, TextDecoder,
|
|
76
|
+
URL, URLSearchParams,
|
|
113
77
|
}
|
|
114
78
|
ctx.global=ctx
|
|
115
79
|
ctx.globalThis=ctx
|
|
@@ -310,11 +274,11 @@ function buildContext(ctx0, option) {
|
|
|
310
274
|
}
|
|
311
275
|
}
|
|
312
276
|
}
|
|
313
|
-
return target
|
|
277
|
+
return Reflect.get(target, prop, receiver)
|
|
314
278
|
},
|
|
315
279
|
})
|
|
316
280
|
|
|
317
|
-
return [pctx, priv]
|
|
281
|
+
return [{...pctx}, priv]
|
|
318
282
|
}
|
|
319
283
|
|
|
320
284
|
function toWritable(x) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sptc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Simple Pretreat Toolkit CLI",
|
|
5
5
|
"main": "engine/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"sptcd": "./bin/sptcd.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"commander": "10.0.1"
|
|
15
|
-
"fs-extra": "^11.2.0"
|
|
14
|
+
"commander": "10.0.1"
|
|
16
15
|
}
|
|
17
16
|
}
|