@shapeshift-labs/frontier-lang-parser 0.3.25 → 0.3.27
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 +15 -0
- package/dist/conversion-constraint-record.js +174 -0
- package/dist/conversion.js +5 -92
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -363,11 +363,26 @@ conversion TodoJavascriptToRust @id("conversion_todo_js_rust") {
|
|
|
363
363
|
dialect nodeProcess @id("dialect_node_process") language javascript dialect node.runtime kind runtime target rust disposition unsupported readiness blocked loss loss_node_process_projection
|
|
364
364
|
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
|
|
365
365
|
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
|
|
366
|
+
constraint module-constraint todoModule @id("module_constraint_todo") role source kind module-boundary specifier ./todo exportedName addTodo packageName @app/todo packageCondition import resolutionKind node16 evidence artifact_todo_title_probe
|
|
367
|
+
constraint scope-binding todoLocal @id("scope_binding_todo") role source kind lexical-binding bindingId binding:todo referenceId ref:todo scopeId scope:handler resolvedBindingId binding:todo evidence artifact_todo_title_probe
|
|
368
|
+
constraint memory-model todoMemory @id("memory_model_todo") role source kind stable-reference resource TodoDb.todos memoryKind shared-memory memoryOrder acquire lockId lock:todo shared evidence artifact_todo_title_probe
|
|
369
|
+
constraint effect-constraint todoWrite @id("effect_constraint_todo_write") role source kind storage-write capability storage.write resource TodoDb.todos adapterRequired evidence artifact_todo_title_probe
|
|
370
|
+
constraint host-environment browserFetch @id("host_environment_fetch") role source kind browser-api capability fetch apiName fetch globalName window permission network adapterRequired evidence artifact_todo_title_probe
|
|
371
|
+
constraint callable-boundary saveUser @id("callable_boundary_save_user") role source kind method-call callableKind function functionName saveUser parameterCount 2 parameterOrder user|options returnKind promise asyncKind async evidence artifact_todo_title_probe
|
|
372
|
+
constraint adt-pattern resultShape @id("adt_pattern_result") role source kind tagged-union adtKind union typeName UserResult variantNames Ok|Err payloadFieldNames value|error exhaustivenessKinds total evidence artifact_todo_title_probe
|
|
373
|
+
constraint numeric-semantics amountNumber @id("numeric_semantics_amount") role source kind integer numericKind int width 53 overflowMode safe-integer specialValues nan|infinity evidence artifact_todo_title_probe
|
|
374
|
+
constraint text-semantics titleText @id("text_semantics_title") role source kind string encoding utf-16 normalizationForm nfc boundaryKinds grapheme|word evidence artifact_todo_title_probe
|
|
375
|
+
constraint collection-semantics todoList @id("collection_semantics_todos") role source kind array collectionKind array elementKind Todo iterationOrder insertion duplicatePolicy allow evidence artifact_todo_title_probe
|
|
376
|
+
constraint serialization-semantics todoJson @id("serialization_semantics_todo_json") role source kind json format json codec JSON.stringify schemaName TodoPayload deterministic evidence artifact_todo_title_probe
|
|
377
|
+
constraint dependency-semantics npmReact @id("dependency_semantics_react") role source kind package packageManager npm packageName react versionRange ^19.0.0 lockfile package-lock.json integrity sha512-demo evidence artifact_todo_title_probe
|
|
378
|
+
constraint protocol serializable @id("protocol_serializable") role target kind trait-bound protocolKind trait traitName Serializable requirementNames serialize|deserialize evidence artifact_todo_title_probe
|
|
366
379
|
}
|
|
367
380
|
```
|
|
368
381
|
|
|
369
382
|
`sourceRuntime` and `targetRuntime` become runtime maps. `runtimeRequirement` rows become proof obligations for host/runtime capabilities, including authored `requiredSignals` denominators such as source hashes, target hashes, probe ids, runtime commands, telemetry hashes, and capability-specific trace hashes. `proofEvidence` and `evidence` attach evidence ids, but the compiler still requires bound evidence records before a proof obligation is satisfied. `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.
|
|
370
383
|
|
|
384
|
+
`constraint` rows accept every universal conversion constraint family used by route admission, including hyphenated spellings such as `module-constraint`, `scope-binding`, `memory-model`, `effect-constraint`, `control-flow`, `borrow-scope`, `borrow-checker`, `host-environment`, `callable-boundary`, `adt-pattern`, `data-layout`, `numeric-semantics`, `text-semantics`, `collection-semantics`, `serialization-semantics`, `dependency-semantics`, `object-model`, and `protocol`. The parser preserves family-specific fields such as module specifiers, package conditions, binding/reference ids, memory ordering, locks, capabilities, host permissions, callable signatures, pattern exhaustiveness, ABI/layout hints, numeric/text/collection behavior, wire formats, dependency lockfile evidence, and effect adapters as authored evidence inputs. Record-level targets use explicit labels such as `effectTarget` so `role target` rows cannot be mistaken for an authored target field. These rows do not prove translation equivalence; they make the required proof surface explicit for downstream gates and admission records.
|
|
385
|
+
|
|
371
386
|
## Authored dialect registry syntax
|
|
372
387
|
|
|
373
388
|
`.frontier` files can carry reusable dialect registries with `dialectRegistry` or `universalDialectRegistry` blocks. These blocks describe language-specific constructs that should stay visible during translation instead of being silently collapsed into generic stubs.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const FAMILY_ROWS = [
|
|
2
|
+
['type', 'typeConstraints', 'sourceTypes', 'targetTypes', ['typeConstraint', 'type-constraint']],
|
|
3
|
+
['resourceTransfer', 'resourceTransfers', 'sourceGraphs', 'targetGraphs', ['resourceTransferConstraint', 'resource-transfer', 'resource-transfer-constraint', 'ownership'], { graph: true }],
|
|
4
|
+
['controlFlow', 'controlFlowConstraints', 'sourceControlFlows', 'targetControlFlows', ['controlFlowConstraint', 'control-flow', 'control-flow-constraint']],
|
|
5
|
+
['lifetime', 'lifetimeConstraints', 'sourceLifetimeConstraints', 'targetLifetimeConstraints', ['lifetimeConstraint', 'lifetime-constraint']],
|
|
6
|
+
['borrowScope', 'borrowScopeConstraints', 'sourceBorrowScopes', 'targetBorrowScopes', ['borrowScopeConstraint', 'borrow-scope', 'borrow-scope-constraint']],
|
|
7
|
+
['borrowChecker', 'borrowCheckerConstraints', 'sourceBorrowScopes', 'targetBorrowScopes', ['borrowCheckerConstraint', 'borrow-checker', 'borrow-checker-constraint']],
|
|
8
|
+
['callableBoundary', 'callableBoundaryConstraints', 'sourceCallables', 'targetCallables', ['callableBoundaryConstraint', 'callable-boundary', 'callable-boundary-constraint'], { extraSourceKeys: ['sourceCallableBoundaryRecords'], extraTargetKeys: ['targetCallableBoundaryRecords'] }],
|
|
9
|
+
['adtPattern', 'adtPatternConstraints', 'sourcePatterns', 'targetPatterns', ['adtPatternConstraint', 'adt-pattern', 'adt-pattern-constraint'], { extraSourceKeys: ['sourceAdtPatternRecords'], extraTargetKeys: ['targetAdtPatternRecords'] }],
|
|
10
|
+
['dataLayout', 'dataLayoutConstraints', 'sourceLayouts', 'targetLayouts', ['dataLayoutConstraint', 'data-layout', 'data-layout-constraint'], { extraSourceKeys: ['sourceDataLayoutRecords'], extraTargetKeys: ['targetDataLayoutRecords'] }],
|
|
11
|
+
['effect', 'effectConstraints', 'sourceEffects', 'targetEffects', ['effectConstraint', 'effect-constraint']],
|
|
12
|
+
['concurrencyModel', 'concurrencyModelConstraints', 'sourceConcurrencyModels', 'targetConcurrencyModels', ['concurrencyModelConstraint', 'concurrency-model', 'concurrency-model-constraint'], { extraSourceKeys: ['sourceConcurrencyModelRecords'], extraTargetKeys: ['targetConcurrencyModelRecords'] }],
|
|
13
|
+
['errorModel', 'errorModelConstraints', 'sourceErrors', 'targetErrors', ['errorModelConstraint', 'error-model', 'error-model-constraint'], { extraSourceKeys: ['sourceErrorModelRecords'], extraTargetKeys: ['targetErrorModelRecords'] }],
|
|
14
|
+
['evaluationModel', 'evaluationModelConstraints', 'sourceEvaluations', 'targetEvaluations', ['evaluationModelConstraint', 'evaluation-model', 'evaluation-model-constraint'], { extraSourceKeys: ['sourceEvaluationModelRecords'], extraTargetKeys: ['targetEvaluationModelRecords'] }],
|
|
15
|
+
['hostEnvironment', 'hostEnvironmentConstraints', 'sourceHosts', 'targetHosts', ['hostEnvironmentConstraint', 'host-environment', 'host-environment-constraint'], { extraSourceKeys: ['sourceHostEnvironmentRecords'], extraTargetKeys: ['targetHostEnvironmentRecords'] }],
|
|
16
|
+
['memoryModel', 'memoryModelConstraints', 'sourceMemoryModels', 'targetMemoryModels', ['memoryModelConstraint', 'memory-model', 'memory-model-constraint'], { extraSourceKeys: ['sourceMemoryModelRecords'], extraTargetKeys: ['targetMemoryModelRecords'] }],
|
|
17
|
+
['metaprogramming', 'metaprogrammingConstraints', 'sourceMetaprograms', 'targetMetaprograms', ['metaprogrammingConstraint', 'metaprogramming-constraint'], { extraSourceKeys: ['sourceMetaprogrammingRecords'], extraTargetKeys: ['targetMetaprogrammingRecords'] }],
|
|
18
|
+
['module', 'moduleConstraints', 'sourceModules', 'targetModules', ['moduleConstraint', 'module-constraint']],
|
|
19
|
+
['scopeBinding', 'scopeBindingConstraints', 'sourceBindings', 'targetBindings', ['scopeBindingConstraint', 'scope-binding', 'scope-binding-constraint'], { extraSourceKeys: ['sourceScopeBindingRecords'], extraTargetKeys: ['targetScopeBindingRecords'] }],
|
|
20
|
+
['numericSemantics', 'numericSemanticsConstraints', 'sourceNumerics', 'targetNumerics', ['numericSemanticsConstraint', 'numeric-semantics', 'numeric-semantics-constraint'], { extraSourceKeys: ['sourceNumericSemanticsRecords'], extraTargetKeys: ['targetNumericSemanticsRecords'] }],
|
|
21
|
+
['textSemantics', 'textSemanticsConstraints', 'sourceTexts', 'targetTexts', ['textSemanticsConstraint', 'text-semantics', 'text-semantics-constraint'], { extraSourceKeys: ['sourceTextSemanticsRecords'], extraTargetKeys: ['targetTextSemanticsRecords'] }],
|
|
22
|
+
['collectionSemantics', 'collectionSemanticsConstraints', 'sourceCollections', 'targetCollections', ['collectionSemanticsConstraint', 'collection-semantics', 'collection-semantics-constraint'], { extraSourceKeys: ['sourceCollectionSemanticsRecords'], extraTargetKeys: ['targetCollectionSemanticsRecords'] }],
|
|
23
|
+
['serializationSemantics', 'serializationSemanticsConstraints', 'sourceSerializations', 'targetSerializations', ['serializationSemanticsConstraint', 'serialization-semantics', 'serialization-semantics-constraint'], { extraSourceKeys: ['sourceSerializationSemanticsRecords'], extraTargetKeys: ['targetSerializationSemanticsRecords'] }],
|
|
24
|
+
['dependencySemantics', 'dependencySemanticsConstraints', 'sourceDependencies', 'targetDependencies', ['dependencySemanticsConstraint', 'dependency-semantics', 'dependency-semantics-constraint'], { extraSourceKeys: ['sourceDependencySemanticsRecords'], extraTargetKeys: ['targetDependencySemanticsRecords'] }],
|
|
25
|
+
['objectModel', 'objectModelConstraints', 'sourceObjects', 'targetObjects', ['objectModelConstraint', 'object-model', 'object-model-constraint'], { extraSourceKeys: ['sourceObjectModelRecords'], extraTargetKeys: ['targetObjectModelRecords'] }],
|
|
26
|
+
['protocol', 'protocolConstraints', 'sourceProtocols', 'targetProtocols', ['protocolConstraint', 'protocol-constraint']]
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const WORD_FIELDS = [
|
|
30
|
+
['symbolId', 'symbol', 'symbolId'], ['symbolName'], ['localName'], ['ownerId', 'owner', 'ownerId'], ['ownerKind'],
|
|
31
|
+
['bindingKind'], ['referenceKind'], ['scopeId', 'scopeId', 'scope'], ['ownerScopeId'], ['bindingId', 'bindingId', 'binding'],
|
|
32
|
+
['externalBindingId', 'externalBindingId', 'externalBinding'], ['resolvedBindingId', 'resolvedBindingId', 'resolvedBinding'],
|
|
33
|
+
['declarationId', 'declarationId', 'declaration'], ['referenceId', 'referenceId', 'reference'], ['occurrenceId', 'occurrenceId', 'occurrence'],
|
|
34
|
+
['resolvedName'], ['namespace'], ['scopeType'], ['variableScopeType'], ['lookupKind'], ['resolutionKind', 'resolutionKind', 'moduleResolutionKind'],
|
|
35
|
+
['moduleKind'], ['edgeKind'], ['declarationKind'], ['specifier', 'specifier', 'moduleSpecifier'], ['moduleSpecifier', 'moduleSpecifier', 'specifier'],
|
|
36
|
+
['importedName', 'importedName', 'importName'], ['importName', 'importName', 'importedName'], ['exportedName', 'exportedName', 'exportName'],
|
|
37
|
+
['exportName', 'exportName', 'exportedName'], ['reExportedName', 'reExportedName', 'reexportedName'], ['packageName', 'packageName', 'package'],
|
|
38
|
+
['packageSubpath', 'packageSubpath', 'subpath'], ['packageCondition', 'packageCondition', 'condition'], ['packageExportKey'], ['packageImportKey'],
|
|
39
|
+
['resolvedPath', 'resolvedPath', 'targetPath'], ['targetPath', 'targetPath', 'resolvedPath'], ['capability'], ['hostKind'], ['runtimeKind'],
|
|
40
|
+
['apiName', 'apiName', 'callee'], ['globalName', 'globalName', 'global', 'objectName'], ['permission', 'permission', 'permissionKind'],
|
|
41
|
+
['permissionKind', 'permissionKind', 'permission'], ['effectKind'], ['memoryKind'],
|
|
42
|
+
['operationKind'], ['memoryOrder', 'memoryOrder', 'ordering'], ['ordering', 'ordering', 'memoryOrder'], ['lockId', 'lockId', 'lock'],
|
|
43
|
+
['channelId', 'channelId', 'channel'], ['actorId', 'actorId', 'actor'], ['synchronizationKey', 'synchronizationKey', 'syncKey'],
|
|
44
|
+
['callableId', 'callableId', 'callable'], ['functionId', 'functionId', 'function'], ['receiverId', 'receiverId', 'receiver'],
|
|
45
|
+
['abi'], ['callingConvention'], ['layoutKind'], ['endian'], ['objectKind'], ['memberKind'], ['protocolId', 'protocolId', 'protocol'],
|
|
46
|
+
['traitId', 'traitId', 'trait'], ['interfaceId', 'interfaceId', 'interface'], ['mode', 'mode', 'loanMode'], ['aliasKind'], ['moveKind'],
|
|
47
|
+
['dropKind'], ['resourceKind'], ['scopeKind'], ['typeKind'], ['signatureHash'], ['contractHash'], ['typeHash'], ['flowKind'],
|
|
48
|
+
['controlFlowKind'], ['sourceControlFlowId'], ['sourceId', 'from', 'sourceId'], ['targetId', 'to', 'targetId'], ['label'],
|
|
49
|
+
['conditionHash'], ['orderingKey', 'orderingKey', 'orderKey'], ['lifetimeKind'], ['lifetimeRegionId', 'lifetimeRegion', 'lifetimeRegionId'],
|
|
50
|
+
['regionKind'], ['resourceId', 'resource', 'resourceId'],
|
|
51
|
+
['functionName'], ['methodName'], ['callableName'], ['callableKind'], ['callSignatureHash'],
|
|
52
|
+
['receiverKind', 'receiverKind', 'receiver'], ['thisBinding'], ['selfBinding'], ['returnKind', 'returnKind', 'returnType'],
|
|
53
|
+
['asyncKind', 'asyncKind', 'asyncMode'], ['generatorKind', 'generatorKind', 'yieldKind'], ['callbackKind'],
|
|
54
|
+
['closureCapture', 'closureCapture', 'captureKind'], ['overloadSet', 'overloadSet', 'overloads'],
|
|
55
|
+
['dispatchKind', 'dispatchKind', 'dispatchMode'], ['constructorKind'], ['abiKind'], ['ffiBoundary', 'ffiBoundary', 'foreignFunction'],
|
|
56
|
+
['exceptionModel'], ['adtKind'], ['patternKind', 'patternKind', 'matchKind', 'caseKind'], ['typeName'], ['enumName'], ['unionName'],
|
|
57
|
+
['symbolKind'], ['relationKind'], ['representationKind'], ['typeId', 'typeId', 'nodeId'], ['nodeId'], ['structId'], ['unionId'],
|
|
58
|
+
['enumId'], ['fieldId'], ['bitfieldId'], ['endianness', 'endianness', 'endian'], ['repr', 'repr', 'reprAttribute'],
|
|
59
|
+
['numericKind', 'numericKind', 'numberKind'], ['numberKind'], ['numericTypeName'], ['signedness'], ['overflowMode', 'overflowMode', 'overflowBehavior'],
|
|
60
|
+
['divisionMode', 'divisionMode', 'integerDivisionMode'], ['moduloMode', 'moduloMode', 'remainderMode'], ['floatPrecision'], ['roundingMode'],
|
|
61
|
+
['separatorPolicy'], ['coercionKind', 'coercionKind', 'conversionKind'], ['conversionKind'], ['literalKind'],
|
|
62
|
+
['textKind', 'textKind', 'stringKind'], ['stringKind'], ['stringTypeName'], ['encoding', 'encoding', 'charset', 'codepage'],
|
|
63
|
+
['charset'], ['codepage'], ['codeUnit', 'codeUnit', 'codeUnitWidth'], ['indexingUnit', 'indexingUnit', 'indexUnit'],
|
|
64
|
+
['normalizationForm', 'normalizationForm', 'normalization'], ['locale', 'locale', 'localePolicy'], ['collation', 'collation', 'collationPolicy'],
|
|
65
|
+
['caseMapping', 'caseMapping', 'caseFolding'], ['regexEngine', 'regexEngine', 'regexFlavor'], ['escapeMode', 'escapeMode', 'escaping'],
|
|
66
|
+
['interpolationMode', 'interpolationMode', 'interpolation'], ['termination', 'termination', 'nullTermination'], ['boundaryKind', 'boundaryKind', 'byteBoundary'],
|
|
67
|
+
['collectionKind', 'collectionKind', 'containerKind'], ['containerKind'], ['collectionTypeName'], ['elementKind', 'elementKind', 'elementType'],
|
|
68
|
+
['keyKind', 'keyKind', 'keyType'], ['valueKind', 'valueKind', 'valueType'], ['orderKind'], ['iterationOrder', 'iterationOrder', 'traversalOrder'],
|
|
69
|
+
['duplicatePolicy', 'duplicatePolicy', 'duplicates'], ['equality', 'equality', 'equalitySemantics'], ['hash', 'hash', 'hashSemantics'],
|
|
70
|
+
['comparator', 'comparator', 'comparison'], ['boundsBehavior', 'boundsBehavior', 'bounds'], ['lengthSemantics', 'lengthSemantics', 'sizeSemantics'],
|
|
71
|
+
['sparseSemantics', 'sparseSemantics', 'holes'], ['mutability', 'mutability', 'collectionMutability', 'stringMutability'],
|
|
72
|
+
['persistence', 'persistence', 'persistent'], ['iteratorInvalidation', 'iteratorInvalidation', 'invalidation'],
|
|
73
|
+
['traversal', 'traversal', 'laziness'], ['capacityGrowth', 'capacityGrowth', 'growth'], ['concurrency', 'concurrency', 'threadSafety'],
|
|
74
|
+
['format', 'format', 'wireFormat', 'serializationFormat'], ['wireFormat'], ['serializationFormat'], ['codec', 'codec', 'runtimeCodec'],
|
|
75
|
+
['schemaName', 'schemaName', 'schemaId', 'schema'], ['schemaId'], ['fieldNaming', 'fieldNaming', 'naming'], ['fieldOrder', 'fieldOrder', 'order'],
|
|
76
|
+
['omissionPolicy'], ['defaultValueSemantics'], ['nullSemantics', 'nullSemantics', 'nullability'], ['unknownFieldPolicy'],
|
|
77
|
+
['enumEncoding', 'enumEncoding', 'tagEncoding'], ['varint', 'varint', 'varintEncoding'], ['schemaVersion', 'schemaVersion', 'version'],
|
|
78
|
+
['compatibility'], ['canonicalization'], ['precision', 'precision', 'precisionLoss'], ['roundtrip', 'roundtrip', 'roundtripStability'],
|
|
79
|
+
['validation'], ['securityEscaping'], ['packageManager', 'packageManager', 'manager'], ['manager'], ['manifestSchema', 'manifestSchema', 'manifestKind'],
|
|
80
|
+
['manifestKind'], ['versionRange', 'versionRange', 'range'], ['resolvedVersion', 'resolvedVersion', 'version'], ['lockfile', 'lockfile', 'lockfilePath'],
|
|
81
|
+
['integrity', 'integrity', 'lockfileIntegrity'], ['dependencyClass', 'dependencyClass', 'dependencyType'], ['dependencyType'],
|
|
82
|
+
['workspace', 'workspace', 'workspaceBoundary'], ['registry', 'registry', 'registrySource'], ['sourceUrl'], ['nativeAbi', 'nativeAbi', 'abi'],
|
|
83
|
+
['buildTool', 'buildTool', 'builder'], ['packageManagerVersion', 'packageManagerVersion', 'managerVersion'],
|
|
84
|
+
['offlineCache', 'offlineCache', 'cachePolicy'], ['dedupeHoist', 'dedupeHoist', 'hoistPolicy'], ['provenance', 'provenance', 'sourceProvenance'],
|
|
85
|
+
['trust', 'trust', 'supplyChainTrust'], ['concurrencyKind'], ['constructId', 'constructId', 'taskId', 'threadId', 'actorId', 'channelId'],
|
|
86
|
+
['taskId'], ['threadId'], ['executor', 'executor', 'queue', 'runtime'], ['executorId'], ['isolationKey'], ['cancellationKey', 'cancellationKey', 'signalId', 'contextId'],
|
|
87
|
+
['signalId'], ['contextId'], ['errorKind'], ['errorType', 'errorType', 'exceptionType', 'resultType'], ['exceptionType'], ['resultType'],
|
|
88
|
+
['boundaryId', 'boundaryId', 'catchId', 'handlerId'], ['catchId'], ['handlerId'], ['evaluationKind', 'evaluationKind', 'expressionKind'],
|
|
89
|
+
['expressionKind'], ['expressionId', 'expressionId', 'nodeId'], ['operator'], ['evaluationOrder', 'evaluationOrder', 'order'],
|
|
90
|
+
['expansionKind', 'expansionKind', 'macroKind', 'templateKind', 'decoratorKind', 'generatorKind'], ['macroKind'], ['templateKind'],
|
|
91
|
+
['decoratorKind'], ['expansionId'], ['generatorId'], ['generatedSourcePath'], ['expandedHash', 'expandedHash', 'generatedHash'],
|
|
92
|
+
['generatedHash'], ['classId'], ['classKind'], ['prototypeId'], ['mixinId'], ['constructorId'], ['inheritanceKind'], ['referenceSemantics'],
|
|
93
|
+
['valueSemantics'], ['protocolKind'], ['protocolName'], ['traitName'], ['interfaceName'], ['subjectName', 'subjectName', 'receiverName', 'implementedFor'],
|
|
94
|
+
['implementedFor'], ['sourcePath', 'sourcePath', 'path'], ['sourceHash'], ['target', 'effectTarget', 'targetResource']
|
|
95
|
+
];
|
|
96
|
+
const LIST_FIELDS = [
|
|
97
|
+
['factKinds', 'fact', 'facts', 'factKind', 'factKinds'], ['importAttributes', 'importAttribute', 'importAttributes', 'assertion', 'assertions'],
|
|
98
|
+
['reads', 'read', 'reads'], ['writes', 'write', 'writes'],
|
|
99
|
+
['requiredParameters'], ['optionalParameters'], ['parameterOrder', 'parameterOrder', 'orderedParameters'], ['defaultParameters', 'defaultParameters', 'defaults'],
|
|
100
|
+
['namedArguments', 'namedArguments', 'keywordArguments'], ['effects'], ['variantNames', 'variantNames', 'variants', 'caseNames', 'cases', 'members'],
|
|
101
|
+
['constructorNames', 'constructorNames', 'constructors', 'caseConstructors'], ['payloadFieldNames', 'payloadFieldNames', 'payloadFields', 'fields', 'tupleFields', 'recordFields'],
|
|
102
|
+
['tagFieldNames', 'tagFieldNames', 'tagFields', 'discriminatorFields', 'discriminants'], ['matchArmNames', 'matchArmNames', 'matchArms', 'arms', 'switchCases'],
|
|
103
|
+
['guardKinds', 'guardKinds', 'guards', 'whereClauses', 'conditions'], ['destructuringKinds', 'destructuringKinds', 'destructuring', 'bindingPatterns', 'deconstruction'],
|
|
104
|
+
['exhaustivenessKinds', 'exhaustivenessKinds', 'exhaustiveness', 'coverageKinds'], ['fallbackKinds', 'fallbackKinds', 'fallbacks', 'defaultCases', 'wildcards'],
|
|
105
|
+
['genericParameterNames', 'genericParameterNames', 'typeParameters', 'genericParameters'], ['specialValues', 'specialValues', 'floatSpecialValues'],
|
|
106
|
+
['coercionKinds', 'coercionKinds', 'coercions'], ['literalKinds'], ['boundaryKinds', 'boundaryKinds', 'boundaries'],
|
|
107
|
+
['omittedFields', 'omittedFields', 'unknownFields'], ['defaultValues'], ['peerDependencies', 'peerDependencies', 'peers'], ['optionalDependencies'],
|
|
108
|
+
['devDependencies'], ['features', 'features', 'extras', 'flags'], ['lifecycleScripts', 'lifecycleScripts', 'scripts'],
|
|
109
|
+
['requirementNames', 'requirementNames', 'requirements', 'methods', 'members'], ['associatedTypeNames', 'associatedTypeNames', 'associatedTypes'],
|
|
110
|
+
['boundNames', 'boundNames', 'bounds', 'traitBounds', 'protocolBounds', 'whereBounds'], ['implementationKinds', 'implementationKinds', 'implKinds', 'implementations'],
|
|
111
|
+
['dispatchKinds', 'dispatchKinds', 'dispatchModes'], ['coherenceKinds', 'coherenceKinds', 'coherenceRules'], ['evidenceIds', 'evidence', 'evidenceIds']
|
|
112
|
+
];
|
|
113
|
+
const NUMBER_FIELDS = [
|
|
114
|
+
['arity'], ['size'], ['alignment'], ['parameterCount'], ['requiredParameterCount'], ['optionalParameterCount'],
|
|
115
|
+
['sizeBytes'], ['alignmentBytes'], ['offsetBytes'], ['pointerWidth'], ['integerWidth'], ['bitWidth'], ['width'],
|
|
116
|
+
['codeUnitWidth'], ['indexBase']
|
|
117
|
+
];
|
|
118
|
+
const FLAG_FIELDS = ['nullable', 'optional', 'publicContract', 'closure', 'captured', 'writeExpr', 'mutable', 'shadowed', 'hoisted', 'typeOnly', 'isTypeReference', 'isValueReference', 'shared', 'volatile', 'atomic', 'adapterRequired', 'async', 'generator', 'exceptional', 'cancellable', 'variadic', 'signed', 'nan', 'infinity', 'deterministic', 'streaming', 'framing', 'copyOnWrite', 'multipleInheritance', 'reflection', 'staticDispatch', 'virtual', 'spawn', 'await', 'structured', 'reentrant', 'cancelable'];
|
|
119
|
+
|
|
120
|
+
export const FAMILIES = Object.freeze(Object.fromEntries(FAMILY_ROWS.flatMap(([name, field, sourceKey, targetKey, aliases = [], extra = {}]) => {
|
|
121
|
+
const config = { field, sourceKey, targetKey, ...extra };
|
|
122
|
+
return [name, ...aliases].map((alias) => [alias, config]);
|
|
123
|
+
})));
|
|
124
|
+
|
|
125
|
+
export function parseConstraintRecord(name, text, role) {
|
|
126
|
+
const kind = wordAny(text, 'kind', 'constraintKind');
|
|
127
|
+
return cleanRecord({
|
|
128
|
+
id: wordAny(text, 'recordId') ?? idFrom(text, `constraint_record_${name}`),
|
|
129
|
+
role,
|
|
130
|
+
kind,
|
|
131
|
+
name: wordAny(text, 'name') ?? name,
|
|
132
|
+
constraintKind: wordAny(text, 'constraintKind'),
|
|
133
|
+
constraintKinds: listAny(text, 'constraint', 'constraints', 'constraintKind', 'constraintKinds') ?? (kind ? [kind] : undefined),
|
|
134
|
+
...readMapped(text, WORD_FIELDS, wordAny),
|
|
135
|
+
...readMapped(text, LIST_FIELDS, listAny),
|
|
136
|
+
...readMapped(text, NUMBER_FIELDS, numberAny),
|
|
137
|
+
...Object.fromEntries(FLAG_FIELDS.map((field) => [field, flag(field, text)])),
|
|
138
|
+
predicate: quoted('predicate', text) ?? wordAny(text, 'predicate'),
|
|
139
|
+
metadata: { name }
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function readMapped(text, specs, reader) {
|
|
144
|
+
return Object.fromEntries(specs.map(([key, ...labels]) => [key, reader(text, ...(labels.length ? labels : [key]))]));
|
|
145
|
+
}
|
|
146
|
+
function wordAny(text, ...labels) {
|
|
147
|
+
for (const label of labels) {
|
|
148
|
+
const value = word(label, text);
|
|
149
|
+
if (value !== undefined) return value;
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
function listAny(text, ...labels) {
|
|
154
|
+
for (const label of labels) {
|
|
155
|
+
const value = list(label, text);
|
|
156
|
+
if (value) return value;
|
|
157
|
+
}
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
function numberAny(text, ...labels) {
|
|
161
|
+
const value = wordAny(text, ...labels);
|
|
162
|
+
return value === undefined ? undefined : Number(value);
|
|
163
|
+
}
|
|
164
|
+
function idFrom(text, fallback) { return /@id\(\s*["']([^"']+)["']\s*\)/.exec(text)?.[1] ?? fallback; }
|
|
165
|
+
function word(label, text) { return new RegExp('(?:^|\\s)' + label + '\\s+([^\\s,]+)').exec(text)?.[1]?.trim(); }
|
|
166
|
+
function quoted(label, text) { return new RegExp("(?:^|\\s)" + label + "\\s+[\"']([^\"']+)[\"']").exec(text)?.[1]?.trim(); }
|
|
167
|
+
function flag(label, text) { return new RegExp('(?:^|\\s)' + label + '(?:\\s|$)').test(text) || undefined; }
|
|
168
|
+
function list(label, text) {
|
|
169
|
+
const value = new RegExp('(?:^|\\s)' + label + '\\s+([^\\s]+)').exec(text)?.[1]?.trim();
|
|
170
|
+
return value ? value.split(/[|,]/).map((item) => item.trim()).filter(Boolean) : undefined;
|
|
171
|
+
}
|
|
172
|
+
function cleanRecord(record) {
|
|
173
|
+
return Object.fromEntries(Object.entries(record).filter(([, value]) => value !== undefined && (!Array.isArray(value) || value.length > 0)));
|
|
174
|
+
}
|
package/dist/conversion.js
CHANGED
|
@@ -1,42 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
type: { field: 'typeConstraints', sourceKey: 'sourceTypes', targetKey: 'targetTypes' },
|
|
3
|
-
typeConstraint: { field: 'typeConstraints', sourceKey: 'sourceTypes', targetKey: 'targetTypes' },
|
|
4
|
-
resourceTransfer: { field: 'resourceTransfers', sourceKey: 'sourceGraphs', targetKey: 'targetGraphs', graph: true },
|
|
5
|
-
resourceTransferConstraint: { field: 'resourceTransfers', sourceKey: 'sourceGraphs', targetKey: 'targetGraphs', graph: true },
|
|
6
|
-
'resource-transfer': { field: 'resourceTransfers', sourceKey: 'sourceGraphs', targetKey: 'targetGraphs', graph: true },
|
|
7
|
-
ownership: { field: 'resourceTransfers', sourceKey: 'sourceGraphs', targetKey: 'targetGraphs', graph: true },
|
|
8
|
-
controlFlow: { field: 'controlFlowConstraints', sourceKey: 'sourceControlFlows', targetKey: 'targetControlFlows' },
|
|
9
|
-
controlFlowConstraint: { field: 'controlFlowConstraints', sourceKey: 'sourceControlFlows', targetKey: 'targetControlFlows' },
|
|
10
|
-
lifetime: { field: 'lifetimeConstraints', sourceKey: 'sourceLifetimeConstraints', targetKey: 'targetLifetimeConstraints' },
|
|
11
|
-
lifetimeConstraint: { field: 'lifetimeConstraints', sourceKey: 'sourceLifetimeConstraints', targetKey: 'targetLifetimeConstraints' },
|
|
12
|
-
borrowScope: { field: 'borrowScopeConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
13
|
-
borrowScopeConstraint: { field: 'borrowScopeConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
14
|
-
'borrow-scope': { field: 'borrowScopeConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
15
|
-
'borrow-scope-constraint': { field: 'borrowScopeConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
16
|
-
borrowChecker: { field: 'borrowCheckerConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
17
|
-
borrowCheckerConstraint: { field: 'borrowCheckerConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
18
|
-
'borrow-checker': { field: 'borrowCheckerConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
19
|
-
'borrow-checker-constraint': { field: 'borrowCheckerConstraints', sourceKey: 'sourceBorrowScopes', targetKey: 'targetBorrowScopes' },
|
|
20
|
-
callableBoundary: { field: 'callableBoundaryConstraints', sourceKey: 'sourceCallables', targetKey: 'targetCallables' },
|
|
21
|
-
adtPattern: { field: 'adtPatternConstraints', sourceKey: 'sourcePatterns', targetKey: 'targetPatterns' },
|
|
22
|
-
dataLayout: { field: 'dataLayoutConstraints', sourceKey: 'sourceLayouts', targetKey: 'targetLayouts' },
|
|
23
|
-
effect: { field: 'effectConstraints', sourceKey: 'sourceEffects', targetKey: 'targetEffects' },
|
|
24
|
-
concurrencyModel: { field: 'concurrencyModelConstraints', sourceKey: 'sourceConcurrencyModels', targetKey: 'targetConcurrencyModels' },
|
|
25
|
-
errorModel: { field: 'errorModelConstraints', sourceKey: 'sourceErrors', targetKey: 'targetErrors' },
|
|
26
|
-
evaluationModel: { field: 'evaluationModelConstraints', sourceKey: 'sourceEvaluations', targetKey: 'targetEvaluations' },
|
|
27
|
-
hostEnvironment: { field: 'hostEnvironmentConstraints', sourceKey: 'sourceHosts', targetKey: 'targetHosts' },
|
|
28
|
-
memoryModel: { field: 'memoryModelConstraints', sourceKey: 'sourceMemoryModels', targetKey: 'targetMemoryModels' },
|
|
29
|
-
metaprogramming: { field: 'metaprogrammingConstraints', sourceKey: 'sourceMetaprograms', targetKey: 'targetMetaprograms' },
|
|
30
|
-
module: { field: 'moduleConstraints', sourceKey: 'sourceModules', targetKey: 'targetModules' },
|
|
31
|
-
scopeBinding: { field: 'scopeBindingConstraints', sourceKey: 'sourceBindings', targetKey: 'targetBindings' },
|
|
32
|
-
numericSemantics: { field: 'numericSemanticsConstraints', sourceKey: 'sourceNumerics', targetKey: 'targetNumerics' },
|
|
33
|
-
textSemantics: { field: 'textSemanticsConstraints', sourceKey: 'sourceTexts', targetKey: 'targetTexts' },
|
|
34
|
-
collectionSemantics: { field: 'collectionSemanticsConstraints', sourceKey: 'sourceCollections', targetKey: 'targetCollections' },
|
|
35
|
-
serializationSemantics: { field: 'serializationSemanticsConstraints', sourceKey: 'sourceSerializations', targetKey: 'targetSerializations' },
|
|
36
|
-
dependencySemantics: { field: 'dependencySemanticsConstraints', sourceKey: 'sourceDependencies', targetKey: 'targetDependencies' },
|
|
37
|
-
objectModel: { field: 'objectModelConstraints', sourceKey: 'sourceObjects', targetKey: 'targetObjects' },
|
|
38
|
-
protocol: { field: 'protocolConstraints', sourceKey: 'sourceProtocols', targetKey: 'targetProtocols' }
|
|
39
|
-
};
|
|
1
|
+
import { FAMILIES, parseConstraintRecord } from './conversion-constraint-record.js';
|
|
40
2
|
|
|
41
3
|
export function parseConversionBlock(block) {
|
|
42
4
|
const name = nameFrom(block.header);
|
|
@@ -133,62 +95,13 @@ function addConstraint(plan, family, name, text) {
|
|
|
133
95
|
metadata: { name, family, authoredConversionBlockId: plan.id }
|
|
134
96
|
});
|
|
135
97
|
const recordKey = role === 'target' ? config.targetKey : config.sourceKey;
|
|
136
|
-
|
|
98
|
+
const recordValue = config.graph ? resourceGraphFromRecord(record, entry) : record;
|
|
99
|
+
for (const key of unique([recordKey, ...(role === 'target' ? config.extraTargetKeys ?? [] : config.extraSourceKeys ?? [])])) {
|
|
100
|
+
entry[key] = [recordValue];
|
|
101
|
+
}
|
|
137
102
|
plan[config.field] = [...(plan[config.field] ?? []), entry];
|
|
138
103
|
}
|
|
139
104
|
|
|
140
|
-
function parseConstraintRecord(name, text, role) {
|
|
141
|
-
const kind = readInlineWord('kind', text) ?? readInlineWord('constraintKind', text);
|
|
142
|
-
return cleanRecord({
|
|
143
|
-
id: readInlineWord('recordId', text) ?? idFrom(text, `constraint_record_${name}`),
|
|
144
|
-
role,
|
|
145
|
-
kind,
|
|
146
|
-
name: readInlineWord('name', text) ?? name,
|
|
147
|
-
constraintKind: readInlineWord('constraintKind', text),
|
|
148
|
-
constraintKinds: readInlineList(text, 'constraint', 'constraints', 'constraintKind', 'constraintKinds') ?? (kind ? [kind] : undefined),
|
|
149
|
-
factKinds: readInlineList(text, 'fact', 'facts', 'factKind', 'factKinds'),
|
|
150
|
-
symbolId: readInlineWord('symbol', text) ?? readInlineWord('symbolId', text),
|
|
151
|
-
symbolName: readInlineWord('symbolName', text),
|
|
152
|
-
localName: readInlineWord('localName', text),
|
|
153
|
-
ownerId: readInlineWord('owner', text) ?? readInlineWord('ownerId', text),
|
|
154
|
-
ownerKind: readInlineWord('ownerKind', text),
|
|
155
|
-
mode: readInlineWord('mode', text) ?? readInlineWord('loanMode', text),
|
|
156
|
-
aliasKind: readInlineWord('aliasKind', text),
|
|
157
|
-
moveKind: readInlineWord('moveKind', text),
|
|
158
|
-
dropKind: readInlineWord('dropKind', text),
|
|
159
|
-
resourceKind: readInlineWord('resourceKind', text),
|
|
160
|
-
scopeKind: readInlineWord('scopeKind', text),
|
|
161
|
-
typeKind: readInlineWord('typeKind', text),
|
|
162
|
-
signatureHash: readInlineWord('signatureHash', text),
|
|
163
|
-
contractHash: readInlineWord('contractHash', text),
|
|
164
|
-
typeHash: readInlineWord('typeHash', text),
|
|
165
|
-
flowKind: readInlineWord('flowKind', text),
|
|
166
|
-
controlFlowKind: readInlineWord('controlFlowKind', text),
|
|
167
|
-
sourceControlFlowId: readInlineWord('sourceControlFlowId', text),
|
|
168
|
-
sourceId: readInlineWord('from', text) ?? readInlineWord('sourceId', text),
|
|
169
|
-
targetId: readInlineWord('to', text) ?? readInlineWord('targetId', text),
|
|
170
|
-
label: readInlineWord('label', text),
|
|
171
|
-
conditionHash: readInlineWord('conditionHash', text),
|
|
172
|
-
orderingKey: readInlineWord('orderingKey', text) ?? readInlineWord('orderKey', text),
|
|
173
|
-
lifetimeKind: readInlineWord('lifetimeKind', text),
|
|
174
|
-
lifetimeRegionId: readInlineWord('lifetimeRegion', text) ?? readInlineWord('lifetimeRegionId', text),
|
|
175
|
-
regionKind: readInlineWord('regionKind', text),
|
|
176
|
-
predicate: readInlineQuoted('predicate', text) ?? readInlineWord('predicate', text),
|
|
177
|
-
resourceId: readInlineWord('resource', text) ?? readInlineWord('resourceId', text),
|
|
178
|
-
sourcePath: readInlineWord('sourcePath', text) ?? readInlineWord('path', text),
|
|
179
|
-
sourceHash: readInlineWord('sourceHash', text),
|
|
180
|
-
evidenceIds: readInlineList(text, 'evidence', 'evidenceIds'),
|
|
181
|
-
nullable: readInlineFlag('nullable', text),
|
|
182
|
-
optional: readInlineFlag('optional', text),
|
|
183
|
-
publicContract: readInlineFlag('publicContract', text),
|
|
184
|
-
async: readInlineFlag('async', text),
|
|
185
|
-
generator: readInlineFlag('generator', text),
|
|
186
|
-
exceptional: readInlineFlag('exceptional', text),
|
|
187
|
-
cancellable: readInlineFlag('cancellable', text),
|
|
188
|
-
metadata: { name }
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
105
|
function resourceGraphFromRecord(record, entry) {
|
|
193
106
|
const tokens = lowerTokens(record);
|
|
194
107
|
const resourceId = record.resourceId ?? record.symbolId ?? `${record.id}_resource`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-lang-parser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.27",
|
|
4
4
|
"description": "Parser for the first Frontier Lang .frontier syntax slice.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "node scripts/build.mjs",
|
|
25
|
-
"test": "npm run build && node test/smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
|
|
25
|
+
"test": "npm run build && node test/smoke.mjs && node test/conversion-constraint-fields-smoke.mjs && node test/view-render-graph-smoke.mjs && node test/resource-graph-smoke.mjs && node test/interlingua-smoke.mjs && node test/dialect-registry-smoke.mjs",
|
|
26
26
|
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit -p test/tsconfig.json",
|
|
27
27
|
"fuzz": "npm run build && node fuzz/smoke.mjs",
|
|
28
28
|
"bench": "npm run build && node bench/smoke.mjs",
|