hclang 0.21.0 → 0.21.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/esm/lib/bundle/hc-sources.js +15 -0
- package/esm/lib/frames/context.js +3 -2
- package/esm/lib/frames/frame-array.js +3 -0
- package/esm/lib/frames/frame-count.js +4 -0
- package/esm/lib/frames/frame-group.js +3 -0
- package/esm/lib/frames/frame-list.js +37 -0
- package/esm/lib/frames/frame-name.js +9 -0
- package/esm/lib/frames/frame-schema.js +3 -0
- package/esm/lib/frames/frame-symbol.js +7 -0
- package/esm/lib/frames/frame.js +25 -0
- package/esm/lib/frames/schema-matcher.js +3 -0
- package/esm/lib/ops/conditionals.js +2 -1
- package/esm/lib/ops/iterators.js +4 -1
- package/esm/lib/ops/math.js +3 -1
- package/esm/lib/ops/type-operations.js +5 -1
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -616,6 +616,21 @@ export const HC_SOURCES = new Map([
|
|
|
616
616
|
"; [.a 1] & {_}",
|
|
617
617
|
"# []",
|
|
618
618
|
"```",
|
|
619
|
+
"`.#` and `.##` count the elements too, the immediate ones and the leaves below",
|
|
620
|
+
"them, so neither counts a property. Every aggregate counts this way, a group as",
|
|
621
|
+
"well as an array. A count is its own size, and any other value has none (#411)",
|
|
622
|
+
"```",
|
|
623
|
+
"; [.meta 1; 2, 3] .#",
|
|
624
|
+
"# 2",
|
|
625
|
+
"; [.meta [1, 2]; [3, []], 4] .##",
|
|
626
|
+
"# 2",
|
|
627
|
+
"; (1, [2, 3]) .##",
|
|
628
|
+
"# 3",
|
|
629
|
+
"; 5.#",
|
|
630
|
+
"# 5",
|
|
631
|
+
"; “abc”.#",
|
|
632
|
+
"# ()",
|
|
633
|
+
"```",
|
|
619
634
|
"**Decision.** Canonical rendering puts the properties first, then the elements.",
|
|
620
635
|
"This reverses the spelling this file carried before. It makes print order agree",
|
|
621
636
|
"with the order the doubled operators iterate, and it leaves canonical output",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Frame } from "./frame.js";
|
|
2
1
|
/**
|
|
3
2
|
* NilContext is an empty context.
|
|
4
3
|
*/
|
|
@@ -31,7 +30,9 @@ export function contextEqual(left, right) {
|
|
|
31
30
|
*/
|
|
32
31
|
export function contextString(context) {
|
|
33
32
|
return Object.entries(context).map(([key, value]) => {
|
|
34
|
-
|
|
33
|
+
// `Frame.kOUT`, spelled out so this module imports Frame only as a type:
|
|
34
|
+
// a value import would evaluate frame.ts, which needs NilContext, first.
|
|
35
|
+
if (key === ">>") {
|
|
35
36
|
return `.${key} ${value.id};`;
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
|
|
2
|
+
// FrameExpr exist before any subclass, whichever module is imported first.
|
|
3
|
+
import "./frame-lazy.js";
|
|
1
4
|
import { Frame } from "./frame.js";
|
|
2
5
|
import { BoundMethod } from "./bound-method.js";
|
|
3
6
|
import { methodEffect } from "./effect-marker.js";
|
|
@@ -30,6 +30,10 @@ export class FrameCount extends FrameInt {
|
|
|
30
30
|
throw new RangeError(`count must not be negative: ${this.spelling}`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/** A count is its own size, so `.#` and `.##` both answer it (#411). */
|
|
34
|
+
sizeFor(_key) {
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
33
37
|
promoteOne() {
|
|
34
38
|
return new FrameInt(this.data);
|
|
35
39
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
|
|
2
|
+
// FrameExpr exist before any subclass, whichever module is imported first.
|
|
3
|
+
import "./frame-lazy.js";
|
|
1
4
|
import { Frame } from "./frame.js";
|
|
2
5
|
import { FrameList } from "./frame-list.js";
|
|
3
6
|
import { NilContext } from "./context.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Frame } from "./frame.js";
|
|
2
2
|
import { NilContext } from "./context.js";
|
|
3
3
|
import { EvaluationScope } from "./evaluation-scope.js";
|
|
4
|
+
import { FrameCount } from "./frame-count.js";
|
|
4
5
|
import { renderNested } from "./stringify.js";
|
|
5
6
|
/**
|
|
6
7
|
* The declaration a term recorded, when it is a declaration echo.
|
|
@@ -105,6 +106,42 @@ export class FrameList extends Frame {
|
|
|
105
106
|
elements() {
|
|
106
107
|
return this.data.filter((item) => item.is.statement !== true && !this.holdsAsProperty(item));
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* `.#` counts this aggregate's elements and `.##` the leaves below them
|
|
111
|
+
* (#411), so neither counts a property. Every aggregate is a list, so each
|
|
112
|
+
* one answers here rather than in its own class.
|
|
113
|
+
*/
|
|
114
|
+
sizeFor(key) {
|
|
115
|
+
if (key === Frame.kCOUNT) {
|
|
116
|
+
return new FrameCount(BigInt(this.elements().length));
|
|
117
|
+
}
|
|
118
|
+
const leaves = this.leafCount(new Set());
|
|
119
|
+
return leaves === undefined
|
|
120
|
+
? Frame.error(`$!.cyclic-aggregate .${key}`)
|
|
121
|
+
: new FrameCount(leaves);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The leaves below this aggregate: each element that is not itself an
|
|
125
|
+
* aggregate counts once, at any depth, so an empty aggregate adds none.
|
|
126
|
+
* `path` holds only the aggregates from the root down to this one, so a
|
|
127
|
+
* branch reached twice counts twice, and one that contains itself answers
|
|
128
|
+
* undefined.
|
|
129
|
+
*/
|
|
130
|
+
leafCount(path) {
|
|
131
|
+
if (path.has(this))
|
|
132
|
+
return undefined;
|
|
133
|
+
path.add(this);
|
|
134
|
+
let leaves = 0n;
|
|
135
|
+
for (const element of this.elements()) {
|
|
136
|
+
const value = element.referent();
|
|
137
|
+
const below = value instanceof FrameList ? value.leafCount(path) : 1n;
|
|
138
|
+
if (below === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
leaves += below;
|
|
141
|
+
}
|
|
142
|
+
path.delete(this);
|
|
143
|
+
return leaves;
|
|
144
|
+
}
|
|
108
145
|
/**
|
|
109
146
|
* The value a term answered, looking through a statement's wrapper.
|
|
110
147
|
*
|
|
@@ -23,6 +23,15 @@ const recognizeName = (symbol, source = "") => {
|
|
|
23
23
|
if (source.endsWith("^")) {
|
|
24
24
|
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
25
25
|
}
|
|
26
|
+
// `#` begins a comment except where it spells a size operator, `.#` or `.##`
|
|
27
|
+
// (#411), which nothing extends: `.foo#bar` still ends at its `#`, and `.###`
|
|
28
|
+
// is `.##` before a comment.
|
|
29
|
+
if ([Frame.kCOUNT, Frame.kLEAVES].includes(source + char)) {
|
|
30
|
+
return { disposition: ScanDisposition.Consume };
|
|
31
|
+
}
|
|
32
|
+
if (source.startsWith(Frame.kCOUNT)) {
|
|
33
|
+
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
34
|
+
}
|
|
26
35
|
// `.^` needs no rule of its own: `^` is an operator character, so it is
|
|
27
36
|
// consumed and completed like any other name.
|
|
28
37
|
if (!includes(char)) {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
|
|
2
|
+
// FrameExpr exist before any subclass, whichever module is imported first.
|
|
3
|
+
import "./frame-lazy.js";
|
|
1
4
|
import { Frame } from "./frame.js";
|
|
2
5
|
import { FrameList } from "./frame-list.js";
|
|
3
6
|
import { FrameNote } from "./frame-note.js";
|
|
@@ -260,6 +260,13 @@ export class FrameSymbol extends FrameAtom {
|
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
262
|
called_by(context) {
|
|
263
|
+
// A size operator answers for the receiver itself rather than looking a
|
|
264
|
+
// name up, so the scope a value was read from never answers for it (#411).
|
|
265
|
+
// Only an address is one, since the lexer looks `#` up as the comment.
|
|
266
|
+
if (this.is.address === true &&
|
|
267
|
+
(this.data === Frame.kCOUNT || this.data === Frame.kLEAVES)) {
|
|
268
|
+
return context.referent().sizeFor(this.data);
|
|
269
|
+
}
|
|
263
270
|
return this.in([context]);
|
|
264
271
|
}
|
|
265
272
|
string_start() {
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -210,6 +210,13 @@ export class Frame extends MetaFrame {
|
|
|
210
210
|
referent() {
|
|
211
211
|
return this;
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* What this frame answers for a size operator, `.#` or `.##` (#411). Only an
|
|
215
|
+
* aggregate counts and a count is its own size, so anything else is nil.
|
|
216
|
+
*/
|
|
217
|
+
sizeFor(_key) {
|
|
218
|
+
return Frame.nil;
|
|
219
|
+
}
|
|
213
220
|
/**
|
|
214
221
|
* Get a frame by key from this frame's own properties and its declared
|
|
215
222
|
* parents only, never its lexical scope.
|
|
@@ -504,6 +511,24 @@ Object.defineProperty(Frame, "kEND", {
|
|
|
504
511
|
writable: true,
|
|
505
512
|
value: "$$"
|
|
506
513
|
});
|
|
514
|
+
/**
|
|
515
|
+
* kCOUNT is the size operator `.#`, an aggregate's element count (#411).
|
|
516
|
+
*/
|
|
517
|
+
Object.defineProperty(Frame, "kCOUNT", {
|
|
518
|
+
enumerable: true,
|
|
519
|
+
configurable: true,
|
|
520
|
+
writable: true,
|
|
521
|
+
value: "#"
|
|
522
|
+
});
|
|
523
|
+
/**
|
|
524
|
+
* kLEAVES is the size operator `.##`, an aggregate's leaf count (#411).
|
|
525
|
+
*/
|
|
526
|
+
Object.defineProperty(Frame, "kLEAVES", {
|
|
527
|
+
enumerable: true,
|
|
528
|
+
configurable: true,
|
|
529
|
+
writable: true,
|
|
530
|
+
value: "##"
|
|
531
|
+
});
|
|
507
532
|
/**
|
|
508
533
|
* BEGIN_EXPR is the symbol for the beginning of an expression.
|
|
509
534
|
*/
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Load the FrameList cycle from FrameLazy, where it closes, so FrameList and
|
|
2
|
+
// FrameExpr exist before any subclass, whichever module is imported first.
|
|
3
|
+
import "./frame-lazy.js";
|
|
1
4
|
import { Frame } from "./frame.js";
|
|
2
5
|
import { FrameList } from "./frame-list.js";
|
|
3
6
|
import { isFrameMatcher, matchFailure, matchSuccess, } from "./frame-match.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
|
|
2
|
+
import { Frame } from "../frames/frame.js";
|
|
2
3
|
export const IfThen = (source, block, receiverState) => {
|
|
3
4
|
if (source !== Frame.nil) {
|
|
4
5
|
return block.call(Frame.nil, Frame.nil, receiverState);
|
package/esm/lib/ops/iterators.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
|
|
2
|
+
import { Frame } from "../frames/frame.js";
|
|
3
|
+
import { FrameArray } from "../frames/frame-array.js";
|
|
4
|
+
import { FrameSymbol } from "../frames/frame-symbol.js";
|
|
2
5
|
/**
|
|
3
6
|
* Iteration is application, twice.
|
|
4
7
|
*
|
package/esm/lib/ops/math.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
|
|
2
|
+
import { Frame } from "../frames/frame.js";
|
|
3
|
+
import { FrameNumeric } from "../frames/frame-numeric.js";
|
|
2
4
|
const numeric = (source, block, operation) => {
|
|
3
5
|
return source instanceof FrameNumeric && block instanceof FrameNumeric
|
|
4
6
|
? operation(source, block)
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// Direct, not ../frames.ts, whose ../ops.ts needs this module loaded first.
|
|
2
|
+
import { Frame } from "../frames/frame.js";
|
|
3
|
+
import { FrameLazy } from "../frames/frame-lazy.js";
|
|
4
|
+
import { FrameLiteral } from "../frames/frame-symbol.js";
|
|
5
|
+
import { isFrameMatcher } from "../frames/frame-match.js";
|
|
2
6
|
/** Test whether a value belongs to a first-class type or schema. */
|
|
3
7
|
export const HasType = (source, type) => {
|
|
4
8
|
if (type === Frame.all)
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.21.
|
|
1
|
+
export const VERSION = "0.21.1";
|