Exemplo n.º 1
0
        //Different ways of generating a LexList

        public static void TestLexList1()
        {
            LexList lex1 = LexList.Get(@"
         public str Convert ( int i ) 
         { 
           return i.ToString() ; 
         }"
                                       );

            string s1 = lex1.CodeFormatText(false);

            string[] lines = new string[] {
                "public str Convert ( int i )",
                "{",
                "  return i.ToString() ; ",
                "}"
            };
            LexList lex2 = LexList.Get(lines);

            string s3 = "public str Convert(int i)\r\n{\r\n  return i.ToString();\r\n}\r\n";

            string s2 = lex2.CodeFormatText(false);

            if (s1 != s2 || s3 != s1)
            {
                MessageBox.Show("Error in TesetLexList1");
            }
        }
Exemplo n.º 2
0
        static public void TokenPasting5()
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add("return typeof(`Type) ;", "Type", typeof(MyClassType));
            LexList lex = llb.ToLexList();
            string  s   = lex.CodeFormatText(false);

            if (s != "return typeof(MyClassType);\r\n" || lex[3].ActualObject != typeof(MyClassType))
            {
                MessageBox.Show("Error in TokenPasting5");
            }
        }
Exemplo n.º 3
0
        public static void TestLexList3()
        {
            LexList lex1 = MakeTheMethod3("Var1");
            LexList lex2 = LexList.Get(@"public int GetValue ()
        { return Examples.Var1 ; }");
            string  s1   = lex1.CodeFormatText(false);
            string  s2   = lex2.CodeFormatText(false);

            if (s1 != s2 || s1 != "public int GetValue()\r\n{\r\n  return Examples.Var1;\r\n}\r\n")
            {
                MessageBox.Show("Error in TestLexList2");
            }
        }
Exemplo n.º 4
0
        public static void TestLexList4()
        {
            LexList lex1 = MakeTheMethod4("A", "B");
            LexList lex2 = LexList.Get(
                @"public int GetValue () { 
            return Alpha.A + Alpha.B + Alpha.A ; }");
            string s1 = lex1.CodeFormatText(false);
            string s2 = lex2.CodeFormatText(false);

            if (s1 != s2 || s1 != "public int GetValue()\r\n{\r\n  return Alpha.A+Alpha.B+Alpha.A;\r\n}\r\n")
            {
                MessageBox.Show("Error in TestLexList2");
            }
        }
Exemplo n.º 5
0
        static public void QuotePromotion()
        {
            string         ActualValue = "VarOne";
            LexListBuilder llb         = new LexListBuilder();

            llb.AddAndPromoteQuotes(
                "string s = 'The string contents' + `Variable ; ",
                "Variable", ActualValue);
            llb.AddAndPromoteQuotes(
                "string anotherStr = 'Another string contents' ;");
            llb.AddAndPromoteQuotes("char ch = `c` ; ");
            LexList lex = llb.ToLexList();
            string  s   = lex.CodeFormatText(false);

            if (s != "string s=\"The string contents\"+VarOne;\r\nstring anotherStr=\"Another string contents\";\r\nchar ch='c';\r\n")
            {
                MessageBox.Show("Error in QuotePromotion");
            }
        }