public CallbackWindow(string code)
 {
     this.InitializeComponent();
     this.lexer = new VbaLexer {
         Editor = this.Editor
     };
     this.Editor.Text = code;
 }
Пример #2
0
        public VbaParseResult CompileSource(TextReader source, Func <VbaParser, ParserRuleContext> rule)
        {
            var headerReader = new ModuleHeaderTextReader(source);
            var preprocessor = new SourceTextReader(headerReader);
            var input        = new AntlrInputStream(preprocessor);
            var lexer        = new VbaLexer(input);
            var proxy        = new LineAdjustProxy(lexer, () => headerReader.Line);
            var tokens       = new CommonTokenStream(proxy);
            var parser       = new VbaParser(tokens);

            return(new VbaParseResult(rule(parser), parser));
        }
Пример #3
0
        internal static VbaLexer BuildVbaLexer(string source)
        {
            var errorHandler = new TestErrorListener();

            var input = new AntlrInputStream(source);

            var lexer = new VbaLexer(input);

            lexer.AddErrorListener(errorHandler);

            return(lexer);
        }
Пример #4
0
        public void CanLexKeywordsInsensitively()
        {
            // loop through each keyword and test the lexer's ability to match the case.
            foreach (var keyword in VbaLexer.AllKeywords)
            {
                foreach (var k in GetKeywordCasings(keyword))
                {
                    var lexer = VbaCompilerHelper.BuildVbaLexer(k);

                    var token = lexer.NextToken();
                    Assert.Equal(VbaLexer.ConvertTokenNameToValue(keyword), token.Type);
                }
            }
        }
Пример #5
0
        internal static VbaParser BuildVbaParser(string source)
        {
            var errorHandler = new TestErrorListener();

            var input = new AntlrInputStream(source);

            var lexer = new VbaLexer(input);

            lexer.AddErrorListener(errorHandler);

            var tokens = new CommonTokenStream(lexer);

            var parser = new VbaParser(tokens);

            parser.AddErrorListener(errorHandler);
            parser.AddErrorListener(new DiagnosticErrorListener());
            parser.ErrorHandler = new BailErrorStrategy();
            return(parser);
        }