@shapeshift-labs/frontier-lang-parser 0.3.65 → 0.3.66
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/target-projection.js +37 -11
- package/package.json +1 -1
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,
|
|
@@ -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) {
|