hclang 0.29.1 → 0.31.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.
|
@@ -1279,6 +1279,30 @@ export const HC_SOURCES = new Map([
|
|
|
1279
1279
|
" .absent (_ &| {.f _; ((kids &| {(_ === f) ? {[f]}}) = []) ? {[f]}});",
|
|
1280
1280
|
" (absent = []) ? {B} : {A}};",
|
|
1281
1281
|
"```",
|
|
1282
|
+
"**Gap**, `x.gap()`: the absolute value of the alternating sum of the Sizes of",
|
|
1283
|
+
"x's immediate children, `|Size(F₁) − Size(F₂) + Size(F₃) − …|`, read as a",
|
|
1284
|
+
"FrameCount. The empty Figure has Gap `0`, and each child contributes its",
|
|
1285
|
+
"existing Size with a sign that starts positive and flips child by child; Gap",
|
|
1286
|
+
"keeps the sum's size and drops its sign, so it is never negative. Nesting",
|
|
1287
|
+
"reaches a child only through that Size, never through its construction. Gap",
|
|
1288
|
+
"observes rather than constructs, so like Cells, Form and Text it leaves the",
|
|
1289
|
+
"class on purpose: the sum it folds can go negative where no Figure does, so it",
|
|
1290
|
+
"is read as a number rather than a tally (#445). It reads each child's Size the",
|
|
1291
|
+
"way the semiring examples do, as `(_.size()).children.#`, and folds those",
|
|
1292
|
+
"readings with native arithmetic without touching construction, so it never",
|
|
1293
|
+
"asserts arithmetic equations or actual closure: a zero Gap is an observed",
|
|
1294
|
+
"value, not a proof. `_^`",
|
|
1295
|
+
"names the receiver so the alternating fold can read the children in order; the",
|
|
1296
|
+
"fold subtracts the sum of the rest, which flips the sign of every later child,",
|
|
1297
|
+
"and the sign of the whole is dropped last",
|
|
1298
|
+
"```;",
|
|
1299
|
+
" .gap {.kids _^.children;",
|
|
1300
|
+
" .count {(_.size()).children.#};",
|
|
1301
|
+
" .tail {(_ && {(((_ .0) = .0) ? {[()]} : {[[__ .1]]}) .0}) &| {_}};",
|
|
1302
|
+
" .alt {.cs _; (cs = []) ? {0} : {(count (cs .0)) - (alt (tail cs))}};",
|
|
1303
|
+
" .signed (alt kids);",
|
|
1304
|
+
" (signed .< 0) ? {0 - signed} : {signed}};",
|
|
1305
|
+
"```",
|
|
1282
1306
|
"**Form**, `x.form()`: the plain bracket tree of x, one bracket per Figure, the",
|
|
1283
1307
|
"way 005.30c wrote Figures before they were a class. It keeps shape and order,",
|
|
1284
1308
|
"and forgets identity and the methods",
|
|
@@ -1549,6 +1573,44 @@ export const HC_SOURCES = new Map([
|
|
|
1549
1573
|
"; [A.withness [B], B.withness []] = [A, B]",
|
|
1550
1574
|
"# <>",
|
|
1551
1575
|
"```",
|
|
1576
|
+
"## Gap",
|
|
1577
|
+
"",
|
|
1578
|
+
"Gap reads the Sizes of a Figure's immediate children, folds them with",
|
|
1579
|
+
"alternating signs, `Size(F₁) − Size(F₂) + Size(F₃) − …`, starting positive, and",
|
|
1580
|
+
"drops the sign. It observes rather than constructs, so it answers a FrameCount,",
|
|
1581
|
+
"never negative, and the empty Figure has Gap `0`. One child is its",
|
|
1582
|
+
"own Size, so `A` and `U` both have Gap `0` because `U`'s one child `Z` has Size",
|
|
1583
|
+
"`0`, while a Figure holding `row2` has Gap `2`. Two children are the difference",
|
|
1584
|
+
"of their Sizes, whichever comes first",
|
|
1585
|
+
"```",
|
|
1586
|
+
"; [(A.gap()) = 0, (U.gap()) = 0, ((Figure [row2]).gap()) = 2, ((Figure [row2, row3]).gap()) = 1, ((Figure [row3, row2]).gap()) = 1]",
|
|
1587
|
+
"# [<>, <>, <>, <>, <>]",
|
|
1588
|
+
"```",
|
|
1589
|
+
"Each child contributes its existing Size, so nesting reaches a child only",
|
|
1590
|
+
"through that Size: a one-child Figure's Gap is that child's Size whatever its",
|
|
1591
|
+
"nesting, and `deep4` nests `row4` to Size 4. The minimal witness is three",
|
|
1592
|
+
"children of Sizes 2, 5 and 3, whose Gap is `0`; the Sizes come from ordinary",
|
|
1593
|
+
"Figures and `row5` is one of Size 5",
|
|
1594
|
+
"```",
|
|
1595
|
+
"; .row5 (Figure [U, U, U, U, U]);",
|
|
1596
|
+
"; [(row5.size()).children.# = 5, ((Figure [row2, row5, row3]).gap()) = 0, ((Figure [row4]).gap()) = 4]",
|
|
1597
|
+
"# [<>, <>, <>]",
|
|
1598
|
+
"; [((Figure [row2, row5, row3]).gap()) = (((row2.size()).children.#) - ((row5.size()).children.#) + ((row3.size()).children.#))]",
|
|
1599
|
+
"# [<>]",
|
|
1600
|
+
"```",
|
|
1601
|
+
"Order still matters: reordering the same three children can change Gap,",
|
|
1602
|
+
"and it is an observation only, never a claim that a Walk is closed",
|
|
1603
|
+
"```",
|
|
1604
|
+
"; [((Figure [row2, row3, row5]).gap()) = 4, ((Figure [row5, row2, row3]).gap()) = 6, ((Figure [row3, row2, row5]).gap()) = 6]",
|
|
1605
|
+
"# [<>, <>, <>]",
|
|
1606
|
+
"```",
|
|
1607
|
+
"A child's own Size decides its contribution, so a child built differently but of",
|
|
1608
|
+
"equal Size contributes the same, and construction, observation and",
|
|
1609
|
+
"interpretation stay apart: Gap reports a number, not a meaning",
|
|
1610
|
+
"```",
|
|
1611
|
+
"; [((Figure [deep4, row2, row3]).gap()) = ((Figure [row4, row2, row3]).gap()), ((Figure [Z, U]).gap()) = 1]",
|
|
1612
|
+
"# [<>, <>]",
|
|
1613
|
+
"```",
|
|
1552
1614
|
"## The Fano plane",
|
|
1553
1615
|
"",
|
|
1554
1616
|
"Seven originals of identical form, each a fresh `Figure []`, and seven triples",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Frame, FrameExpr, FrameSymbol, hasCharacterContent, } from "../frames.js";
|
|
1
|
+
import { Frame, FrameExpr, FrameGroup, FrameLazy, FrameResource, FrameSymbol, hasCharacterContent, } from "../frames.js";
|
|
2
2
|
import { EvalPipe, makeSourcePipe } from "./eval-pipe.js";
|
|
3
|
+
import { LexPipe } from "./lex-pipe.js";
|
|
4
|
+
import { ParsePipe } from "./parse-pipe.js";
|
|
3
5
|
import { sigilizer } from "./sigilizer.js";
|
|
4
6
|
/** Private output state for one imported source evaluation. */
|
|
5
7
|
class ImportProgress extends Frame {
|
|
@@ -164,3 +166,90 @@ function evaluateResourceSourceWithChain(resource, scope, activeImports) {
|
|
|
164
166
|
return finished;
|
|
165
167
|
return progress.firstFailure ?? progress.lastResult;
|
|
166
168
|
}
|
|
169
|
+
/** Holds what the parser emits for a quoted source, evaluating nothing. */
|
|
170
|
+
class QuoteSink extends Frame {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments);
|
|
173
|
+
Object.defineProperty(this, "parsed", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
configurable: true,
|
|
176
|
+
writable: true,
|
|
177
|
+
value: []
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
call(value) {
|
|
181
|
+
// The root pipe passes its terminal, nil, after the parsed form.
|
|
182
|
+
if (!value.is.immediate && value !== Frame.nil)
|
|
183
|
+
this.parsed.push(value);
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* A resource read as an unevaluated closure (#443): the import, stopped
|
|
189
|
+
* before evaluation.
|
|
190
|
+
*
|
|
191
|
+
* The characters pass through the import's own front end, so a testdoc's
|
|
192
|
+
* example lines are dropped and `<-` becomes an inert import, between `{` and
|
|
193
|
+
* `}`. A file's lines are therefore the comma terms of one body, as its lines
|
|
194
|
+
* are one comma expression at top level, and calling the closure answers what
|
|
195
|
+
* running the file answers. Nothing in the file runs until it is called. The
|
|
196
|
+
* closure is bound at `site`, where the read was written, as any closure
|
|
197
|
+
* written there would be.
|
|
198
|
+
*/
|
|
199
|
+
export function quoteResourceSource(resource, site) {
|
|
200
|
+
if (!(resource instanceof FrameResource))
|
|
201
|
+
return sourceTypeFailure(resource);
|
|
202
|
+
const sink = new QuoteSink();
|
|
203
|
+
const lexer = new LexPipe(new ParsePipe(sink, FrameGroup, {
|
|
204
|
+
importSource: evaluateResourceSource,
|
|
205
|
+
strictStructure: true,
|
|
206
|
+
}));
|
|
207
|
+
let receiver = lexer;
|
|
208
|
+
const scan = (character) => {
|
|
209
|
+
receiver = sigilizer.scan(receiver, FrameSymbol.for(character));
|
|
210
|
+
return receiver.isFailedResult() ? receiver : undefined;
|
|
211
|
+
};
|
|
212
|
+
const examples = new ExampleFilter();
|
|
213
|
+
const opened = scan("{");
|
|
214
|
+
if (opened)
|
|
215
|
+
return opened;
|
|
216
|
+
for (const element of resource.elements()) {
|
|
217
|
+
if (element.isFailedResult())
|
|
218
|
+
return element;
|
|
219
|
+
if (!hasCharacterContent(element))
|
|
220
|
+
return sourceTypeFailure(element);
|
|
221
|
+
for (const character of element.characterContent().split("")) {
|
|
222
|
+
const prose = receiver.is.document === true;
|
|
223
|
+
for (const kept of examples.filter(character, prose)) {
|
|
224
|
+
const failure = scan(kept);
|
|
225
|
+
if (failure)
|
|
226
|
+
return failure;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const kept of [...examples.flush(), "\n", "}"]) {
|
|
231
|
+
const failure = scan(kept);
|
|
232
|
+
if (failure)
|
|
233
|
+
return failure;
|
|
234
|
+
}
|
|
235
|
+
receiver = sigilizer.finish(receiver, FrameSymbol.end());
|
|
236
|
+
if (receiver.isFailedResult())
|
|
237
|
+
return receiver;
|
|
238
|
+
const finished = lexer.finish(Frame.nil);
|
|
239
|
+
if (finished.isFailedResult())
|
|
240
|
+
return finished;
|
|
241
|
+
const closure = quotedClosure(sink.parsed);
|
|
242
|
+
if (!closure) {
|
|
243
|
+
return Frame.error(`$!.resource-quote-syntax ${resource.toString()}`);
|
|
244
|
+
}
|
|
245
|
+
return site ? closure.bind(site) : closure;
|
|
246
|
+
}
|
|
247
|
+
/** The one closure a quoted source parses to, through its wrappers. */
|
|
248
|
+
function quotedClosure(parsed) {
|
|
249
|
+
let found = parsed.length === 1 ? parsed[0] : undefined;
|
|
250
|
+
while (found && !(found instanceof FrameLazy) && found.asArray().length === 1) {
|
|
251
|
+
found = found.asArray()[0];
|
|
252
|
+
}
|
|
253
|
+
return found instanceof FrameLazy ? found : undefined;
|
|
254
|
+
}
|
|
255
|
+
FrameLazy.quote = quoteResourceSource;
|
|
@@ -30,26 +30,40 @@ export class FrameExpr extends FrameList {
|
|
|
30
30
|
return FrameExpr.evaluateTerms(this.data, scope);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* Evaluates a closure body
|
|
33
|
+
* Evaluates a closure body: `;` sequences, and `,` collects, as everywhere.
|
|
34
34
|
*
|
|
35
35
|
* `sequence` records that the author wrote `;` between terms, so intent comes
|
|
36
|
-
* from the parser rather than from inspecting flags on the body's children.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
36
|
+
* from the parser rather than from inspecting flags on the body's children.
|
|
37
|
+
* Terms the source separated with `,`, or with a newline, which is the same
|
|
38
|
+
* separator, form one comma expression, and a comma expression is the group
|
|
39
|
+
* of its terms' values, as it is at top level and in a group (#443). So
|
|
40
|
+
* `{3, 4} ()` answers `(3, 4)`, as `3, 4` does. The group does not declare,
|
|
41
|
+
* so its declarations land in the call's own frame, as top level's land in
|
|
42
|
+
* the file: `{.a 1, .b 2; a + b} ()` is `3`.
|
|
39
43
|
*
|
|
40
|
-
* A
|
|
41
|
-
*
|
|
44
|
+
* A body assembled programmatically from bare atoms, or from statements with
|
|
45
|
+
* no recorded `;`, stays one juxtaposed expression, which is what the Frame
|
|
46
|
+
* API has always meant by a multi-item body. A one-term body keeps its
|
|
47
|
+
* existing value and representation either way, so a trailing separator
|
|
48
|
+
* alone does not unwrap a single statement.
|
|
42
49
|
*/
|
|
43
50
|
static evaluateBody(body, input, sequence = false) {
|
|
44
51
|
const scope = EvaluationScope.from(input);
|
|
45
|
-
if (body.length === 1
|
|
52
|
+
if (body.length === 1)
|
|
46
53
|
return FrameExpr.evaluateTerms(body, scope);
|
|
54
|
+
if (!sequence) {
|
|
55
|
+
return isCommaExpression(body)
|
|
56
|
+
? FrameExpr.commaGroup(body, scope)
|
|
57
|
+
: FrameExpr.evaluateTerms(body, scope);
|
|
47
58
|
}
|
|
48
59
|
let result = Frame.nil;
|
|
49
|
-
for (const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
for (const run of commaRuns(body)) {
|
|
61
|
+
const [item] = run;
|
|
62
|
+
result = run.length > 1
|
|
63
|
+
? FrameExpr.commaGroup(run, scope)
|
|
64
|
+
: item instanceof FrameExpr
|
|
65
|
+
? item.evaluate(scope)
|
|
66
|
+
: item.in(scope);
|
|
53
67
|
// A sequence stops at the first failing statement, because later
|
|
54
68
|
// statements were written to run after the earlier ones succeeded.
|
|
55
69
|
if (result.isFailedResult())
|
|
@@ -278,6 +292,32 @@ export function atomsOf(terms, sites = new Map(), resume) {
|
|
|
278
292
|
}
|
|
279
293
|
return atoms;
|
|
280
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Whether a body's terms are one comma expression: two or more parsed terms
|
|
297
|
+
* the source separated with `,`, rather than bare atoms or statements.
|
|
298
|
+
*/
|
|
299
|
+
function isCommaExpression(terms) {
|
|
300
|
+
return terms.length > 1 &&
|
|
301
|
+
terms.every((term) => term.isPlainExpression() && term.is.statement !== true);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* A sequenced body split at its `;`s: each run is the terms of one statement,
|
|
305
|
+
* a comma expression when it has more than one.
|
|
306
|
+
*/
|
|
307
|
+
function commaRuns(body) {
|
|
308
|
+
const runs = [];
|
|
309
|
+
let run = [];
|
|
310
|
+
for (const term of body) {
|
|
311
|
+
run.push(term);
|
|
312
|
+
if (term.is.statement === true) {
|
|
313
|
+
runs.push(run);
|
|
314
|
+
run = [];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (run.length > 0)
|
|
318
|
+
runs.push(run);
|
|
319
|
+
return runs;
|
|
320
|
+
}
|
|
281
321
|
/** The atom a term begins with, through the parser's one-term wrappers. */
|
|
282
322
|
function firstAtom(term) {
|
|
283
323
|
let atom = term;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
|
|
2
2
|
// FrameExpr exist before any subclass, whichever module is imported first.
|
|
3
3
|
import "./frame-lazy.js";
|
|
4
|
+
import { FrameExpr } from "./frame-expr.js";
|
|
4
5
|
import { Frame } from "./frame.js";
|
|
5
6
|
import { FrameList } from "./frame-list.js";
|
|
6
7
|
import { NilContext } from "./context.js";
|
|
@@ -73,3 +74,9 @@ Object.defineProperty(FrameGroup, "SIGIL_STARTS", {
|
|
|
73
74
|
{ key: Frame.END_EXPR, mode: "pop" },
|
|
74
75
|
]
|
|
75
76
|
});
|
|
77
|
+
/**
|
|
78
|
+
* A comma expression in a closure body is a group that declares nothing of
|
|
79
|
+
* its own, as the parser's top-level wrapper is, so its declarations land in
|
|
80
|
+
* the call's frame (#443).
|
|
81
|
+
*/
|
|
82
|
+
FrameExpr.commaGroup = (terms, scope) => new FrameGroup([...terms], {}).in(scope);
|
package/esm/lib/ops/iterators.js
CHANGED
|
@@ -5,6 +5,7 @@ import { FrameSymbol } from "../frames/frame-symbol.js";
|
|
|
5
5
|
import { BoundMethod } from "../frames/bound-method.js";
|
|
6
6
|
import { FrameLazy } from "../frames/frame-lazy.js";
|
|
7
7
|
import { FrameList } from "../frames/frame-list.js";
|
|
8
|
+
import { FrameResource } from "../frames/frame-resource.js";
|
|
8
9
|
import { FrameWord } from "../frames/frame-word.js";
|
|
9
10
|
import { FrameScoped } from "../frames/frame-expr.js";
|
|
10
11
|
import { closureFromAtoms } from "../frames/reread.js";
|
|
@@ -69,6 +70,12 @@ export const SpliceElements = (source, receiver, receiverState) => new FrameArra
|
|
|
69
70
|
* `{…} | (args)` is a second spelling of `{…} (args)`.
|
|
70
71
|
*/
|
|
71
72
|
export const ReduceElements = (source, receiver, receiverState, site) => {
|
|
73
|
+
// A resource folded into the empty closure is read as one: parsed, not
|
|
74
|
+
// evaluated, so a file can be walked before anything in it runs (#443).
|
|
75
|
+
if (FrameLazy.quote && receiver instanceof FrameLazy &&
|
|
76
|
+
receiver.size() === 0 && source.referent() instanceof FrameResource) {
|
|
77
|
+
return FrameLazy.quote(source.referent(), site);
|
|
78
|
+
}
|
|
72
79
|
const code = source instanceof FrameScoped
|
|
73
80
|
? source.live()
|
|
74
81
|
: source.referent();
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.31.0";
|