eliscript 0.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.
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { memoizedSequenceView } from "./collection.mjs";
|
|
2
|
+
import { persistentVector } from "./vector.mjs";
|
|
3
|
+
|
|
4
|
+
const patternStates = new WeakMap();
|
|
5
|
+
const ALLOWED_FLAGS = "imsu";
|
|
6
|
+
|
|
7
|
+
function requireArity(actual, expected, name) {
|
|
8
|
+
if (actual !== expected) {
|
|
9
|
+
const unit = expected === 1 ? "argument" : "arguments";
|
|
10
|
+
throw new TypeError(`${name} requires exactly ${expected} ${unit}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function requireString(value, label) {
|
|
15
|
+
if (typeof value !== "string") {
|
|
16
|
+
throw new TypeError(`${label} must be a string`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeFlags(value) {
|
|
22
|
+
const flags = requireString(value, "regex flags");
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
for (const flag of flags) {
|
|
25
|
+
if (!ALLOWED_FLAGS.includes(flag)) {
|
|
26
|
+
throw new TypeError(`regex flags contain unsupported flag: ${flag}`);
|
|
27
|
+
}
|
|
28
|
+
if (seen.has(flag)) {
|
|
29
|
+
throw new TypeError(`regex flags contain duplicate flag: ${flag}`);
|
|
30
|
+
}
|
|
31
|
+
seen.add(flag);
|
|
32
|
+
}
|
|
33
|
+
return [...ALLOWED_FLAGS].filter((flag) => seen.has(flag)).join("");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function stateOf(pattern) {
|
|
37
|
+
const state = patternStates.get(pattern);
|
|
38
|
+
if (state === undefined) {
|
|
39
|
+
throw new TypeError("operation requires an Eliscript regex pattern");
|
|
40
|
+
}
|
|
41
|
+
return state;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function nativePattern(pattern, global = false) {
|
|
45
|
+
const state = stateOf(pattern);
|
|
46
|
+
return new RegExp(state.source, global ? `${state.flags}g` : state.flags);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function matchValue(match) {
|
|
50
|
+
if (match.length === 1) return match[0];
|
|
51
|
+
return persistentVector(...Array.from(
|
|
52
|
+
match,
|
|
53
|
+
(value) => value === undefined ? null : value,
|
|
54
|
+
));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function requireStart(value) {
|
|
58
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
59
|
+
throw new TypeError("regex start must be a non-negative safe integer");
|
|
60
|
+
}
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function advanceStringIndex(text, index, unicode) {
|
|
65
|
+
if (!unicode || index + 1 >= text.length) return index + 1;
|
|
66
|
+
const first = text.charCodeAt(index);
|
|
67
|
+
if (first < 0xD800 || first > 0xDBFF) return index + 1;
|
|
68
|
+
const second = text.charCodeAt(index + 1);
|
|
69
|
+
return second >= 0xDC00 && second <= 0xDFFF ? index + 2 : index + 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function advanceEmptyMatch(matcher, text, match) {
|
|
73
|
+
if (match[0] === "") {
|
|
74
|
+
matcher.lastIndex = advanceStringIndex(
|
|
75
|
+
text,
|
|
76
|
+
matcher.lastIndex,
|
|
77
|
+
matcher.unicode,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function scanIterator(pattern, text, start) {
|
|
83
|
+
const matcher = nativePattern(pattern, true);
|
|
84
|
+
matcher.lastIndex = start;
|
|
85
|
+
return (function* matches() {
|
|
86
|
+
while (true) {
|
|
87
|
+
const match = matcher.exec(text);
|
|
88
|
+
if (match === null) return;
|
|
89
|
+
advanceEmptyMatch(matcher, text, match);
|
|
90
|
+
yield matchValue(match);
|
|
91
|
+
}
|
|
92
|
+
})();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function compileRegex(...arguments_) {
|
|
96
|
+
if (arguments_.length < 1 || arguments_.length > 2) {
|
|
97
|
+
throw new TypeError("compileRegex expects a source and optional flags");
|
|
98
|
+
}
|
|
99
|
+
const source = requireString(arguments_[0], "regex source");
|
|
100
|
+
const flags = normalizeFlags(arguments_.length === 2 ? arguments_[1] : "");
|
|
101
|
+
try {
|
|
102
|
+
new RegExp(source, flags);
|
|
103
|
+
} catch {
|
|
104
|
+
throw new SyntaxError("regex source is invalid");
|
|
105
|
+
}
|
|
106
|
+
const pattern = Object.freeze({});
|
|
107
|
+
patternStates.set(pattern, Object.freeze({ source, flags }));
|
|
108
|
+
return pattern;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isRegexPattern(value) {
|
|
112
|
+
requireArity(arguments.length, 1, "isRegexPattern");
|
|
113
|
+
return patternStates.has(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function regexSource(pattern) {
|
|
117
|
+
requireArity(arguments.length, 1, "regexSource");
|
|
118
|
+
return stateOf(pattern).source;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function regexFlags(pattern) {
|
|
122
|
+
requireArity(arguments.length, 1, "regexFlags");
|
|
123
|
+
return stateOf(pattern).flags;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function regexMatches(pattern, text) {
|
|
127
|
+
requireArity(arguments.length, 2, "regexMatches");
|
|
128
|
+
const input = requireString(text, "regex input");
|
|
129
|
+
const match = nativePattern(pattern).exec(input);
|
|
130
|
+
return match !== null && match.index === 0 && match[0].length === input.length
|
|
131
|
+
? matchValue(match)
|
|
132
|
+
: null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function regexFind(...arguments_) {
|
|
136
|
+
if (arguments_.length < 2 || arguments_.length > 3) {
|
|
137
|
+
throw new TypeError("regexFind expects a pattern, input, and optional start");
|
|
138
|
+
}
|
|
139
|
+
const input = requireString(arguments_[1], "regex input");
|
|
140
|
+
const start = requireStart(arguments_.length === 3 ? arguments_[2] : 0);
|
|
141
|
+
const matcher = nativePattern(arguments_[0], true);
|
|
142
|
+
matcher.lastIndex = start;
|
|
143
|
+
const match = matcher.exec(input);
|
|
144
|
+
return match === null ? null : matchValue(match);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function regexSequence(...arguments_) {
|
|
148
|
+
if (arguments_.length < 2 || arguments_.length > 3) {
|
|
149
|
+
throw new TypeError("regexSequence expects a pattern, input, and optional start");
|
|
150
|
+
}
|
|
151
|
+
const pattern = arguments_[0];
|
|
152
|
+
stateOf(pattern);
|
|
153
|
+
const input = requireString(arguments_[1], "regex input");
|
|
154
|
+
const start = requireStart(arguments_.length === 3 ? arguments_[2] : 0);
|
|
155
|
+
return memoizedSequenceView(() => scanIterator(pattern, input, start));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function regexReplace(pattern, replacement, text) {
|
|
159
|
+
requireArity(arguments.length, 3, "regexReplace");
|
|
160
|
+
stateOf(pattern);
|
|
161
|
+
const input = requireString(text, "regex input");
|
|
162
|
+
if (typeof replacement !== "string" && typeof replacement !== "function") {
|
|
163
|
+
throw new TypeError("regex replacement must be a string or function");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const matcher = nativePattern(pattern, true);
|
|
167
|
+
let cursor = 0;
|
|
168
|
+
let output = "";
|
|
169
|
+
while (true) {
|
|
170
|
+
const match = matcher.exec(input);
|
|
171
|
+
if (match === null) break;
|
|
172
|
+
output += input.slice(cursor, match.index);
|
|
173
|
+
const value = typeof replacement === "function"
|
|
174
|
+
? replacement(matchValue(match), match.index, input)
|
|
175
|
+
: replacement;
|
|
176
|
+
if (typeof value !== "string") {
|
|
177
|
+
throw new TypeError("regex replacement function must return a string");
|
|
178
|
+
}
|
|
179
|
+
output += value;
|
|
180
|
+
cursor = match.index + match[0].length;
|
|
181
|
+
advanceEmptyMatch(matcher, input, match);
|
|
182
|
+
}
|
|
183
|
+
return output + input.slice(cursor);
|
|
184
|
+
}
|