Beispiel #1
0
        public void LineContinuation()
        {
            string[] lines =
            {
                "in\\\n",
                "t ab\\\n",
                "cde\\\n",
                "fgh;",
                "1234\\\n",
                "56789"
            };

            GLSLLexer lexer = new GLSLLexer();

            MultiLineTextSource source = MultiLineTextSource.FromString(lines);

            List <Token> tokens = lexer.Run(source.CurrentSnapshot).ToList();

            Assert.AreEqual(5, tokens.Count);
            Assert.AreEqual(SyntaxType.IntKeyword, tokens[0].SyntaxType);
            Assert.AreEqual(SyntaxType.IdentifierToken, tokens[1].SyntaxType);
            Assert.AreEqual("abcdefgh", tokens[1].Text);
            Assert.AreEqual(SyntaxType.SemicolonToken, tokens[2].SyntaxType);
            Assert.AreEqual(SyntaxType.IntConstToken, tokens[3].SyntaxType);
            Assert.AreEqual("123456789", tokens[3].Text);
        }
Beispiel #2
0
        public void FromString()
        {
            string lines = "one\r\ntwo\r\nthree\r\n";

            MultiLineTextSource source = MultiLineTextSource.FromString(lines);

            Assert.AreEqual(3, source.CurrentSnapshot.LineCount);
            Assert.AreEqual("one\r\n", source.CurrentSnapshot.GetLineFromLineNumber(0).Text);
            Assert.AreEqual("two\r\n", source.CurrentSnapshot.GetLineFromLineNumber(1).Text);
            Assert.AreEqual("three\r\n", source.CurrentSnapshot.GetLineFromLineNumber(2).Text);
        }
Beispiel #3
0
        public void FullParse()
        {
            string[] lines = File.ReadAllLines("test.glsl");

            GLSLLexer lexer = new GLSLLexer();

            MultiLineTextSource source = MultiLineTextSource.FromString(lines, true);

            GLSLParser parser = new GLSLParser(source.Settings);

            LinkedList <Token> tokens = lexer.Run(source.CurrentSnapshot);

            SyntaxTree tree = parser.Run(source.CurrentSnapshot, tokens);

            tree.WriteToXml("tree.xml", source.CurrentSnapshot);
        }
Beispiel #4
0
        public void PeekAheadToNextLine()
        {
            string lines = "one\r\ntwo\r\nthree\r\n";

            MultiLineTextSource source = MultiLineTextSource.FromString(lines);

            TextNavigator nav = new TextNavigator(source.CurrentSnapshot);

            int index = 0;

            while (nav.PeekChar() != TextNavigator.EndCharacter)
            {
                Assert.AreEqual(lines[index++], nav.PeekChar());
                nav.Advance();
            }
        }
Beispiel #5
0
        public void LexComment()
        {
            string[] lines =
            {
                "/*\n",
                "this is in a block comment/* */\n",
                "*/\n",
                "\n",
                "// this is in a comment\n",
                "/* */ /* /* */ \n",
                "Assert.AreEqual(resultTypes[i], lexer.GetTokens().First.Value.Type);*/\n",
                "// this is a line comment \\\n",
                "that continues to the next line \\\n",
                "and still continues \\\n"
            };

            GLSLLexer lexer = new GLSLLexer();

            MultiLineTextSource source = MultiLineTextSource.FromString(lines);

            LinkedList <Token> list = lexer.Run(source.CurrentSnapshot);

            LinkedListNode <Token> node = list.First;

            Assert.AreEqual(1, list.Count);

            Assert.AreEqual(SyntaxType.EOF, node.Value.SyntaxType);
            Assert.AreEqual(false, node.Value.HasTrailingTrivia);
            Assert.AreEqual(true, node.Value.HasLeadingTrivia);

            Assert.AreEqual(SyntaxType.TriviaList, node.Value.LeadingTrivia.SyntaxType);

            SyntaxTriviaList triviaList = node.Value.LeadingTrivia as SyntaxTriviaList;

            Assert.AreEqual(10, triviaList.List.Count);

            Assert.AreEqual(SyntaxType.BlockCommentTrivia, triviaList.List[0].SyntaxType);
            Assert.AreEqual(SyntaxType.NewLineTrivia, triviaList.List[1].SyntaxType);
            Assert.AreEqual(SyntaxType.NewLineTrivia, triviaList.List[2].SyntaxType);
            Assert.AreEqual(SyntaxType.LineCommentTrivia, triviaList.List[3].SyntaxType);
            Assert.AreEqual(SyntaxType.NewLineTrivia, triviaList.List[4].SyntaxType);
            Assert.AreEqual(SyntaxType.BlockCommentTrivia, triviaList.List[5].SyntaxType);
            Assert.AreEqual(SyntaxType.WhiteSpaceTrivia, triviaList.List[6].SyntaxType);
            Assert.AreEqual(SyntaxType.BlockCommentTrivia, triviaList.List[7].SyntaxType);
            Assert.AreEqual(SyntaxType.NewLineTrivia, triviaList.List[8].SyntaxType);
            Assert.AreEqual(SyntaxType.LineCommentTrivia, triviaList.List[9].SyntaxType);
        }
Beispiel #6
0
        public void ShortSpan()
        {
            string lines = "one\r\ntwo\r\nthree\r\n";

            MultiLineTextSource source = MultiLineTextSource.FromString(lines);

            TextNavigator nav = new TextNavigator(source.CurrentSnapshot, Span.Create(5, 12));

            for (int i = 5; i <= 12; i++)
            {
                Assert.AreEqual(lines[i], nav.PeekChar());

                nav.Advance();
            }

            Assert.AreEqual(TextNavigator.EndCharacter, nav.PeekChar());
        }