Пример #1
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));
         }
     }
 }
Пример #2
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);
     }
 }
Пример #3
0
            void AddMethodInfo(string name, string className, MethodInfoType type, XSharpParser.StatementBlockContext statementBlockContext)
            {
                var methodInfo = new MethodInfo {
                    Name = name, ClassName = className, Type = type
                };

                MethodList.Add(methodInfo);

                RenderStatements(statementBlockContext, methodInfo);
            }
Пример #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));
             }
         }
     }
 }
Пример #5
0
 private void TagRegion(RuleContext _context, int endChild)
 {
     try
     {
         var context  = _context as XSharpParserRuleContext;
         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);
             // Attribute ?
             if (context.Start.Text == "[")
             {
                 // Skip it
                 int newStart = getStatementForAttribute(_snapshot, context.Start.StartIndex);
                 tokenSpan = new TextSpan(newStart, 1);
             }
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
             _regionTags.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);
             // Attribute on top of Function/Method/... ?
             if (context.Start.Text == "[")
             {
                 // Skip it
                 int newStart = getStatementForAttribute(_snapshot, context.Start.StartIndex);
                 tokenSpan = new TextSpan(newStart, 1);
             }
             //
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(lastTokenInContext.Stop.StopIndex - 1, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
         else if (endToken is ParserRuleContext)
         {
             var lastTokenInContext = endToken as ParserRuleContext;
             var tokenSpan          = new TextSpan(context.Start.StartIndex, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStartType));
             tokenSpan = new TextSpan(lastTokenInContext.Stop.StartIndex - 1, 1);
             _regionTags.Add(tokenSpan.ToClassificationSpan(_snapshot, xsharpRegionStopType));
         }
     }
     catch (Exception e)
     {
         XSharpClassifier.Debug("Tagregion failed: " + e.Message);
     }
 }
Пример #6
0
        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.ToTagSpan(Snapshot, xsharpRegionStartType));
                tokenSpan = new TextSpan(sym.StartIndex, sym.StopIndex - sym.StartIndex + 1);
                tags.Add(tokenSpan.ToTagSpan(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.ToTagSpan(Snapshot, xsharpRegionStartType));
                tokenSpan = new TextSpan(lastTokenInContext.Stop.StartIndex - 1, 1);
                tags.Add(tokenSpan.ToTagSpan(Snapshot, xsharpRegionStopType));
            }
        }