public virtual TreeNode OnSplit(TreeNode [] args) { CheckArgumentCount(args, 2); var result = new TreeNode(); string str = GetArgumentString(args, 0); string pattern = GetArgumentString(args, 1); foreach (string item in Regex.Split(str, pattern)) { result.AddChild(new StringLiteral(item)); } return(result); }
private void Flatten(TreeNode result_node, TreeNode node) { if (node == null) { return; } if (!node.HasChildren && !(node is VoidLiteral)) { result_node.AddChild(node); return; } foreach (TreeNode child_node in node.Children) { Flatten(result_node, child_node); } }
public TreeNode(TreeNode parent) { this.parent = parent; parent.AddChild(this); }
private void Flatten(TreeNode result_node, TreeNode node) { if(node == null) { return; } if(!node.HasChildren && !(node is VoidLiteral)) { result_node.AddChild(node); return; } foreach(TreeNode child_node in node.Children) { Flatten(result_node, child_node); } }
private TreeNode SExprConstructPipelinePart (EvaluatorBase evaluator, TreeNode [] args, bool element) { StringBuilder builder = new StringBuilder (); TreeNode list = new TreeNode (); foreach (TreeNode arg in args) { list.AddChild (evaluator.Evaluate (arg)); } list = list.Flatten (); for (int i = 0; i < list.ChildCount; i++) { TreeNode node = list.Children[i]; string value = node.ToString ().Trim (); builder.Append (value); if (i == 0) { if (list.ChildCount > 1) { builder.Append (element ? ' ' : ','); } continue; } else if (i % 2 == 1) { builder.Append ('='); } else if (i < list.ChildCount - 1) { builder.Append (element ? ' ' : ','); } } return new StringLiteral (builder.ToString ()); }
public TreeNode Evaluate(TreeNode node) { if(!node.HasChildren || node is FunctionNode) { return EvaluateNode(node); } TreeNode final_result_node = new TreeNode(); foreach(TreeNode child_node in node.Children) { TreeNode result_node = EvaluateNode(child_node); if(result_node != null) { final_result_node.AddChild(result_node); } if(child_node is FunctionNode) { if(functions.ContainsKey((child_node as FunctionNode).Function)) { break; } FunctionNode impl = ResolveFunction(child_node as FunctionNode); if(impl != null && impl.RequiresArguments) { break; } } } return final_result_node.ChildCount == 1 ? final_result_node.Children[0] : final_result_node; }
public virtual TreeNode OnSplit(TreeNode [] args) { CheckArgumentCount(args, 2); TreeNode result = new TreeNode(); string str = GetArgumentString(args, 0); string pattern = GetArgumentString(args, 1); foreach(string item in Regex.Split(str, pattern)) { result.AddChild(new StringLiteral(item)); } return result; }
void TokenPush(bool as_string) { if (current_token.Length == 0 && !as_string) { return; } string token = current_token.ToString(); if (Debug) { Console.Write("{3}[{0}] TOKEN({4},{5}): [{2}{1}{2}]", scope, token, as_string ? "\"" : string.Empty, string.Empty.PadLeft(scope - 1, ' '), line, column - current_token.Length); } TreeNode node; if (as_string) { node = new StringLiteral(token); } else if (token == "#t") { node = new BooleanLiteral(true); } else if (token == "#f") { node = new BooleanLiteral(false); } else if (token.Length > 0 && token != "." && token != "-" && token != "+" && number_regex.IsMatch(token)) { try { if (token.StartsWith("0x") || token.StartsWith("-0x")) { int offset = token[0] == '-' ? 3 : 2; int value = int.Parse(token.Substring(offset), NumberStyles.HexNumber, culture_info.NumberFormat); node = new IntLiteral(value * (offset == 3 ? -1 : 1)); } else if (token.Contains(".")) { node = new DoubleLiteral(double.Parse(token, NumberStyles.Float, culture_info.NumberFormat)); } else { node = new IntLiteral(int.Parse(token, NumberStyles.Integer, culture_info.NumberFormat)); } } catch { throw new FormatException("Invalid number format: " + token); } } else { node = new FunctionNode(token); } if (Debug) { Console.WriteLine(" => [{0}]", node); } node.Line = line; node.Column = column; current_parent.AddChild(node); current_token.Remove(0, current_token.Length); }