示例#1
0
        private static void GetAllLines(string fullPath, string path)
        {
            var tmpText = File.ReadAllLines(fullPath);

            //var fi = new FileInfo(path);
            for (int i = 0; i < tmpText.Length; i++)
            {
                var tmpLine = new Line(LineBuilder.GetWords(tmpText[i]), tmpText[i]);
                tmpLine.Number = i + 1;
                //tmpLine.FileName = IncludeName + Extension.BPInclude;
                tmpLine.FileName = fullPath;
                //tmpLine.FileName = fi.Name;
                tmpLine.Type = LineBuilder.GetType(tmpLine);

                if (tmpLine.Type == LineType.INCLUDE)
                {
                    Data.Errors.Add(new Errore(tmpLine.Number, IncludeName + Extension.BPInclude, 1105, ""));
                    //Data.Errors.Add(new Errore(tmpLine.Number, fi.Name, 1105, ""));
                    return;
                }
                else if (tmpLine.Type == LineType.FOLDER)
                {
                    Data.Errors.Add(new Errore(tmpLine.Number, IncludeName + Extension.BPInclude, 1106, ""));
                    //Data.Errors.Add(new Errore(tmpLine.Number, fi.Name, 1106, ""));
                    return;
                }
                else if (tmpLine.Type == LineType.IMPORT)
                {
                    ImportErrorParser.Start(tmpLine, path);
                    if (Data.Errors.Count > 0)
                    {
                        return;
                    }
                }

                // Парсим ошибки на количество скобок в строке
                BracketErrorParser.Start(tmpLine);
                if (Data.Errors.Count > 0)
                {
                    return;
                }

                Lines.Add(tmpLine);
                OldText.Add(tmpText[i]);
            }
        }
示例#2
0
        private static List <Line> GetAllLines(string fullName, string[] tmpText)
        {
            var lines     = new List <Line>();
            var propertys = new List <string>();

            string moduleName = GetImportName(fullName.Replace(Extension.BPModule, ""));
            bool   func       = false;
            int    funcNum    = 0;

            for (int i = 0; i < tmpText.Length; i++)
            {
                var tmpLine = new Line(LineBuilder.GetWords(tmpText[i]), tmpText[i]);
                tmpLine.Number = i + 1;
                //tmpLine.FileName = moduleName + Extension.BPModule;
                tmpLine.FileName = fullName;
                tmpLine.Type     = LineBuilder.GetType(tmpLine);

                if (tmpLine.Type == LineType.INCLUDE)
                {
                    Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2005, ""));
                    return(lines);
                }
                else if (tmpLine.Type == LineType.FOLDER)
                {
                    Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2006, ""));
                    return(lines);
                }
                else if (tmpLine.Type == LineType.FUNCINIT)
                {
                    if (func)
                    {
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 1026, ""));
                        return(lines);
                    }
                    else
                    {
                        func    = true;
                        funcNum = tmpLine.Number;
                    }
                }
                else if (tmpLine.Type == LineType.ONEKEYWORD && tmpLine.Words[0].ToLower() == "endfunction")
                {
                    if (!func)
                    {
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 1027, ""));
                        return(lines);
                    }
                    else
                    {
                        func = false;
                    }
                }
                else if (tmpLine.Type == LineType.SUBINIT)
                {
                    Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2007, ""));
                    return(lines);
                }
                else if (tmpLine.Type == LineType.NUMBERINIT || tmpLine.Type == LineType.NUMBERARRAYINIT || tmpLine.Type == LineType.STRINGINIT || tmpLine.Type == LineType.STRINGARRAYINIT)
                {
                    tmpLine.Type = LineType.MODULEPROPERTY;

                    /*
                     * Console.Write("\n");
                     * Console.WriteLine("===>   " + tmpLine.NewLine);
                     * string str = "";
                     * foreach (var w in tmpLine.Words)
                     * {
                     *  str += w.Token.ToString() + " ";
                     * }
                     * Console.WriteLine(str);
                     * Console.Write("\n");
                     */
                    if (func)
                    {
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2015, ""));
                        return(lines);
                    }

                    if (tmpLine.Count != 2)
                    {
                        // Ошибка
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2011, ""));
                        return(lines);
                    }
                    else if (tmpLine.Words[0].Token != Tokens.KEYWORD && tmpLine.Words[0].Token != Tokens.VARIABLE)
                    {
                        // Ошибка
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2012, ""));
                        return(lines);
                    }
                    else if (tmpLine.Words[0].ToLower() != "number" && tmpLine.Words[0].ToLower() != "number[]" && tmpLine.Words[0].ToLower() != "string" && tmpLine.Words[0].ToLower() != "string[]")
                    {
                        // Ошибка
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2013, ""));
                        return(lines);
                    }
                    else if (propertys.Contains(tmpLine.Words[1].ToLower()))
                    {
                        // Ошибка
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2014, tmpLine.Words[1].OriginText));
                        return(lines);
                    }
                    else
                    {
                        propertys.Add(tmpLine.Words[1].ToLower());
                    }
                }
                else if (!func && tmpLine.Type != LineType.FUNCINIT)
                {
                    if (tmpLine.Type != LineType.EMPTY && tmpLine.Type != LineType.IMPORT && tmpLine.NewLine.Trim().IndexOf("'") != 0 && tmpLine.Type != LineType.ONEKEYWORD)
                    {
                        Data.Errors.Add(new Errore(tmpLine.Number, moduleName + Extension.BPModule, 2008, ""));
                        return(lines);
                    }
                }

                // Парсим ошибки на количество скобок в строке
                BracketErrorParser.Start(tmpLine);
                if (Data.Errors.Count > 0)
                {
                    return(lines);
                }

                lines.Add(tmpLine);
            }

            if (func)
            {
                Data.Errors.Add(new Errore(funcNum, moduleName + Extension.BPModule, 1028, ""));
                return(lines);
            }

            return(lines);
        }