private static RowRegexExprNode Replace(RowRegexExprNode optionalParent, RowRegexExprNode originalNode, IList <RowRegexExprNode> expandedRepeat) { if (optionalParent == null) { var newParentNode = new RowRegexExprNodeConcatenation(); newParentNode.ChildNodes.AddAll(expandedRepeat); return(newParentNode); } // for nested nodes, use a concatenation instead if (optionalParent is RowRegexExprNodeNested || optionalParent is RowRegexExprNodeAlteration) { var concatenation = new RowRegexExprNodeConcatenation(); concatenation.ChildNodes.AddAll(expandedRepeat); optionalParent.ReplaceChildNode(originalNode, Collections.SingletonList <RowRegexExprNode>(concatenation)); } // concatenations are simply changed else { optionalParent.ReplaceChildNode(originalNode, expandedRepeat); } return(null); }
private static RowRegexExprNodeAlteration ExpandPermute(RowRegexExprNodePermute permute) { var e = PermutationEnumerator.Create(permute.ChildNodes.Count); var parent = new RowRegexExprNodeAlteration(); foreach (int[] indexes in e) { var concat = new RowRegexExprNodeConcatenation(); parent.AddChildNode(concat); for (var i = 0; i < indexes.Length; i++) { RowRegexExprNode toCopy = permute.ChildNodes[indexes[i]]; var copy = CheckedCopy(toCopy); concat.AddChildNode(copy); } } return(parent); }