Beispiel #1
0
        public static void Show(TypeParser parser)
        {
            REPL repl = new REPL(parser);
            REPLRenderingPanel replPanel = new REPLRenderingPanel(repl.DisplayData, repl.Command, new FontFamily("Lucida Console"), 10);

            repl.ReplPanel = replPanel;
            var win = new StickyWindow((r) => Persist.Put <PersistRect>("REPL", r), () => Persist.Get <PersistRect>("REPL", new PersistRect(150, 150, 500, 400)))
            {
                Title   = "C# REPL by KamimuCode",
                Content = new ScrollerPanel()
                {
                    Content = new CursorPanel()
                    {
                        Content = replPanel
                    }
                }
            };

            replPanel.Focus();

            win.ShowDialog();
        }
Beispiel #2
0
        public TypeParser(Assembly startAssembly, List <string> listUsings)
        {
            Assemblies = TypeParser.GetAllAssemblies(startAssembly);
            Usings     = listUsings;

            ShortcutType("short", typeof(short));
            ShortcutType("ushort", typeof(ushort));
            ShortcutType("uint", typeof(uint));
            ShortcutType("ulong", typeof(ulong));
            ShortcutType("sbyte", typeof(sbyte));
            ShortcutType("int", typeof(int));
            ShortcutType("bool", typeof(bool));
            ShortcutType("long", typeof(long));
            ShortcutType("float", typeof(float));
            ShortcutType("double", typeof(double));
            ShortcutType("string", typeof(string));
            ShortcutType("char", typeof(char));
            ShortcutType("byte", typeof(byte));
            ShortcutType("object", typeof(object));

            PopulateExtensionMethods();
        }
Beispiel #3
0
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                MessageBox.Show(msg + "\n" + theList.CodeFormat, "Error found");
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;


            try {
                {
                    Func <TestClass, int>     getLength;
                    Action <TestClass, int[]> setArray;
                    Action <TestClass>        actInit;
                    MakeClass mc = new MakeClass(parser, LexList.Get(@"
          partial class TestClass 
          {
            public int[] LocalInt ;
            public void SetArray ( int[] input ) 
            {
              LocalInt = input ; 
            }   
            public int GetLength () { return LocalInt.Length ; }
          }")).
                                   GetFunc <TestClass, int>("GetLength", out getLength).
                                   GetAction <TestClass, int[]>("SetArray", out setArray).
                                   GetAction <TestClass>("FieldsInitialiser", out actInit);
                    TestClass tc = new TestClass();
                    actInit(tc);
                    int[] thearray = new int[300];
                    setArray(tc, thearray);
                    if (getLength(tc) != thearray.Length)
                    {
                        MessageBox.Show("There was an error", "Test class with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test class with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test class with dialog");
            }
        }
Beispiel #4
0
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                new LexErrorDialog()
                {
                    Message      = msg,
                    CompilerList = theList,
                }.Show();
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;



            Directory.CreateDirectory(@"C:\KamimuCodeTemp");
            Persist.ReadFromFile(@"C:\KamimuCodeTemp\CsharpEvalConfiguration.xml");

            try {
                {
                    Func <TestClass, int>     getLength;
                    Action <TestClass, int[]> setArray;
                    Action <TestClass>        actInit;
                    MakeClass mc = new MakeClass(parser, LexList.Get(@"
          partial class TestClass 
          {
            public int[] LocalInt ;
            public void SetArray ( int[] input ) 
            {
              LocalInt = input ; 
            }   
            public int GetLength () { return LocalInt.Length ; }
          }")).
                                   GetFunc <TestClass, int>("GetLength", out getLength).
                                   GetAction <TestClass, int[]>("SetArray", out setArray).
                                   GetAction <TestClass>("FieldsInitialiser", out actInit);
                    TestClass tc = new TestClass();
                    actInit(tc);
                    int[] thearray = new int[300];
                    setArray(tc, thearray);
                    if (getLength(tc) != thearray.Length)
                    {
                        MessageBox.Show("There was an error", "Test class with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test class with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test class with dialog");
            }

            Persist.WriteToFile();
        }
Beispiel #5
0
 public MakeClass(TypeParser parser, LexList list)
 {
     Parser = parser;
     AddMethodsAndFields(list, false);
 }
Beispiel #6
0
 public MakeClass(TypeParser parser)
 {
     Parser = parser;
 }
Beispiel #7
0
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                new LexErrorDialog()
                {
                    Message      = msg,
                    CompilerList = theList,
                }.Show();
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;



            Directory.CreateDirectory(@"C:\KamimuCodeTemp");
            Persist.ReadFromFile(@"C:\KamimuCodeTemp\CsharpEvalConfiguration.xml");



            try {
                {
                    var s = "";
                    Func <int, string> fn = MakeMethod <Func <int, string> > .Compile(parser, LexListGet(@"
          string Test (int howMany) 
          { 
            string s = '' ;
            for ( int i = howMany ; i > 0 ; i -- ) s = s + i.ToString() + `~` ;
            return s ; 
          }"));

                    bool error = false;
                    if (fn(0) != "")
                    {
                        error = true;
                    }
                    if (fn(1) != "1~")
                    {
                        error = true;
                    }
                    if (fn(2) != "2~1~")
                    {
                        error = true;
                    }
                    if (fn(3) != "3~2~1~")
                    {
                        error = true;
                    }
                    if (fn(-1) != "")
                    {
                        error = true;
                    }
                    if (error)
                    {
                        MessageBox.Show("There was an error", "Test Make with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test Make with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test Make with dialog");
            }

            Persist.WriteToFile();
        }
Beispiel #8
0
        public static void Main()
        {
            LexToken.ShowError = (msg, theList) =>
            {
                MessageBox.Show(msg + "\n" + theList.CodeFormat, "Error found");
            };

            TypeParser parser = new TypeParser(Assembly.GetExecutingAssembly(), new List <string>()
            {
                "System",
                "System.Collections.Generic",
                "System.Linq",
                "System.Text",
                "System.Windows",
                "System.Windows.Shapes",
                "System.Windows.Controls",
                "System.Windows.Media",
                "System.IO",
                "System.Reflection",
                "Kamimu"
            }
                                               );

            TypeParser.DefaultParser = parser;

            try {
                {
                    var s = "";
                    Func <int, string> fn = MakeMethod <Func <int, string> > .Compile(parser, LexListGet(@"
          string Test (int howMany) 
          { 
            string s = '' ;
            for ( int i = howMany ; i > 0 ; i -- ) s = s + i.ToString() + `~` ;
            return s ; 
          }"));

                    bool error = false;
                    if (fn(0) != "")
                    {
                        error = true;
                    }
                    if (fn(1) != "1~")
                    {
                        error = true;
                    }
                    if (fn(2) != "2~1~")
                    {
                        error = true;
                    }
                    if (fn(3) != "3~2~1~")
                    {
                        error = true;
                    }
                    if (fn(-1) != "")
                    {
                        error = true;
                    }
                    if (error)
                    {
                        MessageBox.Show("There was an error", "Test Make with dialog");
                    }
                    else
                    {
                        MessageBox.Show("Ran OK", "Test Make with dialog");
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show("There was a compilation or execution error.", "Test Make with dialog");
            }
        }