public static List <ConsoleClass> parse(string content) { List <ConsoleClass> retList = new List <ConsoleClass>(); StringReader SR = new StringReader(content); string line; string currentComment = null; // We read the whole contents of the console class dump while ((line = SR.ReadLine()) != null) { line = line.Trim(); // We read comments and save them for later if (Patterns.LineStartsAMultilineComment(line)) { currentComment = ReadComment(SR, line); } // If we find a class, we parse it and assign the current comment to it. if (Patterns.LineStartsAClass(line)) { ConsoleClass currentClass = ReadClass(SR, line, currentComment); currentComment = null; retList.Add(currentClass); } } return(retList); }
public static void Add(string msg, int size = 14) { ConsoleClass dd = new ConsoleClass(); dd.Msg = msg; dd.Size = size; ConsoleList.Add(dd); }
public void InitializeSession(Session session) { this.session = session; Console = new ConsoleClass(session); Environment = new EnvironmentClass(session); Path = new PathClass(session); File = new FileClass(session); Directory = new DirectoryClass(session); Thread = new ThreadClass(session); Process = new ProcessClass(session); }
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); }
private static void AddClassAndSubclasses(Dictionary <ConsoleClass, List <ConsoleClass> > subclassDictionary, List <ConsoleClass> simClasses, ConsoleClass simObjectClass, bool isDatablock = false) { simObjectClass.IsDatablock = isDatablock; // Add this class to the simClasses simClasses.Add(simObjectClass); // If this class has no subclasses, return if (!subclassDictionary.ContainsKey(simObjectClass)) { return; } // Add the class and all subclasses subclassDictionary[simObjectClass].ForEach(x => AddClassAndSubclasses(subclassDictionary, simClasses, x, x.ClassName == "SimDataBlock")); }
public static List <ConsoleClass> BuildAsList(List <ConsoleClass> classes) { Dictionary <ConsoleClass, List <ConsoleClass> > subclassDictionary = new Dictionary <ConsoleClass, List <ConsoleClass> >(); Dictionary <string, ConsoleClass> classNameDictionary = new Dictionary <string, ConsoleClass>(); // Create a mapping from classname to class objects classes.ForEach(x => classNameDictionary[x.ClassName] = x); // Map parent class names to their respective objects classes.ForEach(x => x.ParentClass = x.ParentClassName == null ? null : classNameDictionary[x.ParentClassName]); classes.ForEach(x => { // First, filter out non-simclasses if (x.ParentClass == null) { return; } // Insert the current simclass as a subclass to the parent if (!subclassDictionary.ContainsKey(x.ParentClass)) { subclassDictionary[x.ParentClass] = new List <ConsoleClass>(); } subclassDictionary[x.ParentClass].Add(x); }); List <ConsoleClass> simClasses = new List <ConsoleClass>(); // Locate the top-level class ConsoleClass simObjectClass = classes.Find(x => x.ClassName == "SimObject"); // Insert all sim classes into the simClasses list AddClassAndSubclasses(subclassDictionary, simClasses, simObjectClass); return(simClasses); }