예제 #1
0
        public IEnumerable <ParsedClass> FindAndParse(SearchTask searchTask, string[] extensions, bool isApi)
        {
            var cashFile = Path.Combine(SubDirName, _projName, $"{searchTask.SearchLine}.txt");

            if (!Directory.Exists(SubDirName))
            {
                Directory.CreateDirectory(SubDirName);
            }
            if (!Directory.Exists(Path.Combine(SubDirName, _projName)))
            {
                Directory.CreateDirectory(Path.Combine(SubDirName, _projName));
            }

            if (!string.IsNullOrEmpty(searchTask.FullPath) && File.Exists(searchTask.FullPath))
            {
                if (File.Exists(cashFile))
                {
                    var text = File.ReadAllText(cashFile);
                    yield return(JsonConvert.DeserializeObject <ParsedClass>(text));
                }
            }

            var lines = _grabber.FindClass(searchTask, extensions, isApi);

            foreach (var text in lines)
            {
                var parcedClass = TryParseClass(searchTask, text, isApi);
                parcedClass.AbsPathToFile = searchTask.FullPath.Remove(0, searchTask.SearchDir.Length);
                var json = JsonConvert.SerializeObject(parcedClass);
                File.WriteAllText(cashFile, json);
                yield return(parcedClass);
            }
        }
예제 #2
0
        public virtual IEnumerable <IList <string> > FindClass(SearchTask searchTask, string[] extensions, bool isApi)
        {
            IList <string> text;
            var            cashFile = Path.Combine(SubDirName, _projName, $"{searchTask.SearchLine}.txt");

            if (!Directory.Exists(SubDirName))
            {
                Directory.CreateDirectory(SubDirName);
            }
            if (!Directory.Exists(Path.Combine(SubDirName, _projName)))
            {
                Directory.CreateDirectory(Path.Combine(SubDirName, _projName));
            }

            if (!string.IsNullOrEmpty(searchTask.FullPath) && File.Exists(searchTask.FullPath))
            {
                if (File.Exists(cashFile))
                {
                    text = File.ReadAllLines(cashFile);
                    if (text.Count > 0)
                    {
                        yield return(text);
                    }
                }
                text = TryGrabText(searchTask.FullPath, searchTask.SearchLine, isApi);
                if (text != null && text.Count > 0)
                {
                    File.WriteAllLines(cashFile, text);
                    yield return(text);
                }
            }

            var files = Directory.GetFiles(searchTask.SearchDir, "*.*", SearchOption.AllDirectories).Where(path => extensions.Any(path.EndsWith)).ToArray();

            foreach (var file in files)
            {
                text = TryGrabText(file, searchTask.SearchLine, isApi);

                if (text != null && text.Count > 0)
                {
                    searchTask.FullPath = file;
                    File.WriteAllLines(cashFile, text);
                    yield return(text);
                }
            }
        }
예제 #3
0
        public virtual ParsedClass TryParseClass(SearchTask searchTask, IList <string> text, bool isApi)
        {
            if (!text.Any())
            {
                return(null);
            }

            int index;

            if (text.Count == 1)
            {
                var typedef = TryParseTypedefClass(text[0]);
                if (typedef != null)
                {
                    return(typedef);
                }
            }

            var result = new ParsedClass();

            if (isApi)
            {
                result.ObjectType = ObjectType.Api;
            }

            result.MainComment = TryParseComment(text, 0, out index);
            TryParseTemplate(result, text, index, out index);

            var headerSb = new StringBuilder();

            do
            {
                headerSb.Append(" " + text[index]);
            } while (!StartBodyRegex.IsMatch(text[index++]));

            var header = headerSb.ToString();
            var name   = TryParseClassName(header);

            result.CppName    = name;
            result.Name       = ToTitleCase(name);
            result.ObjectType = EnumRegex.IsMatch(header) ? ObjectType.Enum : result.ObjectType;

            var inherit = TryParseInherit(header).Trim();

            if (!string.IsNullOrEmpty(inherit))
            {
                result.CppInherit = inherit;
            }

            while (index < text.Count)
            {
                if (StartPrivateRegex.IsMatch(text[index]) || (index + 1 == text.Count && text[index].Trim().StartsWith("}")))
                {
                    break;
                }

                if (result.ObjectType == ObjectType.Api && GoToDeclareApiSection(text, index, out index))
                {
                    continue;
                }

                var comm = TryParseComment(text, index, out index);
                if (index == text.Count)
                {
                    break;
                }

                if (StartPrivateRegex.IsMatch(text[index]))
                {
                    break;
                }

                PreParsedElement field = null;
                switch (result.ObjectType)
                {
                case ObjectType.Enum:
                {
                    field = TryParseEnum(text, index, out index);
                    break;
                }

                case ObjectType.Class:
                {
                    field = TryParseElement(text, index, out index, isApi);
                    break;
                }

                case ObjectType.Api:
                {
                    field = TryParseMethod(text, index, out index);
                    break;
                }
                }

                if (field != null)
                {
                    field.MainComment = comm;
                    result.Fields.Add(field);
                }
            }

            return(result);
        }