Beispiel #1
0
        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)));
        }
Beispiel #2
0
        private void FlagAllHiddenToken(ITextSnapshot snapshot, TemplateLexer lexer)
        {
            IToken open = null;

            lexer.Reset();
            foreach (var token in lexer.GetAllTokens())
            {
                if (token.Type == TemplateLexer.COMMENT)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), ClassificationComment));
                }
                else if (token.Type == TemplateLexer.OPEN)
                {
                    if (open == null)
                    {
                        open = token;
                    }
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), ClassificationTag));
                }
                else if (token.Type == TemplateLexer.CLOSE)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), ClassificationTag));
                    if (open != null)
                    {
                        OutlineList.Add(open.StopIndex + 1);
                        OutlineList.Add(token.StartIndex - open.StopIndex - 1);
                    }
                    open = null;
                }
                else if (token.Type == TemplateLexer.TEXT)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), ClassificationText));
                }
                else if (token.Type == TemplateLexer.BREAK || token.Type == TemplateLexer.CONTINUE || token.Type == TemplateLexer.RETURN)
                {
                    ClassfificationList.Add(new ClassificationSpan(new SnapshotSpan(snapshot, new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1)), ClassificationKeyword));
                }
            }
            lexer.Reset();
        }
Beispiel #3
0
        private void RebuidTokens()
        {
            CommentTable.Clear();
            ClassfificationList.Clear();
            StructNameList.Clear();
            BracePairList.Clear();
            OutlineList.Clear();
            ErrorList.Clear();

            var snapshot = this.Buffer.CurrentSnapshot;

            var lexer  = new TemplateLexer(new AntlrInputStream(snapshot.GetText()));
            var parser = new TemplateParser(new CommonTokenStream(lexer));

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

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

            FlagAllHiddenToken(snapshot, lexer);

            //ClassificationChanged?.Invoke(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)));
        }