private List <SyntaxError> ParseAndReturnErrors(string input)
        {
            AntlrInputStream    inputStream       = new AntlrInputStream(input);
            CsharpSubsetLexer   lexer             = new CsharpSubsetLexer(inputStream);
            CommonTokenStream   commonTokenStream = new CommonTokenStream(lexer);
            CsharpSubsetParser  parser            = new CsharpSubsetParser(commonTokenStream);
            SyntaxErrorListener listener          = new SyntaxErrorListener();

            parser.AddErrorListener(listener);
            CsharpSubsetParser.ProgramContext programContext = parser.program();
            return(listener.SyntaxErrors);
        }
Exemplo n.º 2
0
        private void ParseCode(string codeString)
        {
            InputStream       = new AntlrInputStream(codeString);
            Lexer             = new CsharpSubsetLexer(InputStream);
            CommonTokenStream = new CommonTokenStream(Lexer);
            Parser            = new CsharpSubsetParser(CommonTokenStream);
            SyntaxErrorListener errorListener = new SyntaxErrorListener();

            Parser.AddErrorListener(errorListener);
            Tree = Parser.program();
            if (errorListener.SyntaxErrors.Any())
            {
                _logOutput.Add("Couldn't refactor, one or more syntax errors occurred:");
                foreach (var error in errorListener.SyntaxErrors)
                {
                    _logOutput.Add(error.AsString());
                }

                SyntaxErrorsFound = true;
                Tree = null;
            }
        }