コード例 #1
0
        public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req)
        {
            Babel.Source source = (Babel.Source)this.GetSource(req.FileName);
            bool yyparseResult = false;

            // req.DirtySpan seems to be set even though no changes have occurred
            // source.IsDirty also behaves strangely
            // might be possible to use source.ChangeCount to sync instead

            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
                || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) {
                ErrorHandler handler = new ErrorHandler();
                Scanner scanner = new Scanner(); // string interface
                Parser parser = new Parser();  // use noarg constructor
                parser.scanner = scanner;
                scanner.Handler = handler;
                parser.SetHandler(handler);
                scanner.SetSource(req.Text, 0);

                parser.MBWInit(req);
                yyparseResult = parser.Parse();

                // store the parse results
                // source.ParseResult = aast;
                source.ParseResult = null;
                source.Braces = parser.Braces;

                // for the time being, just pull errors back from the error handler
                if (handler.ErrNum > 0) {
                    foreach (Babel.Parser.Error error in handler.SortedErrorList()) {
                        TextSpan span = new TextSpan();
                        span.iStartLine = span.iEndLine = error.line - 1;
                        span.iStartIndex = error.column;
                        span.iEndIndex = error.column + error.length;
                        req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
                    }
                }
            }
            switch (req.Reason) {
                case ParseReason.Check:
                case ParseReason.HighlightBraces:
                case ParseReason.MatchBraces:
                case ParseReason.MemberSelectAndHighlightBraces:
                    // send matches to sink
                    // this should (probably?) be filtered on req.Line / col
                    if (source.Braces != null) {
                        foreach (TextSpan[] brace in source.Braces) {
                            if (brace.Length == 2)
                                req.Sink.MatchPair(brace[0], brace[1], 1);
                            else if (brace.Length >= 3)
                                req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                        }
                    }
                    break;
                default:
                    break;
            }

            return new AuthoringScope(req.Text);
        }
コード例 #2
0
        //gets the variables that are valid within the given scope
        public static void GetVarDecls(Parser.CodeScope scope, Dictionary<string, Parser.VarDecl> varDecls)
        {
            foreach (KeyValuePair<string, Parser.VarDecl> vd in scope.scopeVars)
                varDecls.Add(vd.Key, vd.Value);

            if (scope.outer != null)
                GetVarDecls(scope.outer, varDecls);
        }
コード例 #3
0
        //get the current scope of the cursor
        /*public static Parser.CodeScope GetCurrentScope(int line, int col)
        {
            return GetCurrentScope(Parser.Parser.programScope, line, col);
        }*/
        public static Parser.CodeScope GetCurrentScope(Parser.CodeScope codeScope, int line, int col)
        {
            foreach (Parser.CodeScope cs in codeScope.innerScopes)
            {
                if (TextSpanHelper.ContainsExclusive(cs.scopeLocation, line, col))
                {
                    Parser.CodeScope recursive = GetCurrentScope(cs, line, col);
                    if (recursive == null)
                        return cs;
                    else
                        return recursive;
                }
            }

            return codeScope;
        }
コード例 #4
0
 //If it returns true, scope contains the scope that has the matching TextSpan
 //If it returns false, scope contains the scope that TextSpan ts would be contained in
 public static bool HasScopeForSpan(TextSpan ts, Parser.CodeScope globalScope, out Parser.CodeScope scope)
 {
     foreach (Parser.CodeScope cs in globalScope.innerScopes)
     {
         if (TextSpanHelper.IsSameSpan(ts, cs.scopeLocation))
         {
             scope = cs;
             return true;
         }
         else
         {
             if(TextSpanHelper.IsEmbedded(ts, cs.scopeLocation))
             {
                 return HasScopeForSpan(ts, cs, out scope);
             }
         }
     }
     scope = globalScope;
     return false;
 }
コード例 #5
0
        public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req)
        {
            Source source = (Source) this.GetSource(req.FileName);
            bool yyparseResult = false;

            #if GARRETT
            System.IO.StreamWriter myStream = null;
            if (req.View != null)
            {
                myStream = new System.IO.StreamWriter("E:/Users/Garrett/Documents/Projects/ShaderSense/myOutput.txt");
                Console.SetError(myStream);
            }
            #endif
            // req.DirtySpan seems to be set even though no changes have occurred
            // source.IsDirty also behaves strangely
            // might be possible to use source.ChangeCount to sync instead

            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
                || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine
                || source.IsDirty)
            {
                Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler();
                Babel.Lexer.Scanner scanner = new Babel.Lexer.Scanner(); // string interface
                Parser.Parser parser = new Parser.Parser();  // use noarg constructor

                parser.scanner = scanner;
                scanner.Handler = handler;
                parser.SetHandler(handler);
                scanner.SetSource(req.Text, 0);

                parser.MBWInit(req);
                if (parser.shouldAddDeclarations()) Parser.Parser.clearDeclarations();       //  Hack to purge old parser declarations
                //Parser.Parser.PrepareParse(source.GetDocumentSpan(), source);
                parser.PrepareParse(source.GetDocumentSpan(), source);
                yyparseResult = parser.Parse();
                ((HLSLSource)source).GatherIncludes();

                // store the parse results
                // source.ParseResult = aast;
                source.ParseResult = null;
                source.Braces = parser.Braces;

                // for the time being, just pull errors back from the error handler
                if (handler.ErrNum > 0)
                {
                    foreach (Babel.Parser.Error error in handler.SortedErrorList())
                    {
                        TextSpan span = new TextSpan();
                        span.iStartLine = span.iEndLine = error.line - 1;
                        span.iStartIndex = error.column;
                        span.iEndIndex = error.column + error.length;
                        req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
                    }
                }
            }

            switch (req.Reason)
            {
                case ParseReason.Check:
                case ParseReason.HighlightBraces:
                case ParseReason.MatchBraces:
                case ParseReason.MemberSelectAndHighlightBraces:
                    // send matches to sink
                    // this should (probably?) be filtered on req.Line / col
                    if (source.Braces != null)
                    {
                        foreach (TextSpan[] brace in source.Braces)
                        {
                            if (brace.Length == 2)
                                req.Sink.MatchPair(brace[0], brace[1], 1);
                            else if (brace.Length >= 3)
                                req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                        }
                    }
                    break;
                default:
                    break;
            }
            #if GARRETT
            if(myStream != null)
                myStream.Close();
            #endif

            //			return new AuthoringScope(source.ParseResult);
            return new HLSLAuthoringScope(source);
        }
コード例 #6
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            Source source = (Source)this.GetSource(req.FileName);
             //source.LastParseTime = 0;
             bool yyparseResult = false;

             Parser.Parser parser = new Parser.Parser();  // use noarg constructor

             //redirect
             //using (var stream = File.AppendText("C:\\temp\\out.txt"))
             //{
             //   Console.SetOut(stream);
             //   Console.SetError(stream);

             // req.DirtySpan seems to be set even though no changes have occurred
             // source.IsDirty also behaves strangely
             // might be possible to use source.ChangeCount to sync instead
            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
                || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine)
            {
               Debug.Assert(handler != null);
               handler.Clear();

               Babel.Lexer.Scanner scanner = new Babel.Lexer.Scanner(); // string interface

               handler.SetFileName(req.FileName);

               scanner.Handler = handler;
               SymbolTable symbolTable = BlenXLibraryManager.SymbolTable;
               parser.SetParsingInfo(req.FileName, symbolTable, handler);
               parser.scanner = scanner;

               scanner.SetSource(req.Text, 0);

               parser.SetContext(req);
               yyparseResult = parser.Parse();

               // store the parse results
               // source.ParseResult = aast;
               source.ParseResult = null;
               source.Braces = parser.Braces;

               // for the time being, just pull errors back from the error handler
               if (handler.ErrNum > 0)
               {
                  foreach (Babel.Parser.Error error in handler.SortedErrorList())
                  {
                     TextSpan span = new TextSpan();
                     span.iStartLine = span.iEndLine = error.line - 1;
                     span.iStartIndex = error.column;
                     span.iEndIndex = error.column + error.length;
                     req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
                  }
               }
            //}
             }

             switch (req.Reason)
             {
            case ParseReason.Check:
            case ParseReason.HighlightBraces:
            case ParseReason.MatchBraces:
            case ParseReason.MemberSelectAndHighlightBraces:
               // send matches to sink
               // this should (probably?) be filtered on req.Line / col
               if (source.Braces != null)
               {
                  foreach (TextSpan[] brace in source.Braces)
                  {
                     if (brace.Length == 2)
                     {
                        //if (req.Sink.HiddenRegions == true)
                        {
                           string first = source.GetText(brace[0]);
                           if (source.GetText(brace[0]).Contains("[") && source.GetText(brace[1]).Contains("]"))
                           {
                              //construct a TextSpan of everything between the braces
                              TextSpan hideSpan = new TextSpan();
                              hideSpan.iStartIndex = brace[0].iStartIndex;
                              hideSpan.iStartLine = brace[0].iStartLine;
                              hideSpan.iEndIndex = brace[1].iEndIndex;
                              hideSpan.iEndLine = brace[1].iEndLine;
                              req.Sink.ProcessHiddenRegions = true;
                              req.Sink.AddHiddenRegion(hideSpan);
                           }
                        }
                        req.Sink.MatchPair(brace[0], brace[1], 1);
                     }

                     else if (brace.Length >= 3)
                        req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                  }
               }

               break;
            default:
               break;
             }

             return new BlenXAuthoringScope(parser, source);
        }
コード例 #7
0
ファイル: LanguageService.cs プロジェクト: wgwjifeng/windows
        public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req)
        {
            Source source        = (Source)this.GetSource(req.FileName);
            bool   yyparseResult = false;

            // req.DirtySpan seems to be set even though no changes have occurred
            // source.IsDirty also behaves strangely
            // might be possible to use source.ChangeCount to sync instead

            if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex ||
                req.DirtySpan.iStartLine != req.DirtySpan.iEndLine)
            {
                Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler();
                Babel.Lexer.Scanner       scanner = new Babel.Lexer.Scanner(); // string interface
                Parser.Parser             parser  = new Parser.Parser();       // use noarg constructor

                parser.scanner  = scanner;
                scanner.Handler = handler;
                parser.SetHandler(handler);
                scanner.SetSource(req.Text, 0);

                parser.MBWInit(req);
                yyparseResult = parser.Parse();

                // store the parse results
                // source.ParseResult = aast;
                source.ParseResult = null;
                source.Braces      = parser.Braces;

                // for the time being, just pull errors back from the error handler
                if (handler.ErrNum > 0)
                {
                    foreach (Babel.Parser.Error error in handler.SortedErrorList())
                    {
                        TextSpan span = new TextSpan();
                        span.iStartLine  = span.iEndLine = error.line - 1;
                        span.iStartIndex = error.column;
                        span.iEndIndex   = error.column + error.length;
                        req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
                    }
                }
            }

            switch (req.Reason)
            {
            case ParseReason.Check:
            case ParseReason.HighlightBraces:
            case ParseReason.MatchBraces:
            case ParseReason.MemberSelectAndHighlightBraces:
                // send matches to sink
                // this should (probably?) be filtered on req.Line / col
                if (source.Braces != null)
                {
                    foreach (TextSpan[] brace in source.Braces)
                    {
                        if (brace.Length == 2)
                        {
                            req.Sink.MatchPair(brace[0], brace[1], 1);
                        }
                        else if (brace.Length >= 3)
                        {
                            req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
                        }
                    }
                }
                break;

            default:
                break;
            }

            return(new AuthoringScope(source.ParseResult));
        }