コード例 #1
0
        protected static IEnumerable <NodeBase> Parse(string source)
        {
            var lexer  = new LensLexer(source);
            var parser = new LensParser(lexer.Lexems);

            return(parser.Nodes);
        }
コード例 #2
0
        public void StringEscapeTest()
        {
            void TestEscape(string str, string expectedString)
            {
                var lexer = new LensLexer(str);

                Assert.AreEqual(lexer.Lexems.Count, 2);
                Assert.AreEqual(lexer.Lexems[0].Type, LexemType.String);
                Assert.AreEqual(lexer.Lexems[0].Value, expectedString);
            }

            TestEscape(@"""\n""", "\n");
            TestEscape(@"""\t""", "\t");
            TestEscape(@"""\r""", "\r");
            TestEscape(@"""\\""", "\\");
            TestEscape("\"\\\\\"", "\\");
        }
コード例 #3
0
        public void CharEscapeTest()
        {
            void TestEscape(string str, string expectedChar)
            {
                var lexer = new LensLexer(str);

                Assert.AreEqual(lexer.Lexems.Count, 2);
                Assert.AreEqual(lexer.Lexems[0].Type, LexemType.Char);
                Assert.AreEqual(lexer.Lexems[0].Value, expectedChar);
            }

            TestEscape(@"'\n'", "\n");
            TestEscape(@"'\t'", "\t");
            TestEscape(@"'\r'", "\r");
            TestEscape(@"'\\'", "\\");
            TestEscape("'\\\\'", "\\");
        }
コード例 #4
0
        private void Test(string str, params LexemType[] types)
        {
            var lexer = new LensLexer(str);

            Assert.AreEqual(types, lexer.Lexems.Select(l => l.Type).ToArray());
        }