Пример #1
0
        /// <summary>
        /// Парсит переданный текст на наличие функций и процедур
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static FunctionList Parse(string[] text, FileModule fileModule)
        {
            var result     = new FunctionList(fileModule);
            var countLines = text.Count();
            var index      = 0;
            var areas      = new Stack <string>();

            while (index < countLines)
            {
                var          str            = text[index].Trim();
                var          strLow         = str.ToLower();
                var          indexStartName = 0;
                TypeFunction typeFunc       = TypeFunction.function;

                // Если начало области, то поместим в стек ее название
                if (strLow.StartsWith(strAreaBegin))
                {
                    areas.Push(str.Substring(strAreaBegin.Length + 1));
                }

                // Если конец области то уберем имя последней области из стека
                if (strLow.StartsWith(strAreaEnd))
                {
                    if (areas.Count > 0)
                    {
                        areas.Pop();
                    }
                }

                // Определяем процедура или функция.
                if (strLow.IndexOf(strProc) == 0)
                {
                    indexStartName = strProc.Length;
                    typeFunc       = TypeFunction.procedure;
                }
                else if (strLow.IndexOf(strFunc) == 0)
                {
                    indexStartName = strFunc.Length;
                }

                if (indexStartName > 0)
                {
                    var firstBracket = strLow.IndexOf('(');
                    if (firstBracket == -1)
                    {
                        firstBracket = strLow.IndexOf(';');
                        if (firstBracket == -1)
                        {
                            firstBracket = strLow.Length;
                        }
                    }
                    var export        = strLow.IndexOf(strExport) >= 0;
                    var secondBracket = strLow.IndexOf(')');

                    var newFunction = new FunctionInfo(result);
                    newFunction.Name = str.Substring(indexStartName, firstBracket - indexStartName).Trim();
                    newFunction.IndexStartDescript = GetStartDescriptFunction(text, index);
                    newFunction.Type       = typeFunc;
                    newFunction.IndexStart = index;
                    newFunction.Export     = export;
                    if (areas.Count > 0)
                    {
                        newFunction.Area = areas.ToArray().Reverse().ToArray();
                    }
                    result.Add(newFunction);
                }
                index++;
            }
            result.Sort((x, y) => string.Compare(x.Name, y.Name));
            return(result);
        }
Пример #2
0
 public FunctionInfo(FunctionList functionList)
 {
     FunctionList = functionList;
 }