Replace child expressions in-place.

        :param IRExpr expression:         The expression to look for.
        :param IRExpr replacement:  The expression to replace with.
        :return:                    None
490478
def replace_expression(self, expression, replacement):
        

        for k in self.__slots__:
            v = getattr(self, k)
            if v is expression:
                setattr(self, k, replacement)
            elif isinstance(v, IRExpr):
                v.replace_expression(expression, replacement)
            elif type(v) is tuple:
                # Rebuild the tuple
                _lst = [ ]
                replaced = False
                for expr_ in v:
                    if expr_ is expression:
                        _lst.append(replacement)
                        replaced = True
                    else:
                        _lst.append(expr_)
                if replaced:
                    setattr(self, k, tuple(_lst))
23898
def _replace(variables, match):
    
    expression = match.group(1)

    # Look-up chars and functions for the specified operator
    (prefix_char, separator_char, split_fn, escape_fn,
     format_fn) = operator_map.get(expression[0], defaults)

    replacements = []
    for key, modify_fn, explode in split_fn(expression):
        if key in variables:
            variable = modify_fn(variables[key])
            replacement = format_fn(
                explode, separator_char, escape_fn, key, variable)
            replacements.append(replacement)
    if not replacements:
        return ''
    return prefix_char + separator_char.join(replacements)
463989
function replaceArgsExpr(ctx, forms, expansioncode, replacements, isrestarg) {
  var macroname = forms[0].value;

  var expr_name = expansioncode[0] ? expansioncode[0].value : ""
  var marker = (expr_name !== "#args-get" ? expansioncode[1].value :
        expansioncode[2].value ? expansioncode[2].value : expansioncode[2][0].value);

  if(marker.charAt(0) === "~") {
    marker = marker.substring(1);
  }
  var isSplice = false;
  if(marker.charAt(0) === "@") {
    marker = marker.substring(1);
    isSplice = true;
  }
  var replarray = replacements[marker];
  if (expr_name === "#args-shift") {
    if (!Array.isArray(replarray)) {
      expansioncode[1].error('can\'t #args-shift: invalid argument type in "' + macroname + '"');
    }
    var argshift = replarray.shift()
    if (typeof argshift === "undefined") {
      expansioncode[1].error('can\'t #args-shift: invalid number of arguments to "' + macroname + '"');
    }
    return spliceArgsExprResult(isSplice, argshift);
  }
  if (expr_name === "#args-erase-head") {
    if (!Array.isArray(replarray)) {
      expansioncode[1].error('can\'t #args-rest: invalid argument type in "' + macroname + '"');
    }
    replacements[marker] = replarray.splice(1, replarray.length);
    return undefined;
  }
  if (expr_name === "#args-rest") {
    if (!Array.isArray(replarray)) {
      expansioncode[1].error('can\'t #args-rest: invalid argument type in "' + macroname + '"');
    }
    var argsrest = replarray.splice(1, replarray.length);
    if (typeof argsrest === "undefined") {
      expansioncode[1].error('can\'t #args-rest: invalid number of arguments to "' + macroname + '"');
    }
    return spliceArgsExprResult(isSplice, argsrest);
  }
  if (expr_name === "#args-second") {
    if (!Array.isArray(replarray)) {
      expansioncode[1].error('can\'t #args-second: invalid argument type in "' + macroname + '"');
    }
    // note splice here does *remove* the second element from the array (a side effect!)
    var argsecond = replarray.splice(1, 1)[0]
    if (typeof argsecond === "undefined") {
      expansioncode[1].error('no #args-second: invalid number of arguments to "' + macroname + '"');
    }
    return spliceArgsExprResult(isSplice, argsecond);
  }
  if (expr_name === "#args-get") {
    // we have an extra arg compared to the other #args expressions
    var whichArg = expansioncode[1].value;

    if (!Array.isArray(replarray)) {
      expansioncode[2].error('can\'t #args-get: invalid argument type in "' + macroname + '"');
    }
    if (whichArg < 0 || whichArg >= replarray.length) {
      expansioncode[2].error("can\'t #args-get: no argument at position " + whichArg +
                                ' in "' + macroname + '"');
    }
    var argVal = replarray[whichArg];

    if (typeof argVal === "undefined") {
      expansioncode[2].error("no #args-get: undefined argument at position " + whichArg +
                                ' in "' + macroname + '"');
    }
    return spliceArgsExprResult(isSplice, argVal);

  }
  if (expr_name === "#args-if") {
    var argsif;
    if (!Array.isArray(replarray)) {
      expansioncode[1].error('can\'t #args-if: invalid argument type in "' + macroname + '"');
    }
    if (replarray.length) {
      argsif = replaceCode(ctx, forms, expansioncode[2], replacements, isrestarg);
    } else if (expansioncode[3]) {
      argsif = replaceCode(ctx, forms, expansioncode[3], replacements, isrestarg);
    } else {
      return
    }
    return spliceArgsExprResult(isSplice, argsif);
  }
}
416756
def replaceWith(self, *nodes: Union[AbstractNode, str]) -> None:
        
        if self.parentNode:
            node = _to_node_list(nodes)
            self.parentNode.replaceChild(node, self)
1056172
def _gen_te_xref(self, expr: Union[ShExJ.tripleExpr, ShExJ.tripleExprLabel]) -> None:
        
        if expr is not None and not isinstance_(expr, ShExJ.tripleExprLabel) and 'id' in expr and expr.id is not None:
            if expr.id in self.te_id_map:
                return
            else:
                self.te_id_map[self._resolve_relative_uri(expr.id)] = expr
        if isinstance(expr, (ShExJ.OneOf, ShExJ.EachOf)):
            for expr2 in expr.expressions:
                self._gen_te_xref(expr2)
        elif isinstance(expr, ShExJ.TripleConstraint):
            if expr.valueExpr is not None:
                self._gen_schema_xref(expr.valueExpr)
102188
@Override
  public Fix replace(ExpressionTemplateMatch match) {
    Inliner inliner = match.createInliner();
    Context context = inliner.getContext();
    if (annotations().containsKey(UseImportPolicy.class)) {
      ImportPolicy.bind(context, annotations().getInstance(UseImportPolicy.class).value());
    } else {
      ImportPolicy.bind(context, ImportPolicy.IMPORT_TOP_LEVEL);
    }
    int prec = getPrecedence(match.getLocation(), context);
    SuggestedFix.Builder fix = SuggestedFix.builder();
    try {
      StringWriter writer = new StringWriter();
      pretty(inliner.getContext(), writer).printExpr(expression().inline(inliner), prec);
      fix.replace(match.getLocation(), writer.toString());
    } catch (CouldNotResolveImportException e) {
      logger.log(SEVERE, "Failure to resolve in replacement", e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return addImports(inliner, fix);
  }
765732
public Expression2 substitute(int index, String newConstantExpression) {
    return substitute(index, Expression2.constant(newConstantExpression));
  }
1156609
def __replace_base_variables(text, req_len, idx):
        
        return text \
            .replace("{i}", str(idx + 1)) \
            .replace("{n}", str(req_len))
810040
def compile(expression, escape_funcs=None, unescape_funcs=None):
    
    return _compile_from_parse_tree(
        parse_regex(tokenize_regex(expression)),
        escape_funcs=escape_funcs,
        unescape_funcs=unescape_funcs)
1090338
public static String rewrite(String expression) throws InvalidExpressionException {

        ExpressionTree expTree = parseToTree(expression);

        expTree.reduce();

        return expTree.toString();
    }
1289692
private Node tryFoldExpr(Node subtree) {
    Node result = trySimplifyUnusedResult(subtree.getFirstChild());
    if (result == null) {
      Node parent = subtree.getParent();
      // If the EXPR_RESULT no longer has any children, remove it as well.
      if (parent.isLabel()) {
        Node replacement = IR.block().srcref(subtree);
        parent.replaceChild(subtree, replacement);
        subtree = replacement;
      } else {
        subtree.detach();
        subtree = null;
      }
    }
    return subtree;
  }
588395
def replace(self, src: str) -> str:
        
        if not self.readied:
            self.ready()

        # Brackets + simple pre replacements:
        src = self._dict_replace(self.simple_pre, src)

        # Superscripts and subscripts + pre regexps:
        for regex, replace in self.regex_pre:
            src = regex.sub(replace, src)

        # Unary and binary operators:
        src = self._operators_replace(src)

        # Loop regexps:
        src_prev = src
        for i in range(self.max_iter):
            for regex, replace in self.loop_regexps:
                src = regex.sub(replace, src)
            if src_prev == src:
                break
            else:
                src_prev = src

        # Post regexps:
        for regex, replace in self.regex_post:
            src = regex.sub(replace, src)

        # Simple post replacements:
        src = self._dict_replace(self.simple_post, src)

        # Escape characters:
        src = self.escapes_regex.sub(r'\1', src)

        return src
277560
def _replaced(__values, **__replacements):
    
    return tuple(o for o in (__replacements.get(name, name) for name in __values) if o)
512587
def matchesExpr(cntxt: Context, T: RDFGraph, expr: ShExJ.tripleExpr, _: DebugContext) -> bool:
    

    if isinstance(expr, ShExJ.OneOf):
        return matchesOneOf(cntxt, T, expr)
    elif isinstance(expr, ShExJ.EachOf):
        return matchesEachOf(cntxt, T, expr)
    elif isinstance(expr, ShExJ.TripleConstraint):
        return matchesCardinality(cntxt, T, expr)
    elif isinstance_(expr, ShExJ.tripleExprLabel):
        return matchesTripleExprRef(cntxt, T, expr)
    else:
        raise Exception("Unknown expression")
1076406
@Override
	public void replaceChildren(int startChildIndex, int stopChildIndex, Object t) {
		/*
		System.out.println("replaceChildren "+startChildIndex+", "+stopChildIndex+
						   " with "+((BaseTree)t).toStringTree());
		System.out.println("in="+toStringTree());
		*/
		if ( children==null ) {
			throw new IllegalArgumentException("indexes invalid; no children in list");
		}
		int replacingHowMany = stopChildIndex - startChildIndex + 1;
		int replacingWithHowMany;
		BaseTree newTree = (BaseTree)t;
		List<Object> newChildren;
		// normalize to a list of children to add: newChildren
		if ( newTree.isNil() ) {
			newChildren = newTree.children;
		}
		else {
			newChildren = new ArrayList<Object>(1);
			newChildren.add(newTree);
		}
		replacingWithHowMany = newChildren.size();
		int numNewChildren = newChildren.size();
		int delta = replacingHowMany - replacingWithHowMany;
		// if same number of nodes, do direct replace
		if ( delta == 0 ) {
			int j = 0; // index into new children
			for (int i=startChildIndex; i<=stopChildIndex; i++) {
				BaseTree child = (BaseTree)newChildren.get(j);
				children.set(i, child);
				child.setParent(this);
				child.setChildIndex(i);
                j++;
            }
		}
		else if ( delta > 0 ) { // fewer new nodes than there were
			// set children and then delete extra
			for (int j=0; j<numNewChildren; j++) {
				children.set(startChildIndex+j, newChildren.get(j));
			}
			int indexToDelete = startChildIndex+numNewChildren;
			for (int c=indexToDelete; c<=stopChildIndex; c++) {
				// delete same index, shifting everybody down each time
				children.remove(indexToDelete);
			}
			freshenParentAndChildIndexes(startChildIndex);
		}
		else { // more new nodes than were there before
			// fill in as many children as we can (replacingHowMany) w/o moving data
			for (int j=0; j<replacingHowMany; j++) {
				children.set(startChildIndex+j, newChildren.get(j));
			}
			//int numToInsert = replacingWithHowMany-replacingHowMany;
			for (int j=replacingHowMany; j<replacingWithHowMany; j++) {
				children.add(startChildIndex+j, newChildren.get(j));
			}
			freshenParentAndChildIndexes(startChildIndex);
		}
		//System.out.println("out="+toStringTree());
	}
53134
public void replace(XElement oldChild, XElement newChild) {
        int idx = children.indexOf(oldChild);
        if (idx >= 0) {
            children.get(idx).parent = null;
            children.set(idx, newChild);
            newChild.parent = this;
        }
    }
222632
function changeExprCompareExprs(changeExpr, exprs, data) {
    for (var i = 0, l = exprs.length; i < l; i++) {
        if (changeExprCompare(changeExpr, exprs[i], data)) {
            return 1;
        }
    }

    return 0;
}