private static ConsoleClass ReadClass(StringReader SR, string line, string classComment) { ConsoleClass retClass = new ConsoleClass(); // Make sure that we are actually able to parse the class and fetch the className and parentClassName Match declarationMatch = Patterns.MatchClassDeclaration(line); if (!declarationMatch.Success) { declarationMatch = Patterns.MatchSimObjectClassDeclaration(line); if (!declarationMatch.Success) { Console.WriteLine("Error parsing class: " + line); throw new ArgumentException("Error parsing class: " + line); } retClass.ClassName = declarationMatch.Groups[1].Value.Trim(); } else { retClass.ClassName = declarationMatch.Groups[1].Value.Trim(); retClass.ParentClassName = declarationMatch.Groups[3].Value.Trim(); } // Set the comment retClass.Comment = classComment; string currentComment = null; line = SR.ReadLine(); // Until we come to the end of the class while (!Patterns.LineEndsABody(line)) { // Read class comments, methods and fields if (Patterns.LineStartsAMultilineComment(line)) { currentComment = ReadComment(SR, line); } else if (Patterns.LineContainsAFunction(line)) { ConsoleFunction method = ReadFunction(SR, line, currentComment); currentComment = null; retClass.Methods.Add(method); } else if (Patterns.LineContainsACallback(line)) { //TODO Read callback here } else if (Patterns.LineContainsAField(line)) { ConsoleField field = ReadField(SR, line, currentComment); currentComment = null; retClass.Fields.Add(field); } line = SR.ReadLine(); } return(retClass); }
protected static ConsoleFunction ReadFunction(StringReader sr, string line, string methodComment) { ConsoleFunction method = new ConsoleFunction(); Match methodMatches = Patterns.MatchMethod(line); string type = methodMatches.Groups[1].Value.Trim(); string name = methodMatches.Groups[2].Value.Trim(); method.Type = type; method.Name = name; if (!string.IsNullOrEmpty(methodMatches.Groups[4].Value)) { method.IsStringlyTyped = true; } if (type.Trim().Length == 0) { throw new NotImplementedException(); } if (methodMatches.Groups.Count == 2) { return(method); } string parameters = methodMatches.Groups[3].Value.Trim(); MatchCollection paramMatches = Patterns.MatchMethodParameters(parameters); foreach (Match param in paramMatches) { string pType = param.Groups[1].Value.Trim(); string pName = param.Groups[2].Value.Trim(); ConsoleParameter cParam = new ConsoleParameter { VarArgs = Patterns.IsParamVariadic(pName), Type = pType, Name = pName.Replace("...", "") }; if (param.Groups[3].Length > 0) { string defaultValue = param.Groups[3].Value.Trim(); if (defaultValue.StartsWith("nullAsType<")) { defaultValue = "null"; } cParam.DefaultValue = defaultValue.Trim(); } method.Parameters.Add(cParam); } method.Comment = methodComment; return(method); }
private static void ReadNamespace(StringReader SR, string line, List <ConsoleFunction> retList) { Match declarationMatch = Patterns.MatchNamespace(line); string namespaceName = declarationMatch.Groups[1].Value; string currentComment = null; line = SR.ReadLine(); while (!Patterns.LineEndsABody(line)) { if (Patterns.LineStartsAMultilineComment(line)) { currentComment = ReadComment(SR, line); } else if (Patterns.LineContainsAFunction(line)) { ConsoleFunction function = ReadFunction(SR, line, currentComment); currentComment = null; function.Namespace = namespaceName; retList.Add(function); } line = SR.ReadLine(); } }
public CrestAction() { ConsoleFunction.CallbackDelegate cb = new ConsoleFunction.CallbackDelegate(_ExecuteInConsole); ExecuteInConsole = new ConsoleFunction(menu_text, cb); }
public void AddEntry(ConsoleFunction entry) { entries.Add(entry); }