コード例 #1
0
        public override void ExitCatchBlock([NotNull] XSharpParser.CatchBlockContext context)
        {
            // Here will have all the informations that are AFTER the CATCH keyword, but we need to include the keyword
            XSharpParser.TryStmtContext tryStmt = (XSharpParser.TryStmtContext)context.Parent;
            // Search the CatchBlock
            int i = 0;

            LanguageService.SyntaxTree.Tree.IParseTree token = null;
            for (i = 0; i < tryStmt.ChildCount; i++)
            {
                token = tryStmt.GetChild(i);
                if (token == context)
                {
                    // Ok, we found the current CatchBlock, so the Catch is the previous one
                    if (i > 0)
                    {
                        token = tryStmt.GetChild(i - 1);
                        break;
                    }
                }
            }
            //
            if (token != null)
            {
                LanguageService.SyntaxTree.IToken sym = ((LanguageService.SyntaxTree.Tree.TerminalNodeImpl)token).Symbol;
                var tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
                _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
                //
                XSharpParser.CatchBlockContext lastTokenInContext = context as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.CatchBlockContext;
                tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
                _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
            }
        }
コード例 #2
0
 public override void ExitTryStmt([NotNull] XSharpParser.TryStmtContext context)
 {
     TagRegion(context, context.ChildCount - 1);
     if (context.FinBlock != null)
     {
         // Search the ELSE block, if Any
         int i = 0;
         LanguageService.SyntaxTree.Tree.IParseTree token = null;
         for (i = 0; i < context.ChildCount; i++)
         {
             token = context.GetChild(i);
             String tokenText = token.GetText().ToUpper();
             if (tokenText == "FINALLY")
             {
                 break;
             }
             else
             {
                 token = null;
             }
         }
         //
         if (token is LanguageService.SyntaxTree.Tree.TerminalNodeImpl)
         {
             LanguageService.SyntaxTree.IToken sym = ((LanguageService.SyntaxTree.Tree.TerminalNodeImpl)token).Symbol;
             var tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             //
             XSharpParser.StatementBlockContext lastTokenInContext = context.FinBlock as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
             tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
     }
 }