UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

37 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assignMuTerms = exports.getFreshName = void 0; const VariableDeclaration_1 = require("./nodes/Statement/VariableDeclaration"); /* Generate new name for alpha renaming X -> X_1 -> X_2 -> X_3 -> ... */ function getFreshName(targetName, protectedNames) { const usedNames = new Set([protectedNames, targetName].flat()); return targetName.map(name => { const regex = /(.*)_(\d+)$/; // identify underscore index let currentName = name; do { const match = currentName.match(regex); if (match) { const nextOrder = parseInt(match[2], 10) + 1; currentName = match[1] + '_' + nextOrder.toString(); } else { currentName = name + '_1'; } } while (usedNames.has(currentName)); usedNames.add(currentName); return currentName; }); } exports.getFreshName = getFreshName; // Assign mu term for arrow function expression function assignMuTerms(declarations) { // Scan out arrow function expression and assign mu term return declarations.map(declarator => declarator.init && declarator.init.type === 'ArrowFunctionExpression' ? new VariableDeclaration_1.StepperVariableDeclarator(declarator.id, declarator.init.assignName(declarator.id.name)) : declarator); } exports.assignMuTerms = assignMuTerms; //# sourceMappingURL=utils.js.map