You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`if else for while do let const var function class return throw try catch switch import export /regex/`
43
41
```js
44
42
importjessiefrom'subscript/jessie.js'
@@ -55,6 +53,23 @@ fn({}) // 120
55
53
56
54
Jessie can parse and compile its own source.
57
55
56
+
57
+
## Parse / Compile
58
+
59
+
Subscript exposes `parse` to build AST and `compile` to create evaluators.
60
+
61
+
```js
62
+
import { parse, compile } from'subscript'
63
+
64
+
// parse expression
65
+
let tree =parse('a.b + c - 1')
66
+
tree // ['-', ['+', ['.', 'a', 'b'], 'c'], [,1]]
67
+
68
+
// compile tree to evaluable function
69
+
fn =compile(tree)
70
+
fn({ a: {b:1}, c:2 }) // 2
71
+
```
72
+
58
73
## Extension
59
74
60
75
```js
@@ -73,7 +88,7 @@ import justin from 'subscript/justin.js'
73
88
justin('[1,2,3] ∩ [2,3,4]')({}) // [2, 3]
74
89
```
75
90
76
-
See [docs.md](./docs.md) for full API: `binary`, `unary`, `nary`, `group`, `access`, `literal`, `token`.
91
+
See [docs.md](./docs.md) for full API.
77
92
78
93
79
94
## Syntax Tree
@@ -87,6 +102,14 @@ parse('a + b * 2')
87
102
// ['+', 'a', ['*', 'b', [, 2]]]
88
103
```
89
104
105
+
AST has simplified lispy tree structure (inspired by [frisk](https://ghub.io/frisk) / [nisp](https://github.com/ysmood/nisp)), opposed to [ESTree](https://github.com/estree/estree):
106
+
107
+
* not limited to particular language (JS), can be compiled to different targets;
108
+
* reflects execution sequence, rather than code layout;
109
+
* has minimal overhead, directly maps to operators;
110
+
* simplifies manual evaluation and debugging;
111
+
* has conventional form and one-liner docs:
112
+
90
113
Three forms:
91
114
92
115
```js
@@ -95,7 +118,7 @@ Three forms:
95
118
[op, ...args] // operation — apply operator
96
119
```
97
120
98
-
Portable to any language. See [spec.md](./spec.md).
AST has simplified lispy tree structure (inspired by [frisk](https://ghub.io/frisk) / [nisp](https://github.com/ysmood/nisp)), opposed to [ESTree](https://github.com/estree/estree):
316
-
317
-
* portable to any language, not limited to JS;
318
-
* reflects execution sequence, rather than code layout;
319
-
* has minimal overhead, directly maps to operators;
0 commit comments