Пример #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);
        }
        public static List <ConsoleFunction> parse(string content)
        {
            List <ConsoleFunction> retList = new List <ConsoleFunction>();
            StringReader           SR      = new StringReader(content);
            string line;
            string currentComment = null;

            while ((line = SR.ReadLine()) != null)
            {
                line = line.Trim();
                if (Patterns.LineStartsAMultilineComment(line))
                {
                    throw new NotImplementedException();
                }
                if (Patterns.LineStartsANamespace(line))
                {
                    ReadNamespace(SR, line, retList);
                }
                else
                {
                    if (line.Length > 0)
                    {
                        throw new NotImplementedException();
                    }
                }
            }
            return(retList);
        }
Пример #3
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);
        }
Пример #4
0
        private static ConsoleField ReadField(StringReader sr, string line, string fieldComment)
        {
            ConsoleField field        = new ConsoleField();
            Match        fieldMatches = Patterns.MatchField(line);
            string       type         = fieldMatches.Groups[1].Value.Trim();
            string       name         = fieldMatches.Groups[2].Value.Trim();

            if (fieldMatches.Groups[3].Value != string.Empty)
            {
                field.ElementCount = int.Parse(fieldMatches.Groups[3].Value);
            }
            field.Type = type;
            field.Name = name;
            return(field);
        }
Пример #5
0
        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();
            }
        }