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);
        }
Exemple #2
0
        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.Reason == ParseReason.Check ||
                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

#if DEBUG
                parser.Trace = true;
#endif

                parser.scanner  = scanner;
                scanner.Handler = handler;
                parser.SetHandler(handler);
                scanner.SetSourceText(req.Text);

                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);
                    }
                }
            }

            return(new AuthoringScope(source.ParseResult, source));
        }
        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);
        }
Exemple #4
0
        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));
        }