kei-lisp 2.0.0 → 2.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/README.md +30 -14
- package/dist/cli.cjs +2442 -3020
- package/dist/cli.d.cts +1 -0
- package/dist/index.cjs +2441 -2899
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +402 -328
- package/dist/index.d.ts +402 -328
- package/dist/index.js +2412 -2890
- package/dist/index.js.map +1 -1
- package/package.json +27 -30
package/README.md
CHANGED
|
@@ -65,21 +65,22 @@ const { LispInterpreter, Cons } = require('kei-lisp');
|
|
|
65
65
|
|
|
66
66
|
## API
|
|
67
67
|
|
|
68
|
-
| Export | Description
|
|
69
|
-
| ------------------- |
|
|
70
|
-
| `LispInterpreter` |
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
68
|
+
| Export | Description |
|
|
69
|
+
| ------------------- | ---------------------------------------------------------- |
|
|
70
|
+
| `LispInterpreter` | Programmatic interpreter (parse / eval / environment) |
|
|
71
|
+
| `Repl` | Interactive REPL on stdin / stdout |
|
|
72
|
+
| `Cons` | Cons cell (pair) data type with type predicates |
|
|
73
|
+
| `InterpretedSymbol` | Lisp symbol (interned) |
|
|
74
|
+
| `KeiLispError` | Base class for parse / eval failures (subclass of `Error`) |
|
|
75
|
+
| `ParseError` | Thrown on parse failure (subclass of `KeiLispError`) |
|
|
76
|
+
| `EvalError` | Thrown on evaluation failure (subclass of `KeiLispError`) |
|
|
77
|
+
| `ExitError` | Thrown when `(exit)` is evaluated; catch to handle exit |
|
|
74
78
|
|
|
75
79
|
### `LispInterpreter`
|
|
76
80
|
|
|
77
81
|
```ts
|
|
78
82
|
const interpreter = new LispInterpreter();
|
|
79
83
|
|
|
80
|
-
// Start an interactive REPL on stdin/stdout
|
|
81
|
-
interpreter.run();
|
|
82
|
-
|
|
83
84
|
// Evaluate source and return the last expression's result
|
|
84
85
|
interpreter.evalString('(+ 1 2)'); // 3
|
|
85
86
|
|
|
@@ -87,20 +88,35 @@ interpreter.evalString('(+ 1 2)'); // 3
|
|
|
87
88
|
interpreter.evalAll('(setq x 10) (* x x)'); // [10, 100]
|
|
88
89
|
```
|
|
89
90
|
|
|
90
|
-
###
|
|
91
|
+
### `Repl`
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { Repl } from 'kei-lisp';
|
|
95
|
+
|
|
96
|
+
// Start an interactive REPL on stdin/stdout
|
|
97
|
+
new Repl().run();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Error handling
|
|
91
101
|
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
`evalString`, `evalAll`, `eval`, and `parse` throw on failure. Catch the
|
|
103
|
+
errors at the boundary; `ExitError` is intentionally separate from the
|
|
104
|
+
`KeiLispError` family so a generic Lisp-error catch does not swallow it.
|
|
94
105
|
|
|
95
106
|
```ts
|
|
96
|
-
import { LispInterpreter, ExitError } from 'kei-lisp';
|
|
107
|
+
import { LispInterpreter, KeiLispError, ExitError } from 'kei-lisp';
|
|
97
108
|
|
|
98
109
|
const interpreter = new LispInterpreter();
|
|
99
110
|
try {
|
|
100
111
|
interpreter.evalString(userInput);
|
|
101
112
|
} catch (error) {
|
|
102
113
|
if (error instanceof ExitError) {
|
|
103
|
-
// Lisp
|
|
114
|
+
// Lisp called (exit) — graceful shutdown
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (error instanceof KeiLispError) {
|
|
118
|
+
// ParseError or EvalError — display to user and continue
|
|
119
|
+
console.error(`${error.name}: ${error.message}`);
|
|
104
120
|
return;
|
|
105
121
|
}
|
|
106
122
|
throw error;
|