Beispiel #1
0
        protected override void ReParseImpl()
        {
            var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense);

            Stopwatch stopwatch = Stopwatch.StartNew();

            var snapshot = TextBuffer.CurrentSnapshot;
            var input    = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length));
            var lexer    = new AntlrErrorProvidingLexer(input);
            var tokens   = new AntlrParserTokenStream(lexer);
            var parser   = new AntlrErrorProvidingParser(tokens);

            lexer.Parser  = parser;
            tokens.Parser = parser;

            List <ParseErrorEventArgs> errors = new List <ParseErrorEventArgs>();

            parser.ParseError += (sender, e) =>
            {
                errors.Add(e);

                string message = e.Message;
                if (message.Length > 100)
                {
                    message = message.Substring(0, 100) + " ...";
                }

                if (outputWindow != null)
                {
                    outputWindow.WriteLine(message);
                }

                if (errors.Count > 100)
                {
                    throw new OperationCanceledException();
                }
            };

            AntlrTool.ToolPathRoot = typeof(AntlrTool).Assembly.Location;
            ErrorManager.SetErrorListener(new AntlrErrorProvidingParser.ErrorListener());
            Grammar g      = new Grammar();
            var     result = parser.grammar_(g);

            OnParseComplete(new AntlrParseResultEventArgs(snapshot, errors, stopwatch.Elapsed, tokens.GetTokens(), result));
        }
        protected override void ReParseImpl()
        {
            var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense);

            Stopwatch stopwatch = Stopwatch.StartNew();

            var snapshot = TextBuffer.CurrentSnapshot;
            var input = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length));
            var lexer = new AntlrErrorProvidingLexer(input);
            var tokens = new AntlrParserTokenStream(lexer);
            var parser = new AntlrErrorProvidingParser(tokens);

            lexer.Parser = parser;
            tokens.Parser = parser;

            List<ParseErrorEventArgs> errors = new List<ParseErrorEventArgs>();
            parser.ParseError += (sender, e) =>
            {
                errors.Add(e);

                string message = e.Message;
                if (message.Length > 100)
                    message = message.Substring(0, 100) + " ...";

                if (outputWindow != null)
                    outputWindow.WriteLine(message);

                if (errors.Count > 100)
                    throw new OperationCanceledException();
            };

            AntlrTool.ToolPathRoot = typeof(AntlrTool).Assembly.Location;
            ErrorManager.SetErrorListener(new AntlrErrorProvidingParser.ErrorListener());
            Grammar g = new Grammar();
            var result = parser.grammar_(g);
            OnParseComplete(new AntlrParseResultEventArgs(snapshot, errors, stopwatch.Elapsed, tokens.GetTokens(), result));
        }