@shapeshift-labs/frontier-lang-parser 0.3.66 → 0.3.68
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/operations.js +98 -7
- package/package.json +2 -2
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,24 +43,108 @@ 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
|
-
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
136
|
+
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(unquotedText(text))?.[1]?.trim(); }
|
|
48
137
|
function readInlineQuoted(label, text) { return new RegExp("(?:^|\\s)" + label + "\\s+[\"']([^\"']+)[\"']").exec(text)?.[1]?.trim(); }
|
|
49
|
-
function readInlineFlag(label, text) { return new RegExp('(?:^|\\s)' + label + '(?:\\s|$)').test(text) || undefined; }
|
|
138
|
+
function readInlineFlag(label, text) { return new RegExp('(?:^|\\s)' + label + '(?:\\s|$)').test(unquotedText(text)) || undefined; }
|
|
50
139
|
function readInlineList(text, ...labels) {
|
|
140
|
+
const source = unquotedText(text);
|
|
51
141
|
for (const label of labels) {
|
|
52
|
-
const value = new RegExp('(?:^|\\s)' + label + '\\s+([^\\s]+)').exec(
|
|
142
|
+
const value = new RegExp('(?:^|\\s)' + label + '\\s+([^\\s]+)').exec(source)?.[1]?.trim();
|
|
53
143
|
if (value) return value.split(/[|,]/).map((item) => item.trim()).filter(Boolean);
|
|
54
144
|
}
|
|
55
145
|
return undefined;
|
|
56
146
|
}
|
|
147
|
+
function unquotedText(text) { return text.replace(/"[^"]*"|'[^']*'/g, (match) => ' '.repeat(match.length)); }
|
|
57
148
|
function cleanRecord(record) {
|
|
58
149
|
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0)));
|
|
59
150
|
}
|
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.68",
|
|
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",
|