private Step ParseName(MethodHelper method, char c) { if (c == '(') { return Step.Params; } else { method.Name.Append(c); return Step.Name; } }
private Step ParseBody(MethodHelper method, char c) { if (c == '{') brackets++; if (c == '}') { brackets--; if (brackets == 0) return Step.End; } method.Body.Append(c); return Step.Body; }
private Step ParseChar(MethodHelper method, Step step, char c) { switch (step) { case Step.Return: return ParseReturn(method, c); case Step.Name: return ParseName(method, c); case Step.Params: return ParseParams(method, c); case Step.Body: default: return ParseBody(method, c); } }
public string Parse(IParsedObject parent, ref System.IO.StreamReader file, params object[] parts) { if (!(parent is CrakeFile)) throw new SyntaxErrorException(); var method = new MethodHelper(); var text = (string)parts[0]; var step = Step.Return; do { foreach (var c in text.ToCharArray()) { step = ParseChar(method, step, c); } } while (null != (text = file.ReadLine())); return null; }
private Step ParseReturn(MethodHelper method, char c) { if (c == ' ' || c == '\t' || c == '\r' || c == '\n') { return Step.Name; } else { method.Return.Append(c); return Step.Return; } }
private Step ParseParams(MethodHelper method, char c) { if (c == ')') { brackets = 0; return Step.Body; } else { method.Params.Append(c); return Step.Params; } }
private void ResolveCalls(CrakeFile crakeFile, MethodHelper method) { foreach (var task in crakeFile.Tasks) { task.Body = Regex.Replace(task.Body, string.Format("\\b{0}\\s*\\(", method.Name), "HelperMethods.$0", RegexOptions.Multiline); } var body = method.Body.ToString(); method.Body.Remove(0, method.Body.Length); method.Body.Append(Regex.Replace(body, "\\bPARAMS\\s*\\[[^\\]]+\\]", "CrakeParameters.$0", RegexOptions.Multiline)); }