public static string DoPreProcess(List <DefBlock> blocks, string var) { string varBuf = var; varBuf = FormatCode(varBuf); varBuf = RepairBrackets(varBuf, "{", "}"); varBuf = RepairBrackets(varBuf, "(", ")"); varBuf = FormatCode(varBuf); varBuf = FormatLambda(varBuf); StringReader reader = new StringReader(varBuf); StringBuilder builder = new StringBuilder(); string line, block; DefCall call; bool defRes; builder.Clear(); while (reader.Peek() != -1) { line = reader.ReadLine(); if (line.Contains("<") && !line.StartsWith("<") && line.EndsWith(">") && !line.Split('<')[0].Contains(" ")) { call = DefCall.GetCall(line); defRes = false; foreach (DefBlock blk in blocks) { if (blk.name == call.name) { if (blk.args.Count == call.args.Count) { block = blk.block; for (int i = 0; i < call.args.Count; i++) { block = block.Replace(blk.args[i] + ",", call.args[i] + ","); block = block.Replace(blk.args[i] + "\n", call.args[i] + "\n"); } builder.AppendLine(block); defRes = true; break; } } } if (!defRes) { Print("Error at: \"" + line + "\"\n\n"); return(null); } } else { builder.AppendLine(line); } } varBuf = builder.ToString(); varBuf = FormatCode(varBuf); return(varBuf); }
public static DefCall GetCall(string str) { DefCall ret = new DefCall(); ret.name = str.Split('<')[0]; string arg = str.Split(new char[] { '<', '>' })[1]; ret.args = ParseArgs(arg, ','); return(ret); }
public DefCall(DefCall defCall) { name = defCall.name; args = new List <string>(defCall.args); }