@shapeshift-labs/frontier-lang-parser 0.3.37 → 0.3.39
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 +3 -3
- package/dist/source-syntax-children.js +39 -0
- package/dist/source-syntax-row-config.js +133 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ export function parseFrontierSource(source, options = {}) {
|
|
|
37
37
|
const runtimeCapabilityBlocks = [], targetProjectionTargets = [];
|
|
38
38
|
const documentId = options.id ?? readId(source) ?? 'mod_frontier';
|
|
39
39
|
const documentName = options.name ?? readName(source) ?? 'FrontierModule';
|
|
40
|
-
for (const block of readBlocks(source)) {
|
|
40
|
+
for (const block of readBlocks(source, options)) {
|
|
41
41
|
if (block.kind === 'entity') nodes.push(parseEntity(block));
|
|
42
42
|
if (block.kind === 'state') nodes.push(parseState(block));
|
|
43
43
|
if (block.kind === 'action') nodes.push(parseAction(block));
|
|
@@ -76,8 +76,8 @@ export function parseFrontierFile(name, source) { return parseFrontierSource(sou
|
|
|
76
76
|
|
|
77
77
|
function readName(source) { return /module\s+([A-Za-z_$][\w$]*)/.exec(source)?.[1]; }
|
|
78
78
|
function readId(source) { return /module\s+[A-Za-z_$][\w$]*\s+@id\(\s*["']([^"']+)["']\s*\)/.exec(source)?.[1]; }
|
|
79
|
-
function readBlocks(source) {
|
|
80
|
-
return readFrontierSourceBlocks(source);
|
|
79
|
+
function readBlocks(source, options) {
|
|
80
|
+
return readFrontierSourceBlocks(source, options);
|
|
81
81
|
}
|
|
82
82
|
function idFrom(header, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(header)?.[1] ?? fallback; }
|
|
83
83
|
function nameFrom(header) { return /^([A-Za-z_$][\w$]*)/.exec(header)?.[1] ?? 'Unnamed'; }
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { ROW_SYNTAX_CONFIG } from './source-syntax-row-config.js';
|
|
2
|
+
|
|
3
|
+
const ROW_NAME_PATTERN = '([A-Za-z_$@./:*+-][\\w$./@:*+-]*)';
|
|
4
|
+
|
|
1
5
|
export function readSourceSyntaxChildren(source, block, options = {}) {
|
|
2
6
|
if (block.malformed) return [];
|
|
3
7
|
if (block.kind === 'conversion' || block.kind === 'universalConversionPlan') {
|
|
4
8
|
return readConversionSyntaxChildren(source, block, options);
|
|
5
9
|
}
|
|
10
|
+
const rowConfig = ROW_SYNTAX_CONFIG[block.kind];
|
|
11
|
+
if (rowConfig) return readGenericRowSyntaxChildren(source, block, options, rowConfig);
|
|
6
12
|
return [];
|
|
7
13
|
}
|
|
8
14
|
|
|
@@ -35,6 +41,38 @@ function readConversionSyntaxChildren(source, block, options) {
|
|
|
35
41
|
return children;
|
|
36
42
|
}
|
|
37
43
|
|
|
44
|
+
function readGenericRowSyntaxChildren(source, block, options, config) {
|
|
45
|
+
const children = [];
|
|
46
|
+
const rowPattern = new RegExp('^([A-Za-z_$][\\w$-]*)\\s+' + ROW_NAME_PATTERN + '(.*)$');
|
|
47
|
+
for (const line of readBodyLines(source, block)) {
|
|
48
|
+
if (!line.text || line.text.startsWith('#')) continue;
|
|
49
|
+
const row = rowPattern.exec(line.text);
|
|
50
|
+
if (!row) continue;
|
|
51
|
+
const [, rowKind, name, rest] = row;
|
|
52
|
+
if (!config.rowKinds.has(rowKind)) continue;
|
|
53
|
+
const normalizedRowKind = config.normalize?.(rowKind) ?? rowKind;
|
|
54
|
+
children.push(cleanRecord({
|
|
55
|
+
kind: config.childKind,
|
|
56
|
+
rowKind,
|
|
57
|
+
normalizedRowKind,
|
|
58
|
+
name,
|
|
59
|
+
id: idFrom(rest, `${config.idPrefix}_${safeId(normalizedRowKind)}_${safeId(name)}`),
|
|
60
|
+
header: line.text,
|
|
61
|
+
startOffset: line.startOffset,
|
|
62
|
+
endOffset: line.endOffset,
|
|
63
|
+
location: sourcePosition(source, line.startOffset),
|
|
64
|
+
parentKind: block.kind,
|
|
65
|
+
parentId: block.id,
|
|
66
|
+
parentName: block.name,
|
|
67
|
+
moduleId: block.moduleId,
|
|
68
|
+
moduleName: block.moduleName,
|
|
69
|
+
sourceSpan: sourceSpan(source, block, line.startOffset, line.endOffset, options),
|
|
70
|
+
recognized: true
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
return children;
|
|
74
|
+
}
|
|
75
|
+
|
|
38
76
|
function readBodyLines(source, block) {
|
|
39
77
|
const body = source.slice(block.bodyStartOffset, block.bodyEndOffset);
|
|
40
78
|
const lines = body.split('\n');
|
|
@@ -72,6 +110,7 @@ function sourceSpan(source, block, startOffset, endOffset, options = {}) {
|
|
|
72
110
|
|
|
73
111
|
function idFrom(header, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(header)?.[1] ?? fallback; }
|
|
74
112
|
function readInlineWord(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
113
|
+
function safeId(value) { return String(value).replace(/[^A-Za-z0-9_$-]+/g, '_').replace(/^_+|_+$/g, '') || 'row'; }
|
|
75
114
|
function cleanRecord(record) {
|
|
76
115
|
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0)));
|
|
77
116
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const appRows = words('mount provide provides required requires require route event asset gate gap proofGap evidence proofEvidence');
|
|
2
|
+
const canvasRows = words('element command state stateWrite trace gap proofGap evidence proofEvidence');
|
|
3
|
+
const constraintRows = words('variable var constraint hard soft preference prefer collapse admission');
|
|
4
|
+
const dialectRows = words('dialect record extern');
|
|
5
|
+
const interlinguaRows = words('layer constraint edge obligation proofObligation proof lowering lower source sourceLift lift evidence');
|
|
6
|
+
const packageRows = words('metadata dependency script export gap proofGap evidence proofEvidence');
|
|
7
|
+
const runtimeRows = words('host runtimeHost hostProfile sourceHost targetHost capability hostCapability hostBinding binding requirement runtimeRequirement requiredRuntime evidence proofEvidence gap proofGap');
|
|
8
|
+
|
|
9
|
+
export const ROW_SYNTAX_CONFIG = Object.freeze({
|
|
10
|
+
interlingua: rowConfig('interlinguaRow', 'interlingua_row', interlinguaRows, normalizeInterlinguaRow),
|
|
11
|
+
universalInterlingua: rowConfig('interlinguaRow', 'interlingua_row', interlinguaRows, normalizeInterlinguaRow),
|
|
12
|
+
dialectRegistry: rowConfig('dialectRegistryRow', 'dialect_registry_row', dialectRows, normalizeDialectRegistryRow),
|
|
13
|
+
universalDialectRegistry: rowConfig('dialectRegistryRow', 'dialect_registry_row', dialectRows, normalizeDialectRegistryRow),
|
|
14
|
+
runtimeCapabilities: rowConfig('runtimeCapabilityRow', 'runtime_capability_row', runtimeRows, normalizeRuntimeCapabilityRow),
|
|
15
|
+
runtimeCapabilityMatrix: rowConfig('runtimeCapabilityRow', 'runtime_capability_row', runtimeRows, normalizeRuntimeCapabilityRow),
|
|
16
|
+
runtimeHosts: rowConfig('runtimeCapabilityRow', 'runtime_capability_row', runtimeRows, normalizeRuntimeCapabilityRow),
|
|
17
|
+
resourceGraph: rowConfig('resourceGraphRow', 'resource_graph_row', words('resource owner loan alias move drop escape lifetime lifetimeRegion life outlives lifetimeRelation lifeRelation borrow borrowScope borrowRegion unsafe unsafeBoundary conflict proof proofObligation obligation'), normalizeResourceGraphRow),
|
|
18
|
+
semanticResourceGraph: rowConfig('resourceGraphRow', 'resource_graph_row', words('resource owner loan alias move drop escape lifetime lifetimeRegion life outlives lifetimeRelation lifeRelation borrow borrowScope borrowRegion unsafe unsafeBoundary conflict proof proofObligation obligation'), normalizeResourceGraphRow),
|
|
19
|
+
applicationSurface: rowConfig('applicationSurfaceRow', 'application_surface_row', appRows, normalizeApplicationSurfaceRow),
|
|
20
|
+
appHost: rowConfig('applicationSurfaceRow', 'application_surface_row', appRows, normalizeApplicationSurfaceRow),
|
|
21
|
+
plugin: rowConfig('applicationSurfaceRow', 'application_surface_row', appRows, normalizeApplicationSurfaceRow),
|
|
22
|
+
pluginSurface: rowConfig('applicationSurfaceRow', 'application_surface_row', appRows, normalizeApplicationSurfaceRow),
|
|
23
|
+
pluginContract: rowConfig('applicationSurfaceRow', 'application_surface_row', appRows, normalizeApplicationSurfaceRow),
|
|
24
|
+
target: rowConfig('targetProjectionRow', 'target_projection_row', words('projection lowering layer')),
|
|
25
|
+
packageManifest: rowConfig('packageManifestRow', 'package_manifest_row', packageRows, normalizeProofEvidenceRows),
|
|
26
|
+
packageGraph: rowConfig('packageManifestRow', 'package_manifest_row', packageRows, normalizeProofEvidenceRows),
|
|
27
|
+
packageSurface: rowConfig('packageManifestRow', 'package_manifest_row', packageRows, normalizeProofEvidenceRows),
|
|
28
|
+
canvasSurface: rowConfig('canvasSurfaceRow', 'canvas_surface_row', canvasRows, normalizeCanvasSurfaceRow),
|
|
29
|
+
canvasGraph: rowConfig('canvasSurfaceRow', 'canvas_surface_row', canvasRows, normalizeCanvasSurfaceRow),
|
|
30
|
+
constraintSpace: rowConfig('constraintSpaceRow', 'constraint_space_row', constraintRows, normalizeConstraintSpaceRow),
|
|
31
|
+
possibilitySpace: rowConfig('constraintSpaceRow', 'constraint_space_row', constraintRows, normalizeConstraintSpaceRow),
|
|
32
|
+
decisionGraph: rowConfig('decisionGraphRow', 'decision_graph_row', words('node edge chunk gate evidence semanticChange change patchEvent patch admissionDecision admission candidateDecision candidate mergeDecision merge replay tournament tournamentCandidate panelProjection panel rsiLoop improvementFeedback feedback'), normalizeDecisionGraphRow),
|
|
33
|
+
admissionGraph: rowConfig('decisionGraphRow', 'decision_graph_row', words('node edge chunk gate evidence semanticChange change patchEvent patch admissionDecision admission candidateDecision candidate mergeDecision merge replay tournament tournamentCandidate panelProjection panel rsiLoop improvementFeedback feedback'), normalizeDecisionGraphRow),
|
|
34
|
+
operations: rowConfig('semanticOperationRow', 'semantic_operation_row', words('operation op'), normalizeOperationRow),
|
|
35
|
+
semanticOperations: rowConfig('semanticOperationRow', 'semantic_operation_row', words('operation op'), normalizeOperationRow),
|
|
36
|
+
paradigm: rowConfig('paradigmRow', 'paradigm_row', words('valueSemantics mutationModel effectModel ownership ownershipModel lifetime lifetimeModel bindingScope binding dispatch typeModel moduleModel concurrency errorModel memoryModel evaluation metaprogramming interop lowering'), normalizeParadigmRow),
|
|
37
|
+
paradigmSemantics: rowConfig('paradigmRow', 'paradigm_row', words('valueSemantics mutationModel effectModel ownership ownershipModel lifetime lifetimeModel bindingScope binding dispatch typeModel moduleModel concurrency errorModel memoryModel evaluation metaprogramming interop lowering'), normalizeParadigmRow),
|
|
38
|
+
proof: rowConfig('proofRow', 'proof_row', words('contract refinement invariant termination temporal obligation artifact assumption')),
|
|
39
|
+
nativeSource: rowConfig('nativeSourceRow', 'native_source_row', words('loss evidence proofEvidence sourceMap sourcemap mapping sourceMapMapping mergeCandidate candidate'), normalizeNativeSourceRow)
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function rowConfig(childKind, idPrefix, rowKinds, normalize) {
|
|
43
|
+
return { childKind, idPrefix, rowKinds: new Set(rowKinds), normalize };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function words(source) { return source.split(/\s+/); }
|
|
47
|
+
|
|
48
|
+
function normalizeInterlinguaRow(rowKind) {
|
|
49
|
+
if (rowKind === 'edge') return 'constraint';
|
|
50
|
+
if (rowKind === 'proof' || rowKind === 'proofObligation') return 'obligation';
|
|
51
|
+
if (rowKind === 'lower' || rowKind === 'lowering') return 'lowering';
|
|
52
|
+
if (rowKind === 'source' || rowKind === 'sourceLift') return 'lift';
|
|
53
|
+
return rowKind;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function normalizeDialectRegistryRow(rowKind) {
|
|
57
|
+
if (rowKind === 'record') return 'dialect';
|
|
58
|
+
return rowKind;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function normalizeRuntimeCapabilityRow(rowKind) {
|
|
62
|
+
if (rowKind === 'capability') return 'hostCapability';
|
|
63
|
+
if (rowKind === 'binding') return 'hostBinding';
|
|
64
|
+
if (rowKind === 'requirement' || rowKind === 'requiredRuntime') return 'runtimeRequirement';
|
|
65
|
+
if (rowKind === 'proofEvidence') return 'evidence';
|
|
66
|
+
if (rowKind === 'gap') return 'proofGap';
|
|
67
|
+
return rowKind;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function normalizeResourceGraphRow(rowKind) {
|
|
71
|
+
if (rowKind === 'life' || rowKind === 'lifetimeRegion') return 'lifetime';
|
|
72
|
+
if (rowKind === 'lifeRelation') return 'lifetimeRelation';
|
|
73
|
+
if (rowKind === 'borrowRegion') return 'borrowScope';
|
|
74
|
+
if (rowKind === 'unsafe') return 'unsafeBoundary';
|
|
75
|
+
if (rowKind === 'proof' || rowKind === 'proofObligation') return 'obligation';
|
|
76
|
+
return rowKind;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function normalizeApplicationSurfaceRow(rowKind) {
|
|
80
|
+
if (rowKind === 'provide' || rowKind === 'provides') return 'provided-surface';
|
|
81
|
+
if (rowKind === 'required' || rowKind === 'requires' || rowKind === 'require') return 'required-capability';
|
|
82
|
+
if (rowKind === 'proofEvidence') return 'evidence';
|
|
83
|
+
if (rowKind === 'gap') return 'proofGap';
|
|
84
|
+
return rowKind;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function normalizeProofEvidenceRows(rowKind) {
|
|
88
|
+
if (rowKind === 'proofEvidence') return 'evidence';
|
|
89
|
+
if (rowKind === 'gap') return 'proofGap';
|
|
90
|
+
return rowKind;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizeCanvasSurfaceRow(rowKind) {
|
|
94
|
+
if (rowKind === 'stateWrite') return 'state-write';
|
|
95
|
+
return normalizeProofEvidenceRows(rowKind);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeConstraintSpaceRow(rowKind) {
|
|
99
|
+
if (rowKind === 'var') return 'variable';
|
|
100
|
+
if (rowKind === 'hard' || rowKind === 'soft') return 'constraint';
|
|
101
|
+
if (rowKind === 'prefer') return 'preference';
|
|
102
|
+
return rowKind;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function normalizeDecisionGraphRow(rowKind) {
|
|
106
|
+
if (rowKind === 'change') return 'semanticChange';
|
|
107
|
+
if (rowKind === 'patch') return 'patchEvent';
|
|
108
|
+
if (rowKind === 'admission') return 'admissionDecision';
|
|
109
|
+
if (rowKind === 'candidate') return 'candidateDecision';
|
|
110
|
+
if (rowKind === 'merge') return 'mergeDecision';
|
|
111
|
+
if (rowKind === 'panel') return 'panelProjection';
|
|
112
|
+
if (rowKind === 'feedback') return 'improvementFeedback';
|
|
113
|
+
return rowKind;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function normalizeOperationRow(rowKind) {
|
|
117
|
+
if (rowKind === 'op') return 'operation';
|
|
118
|
+
return rowKind;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function normalizeParadigmRow(rowKind) {
|
|
122
|
+
if (rowKind === 'ownership') return 'ownershipModel';
|
|
123
|
+
if (rowKind === 'lifetime') return 'lifetimeModel';
|
|
124
|
+
if (rowKind === 'binding') return 'bindingScope';
|
|
125
|
+
return rowKind;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalizeNativeSourceRow(rowKind) {
|
|
129
|
+
if (rowKind === 'proofEvidence') return 'evidence';
|
|
130
|
+
if (rowKind === 'sourcemap' || rowKind === 'mapping' || rowKind === 'sourceMapMapping') return 'sourceMap';
|
|
131
|
+
if (rowKind === 'candidate') return 'mergeCandidate';
|
|
132
|
+
return rowKind;
|
|
133
|
+
}
|