@shapeshift-labs/frontier-lang-parser 0.3.15 → 0.3.16
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 +20 -0
- package/dist/index.js +9 -29
- package/dist/metadata.js +16 -1
- package/dist/source-evidence.js +230 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -239,6 +239,26 @@ conversion TodoJavascriptToRust @id("conversion_todo_js_rust") {
|
|
|
239
239
|
|
|
240
240
|
`sourceRuntime` and `targetRuntime` become runtime maps. `runtimeRequirement` rows become proof obligations for host/runtime capabilities. `dialect` and `extern` rows preserve dialect-specific constructs, projection readiness, loss/evidence ids, and binding metadata without requiring the authored Frontier file to drop down to raw JSON.
|
|
241
241
|
|
|
242
|
+
## Authored native source evidence
|
|
243
|
+
|
|
244
|
+
`nativeSource` blocks can also carry source-bound merge evidence. This keeps parser/source-map/merge-candidate facts in `.frontier` text instead of requiring a raw JSON sidecar for the first authored program slice.
|
|
245
|
+
|
|
246
|
+
```frontier
|
|
247
|
+
nativeSource TodoTs @id("native_todo_ts") {
|
|
248
|
+
language typescript
|
|
249
|
+
parser typescript
|
|
250
|
+
sourcePath src/todo.ts
|
|
251
|
+
sourceHash sha256:example
|
|
252
|
+
frontierNodes ent_todo, action_add
|
|
253
|
+
evidence todoTitleProbe @id("artifact_todo_title_probe") kind test status passed path reports/todo-title.json
|
|
254
|
+
sourceMap todoProjection @id("sourcemap_todo_ts") target typescript targetPath src/generated/todo.ts evidence artifact_todo_title_probe
|
|
255
|
+
mapping todoTitle @id("map_todo_title") sourceMap sourcemap_todo_ts semanticNode field_title sourceSpan src/todo.ts:1:1-1:12 generatedSpan src/generated/todo.ts:1:1-1:20 precision exact evidence artifact_todo_title_probe
|
|
256
|
+
mergeCandidate todoTitle @id("candidate_todo_title") symbol symbol:Todo.title semanticNode field_title conflictKey symbol:Todo.title readiness ready sourceMap sourcemap_todo_ts sourceMapMapping map_todo_title
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The parser projects these rows into `metadata.universalAst.sourceMaps`, `metadata.universalAst.mergeCandidates`, and `metadata.universalAst.evidence`. `nativeSource` nodes keep id links through `sourceMapIds`, `mergeCandidateIds`, and `evidenceIds`. Runtime/browser equivalence still requires separate proof artifacts.
|
|
261
|
+
|
|
242
262
|
## Benchmarks
|
|
243
263
|
|
|
244
264
|
Run the package-local benchmark with:
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { actionNode, capabilityNode, createDocument, effectNode, entityNode, externNode, latticeNode, migrationNode,
|
|
1
|
+
import { actionNode, capabilityNode, createDocument, effectNode, entityNode, externNode, latticeNode, migrationNode, stateNode, targetNode, typeNode } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import { parseConversionBlock } from './conversion.js';
|
|
3
3
|
import { createParsedMetadata } from './metadata.js';
|
|
4
4
|
import { parseSemanticOperationsBlock } from './operations.js';
|
|
5
5
|
import { parseParadigmBlock } from './paradigm.js';
|
|
6
6
|
import { parseProofBlock } from './proof.js';
|
|
7
|
+
import { parseNativeSourceBlock } from './source-evidence.js';
|
|
7
8
|
import { parseViewBlock } from './view.js';
|
|
8
9
|
|
|
9
10
|
export function parseFrontierSource(source, options = {}) {
|
|
@@ -12,6 +13,7 @@ export function parseFrontierSource(source, options = {}) {
|
|
|
12
13
|
const paradigmBlocks = [];
|
|
13
14
|
const operationBlocks = [];
|
|
14
15
|
const conversionBlocks = [];
|
|
16
|
+
const nativeSourceBlocks = [];
|
|
15
17
|
const documentId = options.id ?? readId(source) ?? 'mod_frontier';
|
|
16
18
|
const documentName = options.name ?? readName(source) ?? 'FrontierModule';
|
|
17
19
|
for (const block of readBlocks(source)) {
|
|
@@ -25,14 +27,18 @@ export function parseFrontierSource(source, options = {}) {
|
|
|
25
27
|
if (block.kind === 'type') nodes.push(parseType(block));
|
|
26
28
|
if (block.kind === 'extern') nodes.push(parseExtern(block));
|
|
27
29
|
if (block.kind === 'lattice') nodes.push(parseLattice(block));
|
|
28
|
-
if (block.kind === 'nativeSource')
|
|
30
|
+
if (block.kind === 'nativeSource') {
|
|
31
|
+
const parsed = parseNativeSourceBlock(block);
|
|
32
|
+
nodes.push(parsed.node);
|
|
33
|
+
nativeSourceBlocks.push(parsed);
|
|
34
|
+
}
|
|
29
35
|
if (block.kind === 'target') nodes.push(parseTarget(block));
|
|
30
36
|
if (block.kind === 'proof') proofBlocks.push(parseProofBlock(block));
|
|
31
37
|
if (block.kind === 'paradigm' || block.kind === 'paradigmSemantics') paradigmBlocks.push(parseParadigmBlock(block));
|
|
32
38
|
if (block.kind === 'operations' || block.kind === 'semanticOperations') operationBlocks.push(parseSemanticOperationsBlock(block));
|
|
33
39
|
if (block.kind === 'conversion' || block.kind === 'universalConversionPlan') conversionBlocks.push(parseConversionBlock(block));
|
|
34
40
|
}
|
|
35
|
-
const metadata = createParsedMetadata({ proofBlocks, paradigmBlocks, operationBlocks, conversionBlocks });
|
|
41
|
+
const metadata = createParsedMetadata({ proofBlocks, paradigmBlocks, operationBlocks, conversionBlocks, nativeSourceBlocks });
|
|
36
42
|
return createDocument({ id: documentId, name: documentName, nodes, ...(metadata ? { metadata } : {}) });
|
|
37
43
|
}
|
|
38
44
|
|
|
@@ -173,32 +179,6 @@ function parseLattice(block) {
|
|
|
173
179
|
} : undefined
|
|
174
180
|
});
|
|
175
181
|
}
|
|
176
|
-
function parseNativeSource(block) {
|
|
177
|
-
const name = nameFrom(block.header);
|
|
178
|
-
const losses = [];
|
|
179
|
-
const lossRe = /^\s*loss\s+([A-Za-z][\w-]*)\s+["']([^"']+)["'](?:\s+severity\s+([A-Za-z][\w-]*))?/gm;
|
|
180
|
-
let match;
|
|
181
|
-
while ((match = lossRe.exec(block.body))) {
|
|
182
|
-
losses.push({
|
|
183
|
-
id: `loss_${name}_${losses.length}`,
|
|
184
|
-
kind: match[1],
|
|
185
|
-
message: match[2],
|
|
186
|
-
severity: match[3] ?? 'warning'
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
return nativeSourceNode({
|
|
190
|
-
id: idFrom(block.header, `native_${name}`),
|
|
191
|
-
name,
|
|
192
|
-
language: readWord('language', block.body) ?? name,
|
|
193
|
-
parser: readWord('parser', block.body),
|
|
194
|
-
parserVersion: readWord('parserVersion', block.body),
|
|
195
|
-
sourcePath: readWord('sourcePath', block.body) ?? readWord('path', block.body),
|
|
196
|
-
sourceHash: readWord('sourceHash', block.body),
|
|
197
|
-
symbol: readWord('symbol', block.body),
|
|
198
|
-
frontierNodeIds: readList('frontierNodes', block.body),
|
|
199
|
-
losses: losses.length ? losses : undefined
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
182
|
function parseTarget(block) {
|
|
203
183
|
const name = nameFrom(block.header);
|
|
204
184
|
return targetNode({
|
package/dist/metadata.js
CHANGED
|
@@ -21,12 +21,15 @@ const PARADIGM_GROUPS = [
|
|
|
21
21
|
'loweringRecords'
|
|
22
22
|
];
|
|
23
23
|
|
|
24
|
-
export function createParsedMetadata({ proofBlocks = [], paradigmBlocks = [], operationBlocks = [], conversionBlocks = [] } = {}) {
|
|
24
|
+
export function createParsedMetadata({ proofBlocks = [], paradigmBlocks = [], operationBlocks = [], conversionBlocks = [], nativeSourceBlocks = [] } = {}) {
|
|
25
25
|
const metadata = {};
|
|
26
26
|
if (proofBlocks.length) metadata.proof = mergeProofBlocks(proofBlocks);
|
|
27
27
|
if (paradigmBlocks.length) metadata.paradigmSemantics = mergeParadigmBlocks(paradigmBlocks);
|
|
28
28
|
if (operationBlocks.length) metadata.semanticOperations = mergeOperationBlocks(operationBlocks);
|
|
29
29
|
if (conversionBlocks.length) metadata.universalConversionPlan = mergeConversionBlocks(conversionBlocks);
|
|
30
|
+
if (nativeSourceBlocks.some((block) => block.sourceMaps.length || block.mergeCandidates.length || block.evidence.length)) {
|
|
31
|
+
metadata.universalAst = mergeNativeSourceBlocks(nativeSourceBlocks);
|
|
32
|
+
}
|
|
30
33
|
return Object.keys(metadata).length ? metadata : undefined;
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -73,3 +76,15 @@ function mergeConversionBlocks(blocks) {
|
|
|
73
76
|
}
|
|
74
77
|
return plan;
|
|
75
78
|
}
|
|
79
|
+
|
|
80
|
+
function mergeNativeSourceBlocks(blocks) {
|
|
81
|
+
return {
|
|
82
|
+
id: blocks.length === 1 ? `universalAst:${blocks[0].node.id}` : 'universalAst:source',
|
|
83
|
+
nativeSourceIds: blocks.map((block) => block.node.id),
|
|
84
|
+
sourceMaps: blocks.flatMap((block) => block.sourceMaps ?? []),
|
|
85
|
+
mergeCandidates: blocks.flatMap((block) => block.mergeCandidates ?? []),
|
|
86
|
+
evidence: blocks.flatMap((block) => block.evidence ?? []),
|
|
87
|
+
losses: blocks.flatMap((block) => block.losses ?? []),
|
|
88
|
+
metadata: { authoredNativeSourceIds: blocks.map((block) => block.node.id) }
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createSemanticMergeCandidateRecord, createSourceMapRecord, nativeSourceNode } from '@shapeshift-labs/frontier-lang-kernel';
|
|
2
|
+
|
|
3
|
+
export function parseNativeSourceBlock(block) {
|
|
4
|
+
const name = nameFrom(block.header);
|
|
5
|
+
const losses = parseLosses(name, block.body);
|
|
6
|
+
const nativeSourceId = idFrom(block.header, `native_${name}`);
|
|
7
|
+
const evidence = parseEvidenceRecords(block.body);
|
|
8
|
+
const sourceMaps = parseSourceMaps(block.body, {
|
|
9
|
+
nativeSourceId,
|
|
10
|
+
sourcePath: readWord('sourcePath', block.body) ?? readWord('path', block.body),
|
|
11
|
+
sourceHash: readWord('sourceHash', block.body),
|
|
12
|
+
evidence
|
|
13
|
+
});
|
|
14
|
+
const mergeCandidates = parseMergeCandidates(block.body, {
|
|
15
|
+
nativeSourceId,
|
|
16
|
+
language: readWord('language', block.body) ?? name,
|
|
17
|
+
sourcePath: readWord('sourcePath', block.body) ?? readWord('path', block.body),
|
|
18
|
+
sourceMaps,
|
|
19
|
+
evidence
|
|
20
|
+
});
|
|
21
|
+
const node = nativeSourceNode({
|
|
22
|
+
id: nativeSourceId,
|
|
23
|
+
name,
|
|
24
|
+
language: readWord('language', block.body) ?? name,
|
|
25
|
+
parser: readWord('parser', block.body),
|
|
26
|
+
parserVersion: readWord('parserVersion', block.body),
|
|
27
|
+
sourcePath: readWord('sourcePath', block.body) ?? readWord('path', block.body),
|
|
28
|
+
sourceHash: readWord('sourceHash', block.body),
|
|
29
|
+
symbol: readWord('symbol', block.body),
|
|
30
|
+
frontierNodeIds: readList('frontierNodes', block.body),
|
|
31
|
+
sourceMapIds: sourceMaps.map((sourceMap) => sourceMap.id),
|
|
32
|
+
mergeCandidateIds: mergeCandidates.map((candidate) => candidate.id),
|
|
33
|
+
evidenceIds: evidence.map((record) => record.id),
|
|
34
|
+
losses: losses.length ? losses : undefined
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
node,
|
|
38
|
+
sourceMaps,
|
|
39
|
+
mergeCandidates,
|
|
40
|
+
evidence,
|
|
41
|
+
losses
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseLosses(name, body) {
|
|
46
|
+
const losses = [];
|
|
47
|
+
const lossRe = /^\s*loss\s+([A-Za-z][\w-]*)\s+["']([^"']+)["'](?:\s+severity\s+([A-Za-z][\w-]*))?/gm;
|
|
48
|
+
let match;
|
|
49
|
+
while ((match = lossRe.exec(body))) {
|
|
50
|
+
losses.push({
|
|
51
|
+
id: `loss_${name}_${losses.length}`,
|
|
52
|
+
kind: match[1],
|
|
53
|
+
message: match[2],
|
|
54
|
+
severity: match[3] ?? 'warning'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return losses;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function parseEvidenceRecords(body) {
|
|
61
|
+
const records = [];
|
|
62
|
+
for (const { name, rest } of matchingRows(body, /^(?:evidence|proofEvidence)\s+([A-Za-z_$][\w$-]*)(.*)$/)) {
|
|
63
|
+
records.push(cleanRecord({
|
|
64
|
+
id: idFrom(rest, `evidence_${name}`),
|
|
65
|
+
kind: readInlineWord('kind', rest) ?? 'note',
|
|
66
|
+
status: readInlineWord('status', rest) ?? 'unknown',
|
|
67
|
+
path: readInlineWord('path', rest),
|
|
68
|
+
summary: readInlineQuoted('summary', rest),
|
|
69
|
+
metadata: { name }
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
return records;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function parseSourceMaps(body, context) {
|
|
76
|
+
const rows = matchingRows(body, /^(?:sourceMap|sourcemap)\s+([A-Za-z_$][\w$-]*)(.*)$/);
|
|
77
|
+
const evidenceById = new Map(context.evidence.map((record) => [record.id, record]));
|
|
78
|
+
const mappingRows = matchingRows(body, /^(?:mapping|sourceMapMapping)\s+([A-Za-z_$][\w$-]*)(.*)$/);
|
|
79
|
+
const defaultSourceMapId = rows.length === 1 ? idFrom(rows[0].rest, `sourcemap_${rows[0].name}`) : undefined;
|
|
80
|
+
return rows.map(({ name, rest }) => {
|
|
81
|
+
const id = idFrom(rest, `sourcemap_${name}`);
|
|
82
|
+
const evidenceIds = readInlineList(rest, 'evidence', 'evidenceIds');
|
|
83
|
+
const mappings = mappingRows
|
|
84
|
+
.filter((row) => (readInlineWord('sourceMap', row.rest) ?? readInlineWord('sourceMapId', row.rest) ?? defaultSourceMapId) === id)
|
|
85
|
+
.map((row) => parseSourceMapMapping(row.name, row.rest, {
|
|
86
|
+
sourceMapId: id,
|
|
87
|
+
nativeSourceId: context.nativeSourceId,
|
|
88
|
+
sourcePath: readInlineWord('sourcePath', rest) ?? readInlineWord('path', rest) ?? context.sourcePath
|
|
89
|
+
}));
|
|
90
|
+
return createSourceMapRecord(cleanRecord({
|
|
91
|
+
id,
|
|
92
|
+
sourcePath: readInlineWord('sourcePath', rest) ?? readInlineWord('path', rest) ?? context.sourcePath,
|
|
93
|
+
sourceHash: readInlineWord('sourceHash', rest) ?? context.sourceHash,
|
|
94
|
+
target: readInlineWord('target', rest),
|
|
95
|
+
targetPath: readInlineWord('targetPath', rest),
|
|
96
|
+
targetHash: readInlineWord('targetHash', rest),
|
|
97
|
+
semanticIndexId: readInlineWord('semanticIndex', rest) ?? readInlineWord('semanticIndexId', rest),
|
|
98
|
+
universalAstId: readInlineWord('universalAst', rest) ?? readInlineWord('universalAstId', rest),
|
|
99
|
+
nativeAstId: readInlineWord('nativeAst', rest) ?? readInlineWord('nativeAstId', rest),
|
|
100
|
+
nativeSourceId: readInlineWord('nativeSource', rest) ?? readInlineWord('nativeSourceId', rest) ?? context.nativeSourceId,
|
|
101
|
+
mappings,
|
|
102
|
+
evidence: evidenceIds?.map((evidenceId) => evidenceById.get(evidenceId) ?? { id: evidenceId, kind: 'note', status: 'unknown' })
|
|
103
|
+
}));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function parseSourceMapMapping(name, text, context) {
|
|
108
|
+
return cleanRecord({
|
|
109
|
+
id: idFrom(text, `mapping_${name}`),
|
|
110
|
+
semanticNodeId: readInlineWord('semanticNode', text) ?? readInlineWord('semanticNodeId', text),
|
|
111
|
+
nativeSourceId: readInlineWord('nativeSource', text) ?? readInlineWord('nativeSourceId', text) ?? context.nativeSourceId,
|
|
112
|
+
nativeAstNodeId: readInlineWord('nativeAstNode', text) ?? readInlineWord('nativeAstNodeId', text),
|
|
113
|
+
semanticSymbolId: readInlineWord('semanticSymbol', text) ?? readInlineWord('symbol', text) ?? readInlineWord('semanticSymbolId', text),
|
|
114
|
+
semanticOccurrenceId: readInlineWord('semanticOccurrence', text) ?? readInlineWord('semanticOccurrenceId', text),
|
|
115
|
+
mergeCandidateId: readInlineWord('mergeCandidate', text) ?? readInlineWord('mergeCandidateId', text),
|
|
116
|
+
sourceSpan: parseSpan(readInlineWord('sourceSpan', text), context.sourcePath),
|
|
117
|
+
generatedSpan: parseSpan(readInlineWord('generatedSpan', text), readInlineWord('targetPath', text)),
|
|
118
|
+
target: readInlineWord('target', text),
|
|
119
|
+
generatedName: readInlineWord('generatedName', text),
|
|
120
|
+
evidenceIds: readInlineList(text, 'evidence', 'evidenceIds'),
|
|
121
|
+
lossIds: readInlineList(text, 'loss', 'lossIds'),
|
|
122
|
+
precision: readInlineWord('precision', text) ?? 'unknown',
|
|
123
|
+
preservation: readInlineWord('preservation', text),
|
|
124
|
+
metadata: cleanRecord({
|
|
125
|
+
sourceMapId: context.sourceMapId,
|
|
126
|
+
ownershipRegionId: readInlineWord('ownershipRegion', text) ?? readInlineWord('ownershipRegionId', text),
|
|
127
|
+
ownershipRegionKey: readInlineWord('ownershipKey', text) ?? readInlineWord('ownershipRegionKey', text)
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function parseMergeCandidates(body, context) {
|
|
133
|
+
const sourceMapIds = context.sourceMaps.map((sourceMap) => sourceMap.id);
|
|
134
|
+
return matchingRows(body, /^(?:mergeCandidate|candidate)\s+([A-Za-z_$][\w$-]*)(.*)$/).map(({ name, rest }) => {
|
|
135
|
+
const conflictKeys = readInlineList(rest, 'conflictKey', 'conflictKeys', 'ownershipKey', 'ownershipKeys');
|
|
136
|
+
const symbols = readInlineList(rest, 'semanticSymbol', 'semanticSymbols', 'symbol', 'symbols', 'semanticSymbolIds');
|
|
137
|
+
const nodes = readInlineList(rest, 'semanticNode', 'semanticNodes', 'semanticNodeIds');
|
|
138
|
+
const evidenceIds = readInlineList(rest, 'evidence', 'evidenceIds');
|
|
139
|
+
const sourceMapMappingIds = readInlineList(rest, 'sourceMapMapping', 'sourceMapMappings', 'sourceMapMappingIds');
|
|
140
|
+
return createSemanticMergeCandidateRecord(cleanRecord({
|
|
141
|
+
id: idFrom(rest, `merge_candidate_${name}`),
|
|
142
|
+
language: readInlineWord('language', rest) ?? context.language,
|
|
143
|
+
sourcePath: readInlineWord('sourcePath', rest) ?? readInlineWord('path', rest) ?? context.sourcePath,
|
|
144
|
+
baseHash: readInlineWord('baseHash', rest),
|
|
145
|
+
targetHash: readInlineWord('targetHash', rest),
|
|
146
|
+
touchedSymbols: symbols?.map((symbol) => ({ id: symbol, conflictKey: conflictKeys?.[0] ?? symbol })),
|
|
147
|
+
touchedSemanticNodes: nodes?.map((node) => ({ id: node, conflictKey: conflictKeys?.[0] ?? node })),
|
|
148
|
+
nativeSpans: parseCandidateNativeSpans(rest, context),
|
|
149
|
+
conflictKeys,
|
|
150
|
+
readiness: readInlineWord('readiness', rest),
|
|
151
|
+
reasons: uniqueList([readInlineQuoted('reason', rest), ...(readInlineList(rest, 'reasonCode', 'reasonCodes', 'reasons') ?? [])]),
|
|
152
|
+
evidence: evidenceIds?.map((evidenceId) => context.evidence.find((record) => record.id === evidenceId) ?? { id: evidenceId, kind: 'note', status: 'unknown' }),
|
|
153
|
+
metadata: cleanRecord({
|
|
154
|
+
name,
|
|
155
|
+
nativeSourceId: readInlineWord('nativeSource', rest) ?? readInlineWord('nativeSourceId', rest) ?? context.nativeSourceId,
|
|
156
|
+
sourceMapIds: readInlineList(rest, 'sourceMap', 'sourceMaps', 'sourceMapIds') ?? sourceMapIds,
|
|
157
|
+
sourceMapMappingIds,
|
|
158
|
+
ownershipKeys: readInlineList(rest, 'ownershipKey', 'ownershipKeys')
|
|
159
|
+
})
|
|
160
|
+
}));
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function parseCandidateNativeSpans(text, context) {
|
|
165
|
+
const span = parseSpan(readInlineWord('sourceSpan', text), context.sourcePath);
|
|
166
|
+
const nativeAstNodeId = readInlineWord('nativeAstNode', text) ?? readInlineWord('nativeAstNodeId', text);
|
|
167
|
+
if (!span && !nativeAstNodeId) return undefined;
|
|
168
|
+
const conflictKey = readInlineList(text, 'conflictKey', 'conflictKeys')?.[0]
|
|
169
|
+
?? readInlineWord('semanticSymbol', text)
|
|
170
|
+
?? readInlineWord('symbol', text)
|
|
171
|
+
?? nativeAstNodeId
|
|
172
|
+
?? 'native-span';
|
|
173
|
+
return [cleanRecord({
|
|
174
|
+
id: readInlineWord('nativeSpan', text) ?? `native_span_${hashableId(conflictKey)}`,
|
|
175
|
+
path: span?.path ?? context.sourcePath,
|
|
176
|
+
language: readInlineWord('language', text) ?? context.language,
|
|
177
|
+
nativeAstNodeId,
|
|
178
|
+
semanticNodeId: readInlineWord('semanticNode', text) ?? readInlineWord('semanticNodeId', text),
|
|
179
|
+
symbolId: readInlineWord('semanticSymbol', text) ?? readInlineWord('symbol', text),
|
|
180
|
+
span,
|
|
181
|
+
conflictKey
|
|
182
|
+
})];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function parseSpan(value, fallbackPath) {
|
|
186
|
+
if (!value) return undefined;
|
|
187
|
+
const match = /^(.+?):(\d+):(\d+)-(\d+):(\d+)$/.exec(value);
|
|
188
|
+
if (!match) return { path: value };
|
|
189
|
+
return {
|
|
190
|
+
path: match[1] || fallbackPath,
|
|
191
|
+
startLine: Number(match[2]),
|
|
192
|
+
startColumn: Number(match[3]),
|
|
193
|
+
endLine: Number(match[4]),
|
|
194
|
+
endColumn: Number(match[5])
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function matchingRows(body, pattern) {
|
|
199
|
+
const rows = [];
|
|
200
|
+
for (const rawLine of body.split('\n')) {
|
|
201
|
+
const line = rawLine.trim();
|
|
202
|
+
if (!line || line.startsWith('#')) continue;
|
|
203
|
+
const match = pattern.exec(line);
|
|
204
|
+
if (match) rows.push({ name: match[1], rest: match[2] ?? '' });
|
|
205
|
+
}
|
|
206
|
+
return rows;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function idFrom(text, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(text)?.[1] ?? fallback; }
|
|
210
|
+
function nameFrom(header) { return /^([A-Za-z_$][\w$]*)/.exec(header)?.[1] ?? 'Unnamed'; }
|
|
211
|
+
function readWord(label, body) { return new RegExp('^\\s*' + label + '\\s+([^\\s]+)', 'm').exec(body)?.[1]?.trim(); }
|
|
212
|
+
function readList(label, body) { const line = new RegExp('^\\s*' + label + '\\s+([^\\n]+)', 'm').exec(body)?.[1]; return line ? line.split(',').map((item) => item.trim()).filter(Boolean) : undefined; }
|
|
213
|
+
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
214
|
+
function readInlineQuoted(label, text) { return new RegExp("(?:^|\\s)" + label + "\\s+[\"']([^\"']+)[\"']").exec(text)?.[1]?.trim(); }
|
|
215
|
+
function readInlineList(text, ...labels) {
|
|
216
|
+
for (const label of labels) {
|
|
217
|
+
const value = new RegExp('(?:^|\\s)' + label + '\\s+([^\\s]+)').exec(text)?.[1]?.trim();
|
|
218
|
+
if (value) return value.split(/[|,]/).map((item) => item.trim()).filter(Boolean);
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
function cleanRecord(record) {
|
|
223
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0) && (!value || typeof value !== 'object' || Object.keys(value).length > 0)));
|
|
224
|
+
}
|
|
225
|
+
function uniqueList(values) {
|
|
226
|
+
return [...new Set(values.filter(Boolean))];
|
|
227
|
+
}
|
|
228
|
+
function hashableId(value) {
|
|
229
|
+
return String(value ?? 'unknown').replace(/[^A-Za-z0-9_$-]+/g, '_');
|
|
230
|
+
}
|