@lionlang/core 0.1.0 → 0.2.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/README.md +326 -6
- package/dist/analysis/analyze.d.mts +34 -0
- package/dist/analysis/analyze.d.mts.map +1 -0
- package/dist/analysis/analyze.mjs +181 -0
- package/dist/analysis/analyze.mjs.map +1 -0
- package/dist/environment-BQw8BPXl.d.mts +25 -0
- package/dist/{environment-k2Uf6VVc.d.mts.map → environment-BQw8BPXl.d.mts.map} +1 -1
- package/dist/errors/evaluation.d.mts +1 -1
- package/dist/errors/evaluation.mjs +2 -2
- package/dist/errors/evaluation.mjs.map +1 -1
- package/dist/{evaluate-D7ODMrbg.mjs → evaluate-BJOG7kaS.mjs} +36 -33
- package/dist/evaluate-BJOG7kaS.mjs.map +1 -0
- package/dist/evaluation/base-forms/array.d.mts +5 -6
- package/dist/evaluation/base-forms/array.d.mts.map +1 -1
- package/dist/evaluation/base-forms/array.mjs +1 -1
- package/dist/evaluation/base-forms/primitive.d.mts +2 -2
- package/dist/evaluation/base-forms/primitive.mjs +2 -2
- package/dist/evaluation/base-forms/primitive.mjs.map +1 -1
- package/dist/evaluation/base-forms/record.d.mts +5 -5
- package/dist/evaluation/base-forms/record.d.mts.map +1 -1
- package/dist/evaluation/base-forms/record.mjs +1 -1
- package/dist/evaluation/environment.d.mts +1 -1
- package/dist/evaluation/environment.d.mts.map +1 -1
- package/dist/evaluation/environment.mjs +10 -7
- package/dist/evaluation/environment.mjs.map +1 -1
- package/dist/evaluation/evaluate.d.mts +5 -6
- package/dist/evaluation/evaluate.d.mts.map +1 -1
- package/dist/evaluation/evaluate.mjs +1 -1
- package/dist/evaluation/special-forms/begin.d.mts +4 -4
- package/dist/evaluation/special-forms/begin.d.mts.map +1 -1
- package/dist/evaluation/special-forms/begin.mjs +1 -1
- package/dist/evaluation/special-forms/cond.d.mts +4 -5
- package/dist/evaluation/special-forms/cond.d.mts.map +1 -1
- package/dist/evaluation/special-forms/cond.mjs +1 -1
- package/dist/evaluation/special-forms/define.d.mts +4 -4
- package/dist/evaluation/special-forms/define.d.mts.map +1 -1
- package/dist/evaluation/special-forms/define.mjs +1 -1
- package/dist/evaluation/special-forms/eval.d.mts +4 -5
- package/dist/evaluation/special-forms/eval.d.mts.map +1 -1
- package/dist/evaluation/special-forms/eval.mjs +1 -1
- package/dist/evaluation/special-forms/function.d.mts +4 -5
- package/dist/evaluation/special-forms/function.d.mts.map +1 -1
- package/dist/evaluation/special-forms/function.mjs +1 -1
- package/dist/evaluation/special-forms/lambda.d.mts +4 -4
- package/dist/evaluation/special-forms/lambda.d.mts.map +1 -1
- package/dist/evaluation/special-forms/lambda.mjs +1 -1
- package/dist/evaluation/special-forms/match.d.mts +4 -5
- package/dist/evaluation/special-forms/match.d.mts.map +1 -1
- package/dist/evaluation/special-forms/match.mjs +1 -1
- package/dist/evaluation/special-forms/quote.d.mts +1 -1
- package/dist/evaluation-B6K0DbPS.d.mts +14 -0
- package/dist/evaluation-B6K0DbPS.d.mts.map +1 -0
- package/dist/evaluation-Bs36vy1h.d.mts +12 -0
- package/dist/evaluation-Bs36vy1h.d.mts.map +1 -0
- package/dist/evaluation-Dwo4KN_D.d.mts +9 -0
- package/dist/evaluation-Dwo4KN_D.d.mts.map +1 -0
- package/dist/{json-primitive-DUaaoNff.d.mts → json-primitive-gcv9Q1E4.d.mts} +2 -2
- package/dist/json-primitive-gcv9Q1E4.d.mts.map +1 -0
- package/dist/lion-expression-DMR7Psmu.d.mts +16 -0
- package/dist/lion-expression-DMR7Psmu.d.mts.map +1 -0
- package/dist/modules/array.d.mts +9 -10
- package/dist/modules/array.d.mts.map +1 -1
- package/dist/modules/array.mjs +9 -5
- package/dist/modules/array.mjs.map +1 -1
- package/dist/modules/boolean.d.mts +8 -9
- package/dist/modules/boolean.d.mts.map +1 -1
- package/dist/modules/boolean.mjs +6 -6
- package/dist/modules/boolean.mjs.map +1 -1
- package/dist/modules/console.mjs.map +1 -1
- package/dist/modules/lib/shared.d.mts +1 -2
- package/dist/modules/lib/shared.d.mts.map +1 -1
- package/dist/modules/lib/shared.mjs +1 -1
- package/dist/modules/lib/shared.mjs.map +1 -1
- package/dist/modules/number.d.mts +10 -11
- package/dist/modules/number.d.mts.map +1 -1
- package/dist/modules/number.mjs +9 -9
- package/dist/modules/number.mjs.map +1 -1
- package/dist/modules/object.d.mts +39 -59
- package/dist/modules/object.d.mts.map +1 -1
- package/dist/modules/object.mjs +12 -18
- package/dist/modules/object.mjs.map +1 -1
- package/dist/modules/string.d.mts +8 -9
- package/dist/modules/string.d.mts.map +1 -1
- package/dist/modules/string.mjs +6 -6
- package/dist/modules/string.mjs.map +1 -1
- package/dist/schemas/environment.d.mts +1 -1
- package/dist/schemas/environment.mjs +3 -3
- package/dist/schemas/environment.mjs.map +1 -1
- package/dist/schemas/evaluation.d.mts +17 -17
- package/dist/schemas/evaluation.d.mts.map +1 -1
- package/dist/schemas/evaluation.mjs +23 -15
- package/dist/schemas/evaluation.mjs.map +1 -1
- package/dist/schemas/json-primitive.d.mts +1 -1
- package/dist/schemas/json-primitive.mjs +6 -1
- package/dist/schemas/json-primitive.mjs.map +1 -1
- package/dist/schemas/lion-expression.d.mts +1 -1
- package/dist/schemas/lion-expression.mjs +6 -5
- package/dist/schemas/lion-expression.mjs.map +1 -1
- package/dist/services/evaluation.d.mts +2 -2
- package/dist/services/evaluation.mjs +3 -4
- package/dist/services/evaluation.mjs.map +1 -1
- package/dist/types/evaluation.d.mts +1 -1
- package/package.json +8 -6
- package/dist/environment-k2Uf6VVc.d.mts +0 -25
- package/dist/evaluate-D7ODMrbg.mjs.map +0 -1
- package/dist/evaluation-AblffSQw.d.mts +0 -17
- package/dist/evaluation-AblffSQw.d.mts.map +0 -1
- package/dist/evaluation-EqzK8tQV.d.mts +0 -13
- package/dist/evaluation-EqzK8tQV.d.mts.map +0 -1
- package/dist/evaluation-uwZSKxIf.d.mts +0 -10
- package/dist/evaluation-uwZSKxIf.d.mts.map +0 -1
- package/dist/json-primitive-DUaaoNff.d.mts.map +0 -1
- package/dist/lion-expression-6Y3itx9l.d.mts +0 -16
- package/dist/lion-expression-6Y3itx9l.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,335 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lion
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lion is a JSON-based Lisp. Every Lion program is valid JSON, which makes it easy to serialize, store, inspect, and generate from other systems.
|
|
4
|
+
|
|
5
|
+
The evaluator runs on Effect v4.
|
|
6
|
+
|
|
7
|
+
Lion evaluates:
|
|
8
|
+
|
|
9
|
+
- JSON primitives directly
|
|
10
|
+
- strings as environment references when a binding exists
|
|
11
|
+
- arrays as special forms or function-call expressions
|
|
12
|
+
- objects by recursively evaluating their values
|
|
13
|
+
|
|
14
|
+
The result is a small homoiconic language that can describe both computation and data interchange without a separate parser.
|
|
15
|
+
|
|
16
|
+
## Packages
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
packages/
|
|
20
|
+
core/ evaluator, special forms, stdlib
|
|
21
|
+
repl/ interactive web REPL
|
|
22
|
+
agent/ real-world Lion program driving an OpenTUI + AI agent
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Basic Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Effect } from "effect";
|
|
29
|
+
import { run } from "@lionlang/core/evaluation/evaluate";
|
|
30
|
+
import { stdlib } from "@lionlang/core/modules";
|
|
31
|
+
|
|
32
|
+
const result = await Effect.runPromise(
|
|
33
|
+
run(["number/add", 1, 2], stdlib)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// => 3
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Custom Environment
|
|
40
|
+
|
|
41
|
+
Any string can resolve against the evaluation environment. That includes values, objects, classes, and functions.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { Effect } from "effect";
|
|
45
|
+
import { run } from "@lionlang/core/evaluation/evaluate";
|
|
46
|
+
import { stdlib } from "@lionlang/core/modules";
|
|
47
|
+
|
|
48
|
+
const env = {
|
|
49
|
+
...stdlib,
|
|
50
|
+
price: 100,
|
|
51
|
+
taxRate: 0.08,
|
|
52
|
+
clamp: (min: number, max: number, value: number) =>
|
|
53
|
+
Math.min(max, Math.max(min, value)),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
await Effect.runPromise(
|
|
57
|
+
run(["number/add", "price", ["number/multiply", "price", "taxRate"]], env)
|
|
58
|
+
);
|
|
59
|
+
// => 108
|
|
60
|
+
|
|
61
|
+
await Effect.runPromise(run(["clamp", 0, 100, 150], env));
|
|
62
|
+
// => 100
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Expression Model
|
|
66
|
+
|
|
67
|
+
### Primitives
|
|
68
|
+
|
|
69
|
+
Numbers, booleans, and `null` evaluate to themselves. Strings are treated as references first; if no binding exists, the original string is returned.
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
42
|
|
73
|
+
true
|
|
74
|
+
null
|
|
75
|
+
"x"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
With `{ "x": 10 }` in the environment, `"x"` evaluates to `10`. Otherwise it evaluates to `"x"`.
|
|
79
|
+
|
|
80
|
+
### Arrays
|
|
81
|
+
|
|
82
|
+
Arrays are always treated as executable expressions:
|
|
83
|
+
|
|
84
|
+
1. special forms such as `["define", "x", 1]`
|
|
85
|
+
2. function calls when the first element evaluates to a function
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
["number/add", 1, 2]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Evaluates to `3`.
|
|
92
|
+
|
|
93
|
+
### Objects
|
|
94
|
+
|
|
95
|
+
Objects preserve their keys and evaluate each value.
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"sum": ["number/add", 1, 2],
|
|
100
|
+
"ok": true
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Evaluates to `{ "sum": 3, "ok": true }`.
|
|
105
|
+
|
|
106
|
+
## Special Forms
|
|
107
|
+
|
|
108
|
+
### `quote`
|
|
109
|
+
|
|
110
|
+
Returns its argument without evaluating it.
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
["quote", ["number/add", 1, 2]]
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### `eval`
|
|
117
|
+
|
|
118
|
+
Evaluates its argument, then evaluates the result.
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
["eval", ["quote", ["number/add", 1, 2]]]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `begin`
|
|
125
|
+
|
|
126
|
+
Evaluates expressions in order and returns the last result.
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
["begin", ["define", "x", 1], ["define", "x", 2], "x"]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### `define`
|
|
133
|
+
|
|
134
|
+
Evaluates a value, stores it in the global environment, and returns the stored value.
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
["define", "answer", 42]
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### `lambda`
|
|
141
|
+
|
|
142
|
+
Creates a Lion function with lexical scope.
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
["lambda", ["x"], ["number/add", "x", 1]]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Lambdas close over surrounding scope, and they observe updated global bindings when invoked later.
|
|
149
|
+
|
|
150
|
+
### `cond`
|
|
151
|
+
|
|
152
|
+
Evaluates condition/result pairs in order and returns the first matching result. An `else` branch is optional.
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
["cond",
|
|
156
|
+
[["number/greaterThan", "score", 90], "great"],
|
|
157
|
+
[["number/greaterThan", "score", 70], "pass"],
|
|
158
|
+
["else", "retry"]]
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
If no branch matches and no `else` is provided, `cond` returns `null`.
|
|
162
|
+
|
|
163
|
+
### `match`
|
|
164
|
+
|
|
165
|
+
Pattern matches a value against predicate/function pairs, then applies the first matching branch. The last argument is a fallback function.
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
["match",
|
|
169
|
+
"value",
|
|
170
|
+
["value/number?", ["lambda", ["x"], ["number/add", "x", 1]]],
|
|
171
|
+
["value/string?", ["lambda", ["x"], ["string/concat", "x", "!"]]],
|
|
172
|
+
["lambda", ["x"], "x"]]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`match` also supports structural predicates:
|
|
176
|
+
|
|
177
|
+
```json
|
|
178
|
+
["match",
|
|
179
|
+
{ "type": "user", "profile": { "name": "Ada" } },
|
|
180
|
+
[
|
|
181
|
+
{
|
|
182
|
+
"type": ["func/partial", "string/equals?", "user"],
|
|
183
|
+
"profile": { "name": "value/string?" }
|
|
184
|
+
},
|
|
185
|
+
"value/identity"
|
|
186
|
+
],
|
|
187
|
+
["lambda", ["x"], null]]
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Standard Library
|
|
191
|
+
|
|
192
|
+
The default environment exported as `stdlib` namespaces entries as `<module>/<name>`.
|
|
193
|
+
|
|
194
|
+
### `number`
|
|
195
|
+
|
|
196
|
+
```json
|
|
197
|
+
["number/add", 1, 2]
|
|
198
|
+
["number/subtract", 10, 3]
|
|
199
|
+
["number/multiply", 5, 4]
|
|
200
|
+
["number/divide", 20, 4]
|
|
201
|
+
["number/equals?", 5, 5]
|
|
202
|
+
["number/lessThan", 3, 5]
|
|
203
|
+
["number/greaterThan", 5, 3]
|
|
204
|
+
["number/lessThanOrEqualTo", 3, 5]
|
|
205
|
+
["number/greaterThanOrEqualTo", 5, 5]
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### `boolean`
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
["boolean/not", true]
|
|
212
|
+
["boolean/and", true, false]
|
|
213
|
+
["boolean/or", false, true]
|
|
214
|
+
["boolean/xor", true, false]
|
|
215
|
+
["boolean/nand", true, true]
|
|
216
|
+
["boolean/nor", false, false]
|
|
217
|
+
["boolean/equals?", true, true]
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `array`
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
["array/make", 1, 2, 3]
|
|
224
|
+
["array/head", ["array/make", 1, 2, 3]]
|
|
225
|
+
["array/tail", ["array/make", 1, 2, 3]]
|
|
226
|
+
["array/length", ["array/make", 1, 2, 3]]
|
|
227
|
+
["array/concat", ["array/make", 1, 2], ["array/make", 3, 4]]
|
|
228
|
+
["array/includes?", ["array/make", 1, 2, 3], 2]
|
|
229
|
+
["array/map", ["array/make", 1, 2, 3], ["lambda", ["x"], ["number/add", "x", 1]]]
|
|
230
|
+
["array/flat-map", ["array/make", 1, 2], ["lambda", ["x"], ["array/make", "x", "x"]]]
|
|
231
|
+
["array/reduce", ["array/make", 1, 2, 3], 0, ["lambda", ["acc", "x"], ["number/add", "acc", "x"]]]
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### `string`
|
|
235
|
+
|
|
236
|
+
```json
|
|
237
|
+
["string/equals?", "a", "a"]
|
|
238
|
+
["string/length", "lion"]
|
|
239
|
+
["string/concat", "lion", "ized"]
|
|
240
|
+
["string/startsWith", "lion", "li"]
|
|
241
|
+
["string/endsWith", "lion", "on"]
|
|
242
|
+
["string/includes", "lion", "io"]
|
|
243
|
+
["string/indexOf", "lion", "o"]
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### `object`
|
|
247
|
+
|
|
248
|
+
```json
|
|
249
|
+
["object/get", {"a": 1}, "a"]
|
|
250
|
+
["object/get-path", {"a": {"b": {"c": 42}}}, "a.b.c"]
|
|
251
|
+
["object/keys", {"a": 1, "b": 2}]
|
|
252
|
+
["object/values", {"a": 1, "b": 2}]
|
|
253
|
+
["object/json-stringify", {"a": 1}, null, 2]
|
|
254
|
+
["object/get-method", "obj", "methodName"]
|
|
255
|
+
["object/call-method", "obj", "methodName", 1, 2]
|
|
256
|
+
["object/get-method-path", "obj", "nested.methodName"]
|
|
257
|
+
["object/call-method-path", "obj", "nested.methodName", 1, 2]
|
|
258
|
+
["object/new", "SomeClass", "arg1", "arg2"]
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
`object/get-path` understands dot paths and numeric array segments such as `"users.1.name"`.
|
|
262
|
+
|
|
263
|
+
### `func`
|
|
264
|
+
|
|
265
|
+
```json
|
|
266
|
+
["func/bind", "fn", "obj"]
|
|
267
|
+
["func/apply", "fn", "obj", 1, 2]
|
|
268
|
+
["func/callback", ["lambda", ["x"], ["number/add", "x", 1]]]
|
|
269
|
+
["func/partial", "fn", 1, 2]
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`func/callback` is especially useful for turning Lion lambdas into JavaScript callbacks while preserving access to the Lion environment.
|
|
273
|
+
|
|
274
|
+
### `value`
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
["value/function?", "x"]
|
|
278
|
+
["value/number?", 1]
|
|
279
|
+
["value/string?", "lion"]
|
|
280
|
+
["value/boolean?", true]
|
|
281
|
+
["value/object?", {"a": 1}]
|
|
282
|
+
["value/array?", ["array/make", 1, 2]]
|
|
283
|
+
["value/null?", null]
|
|
284
|
+
["value/identity", 42]
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
`value/undefined?` and `value/symbol?` are mainly useful when Lion is evaluating host values supplied through the environment.
|
|
288
|
+
|
|
289
|
+
### `console`
|
|
290
|
+
|
|
291
|
+
```json
|
|
292
|
+
["console/log", "hello"]
|
|
293
|
+
["console/log-json", {"hello": "world"}]
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Host Interop
|
|
297
|
+
|
|
298
|
+
Lion works well as a configuration and orchestration layer over ordinary JavaScript objects and functions.
|
|
299
|
+
|
|
300
|
+
The `packages/agent` package is the clearest example. It injects:
|
|
301
|
+
|
|
302
|
+
- `OpenTUI` classes and enums
|
|
303
|
+
- AI SDK helpers
|
|
304
|
+
- a model instance
|
|
305
|
+
- Node `fs`
|
|
306
|
+
- Zod constructors
|
|
307
|
+
- a renderer instance
|
|
308
|
+
|
|
309
|
+
Then Lion code in [`packages/agent/src/agent.json`](/Users/andrueanderson/Workspace/TypeScript/lion/packages/agent/src/agent.json) uses:
|
|
310
|
+
|
|
311
|
+
- `object/get-path` to traverse host APIs
|
|
312
|
+
- `object/new` to construct classes
|
|
313
|
+
- `object/call-method` via aliases such as `"()"`
|
|
314
|
+
- `func/callback` to hand Lion lambdas to promise and event APIs
|
|
315
|
+
- `match`, `cond`, `begin`, and `define` to orchestrate application flow
|
|
316
|
+
|
|
317
|
+
That lets Lion drive a non-trivial terminal UI agent entirely from JSON.
|
|
318
|
+
|
|
319
|
+
## Development
|
|
320
|
+
|
|
321
|
+
From the repo root:
|
|
4
322
|
|
|
5
323
|
```bash
|
|
6
324
|
bun install
|
|
325
|
+
bun run prepare
|
|
326
|
+
bun test
|
|
327
|
+
bun run build
|
|
7
328
|
```
|
|
8
329
|
|
|
9
|
-
To
|
|
330
|
+
To work on a specific package:
|
|
10
331
|
|
|
11
332
|
```bash
|
|
12
|
-
|
|
333
|
+
turbo test --filter=@lionlang/core
|
|
334
|
+
turbo dev --filter=@lionlang/repl
|
|
13
335
|
```
|
|
14
|
-
|
|
15
|
-
This project was created using `bun init` in bun v1.3.1. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { a as LionExpressionType } from "../lion-expression-DMR7Psmu.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/analysis/analyze.d.ts
|
|
4
|
+
type StructuralPath = readonly (number | string)[];
|
|
5
|
+
type SemanticKind = "primitive" | "record" | "array" | "empty-array" | "call" | "special-form" | "invalid-call";
|
|
6
|
+
type SpecialFormName = "begin" | "cond" | "define" | "eval" | "lambda" | "match" | "quote";
|
|
7
|
+
interface SemanticRelationship {
|
|
8
|
+
readonly kind: "definition" | "reference-candidate";
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}
|
|
11
|
+
interface SemanticChild {
|
|
12
|
+
readonly node: SemanticNode;
|
|
13
|
+
readonly order: number;
|
|
14
|
+
readonly role: string;
|
|
15
|
+
}
|
|
16
|
+
interface SemanticNode {
|
|
17
|
+
readonly children: readonly SemanticChild[];
|
|
18
|
+
readonly diagnostic?: string;
|
|
19
|
+
readonly kind: SemanticKind;
|
|
20
|
+
readonly label: string;
|
|
21
|
+
readonly path: StructuralPath;
|
|
22
|
+
readonly pointer: string;
|
|
23
|
+
readonly quoted: boolean;
|
|
24
|
+
readonly relationships: readonly SemanticRelationship[];
|
|
25
|
+
readonly specialForm?: SpecialFormName;
|
|
26
|
+
readonly value?: boolean | null | number | string;
|
|
27
|
+
}
|
|
28
|
+
declare const pathToPointer: (path: StructuralPath) => string;
|
|
29
|
+
declare const isSpecialFormName: (value: unknown) => value is SpecialFormName;
|
|
30
|
+
declare const analyze: (expression: LionExpressionType) => SemanticNode;
|
|
31
|
+
declare const flattenAnalysis: (root: SemanticNode) => readonly SemanticNode[];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { SemanticChild, SemanticKind, SemanticNode, SemanticRelationship, SpecialFormName, StructuralPath, analyze, flattenAnalysis, isSpecialFormName, pathToPointer };
|
|
34
|
+
//# sourceMappingURL=analyze.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.d.mts","names":[],"sources":["../../src/analysis/analyze.ts"],"mappings":";;;KAYY,cAAA;AAAA,KAEA,YAAA;AAAA,KASA,eAAA;AAAA,UASK,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,IAAA;AAAA;AAAA,UAGM,aAAA;EAAA,SACN,IAAA,EAAM,YAAA;EAAA,SACN,KAAA;EAAA,SACA,IAAA;AAAA;AAAA,UAGM,YAAA;EAAA,SACN,QAAA,WAAmB,aAAA;EAAA,SACnB,UAAA;EAAA,SACA,IAAA,EAAM,YAAA;EAAA,SACN,KAAA;EAAA,SACA,IAAA,EAAM,cAAA;EAAA,SACN,OAAA;EAAA,SACA,MAAA;EAAA,SACA,aAAA,WAAwB,oBAAA;EAAA,SACxB,WAAA,GAAc,eAAA;EAAA,SACd,KAAA;AAAA;AAAA,cAwEE,aAAA,GAAiB,IAAA,EAAM,cAAA;AAAA,cA4IvB,iBAAA,GAAqB,KAAA,cAAiB,KAAA,IAAS,eAAA;AAAA,cAI/C,OAAA,GAAW,UAAA,EAAY,kBAAA,KAAqB,YAAA;AAAA,cAG5C,eAAA,GACX,IAAA,EAAM,YAAA,cACI,YAAA"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { BeginFormSchema, CondFormSchema, DefineFormSchema, EvalFormSchema, LambdaFormSchema, MatchFormSchema, QuoteFormSchema } from "../schemas/evaluation.mjs";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
//#region src/analysis/analyze.ts
|
|
4
|
+
const roleByIndex = (roles, fallback) => (index) => roles[index] ?? fallback;
|
|
5
|
+
const SPECIAL_FORMS = [
|
|
6
|
+
{
|
|
7
|
+
name: "eval",
|
|
8
|
+
matches: Schema.is(EvalFormSchema),
|
|
9
|
+
role: roleByIndex(["operator", "expression"], "argument")
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "quote",
|
|
13
|
+
matches: Schema.is(QuoteFormSchema),
|
|
14
|
+
role: roleByIndex(["operator", "quoted-value"], "quoted-value")
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "begin",
|
|
18
|
+
matches: Schema.is(BeginFormSchema),
|
|
19
|
+
role: roleByIndex(["operator"], "sequence-item")
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "define",
|
|
23
|
+
matches: Schema.is(DefineFormSchema),
|
|
24
|
+
role: roleByIndex([
|
|
25
|
+
"operator",
|
|
26
|
+
"binding",
|
|
27
|
+
"value"
|
|
28
|
+
], "value")
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "lambda",
|
|
32
|
+
matches: Schema.is(LambdaFormSchema),
|
|
33
|
+
role: roleByIndex([
|
|
34
|
+
"operator",
|
|
35
|
+
"parameters",
|
|
36
|
+
"body"
|
|
37
|
+
], "body")
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "cond",
|
|
41
|
+
matches: Schema.is(CondFormSchema),
|
|
42
|
+
role: roleByIndex(["operator"], "branch")
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "match",
|
|
46
|
+
matches: Schema.is(MatchFormSchema),
|
|
47
|
+
role: (index, length) => {
|
|
48
|
+
if (index === 0) return "operator";
|
|
49
|
+
if (index === 1) return "subject";
|
|
50
|
+
return index === length - 1 ? "fallback" : "pattern";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
const SPECIAL_FORM_NAMES = {
|
|
55
|
+
begin: true,
|
|
56
|
+
cond: true,
|
|
57
|
+
define: true,
|
|
58
|
+
eval: true,
|
|
59
|
+
lambda: true,
|
|
60
|
+
match: true,
|
|
61
|
+
quote: true
|
|
62
|
+
};
|
|
63
|
+
const escapePointerSegment = (segment) => String(segment).replaceAll("~", "~0").replaceAll("/", "~1");
|
|
64
|
+
const pathToPointer = (path) => path.length === 0 ? "" : `/${path.map(escapePointerSegment).join("/")}`;
|
|
65
|
+
const primitiveLabel = (value) => {
|
|
66
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
67
|
+
return String(value);
|
|
68
|
+
};
|
|
69
|
+
const analyzeNode = (expression, path, quoted) => {
|
|
70
|
+
if (!Array.isArray(expression) && (expression === null || typeof expression !== "object")) {
|
|
71
|
+
const relationships = [];
|
|
72
|
+
if (typeof expression === "string") relationships.push({
|
|
73
|
+
kind: "reference-candidate",
|
|
74
|
+
name: expression
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
path,
|
|
78
|
+
pointer: pathToPointer(path),
|
|
79
|
+
kind: "primitive",
|
|
80
|
+
label: primitiveLabel(expression),
|
|
81
|
+
value: expression,
|
|
82
|
+
quoted,
|
|
83
|
+
children: [],
|
|
84
|
+
relationships
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (!Array.isArray(expression)) {
|
|
88
|
+
const entries = Object.entries(expression);
|
|
89
|
+
return {
|
|
90
|
+
path,
|
|
91
|
+
pointer: pathToPointer(path),
|
|
92
|
+
kind: "record",
|
|
93
|
+
label: entries.length === 0 ? "empty record" : `record · ${entries.length}`,
|
|
94
|
+
quoted,
|
|
95
|
+
children: entries.map(([key, value], order) => ({
|
|
96
|
+
role: key,
|
|
97
|
+
order,
|
|
98
|
+
node: analyzeNode(value, [...path, key], quoted)
|
|
99
|
+
})),
|
|
100
|
+
relationships: []
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (expression.length === 0) return {
|
|
104
|
+
path,
|
|
105
|
+
pointer: pathToPointer(path),
|
|
106
|
+
kind: "empty-array",
|
|
107
|
+
label: "empty array",
|
|
108
|
+
quoted,
|
|
109
|
+
children: [],
|
|
110
|
+
relationships: []
|
|
111
|
+
};
|
|
112
|
+
const head = expression[0];
|
|
113
|
+
const namedForm = SPECIAL_FORMS.find(({ name }) => name === head);
|
|
114
|
+
const validForm = SPECIAL_FORMS.find(({ matches }) => matches(expression));
|
|
115
|
+
const relationships = [];
|
|
116
|
+
if (!quoted && validForm?.name === "define" && typeof expression[1] === "string") relationships.push({
|
|
117
|
+
kind: "definition",
|
|
118
|
+
name: expression[1]
|
|
119
|
+
});
|
|
120
|
+
const role = quoted ? () => "item" : validForm?.role ?? roleByIndex(["callee"], "argument");
|
|
121
|
+
const children = expression.map((value, order) => ({
|
|
122
|
+
role: role(order, expression.length),
|
|
123
|
+
order,
|
|
124
|
+
node: analyzeNode(value, [...path, order], quoted || validForm?.name === "quote" && order > 0)
|
|
125
|
+
}));
|
|
126
|
+
if (quoted) return {
|
|
127
|
+
path,
|
|
128
|
+
pointer: pathToPointer(path),
|
|
129
|
+
kind: "array",
|
|
130
|
+
label: `array · ${expression.length}`,
|
|
131
|
+
quoted,
|
|
132
|
+
children,
|
|
133
|
+
relationships
|
|
134
|
+
};
|
|
135
|
+
if (!quoted && namedForm && !validForm) return {
|
|
136
|
+
path,
|
|
137
|
+
pointer: pathToPointer(path),
|
|
138
|
+
kind: "invalid-call",
|
|
139
|
+
label: `invalid ${namedForm.name}`,
|
|
140
|
+
specialForm: namedForm.name,
|
|
141
|
+
quoted,
|
|
142
|
+
children,
|
|
143
|
+
relationships,
|
|
144
|
+
diagnostic: `The ${namedForm.name} form has an invalid structure.`
|
|
145
|
+
};
|
|
146
|
+
if (!quoted && validForm) return {
|
|
147
|
+
path,
|
|
148
|
+
pointer: pathToPointer(path),
|
|
149
|
+
kind: "special-form",
|
|
150
|
+
label: validForm.name,
|
|
151
|
+
specialForm: validForm.name,
|
|
152
|
+
quoted,
|
|
153
|
+
children,
|
|
154
|
+
relationships
|
|
155
|
+
};
|
|
156
|
+
const label = typeof head === "string" ? head : "call";
|
|
157
|
+
return {
|
|
158
|
+
path,
|
|
159
|
+
pointer: pathToPointer(path),
|
|
160
|
+
kind: "call",
|
|
161
|
+
label,
|
|
162
|
+
quoted,
|
|
163
|
+
children,
|
|
164
|
+
relationships
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
const isSpecialFormName = (value) => typeof value === "string" && Object.hasOwn(SPECIAL_FORM_NAMES, value);
|
|
168
|
+
const analyze = (expression) => analyzeNode(expression, [], false);
|
|
169
|
+
const flattenAnalysis = (root) => {
|
|
170
|
+
const nodes = [];
|
|
171
|
+
const visit = (node) => {
|
|
172
|
+
nodes.push(node);
|
|
173
|
+
for (const child of node.children) visit(child.node);
|
|
174
|
+
};
|
|
175
|
+
visit(root);
|
|
176
|
+
return nodes;
|
|
177
|
+
};
|
|
178
|
+
//#endregion
|
|
179
|
+
export { analyze, flattenAnalysis, isSpecialFormName, pathToPointer };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=analyze.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze.mjs","names":[],"sources":["../../src/analysis/analyze.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport {\n BeginFormSchema,\n CondFormSchema,\n DefineFormSchema,\n EvalFormSchema,\n LambdaFormSchema,\n MatchFormSchema,\n QuoteFormSchema,\n} from \"@/schemas/evaluation\";\nimport type { LionExpressionType } from \"@/schemas/lion-expression\";\n\nexport type StructuralPath = readonly (number | string)[];\n\nexport type SemanticKind =\n | \"primitive\"\n | \"record\"\n | \"array\"\n | \"empty-array\"\n | \"call\"\n | \"special-form\"\n | \"invalid-call\";\n\nexport type SpecialFormName =\n | \"begin\"\n | \"cond\"\n | \"define\"\n | \"eval\"\n | \"lambda\"\n | \"match\"\n | \"quote\";\n\nexport interface SemanticRelationship {\n readonly kind: \"definition\" | \"reference-candidate\";\n readonly name: string;\n}\n\nexport interface SemanticChild {\n readonly node: SemanticNode;\n readonly order: number;\n readonly role: string;\n}\n\nexport interface SemanticNode {\n readonly children: readonly SemanticChild[];\n readonly diagnostic?: string;\n readonly kind: SemanticKind;\n readonly label: string;\n readonly path: StructuralPath;\n readonly pointer: string;\n readonly quoted: boolean;\n readonly relationships: readonly SemanticRelationship[];\n readonly specialForm?: SpecialFormName;\n readonly value?: boolean | null | number | string;\n}\n\ninterface FormDefinition {\n readonly matches: (value: unknown) => boolean;\n readonly name: SpecialFormName;\n readonly role: (index: number, length: number) => string;\n}\n\nconst roleByIndex =\n (roles: readonly string[], fallback: string) => (index: number) =>\n roles[index] ?? fallback;\n\nconst SPECIAL_FORMS: readonly FormDefinition[] = [\n {\n name: \"eval\",\n matches: Schema.is(EvalFormSchema),\n role: roleByIndex([\"operator\", \"expression\"], \"argument\"),\n },\n {\n name: \"quote\",\n matches: Schema.is(QuoteFormSchema),\n role: roleByIndex([\"operator\", \"quoted-value\"], \"quoted-value\"),\n },\n {\n name: \"begin\",\n matches: Schema.is(BeginFormSchema),\n role: roleByIndex([\"operator\"], \"sequence-item\"),\n },\n {\n name: \"define\",\n matches: Schema.is(DefineFormSchema),\n role: roleByIndex([\"operator\", \"binding\", \"value\"], \"value\"),\n },\n {\n name: \"lambda\",\n matches: Schema.is(LambdaFormSchema),\n role: roleByIndex([\"operator\", \"parameters\", \"body\"], \"body\"),\n },\n {\n name: \"cond\",\n matches: Schema.is(CondFormSchema),\n role: roleByIndex([\"operator\"], \"branch\"),\n },\n {\n name: \"match\",\n matches: Schema.is(MatchFormSchema),\n role: (index, length) => {\n if (index === 0) {\n return \"operator\";\n }\n if (index === 1) {\n return \"subject\";\n }\n return index === length - 1 ? \"fallback\" : \"pattern\";\n },\n },\n];\n\nconst SPECIAL_FORM_NAMES: Readonly<Record<SpecialFormName, true>> = {\n begin: true,\n cond: true,\n define: true,\n eval: true,\n lambda: true,\n match: true,\n quote: true,\n};\n\nconst escapePointerSegment = (segment: number | string) =>\n String(segment).replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n\nexport const pathToPointer = (path: StructuralPath): string =>\n path.length === 0 ? \"\" : `/${path.map(escapePointerSegment).join(\"/\")}`;\n\nconst primitiveLabel = (value: boolean | null | number | string) => {\n if (typeof value === \"string\") {\n return JSON.stringify(value);\n }\n return String(value);\n};\n\nconst analyzeNode = (\n expression: LionExpressionType,\n path: StructuralPath,\n quoted: boolean\n): SemanticNode => {\n if (\n !Array.isArray(expression) &&\n (expression === null || typeof expression !== \"object\")\n ) {\n const relationships: SemanticRelationship[] = [];\n if (typeof expression === \"string\") {\n relationships.push({ kind: \"reference-candidate\", name: expression });\n }\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"primitive\",\n label: primitiveLabel(expression),\n value: expression,\n quoted,\n children: [],\n relationships,\n };\n }\n\n if (!Array.isArray(expression)) {\n const entries = Object.entries(expression);\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"record\",\n label:\n entries.length === 0 ? \"empty record\" : `record · ${entries.length}`,\n quoted,\n children: entries.map(([key, value], order) => ({\n role: key,\n order,\n node: analyzeNode(value, [...path, key], quoted),\n })),\n relationships: [],\n };\n }\n\n if (expression.length === 0) {\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"empty-array\",\n label: \"empty array\",\n quoted,\n children: [],\n relationships: [],\n };\n }\n\n const head = expression[0];\n const namedForm = SPECIAL_FORMS.find(({ name }) => name === head);\n const validForm = SPECIAL_FORMS.find(({ matches }) => matches(expression));\n const relationships: SemanticRelationship[] = [];\n if (\n !quoted &&\n validForm?.name === \"define\" &&\n typeof expression[1] === \"string\"\n ) {\n relationships.push({ kind: \"definition\", name: expression[1] });\n }\n const role = quoted\n ? () => \"item\"\n : (validForm?.role ?? roleByIndex([\"callee\"], \"argument\"));\n const children = expression.map((value, order) => ({\n role: role(order, expression.length),\n order,\n node: analyzeNode(\n value,\n [...path, order],\n quoted || (validForm?.name === \"quote\" && order > 0)\n ),\n }));\n\n if (quoted) {\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"array\",\n label: `array · ${expression.length}`,\n quoted,\n children,\n relationships,\n };\n }\n\n if (!quoted && namedForm && !validForm) {\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"invalid-call\",\n label: `invalid ${namedForm.name}`,\n specialForm: namedForm.name,\n quoted,\n children,\n relationships,\n diagnostic: `The ${namedForm.name} form has an invalid structure.`,\n };\n }\n\n if (!quoted && validForm) {\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"special-form\",\n label: validForm.name,\n specialForm: validForm.name,\n quoted,\n children,\n relationships,\n };\n }\n\n const label = typeof head === \"string\" ? head : \"call\";\n return {\n path,\n pointer: pathToPointer(path),\n kind: \"call\",\n label,\n quoted,\n children,\n relationships,\n };\n};\n\nexport const isSpecialFormName = (value: unknown): value is SpecialFormName =>\n typeof value === \"string\" &&\n Object.hasOwn(SPECIAL_FORM_NAMES, value as SpecialFormName);\n\nexport const analyze = (expression: LionExpressionType): SemanticNode =>\n analyzeNode(expression, [], false);\n\nexport const flattenAnalysis = (\n root: SemanticNode\n): readonly SemanticNode[] => {\n const nodes: SemanticNode[] = [];\n const visit = (node: SemanticNode) => {\n nodes.push(node);\n for (const child of node.children) {\n visit(child.node);\n }\n };\n visit(root);\n return nodes;\n};\n"],"mappings":"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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ref, Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/schemas/environment.d.ts
|
|
4
|
+
type BindingsRef = Ref.Ref<Record<string, unknown>>;
|
|
5
|
+
interface InnerEnvironment {
|
|
6
|
+
readonly bindingsRef: BindingsRef;
|
|
7
|
+
readonly parent: Environment;
|
|
8
|
+
}
|
|
9
|
+
type Environment = typeof EnvironmentSchema.Type;
|
|
10
|
+
type ToplevelEnvironment = typeof ToplevelEnvironmentSchema.Type;
|
|
11
|
+
declare const ToplevelEnvironmentSchema: Schema.Struct<{
|
|
12
|
+
readonly bindingsRef: Schema.Codec<BindingsRef, BindingsRef, never, never>;
|
|
13
|
+
}>;
|
|
14
|
+
declare const EnvironmentSchema: Schema.Union<readonly [Schema.Struct<{
|
|
15
|
+
readonly bindingsRef: Schema.Codec<BindingsRef, BindingsRef, never, never>;
|
|
16
|
+
}>, Schema.suspend<Schema.Codec<InnerEnvironment, InnerEnvironment, never, never>>]>;
|
|
17
|
+
declare const InnerEnvironmentSchema: Schema.Struct<{
|
|
18
|
+
readonly bindingsRef: Schema.Codec<BindingsRef, BindingsRef, never, never>;
|
|
19
|
+
readonly parent: Schema.Union<readonly [Schema.Struct<{
|
|
20
|
+
readonly bindingsRef: Schema.Codec<BindingsRef, BindingsRef, never, never>;
|
|
21
|
+
}>, Schema.suspend<Schema.Codec<InnerEnvironment, InnerEnvironment, never, never>>]>;
|
|
22
|
+
}>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ToplevelEnvironment as a, InnerEnvironmentSchema as i, EnvironmentSchema as n, ToplevelEnvironmentSchema as o, InnerEnvironment as r, Environment as t };
|
|
25
|
+
//# sourceMappingURL=environment-BQw8BPXl.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment-
|
|
1
|
+
{"version":3,"file":"environment-BQw8BPXl.d.mts","names":[],"sources":["../src/schemas/environment.ts"],"mappings":";;;KAEK,WAAA,GAAc,GAAA,CAAI,GAAA,CAAI,MAAA;AAAA,UAQV,gBAAA;EAAA,SACN,WAAA,EAAa,WAAA;EAAA,SACb,MAAA,EAAQ,WAAA;AAAA;AAAA,KAGP,WAAA,UAAqB,iBAAA,CAAkB,IAAA;AAAA,KAEvC,mBAAA,UAA6B,yBAAA,CAA0B,IAAA;AAAA,cAEtD,yBAAA,EAAyB,MAAA,CAAA,MAAA;EAAA;;cAIzB,iBAAA,EAAiB,MAAA,CAAA,KAAA,WAAA,MAAA,CAAA,MAAA;EAAA;;cAKjB,sBAAA,EAAsB,MAAA,CAAA,MAAA;EAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as InvalidFunctionCallError, t as ArgumentMismatchError } from "../evaluation-
|
|
1
|
+
import { n as InvalidFunctionCallError, t as ArgumentMismatchError } from "../evaluation-B6K0DbPS.mjs";
|
|
2
2
|
export { ArgumentMismatchError, InvalidFunctionCallError };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { LionExpressionSchema } from "../schemas/lion-expression.mjs";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
3
|
//#region src/errors/evaluation.ts
|
|
4
|
-
var ArgumentMismatchError = class extends Schema.TaggedError(
|
|
5
|
-
var InvalidFunctionCallError = class extends Schema.TaggedError(
|
|
4
|
+
var ArgumentMismatchError = class extends Schema.TaggedError()("ArgumentMismatchError", {}) {};
|
|
5
|
+
var InvalidFunctionCallError = class extends Schema.TaggedError()("InvalidFunctionCallError", { expression: LionExpressionSchema }) {};
|
|
6
6
|
//#endregion
|
|
7
7
|
export { ArgumentMismatchError, InvalidFunctionCallError };
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluation.mjs","names":[],"sources":["../../src/errors/evaluation.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { LionExpressionSchema } from \"@/schemas/lion-expression\";\n\nexport class ArgumentMismatchError extends Schema.TaggedError<ArgumentMismatchError>(\n \"ArgumentMismatchError\"
|
|
1
|
+
{"version":3,"file":"evaluation.mjs","names":[],"sources":["../../src/errors/evaluation.ts"],"sourcesContent":["import { Schema } from \"effect\";\nimport { LionExpressionSchema } from \"@/schemas/lion-expression\";\n\nexport class ArgumentMismatchError extends Schema.TaggedError<ArgumentMismatchError>()(\n \"ArgumentMismatchError\",\n {}\n) {}\n\nexport class InvalidFunctionCallError extends Schema.TaggedError<InvalidFunctionCallError>()(\n \"InvalidFunctionCallError\",\n { expression: LionExpressionSchema }\n) {}\n"],"mappings":";;;AAGA,IAAa,wBAAb,cAA2C,OAAO,aAAoC,CACpF,yBACA,EAAE,CACH,CAAC;AAEF,IAAa,2BAAb,cAA8C,OAAO,aAAuC,CAC1F,4BACA,EAAE,YAAY,sBAAsB,CACrC,CAAC"}
|