Beispiel #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));
            }
        }
Beispiel #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));
         }
     }
 }
Beispiel #3
0
 public override void ExitIfStmt([NotNull] XSharpParser.IfStmtContext context)
 {
     TagRegion(context, context.ChildCount - 2);
     //
     try
     {
         XSharpParser.StatementBlockContext elseBlock = null;
         XSharpParser.IfElseBlockContext    stmt      = null;
         if (context.IfStmt.ElseBlock != null)
         {
             elseBlock = context.IfStmt.ElseBlock;
             stmt      = context.IfStmt;
         }
         else if (context.IfStmt.ElseIfBlock != null)
         {
             if (context.IfStmt.ElseIfBlock.ElseBlock != null)
             {
                 elseBlock = context.IfStmt.ElseIfBlock.ElseBlock;
                 stmt      = context.IfStmt.ElseIfBlock;
             }
         }
         //
         if (elseBlock != null)
         {
             // Search the ELSE block, if Any
             int i = 0;
             LanguageService.SyntaxTree.Tree.IParseTree token = null;
             for (i = 0; i < stmt.ChildCount; i++)
             {
                 token = stmt.GetChild(i);
                 String tokenText = token.GetText().ToUpper();
                 if (tokenText == "ELSE")
                 {
                     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 = elseBlock as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
                 tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
                 _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
             }
         }
     }
     catch (Exception e)
     {
         XSharpClassifier.Debug("Tagregion failed: " + e.Message);
     }
 }
Beispiel #4
0
 public override void ExitStatementBlock([NotNull] XSharpParser.StatementBlockContext context)
 {
     if (!(context.Parent is XSharpParser.IfElseBlockContext) &&
         !(context.Parent is XSharpParser.CaseBlockContext) &&
         !(context.Parent is XSharpParser.TryStmtContext) &&
         !(context.Parent is XSharpParser.CatchBlockContext) &&
         !(context.Parent is XSharpParser.PropertyAccessorContext))
     {
         TagRegion(context.Parent, context.Parent.ChildCount - 1);
     }
     else if (context.Parent is XSharpParser.IfElseBlockContext)
     {
         var ctxt = context.Parent as XSharpParser.IfElseBlockContext;
         //
         if (ctxt.ElseIfBlock != null)
         {
             // we have Count >= 3
             // 0 : BinaryExpr
             // 1 : EOS
             // 2 : StatementBlock
             //TagRegion(ctxt.ElseIfBlock, 2);
             //
             //// Search the ELSEIF block, if Any
             int i = 0;
             LanguageService.SyntaxTree.Tree.IParseTree token = null;
             for (i = 0; i < ctxt.ChildCount; i++)
             {
                 token = ctxt.GetChild(i);
                 String tokenText = token.GetText().ToUpper();
                 if (tokenText == "ELSEIF")
                 {
                     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));
                 //
                 var endToken = ctxt.ElseIfBlock.GetChild(2);
                 XSharpParser.StatementBlockContext lastTokenInContext = endToken as LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.StatementBlockContext;
                 tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
                 _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
             }
         }
     }
 }