public static DefBlock GetBlock(string head, string body) { if (!head.Contains("<") || !head.EndsWith(">")) { return(null); } DefBlock ret = new DefBlock(); ret.name = head.Substring(1).Split('<')[0]; string arg = head.Split(new char[] { '<', '>' })[1]; ret.args = ParseArgs(arg, ','); ret.block = body; return(ret); }
public static List <DefBlock> GetDefBlocks(string var) { List <DefBlock> blocks = new List <DefBlock>(); string varBuf = var; varBuf = FormatCode(varBuf); varBuf = RepairBrackets(varBuf, "{", "}"); varBuf = RepairBrackets(varBuf, "(", ")"); varBuf = FormatCode(varBuf); varBuf = FormatLambda(varBuf); StringReader reader = new StringReader(varBuf); string head = "", body = "", tmp; DefBlock blk; const int IDLE = 0, RUN = 1; int state = IDLE, count = 0; while (reader.Peek() != -1) { switch (state) { case IDLE: head = reader.ReadLine(); count = 0; body = ""; if (head.Contains("{")) { head = head.Replace("{", ""); count += 1; state = RUN; } break; case RUN: if (reader.Peek() != -1) { tmp = reader.ReadLine(); if (tmp.Contains("{")) { count += 1; } else if (tmp.Contains("}")) { count -= 1; } if (tmp.Contains("(") && tmp.Contains(")")) { if (tmp.Contains("{") && tmp.Contains("}")) { count -= 1; } } if (count == 0) { if (head.StartsWith(".") && !head.StartsWith(".<")) { blk = DefBlock.GetBlock(head, body); if (blk == null) { Print("Error at: \"" + head + "\"\n\n"); return(null); } blocks.Add(blk); } state = IDLE; } body = body + (tmp + "\n"); } break; default: break; } } return(blocks); }
public DefBlock(DefBlock defBlock) { name = defBlock.name; args = new List <string>(defBlock.args); block = defBlock.name; }