@shapeshift-labs/frontier-lang-parser 0.3.19 → 0.3.20
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 +28 -0
- package/dist/index.js +5 -2
- package/dist/metadata.js +47 -1
- package/dist/resource-graph.js +208 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -243,6 +243,34 @@ decisionGraph TodoAdmission @id("decision_graph_todo") {
|
|
|
243
243
|
|
|
244
244
|
The parser projects these rows into `metadata.decisionGraph`. Decision graph records are normalized by the kernel helpers, so authored files can describe why a merge is admissible without embedding raw JSON. This is intentionally evidence-first: a safe merge can be represented as a graph of changes, gates, evidence, and decisions, while missing proof can remain explicit as blocked or review-required records.
|
|
245
245
|
|
|
246
|
+
## Authored resource graph syntax
|
|
247
|
+
|
|
248
|
+
`.frontier` files can carry semantic resource graph evidence directly in `resourceGraph` or `semanticResourceGraph` blocks. These blocks make ownership, aliases, loans, moves, drops, lifetimes, unsafe boundaries, conflicts, and proof obligations explicit for translation and semantic merge admission.
|
|
249
|
+
|
|
250
|
+
```frontier
|
|
251
|
+
resourceGraph TodoResources @id("resource_graph_todo") {
|
|
252
|
+
sourceLanguage javascript
|
|
253
|
+
sourcePath src/todo.ts
|
|
254
|
+
sourceHash sha256:example
|
|
255
|
+
evidence artifact_todo_title_probe
|
|
256
|
+
resource todos @id("resource_todos") kind collection owner owner_todo_store
|
|
257
|
+
owner todoStore @id("owner_todo_store") kind store
|
|
258
|
+
lifetime request @id("life_request") kind lexical startLine 1 endLine 80
|
|
259
|
+
loan readTodos @id("loan_read_todos") resource resource_todos owner owner_todo_store lifetime life_request mode shared access read
|
|
260
|
+
alias todosAlias @id("alias_todos") resource resource_todos owner owner_todo_store alias alias:todos kind local
|
|
261
|
+
move todoMove @id("move_todos") resource resource_todos fromOwner owner_todo_store toOwner owner_worker kind transfer
|
|
262
|
+
drop todoDrop @id("drop_todos") resource resource_todos owner owner_worker lifetime life_request kind lexical-drop order 1
|
|
263
|
+
escape todoEscape @id("escape_todos") resource resource_todos loan loan_read_todos lifetime life_request kind returned-borrow status needs-proof
|
|
264
|
+
outlives requestModule @id("life_request_outlives_module") from life_module to life_request kind contains
|
|
265
|
+
borrow readScope @id("borrow_scope_todos") resource resource_todos lifetime life_request kind shared-borrow constraint shared|read-only
|
|
266
|
+
unsafe ffiBoundary @id("unsafe_todos_ffi") resource resource_todos kind ffi proofStatus missing
|
|
267
|
+
conflict aliasConflict @id("conflict_todos_alias") resource resource_todos loan loan_read_todos alias alias_todos reasonCode exclusive-resource-alias-overlap-requires-proof status open severity error
|
|
268
|
+
proof aliasProof @id("proof_obligation_alias") resource resource_todos conflict conflict_todos_alias kind alias-safety status open statement "Prove the alias cannot mutate during the shared loan."
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The parser projects these rows into `metadata.semanticResourceGraphs`. Resource graphs are evidence, not proof: generated claims for borrow-checker soundness, alias safety, lifetime soundness, semantic equivalence, and auto-merge stay false. Compiler conversion routes can use these authored graphs as source-side resource, ownership, lifetime, and borrow-checker evidence while still requiring target proof before admission.
|
|
273
|
+
|
|
246
274
|
## Authored conversion syntax
|
|
247
275
|
|
|
248
276
|
`.frontier` files can carry universal conversion evidence directly in `conversion` or `universalConversionPlan` blocks. The parser projects these records into `metadata.universalConversionPlan` for the compiler facade and downstream semantic merge tooling.
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createParsedMetadata } from './metadata.js';
|
|
|
6
6
|
import { parseSemanticOperationsBlock } from './operations.js';
|
|
7
7
|
import { parseParadigmBlock } from './paradigm.js';
|
|
8
8
|
import { parseProofBlock } from './proof.js';
|
|
9
|
+
import { parseResourceGraphBlock } from './resource-graph.js';
|
|
9
10
|
import { parseNativeSourceBlock } from './source-evidence.js';
|
|
10
11
|
import { parseViewBlock } from './view.js';
|
|
11
12
|
|
|
@@ -17,6 +18,7 @@ export function parseFrontierSource(source, options = {}) {
|
|
|
17
18
|
const conversionBlocks = [];
|
|
18
19
|
const constraintSpaceBlocks = [];
|
|
19
20
|
const decisionGraphBlocks = [];
|
|
21
|
+
const resourceGraphBlocks = [];
|
|
20
22
|
const nativeSourceBlocks = [];
|
|
21
23
|
const documentId = options.id ?? readId(source) ?? 'mod_frontier';
|
|
22
24
|
const documentName = options.name ?? readName(source) ?? 'FrontierModule';
|
|
@@ -43,8 +45,9 @@ export function parseFrontierSource(source, options = {}) {
|
|
|
43
45
|
if (block.kind === 'conversion' || block.kind === 'universalConversionPlan') conversionBlocks.push(parseConversionBlock(block));
|
|
44
46
|
if (block.kind === 'constraintSpace' || block.kind === 'possibilitySpace') constraintSpaceBlocks.push(parseConstraintSpaceBlock(block));
|
|
45
47
|
if (block.kind === 'decisionGraph' || block.kind === 'admissionGraph') decisionGraphBlocks.push(parseDecisionGraphBlock(block));
|
|
48
|
+
if (block.kind === 'resourceGraph' || block.kind === 'semanticResourceGraph') resourceGraphBlocks.push(parseResourceGraphBlock(block));
|
|
46
49
|
}
|
|
47
|
-
const metadata = createParsedMetadata({ proofBlocks, paradigmBlocks, operationBlocks, conversionBlocks, constraintSpaceBlocks, decisionGraphBlocks, nativeSourceBlocks });
|
|
50
|
+
const metadata = createParsedMetadata({ proofBlocks, paradigmBlocks, operationBlocks, conversionBlocks, constraintSpaceBlocks, decisionGraphBlocks, resourceGraphBlocks, nativeSourceBlocks });
|
|
48
51
|
return createDocument({ id: documentId, name: documentName, nodes, ...(metadata ? { metadata } : {}) });
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -54,7 +57,7 @@ function readName(source) { return /module\s+([A-Za-z_$][\w$]*)/.exec(source)?.[
|
|
|
54
57
|
function readId(source) { return /module\s+[A-Za-z_$][\w$]*\s+@id\(\s*["']([^"']+)["']\s*\)/.exec(source)?.[1]; }
|
|
55
58
|
function readBlocks(source) {
|
|
56
59
|
const blocks = [];
|
|
57
|
-
const header = /\b(entity|state|action|view|migration|capability|effect|type|extern|lattice|nativeSource|target|proof|paradigm|paradigmSemantics|operations|semanticOperations|conversion|universalConversionPlan|constraintSpace|possibilitySpace|decisionGraph|admissionGraph)\s+([^{}]+)\{/g;
|
|
60
|
+
const header = /\b(entity|state|action|view|migration|capability|effect|type|extern|lattice|nativeSource|target|proof|paradigm|paradigmSemantics|operations|semanticOperations|conversion|universalConversionPlan|constraintSpace|possibilitySpace|decisionGraph|admissionGraph|resourceGraph|semanticResourceGraph)\s+([^{}]+)\{/g;
|
|
58
61
|
let match;
|
|
59
62
|
while ((match = header.exec(source))) {
|
|
60
63
|
let depth = 1; let index = header.lastIndex;
|
package/dist/metadata.js
CHANGED
|
@@ -21,7 +21,7 @@ const PARADIGM_GROUPS = [
|
|
|
21
21
|
'loweringRecords'
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
-
export function createParsedMetadata({ proofBlocks = [], paradigmBlocks = [], operationBlocks = [], conversionBlocks = [], constraintSpaceBlocks = [], decisionGraphBlocks = [], nativeSourceBlocks = [] } = {}) {
|
|
24
|
+
export function createParsedMetadata({ proofBlocks = [], paradigmBlocks = [], operationBlocks = [], conversionBlocks = [], constraintSpaceBlocks = [], decisionGraphBlocks = [], resourceGraphBlocks = [], nativeSourceBlocks = [] } = {}) {
|
|
25
25
|
const metadata = {};
|
|
26
26
|
if (proofBlocks.length) metadata.proof = mergeProofBlocks(proofBlocks);
|
|
27
27
|
if (paradigmBlocks.length) metadata.paradigmSemantics = mergeParadigmBlocks(paradigmBlocks);
|
|
@@ -29,6 +29,7 @@ export function createParsedMetadata({ proofBlocks = [], paradigmBlocks = [], op
|
|
|
29
29
|
if (conversionBlocks.length) metadata.universalConversionPlan = mergeConversionBlocks(conversionBlocks);
|
|
30
30
|
if (constraintSpaceBlocks.length) metadata.constraintSpaces = mergeConstraintSpaceBlocks(constraintSpaceBlocks);
|
|
31
31
|
if (decisionGraphBlocks.length) metadata.decisionGraph = mergeDecisionGraphBlocks(decisionGraphBlocks);
|
|
32
|
+
if (resourceGraphBlocks.length) metadata.semanticResourceGraphs = mergeResourceGraphBlocks(resourceGraphBlocks);
|
|
32
33
|
if (nativeSourceBlocks.some((block) => block.sourceMaps.length || block.mergeCandidates.length || block.evidence.length)) {
|
|
33
34
|
metadata.universalAst = mergeNativeSourceBlocks(nativeSourceBlocks);
|
|
34
35
|
}
|
|
@@ -152,6 +153,51 @@ function mergeDecisionGraphBlocks(blocks) {
|
|
|
152
153
|
};
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
function mergeResourceGraphBlocks(blocks) {
|
|
157
|
+
const graphs = blocks.map((block) => block.graph).filter(Boolean);
|
|
158
|
+
const records = blocks.flatMap((block) => block.records ?? []);
|
|
159
|
+
return {
|
|
160
|
+
id: blocks.length === 1 ? blocks[0].id : 'semanticResourceGraphs:source',
|
|
161
|
+
graphs,
|
|
162
|
+
resourceGraphs: graphs,
|
|
163
|
+
records,
|
|
164
|
+
graphIds: ids(graphs),
|
|
165
|
+
recordIds: ids(records),
|
|
166
|
+
resourceIds: blocks.flatMap((block) => ids(block.graph?.resources)),
|
|
167
|
+
ownerIds: blocks.flatMap((block) => ids(block.graph?.owners)),
|
|
168
|
+
loanIds: blocks.flatMap((block) => ids(block.graph?.loans)),
|
|
169
|
+
aliasIds: blocks.flatMap((block) => ids(block.graph?.aliases)),
|
|
170
|
+
moveIds: blocks.flatMap((block) => ids(block.graph?.moves)),
|
|
171
|
+
dropIds: blocks.flatMap((block) => ids(block.graph?.drops)),
|
|
172
|
+
escapeIds: blocks.flatMap((block) => ids(block.graph?.escapes)),
|
|
173
|
+
lifetimeRegionIds: blocks.flatMap((block) => ids(block.graph?.lifetimeRegions)),
|
|
174
|
+
lifetimeRelationIds: blocks.flatMap((block) => ids(block.graph?.lifetimeRelations)),
|
|
175
|
+
borrowScopeIds: blocks.flatMap((block) => ids(block.graph?.borrowScopes)),
|
|
176
|
+
unsafeBoundaryIds: blocks.flatMap((block) => ids(block.graph?.unsafeBoundaries)),
|
|
177
|
+
conflictIds: blocks.flatMap((block) => ids(block.graph?.conflicts)),
|
|
178
|
+
proofObligationIds: blocks.flatMap((block) => ids(block.graph?.proofObligations)),
|
|
179
|
+
summary: {
|
|
180
|
+
graphCount: blocks.length,
|
|
181
|
+
recordCount: records.length,
|
|
182
|
+
resourceCount: sum(blocks, 'resources'),
|
|
183
|
+
ownerCount: sum(blocks, 'owners'),
|
|
184
|
+
loanCount: sum(blocks, 'loans'),
|
|
185
|
+
aliasCount: sum(blocks, 'aliases'),
|
|
186
|
+
moveCount: sum(blocks, 'moves'),
|
|
187
|
+
dropCount: sum(blocks, 'drops'),
|
|
188
|
+
escapeCount: sum(blocks, 'escapes'),
|
|
189
|
+
lifetimeRegionCount: sum(blocks, 'lifetimeRegions'),
|
|
190
|
+
lifetimeRelationCount: sum(blocks, 'lifetimeRelations'),
|
|
191
|
+
borrowScopeCount: sum(blocks, 'borrowScopes'),
|
|
192
|
+
unsafeBoundaryCount: sum(blocks, 'unsafeBoundaries'),
|
|
193
|
+
conflictCount: sum(blocks, 'conflicts'),
|
|
194
|
+
proofObligationCount: sum(blocks, 'proofObligations'),
|
|
195
|
+
unsafeBoundariesWithoutProof: sum(blocks, 'unsafeBoundariesWithoutProof')
|
|
196
|
+
},
|
|
197
|
+
metadata: { authoredResourceGraphBlockIds: blocks.map((block) => block.id) }
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
155
201
|
function ids(records = []) {
|
|
156
202
|
return records.map((record) => record?.id).filter(Boolean);
|
|
157
203
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const GROUPS = {
|
|
2
|
+
resource: 'resources',
|
|
3
|
+
owner: 'owners',
|
|
4
|
+
loan: 'loans',
|
|
5
|
+
alias: 'aliases',
|
|
6
|
+
move: 'moves',
|
|
7
|
+
drop: 'drops',
|
|
8
|
+
escape: 'escapes',
|
|
9
|
+
lifetimeRegion: 'lifetimeRegions',
|
|
10
|
+
lifetimeRelation: 'lifetimeRelations',
|
|
11
|
+
borrowScope: 'borrowScopes',
|
|
12
|
+
unsafeBoundary: 'unsafeBoundaries',
|
|
13
|
+
conflict: 'conflicts',
|
|
14
|
+
proofObligation: 'proofObligations'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function parseResourceGraphBlock(block) {
|
|
18
|
+
const name = nameFrom(block.header);
|
|
19
|
+
const graph = {
|
|
20
|
+
kind: 'frontier.lang.semanticResourceGraph',
|
|
21
|
+
version: 1,
|
|
22
|
+
id: idFrom(block.header, `resource_graph_${name}`),
|
|
23
|
+
sourceLanguage: readLine('sourceLanguage', block.body) ?? readLine('language', block.body),
|
|
24
|
+
sourcePath: readLine('sourcePath', block.body) ?? readLine('path', block.body),
|
|
25
|
+
sourceHash: readLine('sourceHash', block.body),
|
|
26
|
+
status: readLine('status', block.body) ?? 'partial',
|
|
27
|
+
evidenceIds: readListLine('evidence', block.body) ?? readListLine('evidenceIds', block.body) ?? [],
|
|
28
|
+
resources: [],
|
|
29
|
+
owners: [],
|
|
30
|
+
loans: [],
|
|
31
|
+
aliases: [],
|
|
32
|
+
moves: [],
|
|
33
|
+
drops: [],
|
|
34
|
+
escapes: [],
|
|
35
|
+
lifetimeRegions: [],
|
|
36
|
+
lifetimeRelations: [],
|
|
37
|
+
outlives: [],
|
|
38
|
+
borrowScopes: [],
|
|
39
|
+
borrowScopeRegions: [],
|
|
40
|
+
unsafeBoundaries: [],
|
|
41
|
+
conflicts: [],
|
|
42
|
+
proofObligations: [],
|
|
43
|
+
claims: {
|
|
44
|
+
borrowCheckerClaim: false,
|
|
45
|
+
aliasSafetyClaim: false,
|
|
46
|
+
lifetimeSoundnessClaim: false,
|
|
47
|
+
semanticEquivalenceClaim: false,
|
|
48
|
+
autoMergeClaim: false
|
|
49
|
+
},
|
|
50
|
+
metadata: { name }
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
for (const rawLine of block.body.split('\n')) {
|
|
54
|
+
const line = rawLine.trim();
|
|
55
|
+
if (!line || line.startsWith('#') || isGraphPropertyLine(line)) continue;
|
|
56
|
+
const match = /^([A-Za-z_$][\w$-]*)\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
|
|
57
|
+
if (!match) continue;
|
|
58
|
+
const [, rowKind, rowName, rest] = match;
|
|
59
|
+
const normalized = normalizeRowKind(rowKind);
|
|
60
|
+
const record = parseResourceRecord(normalized, rowName, rest, graph);
|
|
61
|
+
const group = GROUPS[normalized];
|
|
62
|
+
if (record && group) graph[group].push(record);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
graph.outlives = graph.lifetimeRelations;
|
|
66
|
+
graph.borrowScopeRegions = graph.borrowScopes;
|
|
67
|
+
graph.summary = summarize(graph);
|
|
68
|
+
graph.query = {
|
|
69
|
+
resourceIds: ids(graph.resources),
|
|
70
|
+
ownerIds: ids(graph.owners),
|
|
71
|
+
lifetimeRegionIds: ids(graph.lifetimeRegions),
|
|
72
|
+
sourcePaths: unique(allRecords(graph).map((record) => record.sourcePath)),
|
|
73
|
+
evidenceIds: unique([...graph.evidenceIds, ...allRecords(graph).flatMap((record) => record.evidenceIds ?? [])]),
|
|
74
|
+
blockerReasonCodes: unique(graph.conflicts.map((record) => record.reasonCode))
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
id: graph.id,
|
|
79
|
+
graph,
|
|
80
|
+
records: allRecords(graph),
|
|
81
|
+
summary: {
|
|
82
|
+
graphCount: 1,
|
|
83
|
+
...graph.summary
|
|
84
|
+
},
|
|
85
|
+
metadata: { name }
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parseResourceRecord(kind, name, text, graph) {
|
|
90
|
+
const common = commonRecord(kind, name, text, graph);
|
|
91
|
+
if (kind === 'resource') return cleanRecord({ ...common, resourceKind: readInlineWord('resourceKind', text) ?? readInlineWord('kind', text) ?? name, ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), ownerName: readInlineWord('ownerName', text) });
|
|
92
|
+
if (kind === 'owner') return cleanRecord({ ...common, ownerKind: readInlineWord('ownerKind', text) ?? readInlineWord('kind', text) ?? 'owner' });
|
|
93
|
+
if (kind === 'loan') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), lifetimeRegionId: readInlineWord('lifetime', text) ?? readInlineWord('lifetimeRegion', text) ?? readInlineWord('lifetimeRegionId', text), mode: readInlineWord('mode', text) ?? 'unknown', access: readInlineWord('access', text) });
|
|
94
|
+
if (kind === 'alias') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), aliasId: readInlineWord('alias', text) ?? readInlineWord('aliasId', text), aliasKind: readInlineWord('aliasKind', text) ?? readInlineWord('kind', text) ?? 'alias' });
|
|
95
|
+
if (kind === 'move') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), fromOwnerId: readInlineWord('fromOwner', text) ?? readInlineWord('fromOwnerId', text), toOwnerId: readInlineWord('toOwner', text) ?? readInlineWord('toOwnerId', text), moveKind: readInlineWord('moveKind', text) ?? readInlineWord('kind', text) });
|
|
96
|
+
if (kind === 'drop') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), lifetimeRegionId: readInlineWord('lifetime', text) ?? readInlineWord('lifetimeRegion', text) ?? readInlineWord('lifetimeRegionId', text), dropKind: readInlineWord('dropKind', text) ?? readInlineWord('kind', text) ?? 'drop', line: readInlineNumber('line', text), order: readInlineNumber('order', text) });
|
|
97
|
+
if (kind === 'escape') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), lifetimeRegionId: readInlineWord('lifetime', text) ?? readInlineWord('lifetimeRegion', text) ?? readInlineWord('lifetimeRegionId', text), loanId: readInlineWord('loan', text) ?? readInlineWord('loanId', text), escapeKind: readInlineWord('escapeKind', text) ?? readInlineWord('kind', text) ?? 'escape', status: readInlineWord('status', text) ?? 'needs-proof' });
|
|
98
|
+
if (kind === 'lifetimeRegion') return cleanRecord({ ...common, lifetimeKind: readInlineWord('lifetimeKind', text) ?? readInlineWord('kind', text) ?? 'lexical', startLine: readInlineNumber('startLine', text), endLine: readInlineNumber('endLine', text) });
|
|
99
|
+
if (kind === 'lifetimeRelation') return cleanRecord({ ...common, relationKind: readInlineWord('relationKind', text) ?? readInlineWord('kind', text) ?? 'outlives', fromLifetimeId: readInlineWord('fromLifetime', text) ?? readInlineWord('fromLifetimeId', text) ?? readInlineWord('from', text), toLifetimeId: readInlineWord('toLifetime', text) ?? readInlineWord('toLifetimeId', text) ?? readInlineWord('to', text), from: readInlineWord('from', text), to: readInlineWord('to', text) });
|
|
100
|
+
if (kind === 'borrowScope') return cleanRecord({ ...common, scopeKind: readInlineWord('scopeKind', text) ?? readInlineWord('kind', text) ?? 'borrow-scope', constraintKind: readInlineWord('constraintKind', text), constraintKinds: readInlineList(text, 'constraint', 'constraints', 'constraintKind', 'constraintKinds') ?? [], ownershipKind: readInlineWord('ownershipKind', text), lifetimeKind: readInlineWord('lifetimeKind', text), controlFlowKind: readInlineWord('controlFlowKind', text), sourceControlFlowId: readInlineWord('sourceControlFlow', text) ?? readInlineWord('sourceControlFlowId', text), lifetimeRegionId: readInlineWord('lifetime', text) ?? readInlineWord('lifetimeRegion', text) ?? readInlineWord('lifetimeRegionId', text), resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text) });
|
|
101
|
+
if (kind === 'unsafeBoundary') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), unsafeBoundary: true, proofStatus: readInlineWord('proofStatus', text) ?? readInlineWord('status', text) ?? 'missing', kind: readInlineWord('kind', text) });
|
|
102
|
+
if (kind === 'conflict') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text), loanId: readInlineWord('loan', text) ?? readInlineWord('loanId', text), aliasId: readInlineWord('alias', text) ?? readInlineWord('aliasId', text), unsafeBoundaryId: readInlineWord('unsafeBoundary', text) ?? readInlineWord('unsafeBoundaryId', text), reasonCode: readInlineWord('reasonCode', text), message: readInlineQuoted('message', text), status: readInlineWord('status', text) ?? 'open', severity: readInlineWord('severity', text) ?? 'error' });
|
|
103
|
+
if (kind === 'proofObligation') return cleanRecord({ ...common, resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text), conflictId: readInlineWord('conflict', text) ?? readInlineWord('conflictId', text), kind: readInlineWord('kind', text), status: readInlineWord('status', text) ?? 'open', statement: readInlineQuoted('statement', text) });
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function commonRecord(kind, name, text, graph) {
|
|
108
|
+
return cleanRecord({
|
|
109
|
+
recordKind: recordKind(kind),
|
|
110
|
+
id: idFrom(text, `${recordPrefix(kind)}_${name}`),
|
|
111
|
+
name,
|
|
112
|
+
sourcePath: readInlineWord('sourcePath', text) ?? readInlineWord('path', text) ?? graph.sourcePath,
|
|
113
|
+
sourceHash: readInlineWord('sourceHash', text) ?? graph.sourceHash,
|
|
114
|
+
evidenceIds: readInlineList(text, 'evidence', 'evidenceIds') ?? graph.evidenceIds,
|
|
115
|
+
metadata: { authoredName: name }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function summarize(graph) {
|
|
120
|
+
return {
|
|
121
|
+
records: allRecords(graph).length,
|
|
122
|
+
resources: graph.resources.length,
|
|
123
|
+
owners: graph.owners.length,
|
|
124
|
+
loans: graph.loans.length,
|
|
125
|
+
aliases: graph.aliases.length,
|
|
126
|
+
moves: graph.moves.length,
|
|
127
|
+
drops: graph.drops.length,
|
|
128
|
+
escapes: graph.escapes.length,
|
|
129
|
+
lifetimeRegions: graph.lifetimeRegions.length,
|
|
130
|
+
lifetimeRelations: graph.lifetimeRelations.length,
|
|
131
|
+
borrowScopes: graph.borrowScopes.length,
|
|
132
|
+
unsafeBoundaries: graph.unsafeBoundaries.length,
|
|
133
|
+
conflicts: graph.conflicts.length,
|
|
134
|
+
proofObligations: graph.proofObligations.length,
|
|
135
|
+
unsafeBoundariesWithoutProof: graph.unsafeBoundaries.filter((record) => record.proofStatus !== 'passed').length,
|
|
136
|
+
reasonCodes: unique(graph.conflicts.map((record) => record.reasonCode))
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function allRecords(graph) {
|
|
141
|
+
return [
|
|
142
|
+
...graph.resources,
|
|
143
|
+
...graph.owners,
|
|
144
|
+
...graph.loans,
|
|
145
|
+
...graph.aliases,
|
|
146
|
+
...graph.moves,
|
|
147
|
+
...graph.drops,
|
|
148
|
+
...graph.escapes,
|
|
149
|
+
...graph.lifetimeRegions,
|
|
150
|
+
...graph.lifetimeRelations,
|
|
151
|
+
...graph.borrowScopes,
|
|
152
|
+
...graph.unsafeBoundaries,
|
|
153
|
+
...graph.conflicts,
|
|
154
|
+
...graph.proofObligations
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function normalizeRowKind(kind) {
|
|
159
|
+
if (kind === 'lifetime' || kind === 'life') return 'lifetimeRegion';
|
|
160
|
+
if (kind === 'outlives' || kind === 'lifetimeRelation' || kind === 'lifeRelation') return 'lifetimeRelation';
|
|
161
|
+
if (kind === 'borrow' || kind === 'borrowScope' || kind === 'borrowRegion') return 'borrowScope';
|
|
162
|
+
if (kind === 'unsafe' || kind === 'unsafeBoundary') return 'unsafeBoundary';
|
|
163
|
+
if (kind === 'proof' || kind === 'obligation' || kind === 'proofObligation') return 'proofObligation';
|
|
164
|
+
return kind;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function recordKind(kind) {
|
|
168
|
+
if (kind === 'lifetimeRegion') return 'lifetime-region';
|
|
169
|
+
if (kind === 'lifetimeRelation') return 'lifetime-relation';
|
|
170
|
+
if (kind === 'borrowScope') return 'borrow-scope';
|
|
171
|
+
if (kind === 'unsafeBoundary') return 'unsafe-boundary';
|
|
172
|
+
if (kind === 'proofObligation') return 'proof-obligation';
|
|
173
|
+
return kind;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function recordPrefix(kind) {
|
|
177
|
+
return recordKind(kind).replace(/-/g, '_');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isGraphPropertyLine(line) {
|
|
181
|
+
return /^(sourceLanguage|language|sourcePath|path|sourceHash|status|evidence|evidenceIds)\s+/.test(line);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function idFrom(text, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(text)?.[1] ?? fallback; }
|
|
185
|
+
function nameFrom(header) { return /^([A-Za-z_$][\w$]*)/.exec(header)?.[1] ?? 'ResourceGraph'; }
|
|
186
|
+
function readLine(label, body) { return new RegExp('^\\s*' + label + '\\s+([^\\n]+)', 'm').exec(body)?.[1]?.trim(); }
|
|
187
|
+
function readListLine(label, body) {
|
|
188
|
+
const line = readLine(label, body);
|
|
189
|
+
return line ? line.split(/[|,]/).map((item) => item.trim()).filter(Boolean) : undefined;
|
|
190
|
+
}
|
|
191
|
+
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
192
|
+
function readInlineQuoted(label, text) { return new RegExp("(?:^|\\s)" + label + "\\s+[\"']([^\"']+)[\"']").exec(text)?.[1]?.trim(); }
|
|
193
|
+
function readInlineNumber(label, text) {
|
|
194
|
+
const value = readInlineWord(label, text);
|
|
195
|
+
return value === undefined ? undefined : Number(value);
|
|
196
|
+
}
|
|
197
|
+
function readInlineList(text, ...labels) {
|
|
198
|
+
for (const label of labels) {
|
|
199
|
+
const value = new RegExp('(?:^|\\s)' + label + '\\s+([^\\s]+)').exec(text)?.[1]?.trim();
|
|
200
|
+
if (value) return value.split(/[|,]/).map((item) => item.trim()).filter(Boolean);
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
function ids(records = []) { return records.map((record) => record?.id).filter(Boolean); }
|
|
205
|
+
function unique(values = []) { return [...new Set(values.filter(Boolean))]; }
|
|
206
|
+
function cleanRecord(record) {
|
|
207
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0)));
|
|
208
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-lang-parser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
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",
|
|
25
|
+
"test": "npm run build && node test/smoke.mjs && node test/resource-graph-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",
|