コード例 #1
0
ファイル: Classification.cs プロジェクト: chwlili/FBSEditor
        private void RebuidTokens()
        {
            CommentTable.Clear();
            ClassfificationList.Clear();
            QuickInfoList.Clear();
            StructNameList.Clear();
            BracePairList.Clear();
            OutlineList.Clear();
            ErrorList.Clear();

            var snapshot = this.Buffer.CurrentSnapshot;

            var lexer = new FlatbufferLexer(new AntlrInputStream(snapshot.GetText()));

            foreach (var token in lexer.GetAllTokens())
            {
                if (token.Type == FlatbufferLexer.COMMENT)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), FBSComment));
                    var txt = token.Text;
                    if (txt.StartsWith("//"))
                    {
                        txt = txt.Substring(2).Trim();
                    }
                    else if (txt.StartsWith("/*"))
                    {
                        txt = txt.Substring(2, txt.Length - 4).Trim().Trim('*').Trim();
                    }
                    var lines = txt.Split('\n');
                    for (int i = 0; i < lines.Length; i++)
                    {
                        CommentTable.Add(token.Line + i, txt);
                    }
                }
            }
            lexer.Reset();

            var parser = new FlatbufferParser(new CommonTokenStream(lexer));

            parser.ErrorHandler = classificationErrorHandler;
            parser.RemoveErrorListeners();
            parser.AddErrorListener(classificationErrorListener);

            parser.schema().Accept <int>(classificationVisitor);

            var dom = this.Buffer.Properties.GetProperty(typeof(ITextDocument));

            if (dom != null)
            {
                filePath = (dom as ITextDocument).FilePath;

                FBSProject builder = new FBSProject("", new string[] { filePath }, ErrorReport);
                builder.Build(filePath, snapshot.GetText());
            }

            ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)));
        }
コード例 #2
0
        private void OnMenuClick3(object sender, EventArgs e)
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;

            if (dte != null && dte.SelectedItems.Count == 1 && dte.SelectedItems.Item(1).Name.EndsWith(Constants.ExtName))
            {
                var selectedItem    = dte.SelectedItems.Item(1).ProjectItem;
                var selectedProject = selectedItem.ContainingProject;

                var provider = ErrorTracking.Provider;

                ErrorTracking.Provider = this;

                ErrorTracking.ClearError();

                var builder = new FBSProject(selectedProject.Name, GetAllFBSFiles(selectedProject), ErrorHandler);
                var file    = builder.Build(selectedItem.FileNames[0]);
                if (errorCount <= 0)
                {
                    if (file.RootTable != null)
                    {
                        var xls  = file.RootTable.Attributes.GetAttribute <XLS>();
                        var json = file.RootTable.Attributes.GetAttribute <JsonFile>();
                        var csv  = file.RootTable.Attributes.GetAttribute <CSV>();
                        if (json != null)
                        {
                            List <string> errors = new List <string>();
                            var           obj    = JsonUtil.ParseJson(json.filePath, file.RootTable, file.RootTable.Attributes, ErrorHandler);
                            foreach (var error in errors)
                            {
                                package.AddError(json.filePath, json.filePath, error, 0, 0);
                            }
                        }
                        else if (csv != null)
                        {
                            CsvUtil.ParseCSV(csv.filePath, csv, file.RootTable, file.RootTable.Attributes);
                        }
                        //new DataReaderFactory(selectedProject.Name, ErrorHandler).ReadData(file.RootTable);
                    }
                }

                ErrorTracking.Provider = provider;
            }
        }
コード例 #3
0
        private void OnMenuClick4(object sender, EventArgs e)
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;

            if (dte != null && dte.SelectedItems.Count == 1 && dte.SelectedItems.Item(1).Name.EndsWith(Constants.ExtName))
            {
                var selectedItem    = dte.SelectedItems.Item(1).ProjectItem;
                var selectedProject = selectedItem.ContainingProject;

                errorCount = 0;
                package.ClearError();

                var files   = new List <Model.FBSFile>();
                var builder = new FBSProject(selectedProject.Name, GetAllFBSFiles(selectedProject), ErrorHandler);

                foreach (var path in GetAllFBSFiles(selectedProject))
                {
                    files.Add(builder.Build(path));
                }

                if (errorCount <= 0)
                {
                    var factory = new DataReaderFactory(selectedProject.Name, ErrorHandler);
                    foreach (var file in files)
                    {
                        if (file.RootTable != null)
                        {
                            var xls = file.RootTable.Attributes.GetAttribute <XLS>();
                            if (xls != null)
                            {
                                factory.ReadData(file.RootTable);
                            }
                        }
                    }
                }
                else
                {
                    package.ShowError();
                    errorCount = 0;
                }
            }
        }
コード例 #4
0
        private void OnMenuClick1(object sender, EventArgs e)
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as DTE;

            if (dte != null && dte.SelectedItems.Count == 1 && dte.SelectedItems.Item(1).Name.EndsWith(Constants.ExtName))
            {
                var selectedItem    = dte.SelectedItems.Item(1).ProjectItem;
                var selectedProject = selectedItem.ContainingProject;

                errorCount = 0;
                package.ClearError();

                var builder = new FBSProject(selectedProject.Name, GetAllFBSFiles(selectedProject), ErrorHandler);
                builder.Build(selectedItem.FileNames[0]);

                if (errorCount > 0)
                {
                    package.ShowError();
                }
                errorCount = 0;
            }
        }