@shapeshift-labs/frontier-lang-parser 0.3.14 → 0.3.15

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 CHANGED
@@ -220,6 +220,25 @@ npm install @shapeshift-labs/frontier-lang-parser
220
220
 
221
221
  The parser projects text into `@shapeshift-labs/frontier-lang-kernel` documents. The syntax is intentionally small and experimental.
222
222
 
223
+ ## Authored conversion syntax
224
+
225
+ `.frontier` files can carry universal conversion evidence directly in `conversion` or `universalConversionPlan` blocks. The parser projects these records into `metadata.universalConversionPlan` for the compiler facade and downstream semantic merge tooling.
226
+
227
+ ```frontier
228
+ conversion TodoJavascriptToRust @id("conversion_todo_js_rust") {
229
+ sourceLanguage javascript
230
+ target rust
231
+ sourceRuntime javascript node
232
+ targetRuntime rust cli
233
+ runtimeRequirement fetchRuntime @id("runtime_requirement_fetch") capability fetch sourceRuntime node targetRuntime cli evidence artifact_todo_title_probe
234
+ dialect nodeProcess @id("dialect_node_process") language javascript dialect node.runtime kind runtime target rust disposition unsupported readiness blocked loss loss_node_process_projection
235
+ extern viteRoutes @id("extern_vite_routes") language javascript dialect vite.plugin.virtual-module externKind generatorArtifact target rust disposition runtime-required evidence evidence_vite_routes_manifest bindingSymbol virtual:routes
236
+ constraint type publicApi @id("type_constraint_public_api") role source kind public-function symbol symbol:addTodo signatureHash sig_add_todo evidence artifact_todo_title_probe
237
+ }
238
+ ```
239
+
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
+
223
242
  ## Benchmarks
224
243
 
225
244
  Run the package-local benchmark with:
@@ -46,14 +46,75 @@ export function parseConversionBlock(block) {
46
46
  if (!line || line.startsWith('#')) continue;
47
47
  const target = /^target\s+([^\s,]+)/.exec(line)?.[1];
48
48
  const sourceLanguage = /^sourceLanguage\s+([^\s,]+)/.exec(line)?.[1] ?? /^source\s+([^\s,]+)/.exec(line)?.[1];
49
+ const sourceRuntime = /^sourceRuntime\s+([^\s,]+)\s+([^\s,]+)/.exec(line);
50
+ const targetRuntime = /^targetRuntime\s+([^\s,]+)\s+([^\s,]+)/.exec(line);
51
+ const runtimeRequirement = /^(?:runtimeRequirement|requiredRuntime|requiresRuntime)\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
52
+ const dialect = /^dialect\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
53
+ const extern = /^extern\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
49
54
  const constraint = /^constraint\s+([A-Za-z_$][\w$-]*)\s+([A-Za-z_$][\w$-]*)(.*)$/.exec(line);
50
55
  if (target) plan.targets.push(target);
51
56
  else if (sourceLanguage) plan.sourceLanguage = sourceLanguage;
57
+ else if (sourceRuntime) plan.sourceRuntimes = { ...(plan.sourceRuntimes ?? {}), [sourceRuntime[1]]: sourceRuntime[2] };
58
+ else if (targetRuntime) plan.targetRuntimes = { ...(plan.targetRuntimes ?? {}), [targetRuntime[1]]: targetRuntime[2] };
59
+ else if (runtimeRequirement) addRuntimeRequirement(plan, runtimeRequirement[1], runtimeRequirement[2]);
60
+ else if (dialect) addDialectRecord(plan, dialect[1], dialect[2], false);
61
+ else if (extern) addDialectRecord(plan, extern[1], extern[2], true);
52
62
  else if (constraint) addConstraint(plan, constraint[1], constraint[2], constraint[3]);
53
63
  }
54
64
  return cleanRecord({ ...plan, targets: unique(plan.targets) });
55
65
  }
56
66
 
67
+ function addRuntimeRequirement(plan, name, text) {
68
+ plan.runtimeRequirements = [...(plan.runtimeRequirements ?? []), cleanRecord({
69
+ id: idFrom(text, `runtime_requirement_${name}`),
70
+ name,
71
+ sourceLanguage: readInlineWord('sourceLanguage', text) ?? plan.sourceLanguage,
72
+ target: readInlineWord('target', text) ?? readInlineWord('targetLanguage', text) ?? plan.targets[0],
73
+ capability: readInlineWord('capability', text) ?? readInlineWord('kind', text) ?? name,
74
+ kind: readInlineWord('kind', text),
75
+ sourceRuntime: readInlineWord('sourceRuntime', text) ?? readInlineWord('runtime', text),
76
+ targetRuntime: readInlineWord('targetRuntime', text),
77
+ sourceHost: readInlineWord('sourceHost', text),
78
+ targetHost: readInlineWord('targetHost', text),
79
+ reason: readInlineQuoted('reason', text) ?? readInlineWord('reason', text),
80
+ evidenceIds: readInlineList(text, 'evidence', 'evidenceIds')
81
+ })];
82
+ }
83
+
84
+ function addDialectRecord(plan, name, text, isExtern) {
85
+ const projection = cleanRecord({
86
+ disposition: readInlineWord('disposition', text),
87
+ readiness: readInlineWord('readiness', text),
88
+ targets: readInlineList(text, 'target', 'targets', 'targetLanguage') ?? plan.targets,
89
+ evidenceIds: readInlineList(text, 'projectionEvidence', 'projectionEvidenceIds', 'evidence', 'evidenceIds'),
90
+ lossIds: readInlineList(text, 'projectionLoss', 'projectionLossIds', 'loss', 'lossId', 'lossIds')
91
+ });
92
+ const record = cleanRecord({
93
+ id: idFrom(text, `${isExtern ? 'extern' : 'dialect'}_${name}`),
94
+ language: readInlineWord('language', text) ?? plan.sourceLanguage,
95
+ dialect: readInlineWord('dialect', text) ?? name,
96
+ name: readInlineWord('name', text) ?? name,
97
+ nativeKind: readInlineWord('nativeKind', text),
98
+ sourcePath: readInlineWord('sourcePath', text) ?? readInlineWord('path', text),
99
+ nativeSourceId: readInlineWord('nativeSource', text) ?? readInlineWord('nativeSourceId', text),
100
+ nativeAstId: readInlineWord('nativeAst', text) ?? readInlineWord('nativeAstId', text),
101
+ nativeAstNodeId: readInlineWord('nativeAstNode', text) ?? readInlineWord('nativeAstNodeId', text),
102
+ semanticNodeId: readInlineWord('semanticNode', text) ?? readInlineWord('semanticNodeId', text),
103
+ semanticSymbolId: readInlineWord('symbol', text) ?? readInlineWord('semanticSymbolId', text),
104
+ sourceMapId: readInlineWord('sourceMap', text) ?? readInlineWord('sourceMapId', text),
105
+ sourceMapMappingId: readInlineWord('sourceMapMapping', text) ?? readInlineWord('sourceMapMappingId', text),
106
+ lossIds: readInlineList(text, 'loss', 'lossId', 'lossIds'),
107
+ evidenceIds: readInlineList(text, 'evidence', 'evidenceIds'),
108
+ projection
109
+ });
110
+ if (isExtern) {
111
+ const binding = cleanRecord({ module: readInlineWord('module', text), path: readInlineWord('bindingPath', text), symbol: readInlineWord('bindingSymbol', text) ?? readInlineWord('symbol', text), abi: readInlineWord('abi', text), version: readInlineWord('version', text) });
112
+ plan.externs = [...(plan.externs ?? []), cleanRecord({ ...record, externKind: readInlineWord('externKind', text) ?? readInlineWord('kind', text) ?? 'extern', ...(Object.keys(binding).length ? { binding } : {}) })];
113
+ } else {
114
+ plan.dialects = [...(plan.dialects ?? []), cleanRecord({ ...record, constructKind: readInlineWord('constructKind', text) ?? readInlineWord('kind', text) ?? 'runtime', externIds: readInlineList(text, 'extern', 'externIds') })];
115
+ }
116
+ }
117
+
57
118
  function addConstraint(plan, family, name, text) {
58
119
  const config = FAMILIES[family] ?? { field: family.endsWith('s') ? family : `${family}Constraints`, sourceKey: 'sourceRecords', targetKey: 'targetRecords' };
59
120
  const role = readInlineWord('role', text) ?? 'source';
package/dist/metadata.js CHANGED
@@ -66,6 +66,9 @@ function mergeConversionBlocks(blocks) {
66
66
  if (block.sourceLanguage && !plan.sourceLanguage) plan.sourceLanguage = block.sourceLanguage;
67
67
  for (const [key, value] of Object.entries(block)) {
68
68
  if (Array.isArray(value) && key !== 'targets') plan[key] = [...(plan[key] ?? []), ...value];
69
+ else if ((key === 'sourceRuntimes' || key === 'targetRuntimes') && value && typeof value === 'object') {
70
+ plan[key] = { ...(plan[key] ?? {}), ...value };
71
+ }
69
72
  }
70
73
  }
71
74
  return plan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-parser",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "description": "Parser for the first Frontier Lang .frontier syntax slice.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",