public void UpdateText(ITextView view, string text, long version)
        {
            m_version = version;
            m_view    = view;

            // 创建文件对象
            if (m_file == null)
            {
                m_file = CreateABnfFile(m_abnf, text);
            }
            else
            {
                m_file.UpdateText(text);
            }

            m_file.ClearAnalysisError();
            m_file.ClearCheckError();
            m_file.ClearReference();

            // 如果在工程中,那么就从工程中更新,否则直接更新
            if (m_project != null)
            {
                m_project.UpdateFileItem(m_item_id, m_file, true);
            }
            else
            {
                m_file.UpdateAnalysis();
            }

            // 解析ALanguageClassifierInfo
            {
                var info_list = new List <ALanguageClassifierInfo>();
                if (m_file.GetRoot() != null)
                {
                    AnalysisClassificationTag(m_file.GetRoot(), info_list, false);
                }

                try
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        if (m_view.Properties.TryGetProperty(nameof(ALanguageClassifier), out ALanguageClassifier tagger))
                        {
                            tagger.Refresh(version, info_list);
                        }
                    });
                }
                catch (Exception)
                {
                }
            }
        }
Exemple #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);
        }