Example #1
0
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, CommonTokenStream unprocessedTokenStream, BaseErrorListener errorListener)
        {
            unprocessedTokenStream.Reset();
            var parser = new VBAConditionalCompilationParser(unprocessedTokenStream);

            parser.AddErrorListener(errorListener);
            VBAConditionalCompilationParser.CompilationUnitContext tree;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (ParsePassSyntaxErrorException syntaxErrorException)
            {
                var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass
                    ? "code pane"
                    : "exported";
                Logger.Warn($"SLL mode failed while preprocessing the {parsePassText} version of module {moduleName} at symbol {syntaxErrorException.OffendingSymbol.Text} at L{syntaxErrorException.LineNumber}C{syntaxErrorException.Position}. Retrying using LL.");
                Logger.Debug(syntaxErrorException, "SLL mode exception");
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            catch (Exception exception)
            {
                Logger.Warn($"SLL mode failed while prprocessing module {moduleName}. Retrying using LL.");
                Logger.Debug(exception, "SLL mode exception");
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }
Example #2
0
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, CommonTokenStream unprocessedTokenStream)
        {
            unprocessedTokenStream.Reset();
            var parser = new VBAConditionalCompilationParser(unprocessedTokenStream);

            parser.AddErrorListener(new ExceptionErrorListener()); // notify?
            VBAConditionalCompilationParser.CompilationUnitContext tree;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (Exception ex)
            {
                Logger.Warn(ex, "SLL mode failed in module {0}. Retrying using LL.", moduleName);
                unprocessedTokenStream.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }
        public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, string unprocessedCode)
        {
            var stream = new AntlrInputStream(unprocessedCode);
            var lexer  = new VBALexer(stream);
            var tokens = new CommonTokenStream(lexer);
            var parser = new VBAConditionalCompilationParser(tokens);

            parser.AddErrorListener(new ExceptionErrorListener());
            VBAConditionalCompilationParser.CompilationUnitContext tree = null;
            try
            {
                parser.Interpreter.PredictionMode = PredictionMode.Sll;
                tree = parser.compilationUnit();
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "SLL mode failed in module {0}. Retrying using LL.", moduleName);
                tokens.Reset();
                parser.Reset();
                parser.Interpreter.PredictionMode = PredictionMode.Ll;
                tree = parser.compilationUnit();
            }
            return(tree);
        }