public void Sample1()
        {
            const string js = @"(function($) { $("".foo"").hide(); })(jQuery);";

            var subject = new JavascriptLexer();

            var tokens = subject.GetTokens(js).Where(t => t.Value != "").ToArray();

            Check.That(tokens).ContainsExactly(
                new Token(0, TokenTypes.Punctuation, "("),
                new Token(1, TokenTypes.Keyword.Declaration, "function"),
                new Token(9, TokenTypes.Punctuation, "("),
                new Token(10, TokenTypes.Name.Other, "$"),
                new Token(11, TokenTypes.Punctuation, ")"),
                new Token(12, TokenTypes.Text, " "),
                new Token(13, TokenTypes.Punctuation, "{"),
                new Token(14, TokenTypes.Text, " "),
                new Token(15, TokenTypes.Name.Other, "$"),
                new Token(16, TokenTypes.Punctuation, "("),
                new Token(17, TokenTypes.Literal.String.Double, @""".foo"""),
                new Token(23, TokenTypes.Punctuation, ")"),
                new Token(24, TokenTypes.Punctuation, "."),
                new Token(25, TokenTypes.Name.Other, "hide"),
                new Token(29, TokenTypes.Punctuation, "("),
                new Token(30, TokenTypes.Punctuation, ")"),
                new Token(31, TokenTypes.Punctuation, ";"),
                new Token(32, TokenTypes.Text, " "),
                new Token(33, TokenTypes.Punctuation, "}"),
                new Token(34, TokenTypes.Punctuation, ")"),
                new Token(35, TokenTypes.Punctuation, "("),
                new Token(36, TokenTypes.Name.Other, "jQuery"),
                new Token(42, TokenTypes.Punctuation, ")"),
                new Token(43, TokenTypes.Punctuation, ";")
                );
        }
Example #2
0
        private ITree GetAntlrComputedExpressionTree()
        {
            ICharStream       input  = new ANTLRStringStream(sourceText);
            JavascriptLexer   lexer  = new JavascriptLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            JavascriptParser  parser = new JavascriptParser(tokens);

            try
            {
                return(parser.Expression().Tree);
            }
            catch (RecognitionException re)
            {
                throw new ArgumentException(re.Message, re);
            }
        }
Example #3
0
        private ITree GetAntlrComputedExpressionTree()
        {
            ICharStream       input  = new ANTLRStringStream(sourceText);
            JavascriptLexer   lexer  = new JavascriptLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            JavascriptParser  parser = new JavascriptParser(tokens);

            try
            {
                return(parser.Expression().Tree);
            }
            catch (RecognitionException re)
            {
                throw new ArgumentException(re.Message, re);
            }
            // LUCENENET: Antlr 3.5.1 doesn't ever wrap ParseException, so the other catch block
            // for RuntimeException that wraps ParseException would have
            // been completely unnecesary in Java and is also unnecessary here.
        }