UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

75 lines 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.substitutionsToString = exports.canonicalTypeScheme = exports.typeSchemeToString = exports.constraintToString = void 0; const IRprinting_1 = require("../ir/IRprinting"); const substitutions_1 = require("./substitutions"); /** * Formats the string representation of a constraint * * @param c the Constraint to be formatted * * @returns a string with the formatted constraint */ function constraintToString(c) { switch (c.kind) { case 'eq': return `${(0, IRprinting_1.typeToString)(c.types[0])} ~ ${(0, IRprinting_1.typeToString)(c.types[1])}`; case 'conjunction': return c.constraints.map(constraintToString).join(' /\\ '); case 'isDefined': return `${(0, IRprinting_1.typeToString)(c.type)} is defined`; case 'empty': return 'true'; } } exports.constraintToString = constraintToString; /** * Formats the string representation of a type scheme * * @param t the type scheme to be formatted * * @returns a string with the formatted type scheme */ function typeSchemeToString(t) { const [vars, type] = canonicalTypeScheme(t); const varsString = vars.length > 0 ? `∀ ${vars.join(', ')} . ` : ''; return `${varsString}${(0, IRprinting_1.typeToString)(type)}`; } exports.typeSchemeToString = typeSchemeToString; function canonicalTypeScheme(t) { const typeNames = Array.from(t.typeVariables); const rowNames = Array.from(t.rowVariables); const vars = []; const typeSubs = typeNames.map((name, i) => { vars.push(`t${i}`); return { kind: 'type', name, value: { kind: 'var', name: `t${i}` } }; }); const rowSubs = rowNames.map((name, i) => { vars.push(`r${i}`); return { kind: 'row', name: name, value: { kind: 'var', name: `r${i}` } }; }); const subs = (0, substitutions_1.compose)(new Map(), typeSubs, rowSubs); const type = (0, substitutions_1.applySubstitution)(new Map(), subs, t.type); return [vars, type]; } exports.canonicalTypeScheme = canonicalTypeScheme; /** * Formats the string representation of substitutions * * @param subs the Substitution to be formatted * * @returns a string with the pretty printed substitution */ function substitutionsToString(subs) { const subsString = subs.map(s => { if (s.kind === 'type') { return `${s.name} |-> ${(0, IRprinting_1.typeToString)(s.value)}`; } else { return `${s.name} |-> ${(0, IRprinting_1.rowToString)(s.value)}`; } }); return `[ ${subsString.join(', ')} ]`; } exports.substitutionsToString = substitutionsToString; //# sourceMappingURL=printing.js.map