Ejemplo n.º 1
0
        internal static void CanParseSourceRegex(string source, string regex, Func <VbaParser, ParserRuleContext> rule)
        {
            var parser = VbaCompilerHelper.BuildVbaParser(source);

            var result = rule(parser);

            Assert.Null(result.exception);
            Assert.True(Regex.IsMatch(result.ToStringTree(parser), regex));
        }
Ejemplo n.º 2
0
        private static void AssertTokenIsType(string source, int tokenType)
        {
            var lexer = VbaCompilerHelper.BuildVbaLexer(source);

            var tokens = lexer.GetAllTokens();

            Assert.Equal(1, tokens.Count);
            Assert.Equal(tokenType, tokens[0].Type);
        }
Ejemplo n.º 3
0
        internal static void CanParseSource(string source, string expectedTree, Func <VbaParser, ParserRuleContext> rule)
        {
            var parser = VbaCompilerHelper.BuildVbaParser(source);

            var result = rule(parser);

            Assert.Null(result.exception);
            ParseTreeHelper.TreesAreEqual(expectedTree, result.ToStringTree(parser));
        }
Ejemplo n.º 4
0
        public void CannotParseInvalidIdentifierInTypeMemberDeclaration()
        {
            const string typeDeclarationTemplate = "Type MyType\r\n{0} As String\r\nEnd Type";
            // the only invalid keyword is 'Me'.
            var source = string.Format(typeDeclarationTemplate, "Me");
            var parser = VbaCompilerHelper.BuildVbaParser(source);

            Assert.Throws <ParseCanceledException>(() => parser.typeDeclaration());
        }
Ejemplo n.º 5
0
        public void CanParseDirectiveElement(string source, string expectedTree)
        {
            var parser = VbaCompilerHelper.BuildVbaParser(source);

            var result = parser.directiveElement();

            Assert.Null(result.exception);
            ParseTreeHelper.TreesAreEqual(expectedTree, result.ToStringTree(parser));
        }
Ejemplo n.º 6
0
        private void CannotParseAnyTrueKeywords(string sourceTemplate, Func <VbaParser, ParserRuleContext> rule)
        {
            foreach (var id in VbaLexer.TrueKeywords)
            {
                var source = string.Format(sourceTemplate, id);
                var parser = VbaCompilerHelper.BuildVbaParser(source);

                Assert.Throws <ParseCanceledException>(() => rule(parser));
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }