@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 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.body, name);
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(body, targetName) {
2
- const projectionContracts = readTargetProjectionContracts(body, targetName);
3
- const projectionLayers = readTargetProjectionLayers(body, targetName);
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(body, targetName) {
20
+ function readTargetProjectionContracts(blockOrBody, targetName) {
21
21
  const rows = [];
22
- const re = /^\s*(projection|lowering)\s+([A-Za-z_$][\w$-]*)([^\n]*)$/gm;
23
- let match;
24
- while ((match = re.exec(body))) {
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(body, targetName) {
53
+ function readTargetProjectionLayers(blockOrBody, targetName) {
52
54
  const rows = [];
53
- const re = /^\s*layer\s+([A-Za-z_$][\w$-]*)([^\n]*)$/gm;
54
- let match;
55
- while ((match = re.exec(body))) {
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.65",
3
+ "version": "0.3.66",
4
4
  "description": "Parser for the first Frontier Lang .frontier syntax slice.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",