Exemple #1
0
        private ZsharpParser CreateParser(string sourceName, string code)
        {
            var stream = new AntlrInputStream(code)
            {
                name = sourceName
            };

            var lexer       = new ZsharpLexer(stream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new ZsharpParser(tokenStream);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(new AstErrorHandlerParser(Context));

            return(parser);
        }
Exemple #2
0
        public static ZsharpParser Create(string sourceCode,
                                          ErrorMode errorMode = ErrorMode.Active)
        {
            var stream      = new AntlrInputStream(sourceCode);
            var lexer       = new ZsharpLexer(stream);
            var tokenStream = new CommonTokenStream(lexer);
            var parser      = new ZsharpParser(tokenStream);

            if (errorMode == ErrorMode.Active)
            {
                lexer.RemoveErrorListeners();
                lexer.AddErrorListener(new ThrowingErrorListener <int>());
                parser.RemoveErrorListeners();
                parser.AddErrorListener(new ThrowingErrorListener <IToken>());
            }

            return(parser);
        }