@shapeshift-labs/frontier-lang-parser 0.3.77 → 0.3.78

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/dist/index.d.ts CHANGED
@@ -97,6 +97,12 @@ export interface FrontierSourceSyntaxReport {
97
97
  readonly recognizedChildKinds: readonly string[];
98
98
  readonly unknownKinds: readonly string[];
99
99
  readonly unknownChildKinds: readonly string[];
100
+ readonly sourceSyntaxBlockFamilies: readonly string[];
101
+ readonly sourceSyntaxBlockFamilyCounts: Readonly<Record<string, number>>;
102
+ readonly sourceSyntaxRowFamilies: readonly string[];
103
+ readonly sourceSyntaxRowFamilyCounts: Readonly<Record<string, number>>;
104
+ readonly sourceSyntaxRowFamiliesByBlockFamily: Readonly<Record<string, readonly string[]>>;
105
+ readonly sourceSyntaxRowFamilyCountsByBlockFamily: Readonly<Record<string, Readonly<Record<string, number>>>>;
100
106
  readonly failClosed: boolean;
101
107
  readonly unsupportedSyntax: boolean;
102
108
  };
@@ -0,0 +1,63 @@
1
+ export function summarizeSourceSyntaxFamilies(blocks) {
2
+ const childEntries = blocks.flatMap((block) => (block.children ?? []).map((child) => ({
3
+ blockFamily: sourceSyntaxBlockFamily(block),
4
+ rowFamily: sourceSyntaxRowFamily(child)
5
+ })));
6
+ const blockFamilies = unique(blocks.map(sourceSyntaxBlockFamily));
7
+ return {
8
+ sourceSyntaxBlockFamilies: blockFamilies,
9
+ sourceSyntaxBlockFamilyCounts: countBy(blocks, sourceSyntaxBlockFamily),
10
+ sourceSyntaxRowFamilies: unique(childEntries.map((entry) => entry.rowFamily)),
11
+ sourceSyntaxRowFamilyCounts: countBy(childEntries, (entry) => entry.rowFamily),
12
+ sourceSyntaxRowFamiliesByBlockFamily: groupUniqueByKnownKeys(blockFamilies, childEntries, (entry) => entry.blockFamily, (entry) => entry.rowFamily),
13
+ sourceSyntaxRowFamilyCountsByBlockFamily: groupCountsByKnownKeys(blockFamilies, childEntries, (entry) => entry.blockFamily, (entry) => entry.rowFamily)
14
+ };
15
+ }
16
+
17
+ function sourceSyntaxBlockFamily(block) {
18
+ return block.kind ?? 'unknown';
19
+ }
20
+
21
+ function sourceSyntaxRowFamily(child) {
22
+ return child.recognized
23
+ ? child.family ?? child.normalizedRowKind ?? child.rowKind ?? child.kind ?? 'unknown'
24
+ : child.rowKind ?? child.normalizedRowKind ?? child.family ?? child.kind ?? 'unknown';
25
+ }
26
+
27
+ function countBy(values, keyFor) {
28
+ const counts = {};
29
+ for (const value of values) {
30
+ const key = keyFor(value);
31
+ if (!key) continue;
32
+ counts[key] = (counts[key] ?? 0) + 1;
33
+ }
34
+ return counts;
35
+ }
36
+
37
+ function groupUniqueByKnownKeys(keys, values, keyFor, valueFor) {
38
+ const groups = Object.fromEntries(keys.map((key) => [key, []]));
39
+ for (const value of values) {
40
+ const key = keyFor(value);
41
+ const item = valueFor(value);
42
+ if (!key || !item) continue;
43
+ groups[key] ??= [];
44
+ if (!groups[key].includes(item)) groups[key].push(item);
45
+ }
46
+ return groups;
47
+ }
48
+
49
+ function groupCountsByKnownKeys(keys, values, keyFor, valueFor) {
50
+ const groups = Object.fromEntries(keys.map((key) => [key, {}]));
51
+ for (const value of values) {
52
+ const key = keyFor(value);
53
+ const item = valueFor(value);
54
+ if (!key || !item) continue;
55
+ groups[key] ??= {};
56
+ groups[key][item] = (groups[key][item] ?? 0) + 1;
57
+ }
58
+ return groups;
59
+ }
60
+
61
+ function unique(values) {
62
+ return [...new Set(values.filter(Boolean))];
63
+ }
@@ -1,4 +1,5 @@
1
1
  import { readSourceSyntaxChildren } from './source-syntax-children.js';
2
+ import { summarizeSourceSyntaxFamilies } from './source-syntax-family-summary.js';
2
3
  import { FrontierSourceBlockKinds } from './source-block-kinds.js';
3
4
 
4
5
  export { FrontierSourceBlockKinds };
@@ -43,6 +44,7 @@ export function inspectFrontierSourceSyntax(source, options = {}) {
43
44
  ];
44
45
  const malformedBlocks = blocks.filter((block) => block.malformed);
45
46
  const failClosed = unknownBlocks.length > 0 || unknownChildren.length > 0 || diagnostics.length > 0;
47
+ const familySummary = summarizeSourceSyntaxFamilies(blocks);
46
48
  return {
47
49
  kind: 'frontier.lang.sourceSyntaxReport',
48
50
  version: 1,
@@ -65,6 +67,7 @@ export function inspectFrontierSourceSyntax(source, options = {}) {
65
67
  recognizedChildKinds: unique(childRecords.filter((child) => child.recognized).map((child) => child.kind)),
66
68
  unknownKinds: unique(unknownBlocks.map((block) => block.kind)),
67
69
  unknownChildKinds: unique(unknownChildren.map((child) => child.rowKind ?? child.kind)),
70
+ ...familySummary,
68
71
  failClosed,
69
72
  unsupportedSyntax: unknownBlocks.length > 0 || unknownChildren.length > 0
70
73
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-parser",
3
- "version": "0.3.77",
3
+ "version": "0.3.78",
4
4
  "description": "Parser for the first Frontier Lang .frontier syntax slice.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build": "node scripts/build.mjs",
25
- "test": "npm run build && node test/smoke.mjs && node test/member-identity-smoke.mjs && node test/generic-row-parse-identity-smoke.mjs && node test/type-variant-payload-smoke.mjs && node test/type-generic-ref-smoke.mjs && node test/type-parameter-constraints-smoke.mjs && node test/type-structural-expression-smoke.mjs && node test/action-body-smoke.mjs && node test/action-structured-literals-smoke.mjs && node test/action-return-smoke.mjs && node test/action-else-smoke.mjs && node test/action-match-smoke.mjs && node test/action-for-in-smoke.mjs && node test/action-repeat-smoke.mjs && node test/action-call-smoke.mjs && node test/semantic-operation-edit-smoke.mjs && node test/target-projection-aggregate-smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/conversion-evidence-smoke.mjs && node test/gate-admission-evidence-smoke.mjs && node test/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/view-source-syntax-smoke.mjs && node test/resource-graph-smoke.mjs && node test/machine-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
25
+ "test": "npm run build && node test/smoke.mjs && node test/source-syntax-family-summary-smoke.mjs && node test/member-identity-smoke.mjs && node test/generic-row-parse-identity-smoke.mjs && node test/type-variant-payload-smoke.mjs && node test/type-generic-ref-smoke.mjs && node test/type-parameter-constraints-smoke.mjs && node test/type-structural-expression-smoke.mjs && node test/action-body-smoke.mjs && node test/action-structured-literals-smoke.mjs && node test/action-return-smoke.mjs && node test/action-else-smoke.mjs && node test/action-match-smoke.mjs && node test/action-for-in-smoke.mjs && node test/action-repeat-smoke.mjs && node test/action-call-smoke.mjs && node test/semantic-operation-edit-smoke.mjs && node test/target-projection-aggregate-smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/conversion-evidence-smoke.mjs && node test/gate-admission-evidence-smoke.mjs && node test/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/view-source-syntax-smoke.mjs && node test/resource-graph-smoke.mjs && node test/machine-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
26
26
  "typecheck": "node ./node_modules/typescript/bin/tsc --noEmit -p test/tsconfig.json",
27
27
  "fuzz": "npm run build && node fuzz/smoke.mjs",
28
28
  "bench": "npm run build && node bench/smoke.mjs",