Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static void Add(string msg, int size = 14)
        {
            ConsoleClass dd = new ConsoleClass();

            dd.Msg  = msg;
            dd.Size = size;
            ConsoleList.Add(dd);
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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"));
        }
Ejemplo n.º 6
0
        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);
        }