Variable renaming
428872
function rename(ts, cm) {
    var token = cm.getTokenAt(cm.getCursor());
    if (!/\w/.test(token.string)) showError(ts, cm, "Not at a variable");
    dialog(cm, "New name for " + token.string, function(newName) {
      ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
        if (error) return showError(ts, cm, error);
        applyChanges(ts, data.changes);
      });
    });
  }
608794
function renameKey(obj, oldKey, newKey) {
    var retObject = {};
    var index, ptr;

    if (typeof obj != "object") {
        return retObject;
    }

    var oldKeyType = typeof oldKey;
    var newKeyType = typeof newKey;
    if (oldKeyType == "string"
        && newKeyType == "string") {
        for (index in obj) {
            if (obj.hasOwnProperty(index)) {
                if (index == oldKey) {
                    retObject[newKey] = obj[index];
                } else {
                    retObject[index] = obj[index];
                }
            }
        }
    } else if (oldKeyType == "object"
        && newKeyType == "object"
        && oldKey.hasOwnProperty("length")
        && newKey.hasOwnProperty("length")
        && oldKey.length <= newKey.length
        ) {
        for (index in obj) {
            if (obj.hasOwnProperty(index)) {
                ptr = oldKey.indexOf(index);
                if (ptr >= 0) {
                    retObject[newKey[ptr]] = obj[index];
                } else {
                    retObject[index] = obj[index];
                }
            }
        }
    }

    return retObject;
}
519058
private String replaceVariablesWithPatterns(String pattern) {
        int group = 0;
        Matcher findVariablesMatcher = variablePattern.matcher(pattern);
        while(findVariablesMatcher.find()) {
            String variable = findVariablesMatcher.group(0);
            pattern = pattern.replaceFirst(variable, "(.+)");
            variableToGroupNumber.put(variable, ++group);
        }
        return pattern;
    }
482331
def name_check(self, original, loc, tokens):
        """"""
        internal_assert(len(tokens) == 1, "invalid name tokens", tokens)
        if self.strict:
            self.unused_imports.discard(tokens[0])
        if tokens[0] == "exec":
            return self.check_py("3", "exec function", original, loc, tokens)
        elif tokens[0].startswith(reserved_prefix):
            raise self.make_err(CoconutSyntaxError, "variable names cannot start with reserved prefix " + reserved_prefix, original, loc)
        else:
            return tokens[0]
1293516
def _replaceRenamedPairMembers(kerning, leftRename, rightRename):
    
    renamedKerning = {}
    for (left, right), value in kerning.items():
        left = leftRename.get(left, left)
        right = rightRename.get(right, right)
        renamedKerning[left, right] = value
    return renamedKerning
991409
function replaceInString(string, variables) {
    const model = createModel(string);
    let offset = 0;
    let output = '';

    for (let i = 0, il = model.variables.length; i < il; i++) {
        const v = model.variables[i];
        let value = v.name in variables ? variables[v.name] : v.name;
        if (typeof value === 'function') {
            value = value(model.string, v, offset + v.location);
        }

        output += model.string.slice(offset, v.location) + value;
        offset = v.location + v.length;
    }

    return output + model.string.slice(offset);
}
1070305
private static function RemoveUndefinedVars(){
            $oThis = self::CreateInstanceIfNotExists();
            $iOffset = 0;

            while(preg_match('/{\$(.*?)}/i', $oThis->sBuffer, $aMatches, PREG_OFFSET_CAPTURE, $iOffset)){
                $oThis->sBuffer = str_replace($aMatches[0][0], "false", $oThis->sBuffer);
                $iOffset = $aMatches[0][1]+strlen($aMatches[0][0]);
            }
        }
1127495
public void setVariableName(String v) {
    if (VariableAssignment_Type.featOkTst && ((VariableAssignment_Type)jcasType).casFeat_variableName == null)
      jcasType.jcas.throwFeatMissing("variableName", "ch.epfl.bbp.uima.types.VariableAssignment");
    jcasType.ll_cas.ll_setStringValue(addr, ((VariableAssignment_Type)jcasType).casFeatCode_variableName, v);}
466110
function renameFunction(func, newName) {
    // eslint-disable-next-line no-unused-vars
    const prop = Object.getOwnPropertyDescriptor(func, 'name');
    if (prop) {
        const { value, ...others } = prop;
        Object.defineProperty(func, 'name', { value: newName, ...others });
    }
}
147186
def transform_file_name(file)
			if @bind
				variables = file.scan(/{{([^}]*)}}/).flatten

				variables.each do |v|
					file.sub!("{{#{v}}}", @bind.get_binding.eval(v))
				end
			end

			(!@nomodify && file.end_with?(".erb") && !File.directory?(file)) ? File.basename(file, ".*") : file
		end
640049
function markDuplicateVariableNames (row, i, rows) {
  var ast = row[kAst]

  var scope = scan.scope(ast)
  if (scope) {
    scope.forEach(function (binding, name) {
      binding[kShouldRename] = rows.usedGlobalVariables.has(name)
      rows.usedGlobalVariables.add(name)
    })
  }
}
621848
private static String toVariableName(String str) {

	StringBuffer rtn = new StringBuffer();
	char[] chars = str.toCharArray();
	long changes = 0;
	boolean doCorrect = true;
	for (int i = 0; i < chars.length; i++) {
	    char c = chars[i];
	    if (i == 0 && (c >= '0' && c <= '9')) rtn.append("_" + c);
	    else if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || c == '$') rtn.append(c);
	    else {
		doCorrect = false;
		rtn.append('_');
		changes += (c * (i + 1));
	    }
	}

	if (changes > 0) rtn.append(changes);

	if (doCorrect) return correctReservedWord(rtn.toString());
	return rtn.toString();
    }
459683
def _variable(lexer):
    """"""
    names = _names(lexer)

    tok = next(lexer)
    # NAMES '[' ... ']'
    if isinstance(tok, LBRACK):
        indices = _indices(lexer)
        _expect_token(lexer, {RBRACK})
    # NAMES
    else:
        lexer.unpop_token(tok)
        indices = tuple()

    return ('var', names, indices)
478085
def convertVariable(self, key, varName, varValue):
        """"""
        if isinstance(varValue, encapsulation.FunctionEncapsulation):
            result = varValue.getFunction()

            # Update the global scope of the function to match the current module
            mainModule = sys.modules["__main__"]
            result.__name__ = varName
            result.__globals__.update(mainModule.__dict__)
            setattr(mainModule, varName, result)
            shared.elements[key].update({
                varName: result,
            })
443568
private Context translateVariableAssign(WyilFile.Expr.VariableAccess lval, Expr rval, Context context) {
		WyilFile.Decl.Variable decl = lval.getVariableDeclaration();
		context = context.havoc(decl);
		WyalFile.VariableDeclaration nVersionedVar = context.read(decl);
		Expr.VariableAccess var = new Expr.VariableAccess(nVersionedVar);
		return context.assume(new Expr.Equal(var, rval));
	}
419634
def _rename_coords(ds, attrs):
    """"""
    for name_int, names_ext in attrs.items():
        # Check if coord is in dataset already.
        ds_coord_name = set(names_ext).intersection(set(ds.coords))
        if ds_coord_name:
            # Rename to the aospy internal name.
            try:
                ds = ds.rename({list(ds_coord_name)[0]: name_int})
                logging.debug("Rename coord from `{0}` to `{1}` for "
                              "Dataset `{2}`".format(ds_coord_name,
                                                     name_int, ds))
            # xarray throws a ValueError if the name already exists
            except ValueError:
                ds = ds
    return ds
39515
def substitute_filename(fn, variables):
    
    for var, value in variables.items():
        fn = fn.replace('+%s+' % var, str(value))
    return fn