private static bool InsertedNodeContainsNode(PythonNode modifiedNode, PythonNode child) { if (child.Equals(modifiedNode)) { return(true); } foreach (var pythonNode in modifiedNode.Children) { var childResult = InsertedNodeContainsNode(pythonNode, child); if (childResult) { return(true); } } return(false); }
private bool RecursivelyMatch(PythonNode current, PythonNode node) { if (Token.Match(current)) { _index++; if (_index == _k) { return(current.Equals(node)); } } foreach (var child in current.Children) { if (RecursivelyMatch(child, node)) { return(true); } } return(false); }
//[WitnessFunction("Relative", 1, DependsOnParameters = new[] { 0 }) ] //public static ExampleSpec WitnessRelativeK(GrammarRule rule, int parameter, ExampleSpec spec, ExampleSpec tokenSpec) //{ // var result = new Dictionary<State, object>(); // foreach (var input in spec.ProvidedInputs) // { // var example = spec.DisjunctiveExamples[input].First() as Tuple<PythonNode, PythonNode>; // var template = (TreeTemplate)tokenSpec.Examples[input]; // if (example != null) // { // var parent = example.Item2; // var target = example.Item1; // var k = 0; // var exampleK = 0; // foreach (var child in parent.Children) // { // if (MatchRecursively(child, template, target, ref k)) // { // exampleK = k; // } // } // if (exampleK != 0) // result[input] = exampleK; // else // { // return null; // } // } // else // { // return null; // } // } // return new ExampleSpec(result); //} //[WitnessFunction("Relative", 1, DependsOnParameters = new[] { 0 }) ] //public static ExampleSpec WitnessRelativeK(GrammarRule rule, int parameter, ExampleSpec spec, ExampleSpec tokenSpec) //{ // var result = new Dictionary<State, object>(); // foreach (var input in spec.ProvidedInputs) // { // var example = spec.DisjunctiveExamples[input].First() as Tuple<PythonNode, PythonNode>; // var template = (TreeTemplate)tokenSpec.Examples[input]; // if (example != null) // { // var parent = example.Item2; // var target = example.Item1; // var k = 0; // var exampleK = 0; // foreach (var child in parent.Children) // { // if (MatchRecursively(child, template, target, ref k)) // { // exampleK = k; // } // } // if (exampleK != 0) // result[input] = exampleK; // else // { // return null; // } // } // else // { // return null; // } // } // return new ExampleSpec(result); //} private static bool MatchRecursively(PythonNode current, TreeTemplate pattern, PythonNode target, ref int i) { if (pattern.Match(current)) { i++; if (current.Equals(target)) { return(true); } } foreach (var child in current.Children) { if (MatchRecursively(child, pattern, target, ref i)) { return(true); } } return(false); }