예제 #1
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);
        }
        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();
            }
        }