@informalsystems/quint
Version:
Core tool for the Quint specification language
61 lines • 2.14 kB
JavaScript
;
/* ----------------------------------------------------------------------------------
* Copyright 2023 Informal Systems
* Licensed under the Apache License, Version 2.0.
* See LICENSE in the project root for license information.
* --------------------------------------------------------------------------------- */
Object.defineProperty(exports, "__esModule", { value: true });
exports.addNamespaces = void 0;
/**
* Adds a namespace, in the format of the namespaces attribute in LookupDefinition, to all state variables in an effect.
*
* @param effect - The effect to add the namespaces to
* @param namespaces - The namespaces to add
*
* @return The effect with namespaces added to all state variables
*/
function addNamespaces(effect, namespaces) {
switch (effect.kind) {
case 'variable': {
return effect;
}
case 'arrow': {
return {
...effect,
params: effect.params.map(p => addNamespaces(p, namespaces)),
result: addNamespaces(effect.result, namespaces),
};
}
case 'concrete': {
return {
...effect,
components: effect.components.map(c => ({ ...c, entity: addNamespacesToEntity(c.entity, namespaces) })),
};
}
}
}
exports.addNamespaces = addNamespaces;
function addNamespacesToEntity(entity, namespaces) {
switch (entity.kind) {
case 'variable': {
return entity;
}
case 'union': {
return { ...entity, entities: entity.entities.map(p => addNamespacesToEntity(p, namespaces)) };
}
case 'concrete': {
if (namespaces.length === 0) {
return entity;
}
const pathPrefix = namespaces.reduce((a, b) => `${b}::${a}`);
return {
...entity,
stateVariables: entity.stateVariables.map(v => ({
...v,
name: `${pathPrefix}::${v.name}`,
})),
};
}
}
}
//# sourceMappingURL=namespaces.js.map