@shapeshift-labs/frontier-lang-parser 0.3.65 → 0.3.67
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.js +1 -1
- package/dist/operations.js +93 -4
- package/dist/target-projection.js +37 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -182,7 +182,7 @@ function parseLattice(block) {
|
|
|
182
182
|
}
|
|
183
183
|
function parseTarget(block) {
|
|
184
184
|
const name = nameFrom(block.header);
|
|
185
|
-
const metadata = parseTargetProjectionMetadata(block
|
|
185
|
+
const metadata = parseTargetProjectionMetadata(block, name);
|
|
186
186
|
return targetNode({
|
|
187
187
|
id: idFrom(block.header, `target_${name}`),
|
|
188
188
|
name,
|
package/dist/operations.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
export function parseSemanticOperationsBlock(block) {
|
|
2
2
|
const name = nameFrom(block.header);
|
|
3
3
|
const operationSet = { id: idFrom(block.header, `semanticOperations_${name}`), operations: [], metadata: { name } };
|
|
4
|
-
for (const
|
|
5
|
-
const line =
|
|
4
|
+
for (const authoredLine of readAuthoredLines(block)) {
|
|
5
|
+
const line = authoredLine.text;
|
|
6
6
|
if (!line || line.startsWith('#')) continue;
|
|
7
7
|
const match = /^(operation|op)\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
|
|
8
|
-
if (match) operationSet.operations.push(parseSemanticOperationRecord(match[2], match[3]));
|
|
8
|
+
if (match) operationSet.operations.push(parseSemanticOperationRecord(match[2], match[3], authoredLine));
|
|
9
9
|
}
|
|
10
10
|
return operationSet;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function parseSemanticOperationRecord(name, text) {
|
|
13
|
+
function parseSemanticOperationRecord(name, text, authoredLine = {}) {
|
|
14
|
+
const sourceBackprojectionMode = readInlineWord('sourceBackprojection', text) ?? readInlineWord('sourceBackprojectionMode', text);
|
|
14
15
|
return cleanRecord({
|
|
15
16
|
id: idFrom(text, `semanticOperation_${name}`),
|
|
16
17
|
operationKind: readInlineWord('operationKind', text) ?? readInlineWord('op', text) ?? readInlineWord('kind', text),
|
|
17
18
|
language: readInlineWord('language', text),
|
|
18
19
|
name,
|
|
19
20
|
target: readInlineWord('target', text),
|
|
21
|
+
targetLanguage: readInlineWord('targetLanguage', text),
|
|
22
|
+
sourcePath: readInlineWord('sourcePath', text) ?? readInlineWord('path', text),
|
|
23
|
+
targetPath: readInlineWord('targetPath', text),
|
|
24
|
+
routeId: readInlineWord('route', text) ?? readInlineWord('routeId', text),
|
|
25
|
+
routeIds: readInlineList(text, 'routeIds'),
|
|
20
26
|
nativeSourceId: readInlineWord('nativeSource', text) ?? readInlineWord('nativeSourceId', text),
|
|
21
27
|
nativeAstId: readInlineWord('nativeAst', text) ?? readInlineWord('nativeAstId', text),
|
|
22
28
|
nativeAstNodeIds: readInlineList(text, 'nativeAstNode', 'nativeAstNodes', 'nativeAstNodeIds'),
|
|
@@ -24,6 +30,7 @@ function parseSemanticOperationRecord(name, text) {
|
|
|
24
30
|
semanticSymbolIds: readInlineList(text, 'semanticSymbol', 'semanticSymbols', 'semanticSymbolIds'),
|
|
25
31
|
semanticOccurrenceIds: readInlineList(text, 'semanticOccurrence', 'semanticOccurrences', 'semanticOccurrenceIds'),
|
|
26
32
|
sourceMapIds: readInlineList(text, 'sourceMap', 'sourceMaps', 'sourceMapIds'),
|
|
33
|
+
sourceMapLinkIds: readInlineList(text, 'sourceMapLink', 'sourceMapLinks', 'sourceMapLinkIds'),
|
|
27
34
|
sourceMapMappingIds: readInlineList(text, 'sourceMapMapping', 'sourceMapMappings', 'sourceMapMappingIds'),
|
|
28
35
|
proofObligationIds: readInlineList(text, 'proofObligation', 'proofObligations', 'proofObligationIds'),
|
|
29
36
|
proofArtifactIds: readInlineList(text, 'proofArtifact', 'proofArtifacts', 'proofArtifactIds'),
|
|
@@ -36,12 +43,94 @@ function parseSemanticOperationRecord(name, text) {
|
|
|
36
43
|
ownershipKeys: readInlineList(text, 'ownerKey', 'ownershipKey', 'ownershipKeys'),
|
|
37
44
|
conflictKeys: readInlineList(text, 'conflictKey', 'conflictKeys'),
|
|
38
45
|
readiness: readInlineWord('readiness', text),
|
|
46
|
+
status: readInlineWord('status', text),
|
|
47
|
+
action: readInlineWord('action', text),
|
|
48
|
+
changeKind: readInlineWord('changeKind', text),
|
|
49
|
+
regionKind: readInlineWord('regionKind', text),
|
|
50
|
+
regionId: readInlineWord('region', text) ?? readInlineWord('regionId', text),
|
|
51
|
+
symbolName: readInlineWord('symbolName', text),
|
|
52
|
+
symbolKind: readInlineWord('symbolKind', text),
|
|
53
|
+
symbolId: readInlineWord('symbolId', text),
|
|
54
|
+
semanticKey: readInlineWord('semanticKey', text),
|
|
55
|
+
semanticIdentityHash: readInlineWord('semanticIdentityHash', text),
|
|
56
|
+
sourceIdentityHash: readInlineWord('sourceIdentityHash', text),
|
|
57
|
+
operationContentHash: readInlineWord('operationContentHash', text),
|
|
58
|
+
editContentHash: readInlineWord('editContentHash', text),
|
|
59
|
+
editScriptIds: readInlineList(text, 'editScript', 'editScriptId', 'editScriptIds'),
|
|
60
|
+
patchIds: readInlineList(text, 'patch', 'patchId', 'patchIds'),
|
|
61
|
+
patchHash: readInlineWord('patchHash', text),
|
|
62
|
+
editScriptHash: readInlineWord('editScriptHash', text),
|
|
63
|
+
baseHash: readInlineWord('baseHash', text),
|
|
64
|
+
targetHash: readInlineWord('targetHash', text),
|
|
65
|
+
baseTextHash: readInlineWord('baseTextHash', text),
|
|
66
|
+
workerTextHash: readInlineWord('workerTextHash', text),
|
|
67
|
+
headTextHash: readInlineWord('headTextHash', text),
|
|
68
|
+
projectionContractIds: readInlineList(text, 'projectionContract', 'projectionContractId', 'projectionContractIds'),
|
|
69
|
+
projectionLayerIds: readInlineList(text, 'projectionLayer', 'projectionLayerId', 'projectionLayerIds'),
|
|
70
|
+
targetProjectionIds: readInlineList(text, 'targetProjection', 'targetProjectionId', 'targetProjectionIds'),
|
|
71
|
+
projectionHash: readInlineWord('projectionHash', text),
|
|
72
|
+
semanticEditScriptId: readInlineWord('semanticEditScript', text) ?? readInlineWord('semanticEditScriptId', text) ?? readInlineWord('script', text) ?? readInlineWord('scriptId', text),
|
|
73
|
+
semanticEditProjectionId: readInlineWord('semanticEditProjection', text) ?? readInlineWord('semanticEditProjectionId', text) ?? readInlineWord('projection', text) ?? readInlineWord('projectionId', text),
|
|
74
|
+
semanticEditReplayId: readInlineWord('semanticEditReplay', text) ?? readInlineWord('semanticEditReplayId', text) ?? readInlineWord('replay', text) ?? readInlineWord('replayId', text),
|
|
75
|
+
replayRecordIds: readInlineList(text, 'replayRecord', 'replayRecordId', 'replayRecordIds'),
|
|
76
|
+
replayEventIds: readInlineList(text, 'replayEvent', 'replayEventId', 'replayEventIds'),
|
|
77
|
+
replayStatus: readInlineWord('replayStatus', text),
|
|
78
|
+
replayAction: readInlineWord('replayAction', text),
|
|
79
|
+
replayCurrentHash: readInlineWord('replayCurrentHash', text) ?? readInlineWord('currentHash', text),
|
|
80
|
+
replayOutputHash: readInlineWord('replayOutputHash', text) ?? readInlineWord('outputHash', text),
|
|
81
|
+
replayReasonCodes: readInlineList(text, 'replayReasonCode', 'replayReasonCodes'),
|
|
82
|
+
finalHash: readInlineWord('finalHash', text),
|
|
83
|
+
replayHash: readInlineWord('replayHash', text),
|
|
84
|
+
deterministic: readInlineFlag('deterministic', text),
|
|
85
|
+
replayComplete: readInlineFlag('replayComplete', text),
|
|
86
|
+
admissionDecisionIds: readInlineList(text, 'admissionDecision', 'admissionDecisionId', 'admissionDecisionIds'),
|
|
87
|
+
semanticMergeCandidateIds: readInlineList(text, 'semanticMergeCandidate', 'semanticMergeCandidateId', 'semanticMergeCandidateIds'),
|
|
88
|
+
classification: readInlineWord('classification', text),
|
|
89
|
+
decision: readInlineWord('decision', text),
|
|
90
|
+
autoMergeable: readInlineFlag('autoMergeable', text),
|
|
91
|
+
conflictKeyKinds: readInlineList(text, 'conflictKeyKind', 'conflictKeyKinds'),
|
|
92
|
+
admissionStatus: readInlineWord('admissionStatus', text),
|
|
93
|
+
admissionAction: readInlineWord('admissionAction', text),
|
|
94
|
+
admissionReadiness: readInlineWord('admissionReadiness', text),
|
|
95
|
+
semanticTransformId: readInlineWord('semanticTransform', text) ?? readInlineWord('semanticTransformId', text) ?? readInlineWord('transform', text) ?? readInlineWord('transformId', text),
|
|
96
|
+
transformId: readInlineWord('transformId', text) ?? readInlineWord('transform', text),
|
|
97
|
+
transformKey: readInlineWord('transformKey', text),
|
|
98
|
+
transformHash: readInlineWord('transformHash', text),
|
|
99
|
+
identityHash: readInlineWord('identityHash', text),
|
|
100
|
+
transformIdentityHash: readInlineWord('transformIdentityHash', text),
|
|
101
|
+
transformContentHash: readInlineWord('transformContentHash', text),
|
|
102
|
+
projectionIdentityHash: readInlineWord('projectionIdentityHash', text),
|
|
103
|
+
sourceBackprojectionMode,
|
|
104
|
+
sourceBackprojection: sourceBackprojectionMode ? { mode: sourceBackprojectionMode } : undefined,
|
|
105
|
+
sourceSpan: authoredLine.sourceSpan,
|
|
106
|
+
authoredSourceSpan: authoredLine.sourceSpan,
|
|
39
107
|
dynamic: readInlineFlag('dynamic', text),
|
|
40
108
|
opaque: readInlineFlag('opaque', text),
|
|
41
109
|
summary: readInlineQuoted('summary', text)
|
|
42
110
|
});
|
|
43
111
|
}
|
|
44
112
|
|
|
113
|
+
function readAuthoredLines(block) {
|
|
114
|
+
const lines = block.body.split('\n');
|
|
115
|
+
const records = [];
|
|
116
|
+
let lineStart = block.syntax?.bodyStartOffset ?? 0;
|
|
117
|
+
for (const rawLine of lines) {
|
|
118
|
+
const rawEnd = lineStart + rawLine.length;
|
|
119
|
+
const leading = /^\s*/.exec(rawLine)?.[0].length ?? 0;
|
|
120
|
+
const trailing = /\s*$/.exec(rawLine)?.[0].length ?? 0;
|
|
121
|
+
const startOffset = lineStart + leading;
|
|
122
|
+
const endOffset = Math.max(startOffset, rawEnd - trailing);
|
|
123
|
+
records.push({
|
|
124
|
+
text: rawLine.trim(),
|
|
125
|
+
startOffset,
|
|
126
|
+
endOffset,
|
|
127
|
+
sourceSpan: typeof block.sourceSpan === 'function' ? block.sourceSpan(startOffset, endOffset) : undefined
|
|
128
|
+
});
|
|
129
|
+
lineStart = rawEnd + 1;
|
|
130
|
+
}
|
|
131
|
+
return records;
|
|
132
|
+
}
|
|
133
|
+
|
|
45
134
|
function idFrom(text, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(text)?.[1] ?? fallback; }
|
|
46
135
|
function nameFrom(header) { return /^([A-Za-z_$][\w$]*)/.exec(header)?.[1] ?? 'SemanticOperations'; }
|
|
47
136
|
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function parseTargetProjectionMetadata(
|
|
2
|
-
const projectionContracts = readTargetProjectionContracts(
|
|
3
|
-
const projectionLayers = readTargetProjectionLayers(
|
|
1
|
+
export function parseTargetProjectionMetadata(blockOrBody, targetName) {
|
|
2
|
+
const projectionContracts = readTargetProjectionContracts(blockOrBody, targetName);
|
|
3
|
+
const projectionLayers = readTargetProjectionLayers(blockOrBody, targetName);
|
|
4
4
|
if (!projectionContracts.length && !projectionLayers.length) return undefined;
|
|
5
5
|
return cleanObject({
|
|
6
6
|
authoredTargetProjection: true,
|
|
@@ -17,11 +17,11 @@ export function parseTargetProjectionMetadata(body, targetName) {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function readTargetProjectionContracts(
|
|
20
|
+
function readTargetProjectionContracts(blockOrBody, targetName) {
|
|
21
21
|
const rows = [];
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
for (const authoredLine of readAuthoredLines(blockOrBody)) {
|
|
23
|
+
const match = /^(projection|lowering)\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(authoredLine.text);
|
|
24
|
+
if (!match) continue;
|
|
25
25
|
const [, rowKind, name, text] = match;
|
|
26
26
|
rows.push(cleanObject({
|
|
27
27
|
id: idFrom(text, `target_projection_${targetName}_${name}`),
|
|
@@ -41,6 +41,8 @@ function readTargetProjectionContracts(body, targetName) {
|
|
|
41
41
|
missingEvidence: readInlineList(text, 'missingEvidence'),
|
|
42
42
|
review: readInlineList(text, 'review'),
|
|
43
43
|
blockers: readInlineList(text, 'blocker', 'blockers'),
|
|
44
|
+
sourceSpan: authoredLine.sourceSpan,
|
|
45
|
+
authoredSourceSpan: authoredLine.sourceSpan,
|
|
44
46
|
semanticEquivalenceClaim: false,
|
|
45
47
|
autoMergeClaim: false
|
|
46
48
|
}));
|
|
@@ -48,11 +50,11 @@ function readTargetProjectionContracts(body, targetName) {
|
|
|
48
50
|
return rows;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
function readTargetProjectionLayers(
|
|
53
|
+
function readTargetProjectionLayers(blockOrBody, targetName) {
|
|
52
54
|
const rows = [];
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
for (const authoredLine of readAuthoredLines(blockOrBody)) {
|
|
56
|
+
const match = /^layer\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(authoredLine.text);
|
|
57
|
+
if (!match) continue;
|
|
56
58
|
const [, name, text] = match;
|
|
57
59
|
rows.push(cleanObject({
|
|
58
60
|
id: idFrom(text, `target_layer_${targetName}_${name}`),
|
|
@@ -64,6 +66,8 @@ function readTargetProjectionLayers(body, targetName) {
|
|
|
64
66
|
missingEvidence: readInlineList(text, 'missingEvidence'),
|
|
65
67
|
review: readInlineList(text, 'review'),
|
|
66
68
|
blockers: readInlineList(text, 'blocker', 'blockers'),
|
|
69
|
+
sourceSpan: authoredLine.sourceSpan,
|
|
70
|
+
authoredSourceSpan: authoredLine.sourceSpan,
|
|
67
71
|
semanticEquivalenceClaim: false,
|
|
68
72
|
autoMergeClaim: false
|
|
69
73
|
}));
|
|
@@ -71,6 +75,28 @@ function readTargetProjectionLayers(body, targetName) {
|
|
|
71
75
|
return rows;
|
|
72
76
|
}
|
|
73
77
|
|
|
78
|
+
function readAuthoredLines(blockOrBody) {
|
|
79
|
+
const body = typeof blockOrBody === 'string' ? blockOrBody : blockOrBody?.body ?? '';
|
|
80
|
+
const lines = body.split('\n');
|
|
81
|
+
const records = [];
|
|
82
|
+
let lineStart = typeof blockOrBody === 'string' ? 0 : blockOrBody?.syntax?.bodyStartOffset ?? 0;
|
|
83
|
+
for (const rawLine of lines) {
|
|
84
|
+
const rawEnd = lineStart + rawLine.length;
|
|
85
|
+
const leading = /^\s*/.exec(rawLine)?.[0].length ?? 0;
|
|
86
|
+
const trailing = /\s*$/.exec(rawLine)?.[0].length ?? 0;
|
|
87
|
+
const startOffset = lineStart + leading;
|
|
88
|
+
const endOffset = Math.max(startOffset, rawEnd - trailing);
|
|
89
|
+
records.push({
|
|
90
|
+
text: rawLine.trim(),
|
|
91
|
+
startOffset,
|
|
92
|
+
endOffset,
|
|
93
|
+
sourceSpan: typeof blockOrBody?.sourceSpan === 'function' ? blockOrBody.sourceSpan(startOffset, endOffset) : undefined
|
|
94
|
+
});
|
|
95
|
+
lineStart = rawEnd + 1;
|
|
96
|
+
}
|
|
97
|
+
return records;
|
|
98
|
+
}
|
|
99
|
+
|
|
74
100
|
function idFrom(text, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(text)?.[1] ?? fallback; }
|
|
75
101
|
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
76
102
|
function readInlineList(text, ...labels) {
|
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.67",
|
|
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/target-projection-aggregate-smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/conversion-evidence-smoke.mjs && node test/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-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/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/package-canvas-surface-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-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",
|