Beispiel #1
0
        // 获取所在工程路径
        public virtual string GetProjectPath()
        {
            if (m_file == null)
            {
                return(null);
            }
            var project = m_file.GetProjectInfo();

            if (project == null)
            {
                return(null);
            }
            return(project.GetProjectPath());
        }
Beispiel #2
0
        public virtual ABnfGuessError Generate(ABnfFile file, bool full_check)
        {
            // 判断是否在工程中
            var project_info = file.GetProjectInfo();

            if (project_info == null)
            {
                return(new ABnfGuessError(null, "文件没有添加到工程中"));
            }

            // 解析失败
            var root_dec = file.GetRoot() as ALittleScriptRootElement;

            if (root_dec == null)
            {
                return(new ABnfGuessError(null, "文件还未解析"));
            }
            var namespace_dec = root_dec.GetNamespaceDec();

            if (namespace_dec == null)
            {
                return(new ABnfGuessError(null, "命名域没有定义名字"));
            }

            var name_dec = namespace_dec.GetNamespaceNameDec();

            if (name_dec == null)
            {
                return(new ABnfGuessError(null, "命名域没有定义名字"));
            }

            m_namespace_name = name_dec.GetElementText();

            m_project_path = file.GetRoot().GetProjectPath();
            m_file_path    = file.GetRoot().GetFullPath();

            // 如果命名域有register标记,那么就不需要生成
            if (ALittleScriptUtility.IsRegister(namespace_dec.GetModifierList()))
            {
                return(null);
            }
            if (!ALittleScriptUtility.IsLanguageEnable(namespace_dec.GetModifierList()))
            {
                return(null);
            }

            // 获取语法错误
            var error = CheckErrorElement(file.GetRoot(), full_check);

            if (error != null)
            {
                return(error);
            }

            // 获取工作目录
            string full_path = ALittleScriptUtility.CalcTargetFullPath(project_info.GetProjectPath(), file.GetFullPath(), GetExt(), out string path_error);

            if (full_path == null)
            {
                return(new ABnfGuessError(null, path_error));
            }
            string full_dir = Path.GetDirectoryName(full_path);

            try
            {
                Directory.CreateDirectory(full_dir);
            }
            catch (Exception e)
            {
                return(new ABnfGuessError(null, e.Message));
            }

            // 生成代码
            error = GenerateRoot(namespace_dec.GetNamespaceElementDecList(), out string content);
            if (error != null)
            {
                return(error);
            }

            File.WriteAllText(full_path, content);
            return(null);
        }