예제 #1
0
        private static void ParseModule(Module module)
        {
            var lines        = module.Lines;
            var privateLines = false;

            int    start = -1;
            int    end   = -1;
            string name  = "";

            foreach (var line in lines)
            {
                if (line.Type == LineType.ONEKEYWORD && line.Words[0].ToLower() == "private")
                {
                    privateLines = true;
                }

                if (line.Type == LineType.FUNCINIT)
                {
                    // Проверим, что в инициализации функции нет имён свойств модуля

                    ModuleErrorParser.ParsePropertyInFuncInit(line, module.Propertys, module.Name);
                    if (Data.Errors.Count > 0)
                    {
                        return;
                    }

                    start = line.Number;
                    if (line.Words.Count > 1)
                    {
                        name = line.Words[1].ToLower() + "_" + GetParamCount(line).ToString();
                    }
                }
                else if (line.Type == LineType.ONEKEYWORD && line.Words[0].ToLower() == "endfunction")
                {
                    end = line.Number;
                }

                if (start > 0 && end > 0 && name != "")
                {
                    if (!module.Methods.ContainsKey(name))
                    {
                        var mLines = new List <Line>();
                        foreach (var l in lines)
                        {
                            if (l.Number >= start && l.Number <= end)
                            {
                                mLines.Add(l);
                            }
                            else if (l.Number > end)
                            {
                                break;
                            }
                        }
                        module.Methods.Add(name, (mLines, privateLines));
                        //Console.WriteLine(name);
                    }
                    start = -1;
                    end   = -1;
                    name  = "";
                }
            }
        }
예제 #2
0
        internal static void Start(Line line, string callPath)
        {
            NewCallPath = callPath;
            if (line.Count == 1)
            {
                Data.Errors.Add(new Errore(line.Number, line.FileName, 2002, ""));
            }
            else if (line.Count > 2 || line.Words.Count <= 0)
            {
                Data.Errors.Add(new Errore(line.Number, line.FileName, 2003, ""));
            }
            else if (line.Words[1].Token != Enums.Tokens.STRING)
            {
                Data.Errors.Add(new Errore(line.Number, line.FileName, 2004, ""));
            }
            else
            {
                //var importFullPath = line.Words[1].OriginText.Replace("\"","");

                var importFullPath = CreateFullPath(line.Words[1].OriginText.Replace("\"", ""), NewCallPath);

                /*
                 * if (importFullPath.IndexOf("..\\") != -1)
                 * {
                 *  importFullPath = importFullPath.Replace("..\\", Data.Project.ModuleLibPath);
                 * }
                 * else if (importFullPath.IndexOf("../") != -1)
                 * {
                 *  importFullPath = importFullPath.Replace("../", Data.Project.ModuleLibPath);
                 * }
                 * else
                 * {
                 *  importFullPath = Data.Project.Path + line.Words[1].Text.Replace("\"", "").Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar);
                 * }
                 */

                //Console.WriteLine('\n');
                //Console.WriteLine("call path =>" + NewCallPath);
                //Console.WriteLine("fuul path =>" + importFullPath);

                string name = GetImportName(importFullPath);
                string path = GetImportPath(importFullPath);
                NewCallPath = path;



                string tmpPath = path + name + Extension.BPModule;



                //Console.WriteLine(path);
                //Console.WriteLine(name);
                //Console.WriteLine(tmpPath);

                FileInfo fi = new FileInfo(tmpPath);
                if (!fi.Exists)
                {
                    Data.Errors.Add(new Errore(line.Number, line.FileName, 2001, importFullPath + Extension.BPModule));
                    return;
                }

                if (!Data.Project.Modules.ContainsKey(name.ToLower()))
                {
                    var tmpText = File.ReadAllLines(tmpPath);
                    var lines   = GetAllLines(tmpPath, tmpText);
                    if (Data.Errors.Count > 0)
                    {
                        return;
                    }

                    var tmpLines = new List <Line>();
                    foreach (var l in lines)
                    {
                        if (l.Type != LineType.IMPORT && l.Type != LineType.EMPTY)
                        {
                            tmpLines.Add(l);
                        }
                    }

                    ModuleErrorParser.Start(tmpLines);
                    if (Data.Errors.Count > 0)
                    {
                        return;
                    }

                    var import = new Module(name, path, tmpLines, tmpText.ToList());
                    // Парсим все объявление свойств
                    ParseModulePropertys(import);

                    // Пропарсим все имена функций
                    ParseModule(import);

                    // Переименуем вызовы собственных методов модуля в вид ИмяМодуля.ИмяМетода
                    // Также переимениуем все вызовы свойст в вид имямодуля_имясвойства
                    // Словам свойств временно назвачим токен MODULEPROPERTY для последующего корректного
                    // переименования переменных
                    RenameModleMethodsAndPropertys(import);
                    Data.Project.Modules.Add(name.ToLower(), import);

                    foreach (var l in lines)
                    {
                        if (l.Type == LineType.IMPORT)
                        {
                            Start(l, NewCallPath);
                            if (Data.Errors.Count > 0)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }