当前位置: 首页>>代码示例>>C#>>正文


C# TextSpan.ToClassificationSpan方法代码示例

本文整理汇总了C#中TextSpan.ToClassificationSpan方法的典型用法代码示例。如果您正苦于以下问题:C# TextSpan.ToClassificationSpan方法的具体用法?C# TextSpan.ToClassificationSpan怎么用?C# TextSpan.ToClassificationSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextSpan的用法示例。


在下文中一共展示了TextSpan.ToClassificationSpan方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExitEveryRule

        public override void ExitEveryRule([NotNull] ParserRuleContext context)
        {
            base.ExitEveryRule(context);
            if ((context is XSharpParser.Namespace_Context) ||
                (context is XSharpParser.Class_Context) ||
                (context is XSharpParser.PropertyContext) ||
                (context is XSharpParser.PropertyAccessorContext))
            {
                // already done
                // BEGIN         NAMESPACE .... END NAMESPACE 
                //
                TagRegion(context, context.ChildCount - 2 );
            }
            else if ((context is XSharpParser.FunctionContext) ||
                    (context is XSharpParser.ProcedureContext) ||
                    (context is XSharpParser.MethodContext) ||
                    (context is XSharpParser.ClsctorContext) ||
                    (context is XSharpParser.ClsdtorContext))
            {
                // Put a region up to the end of the Entity
                TagRegion(context, context.ChildCount - 1);
            }
			else if (context is XSharpParser.IdentifierContext)
			{
				LanguageService.SyntaxTree.IToken sym = context.Start;
                // Add tag for Keyword that is used as Identifier
                if (XSharpLexer.IsKeyword(sym.Type))
                {
                    TextSpan tokenSpan;
                    tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
                    tags.Add(tokenSpan.ToClassificationSpan(Snapshot, xsharpIdentifierType));
                }
            }
        }
开发者ID:X-Sharp,项目名称:XSharpPublic,代码行数:34,代码来源:XSharpTreeDiscover.cs

示例2: TagRegion

 private void TagRegion(ParserRuleContext context, int endChild)
 {
     var endToken = context.GetChild(endChild);
     if (endToken is LanguageService.SyntaxTree.Tree.TerminalNodeImpl)
     {
         LanguageService.SyntaxTree.IToken sym = ((LanguageService.SyntaxTree.Tree.TerminalNodeImpl)endToken).Symbol;
         var tokenSpan = new TextSpan(context.Start.StartIndex, 1);
         tags.Add(tokenSpan.ToClassificationSpan(Snapshot, xsharpRegionStartType));
         tokenSpan = new TextSpan( sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
         tags.Add(tokenSpan.ToClassificationSpan(Snapshot, xsharpRegionStopType));
     }
     else if (endToken is LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext)
     {
         XSharpParser.StatementBlockContext lastTokenInContext = endToken as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
         var tokenSpan = new TextSpan(context.Start.StartIndex, 1);
         tags.Add(tokenSpan.ToClassificationSpan(Snapshot, xsharpRegionStartType));
         tokenSpan = new TextSpan(lastTokenInContext.Stop.StartIndex - 1, 1);
         tags.Add(tokenSpan.ToClassificationSpan(Snapshot, xsharpRegionStopType));
     }
 }
开发者ID:X-Sharp,项目名称:XSharpPublic,代码行数:20,代码来源:XSharpTreeDiscover.cs

示例3: Parse

        private void Parse( ITextSnapshot snapshot)
        {
            Snapshot = snapshot;
            ITokenStream TokenStream = null;
            // parse for positional keywords that change the colors
            // and get a reference to the tokenstream
            System.Diagnostics.Debug.WriteLine("Starting parse at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
            string path = String.Empty;
            isBusy = true;
            if (txtdocfactory != null)
            {
                ITextDocument doc = null;
                if (txtdocfactory.TryGetTextDocument(this.buffer, out doc))
                {
                    path = doc.FilePath;
                }
            }
            // Parse the source and get the (Lexer) Tokenstream to locate comments, keywords and other tokens.
            // The parser will identify (positional) keywords that are used as identifier
            xsTagger.Parse(snapshot, out TokenStream, path);
            if (TokenStream != null)
            {
                List<ClassificationSpan> newtags = new List<ClassificationSpan>();
                for (var iToken = 0; iToken < TokenStream.Size; iToken++)
                {
                    var token = TokenStream.Get(iToken);
                    var tokenType = token.Type;
                    TextSpan tokenSpan = new TextSpan(token.StartIndex, token.StopIndex - token.StartIndex + 1);
                    if (XSharpLexer.IsKeyword(tokenType))
                    {
                        newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpKeywordType));
                    }
                    else if (XSharpLexer.IsConstant(tokenType))
                    {
                        newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpConstantType));

                    }
                    else if (XSharpLexer.IsOperator(tokenType))
                    {
                        switch (tokenType)
                        {
                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.LPAREN:
                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.LCURLY:
                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.LBRKT:
                                newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpBraceOpenType));
                                break;

                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.RPAREN:
                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.RCURLY:
                            case LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpLexer.RBRKT:
                                newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpBraceCloseType));
                                break;
                            default:
                                newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpOperatorType));
                                break;
                        }
                    }
                    else if (XSharpLexer.IsIdentifier(tokenType))
                    {
                        newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpIdentifierType));
                    }
                    else if (XSharpLexer.IsComment(tokenType))
                    {
                        newtags.Add(tokenSpan.ToClassificationSpan(snapshot, xsharpCommentType));
                    }
                }
                foreach (var tag in xsTagger.Tags)
                {
                    newtags.Add(tag);
                }
                tags = newtags;
                System.Diagnostics.Debug.WriteLine("Ending parse at {0}, version {1}", DateTime.Now, snapshot.Version.ToString());
                if (ClassificationChanged != null)
                {
                    ClassificationChanged(this, new ClassificationChangedEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length)));
                }
            }
        }
开发者ID:X-Sharp,项目名称:XSharpPublic,代码行数:78,代码来源:XSharpClassifier.cs


注:本文中的TextSpan.ToClassificationSpan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。