Esempio n. 1
0
        private void BuildModelDoWork(object sender, DoWorkEventArgs e)
        {
            if (XSettings.DisableEntityParsing)
            {
                return;
            }
            Trace.WriteLine("-->> XSharpClassifier.BuildModelDoWork()");
            // Note this runs in the background
            // parse for positional keywords that change the colors
            // and get a reference to the tokenstream
            // do we need to create a new tree
            // this happens the first time in the buffer only
            var snapshot = _buffer.CurrentSnapshot;
            var tokens   = _tokens;

            if (tokens != null)
            {
                Debug("Starting model build  at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
                _sourceWalker.ParseTokens(_tokens, true, false);
                var regionTags = BuildRegionTags(_sourceWalker.EntityList, _sourceWalker.BlockList, snapshot, xsharpRegionStart, xsharpRegionStop);
                lock (gate)
                {
                    _parserRegions = regionTags.ToArray();
                }
                DoRepaintRegions();
                Debug("Ending model build  at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
            }
            Trace.WriteLine("<<-- XSharpClassifier.BuildModelDoWork()");
        }
        private async Task ParseAsync()
        {
            if (XSettings.DisableEntityParsing)
            {
                return;
            }
            if (IsLexing)
            {
                return;
            }

            var snapshot  = _buffer.CurrentSnapshot;
            var xDocument = GetDocument();

            if (xDocument.SnapShot != snapshot)
            {
                XSettings.LogMessage($"XSharpClassifier.ParseAsync() aborted because snapshot is version {xDocument.SnapShot.Version} and buffer has version {snapshot.Version}");
                return;
            }

            await TaskScheduler.Default;

            XSettings.LogMessage("-->> XSharpClassifier.ParseAsync()");
            // Note this runs in the background
            // parse for positional keywords that change the colors
            // and get a reference to the tokenstream
            // do we need to create a new tree
            // this happens the first time in the buffer only
            var tokens = xDocument.TokenStream;

            if (tokens != null)
            {
                Debug("Starting model build  at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
                _sourceWalker.SaveToDisk = true;
                _sourceWalker.ParseTokens(tokens, true, false);
                RegisterEntityBoundaries();
                var regionTags = BuildRegionTags(_sourceWalker.EntityList, _sourceWalker.BlockList, snapshot, xsharpRegionStart, xsharpRegionStop);
                lock (gate)
                {
                    _parserRegions = regionTags.ToArray();
                }
                DoRepaintRegions();
                Debug("Ending model build  at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
            }
            XSettings.LogMessage("<<-- XSharpClassifier.ParseAsync()");
        }