static LexList LexListGet(string s)
        {
            LexListBuilder lb = new LexListBuilder();

            lb.Add(s);
            return(lb.ToLexList());
        }
Example #2
0
        public void DoStatement <T>(T instance, ReadOnlyCollection <string> input, bool promoteQuotes)
        {
            LexListBuilder ll = new LexListBuilder();
            Action <T>     act;

            ll.AddAndPromoteQuotes(@"
          partial class `Type 
          {
            public void DoStatement () { ", "Type", typeof(T));
            foreach (string line in input)
            {
                if (promoteQuotes)
                {
                    ll.AddAndPromoteQuotes(line);
                }
                else
                {
                    ll.Add(line);
                }
            }
            ll.AddAndPromoteQuotes("}}");
            AddMethodsAndFields(ll.ToLexList(), true).GetAction <T>("DoStatement", out act);
            try {
                act(instance);
            } catch (Exception ex) {
                ll.ToLexList().ThrowException("This did not run: " + ex.Message);
            }
        }
Example #3
0
        public R DoExpression <T, R>(T instance, ReadOnlyCollection <string> input, bool promoteQuotes)
        {
            LexListBuilder ll = new LexListBuilder();
            Func <T, R>    fn;

            ll.AddAndPromoteQuotes(@" 
          partial class `Type
          {
            public `ReturnType `MethodName() { return ", "Type", typeof(T), "ReturnType", typeof(R), "MethodName", DoExpressionName);
            foreach (string line in input)
            {
                if (promoteQuotes)
                {
                    ll.AddAndPromoteQuotes(line);
                }
                else
                {
                    ll.Add(line);
                }
            }
            ll.AddAndPromoteQuotes(" ;  }}");
            AddMethodsAndFields(ll.ToLexList(), true).GetFunc <T, R>(DoExpressionName, out fn);
            try {
                return(fn(instance));
            } catch (Exception ex) {
                ll.ToLexList().ThrowException("This did not run: " + ex.Message);
                return(default(R));
            }
        }
Example #4
0
        static public LexList MakeTheMethod2(string nameA)
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add("public int GetValue()");
            llb.Add("{ return Examples." + nameA + "; }");
            return(llb.ToLexList());
        }
Example #5
0
        static public void TokenPasting3()
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add("return 'NameOne'NameTwo ; ", "NameOne", "One", "NameTwo", "Two");
            string s = llb.ToLexList().CodeFormatText(false);

            if (s != "return OneTwo;\r\n")
            {
                MessageBox.Show("Error in TokenPasting3");
            }
        }
Example #6
0
        static public void TokenPasting2()
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add("return 'TheName''Last ; ", "TheName", "Value");
            string s = llb.ToLexList().CodeFormatText(false);

            if (s != "return ValueLast;\r\n")
            {
                MessageBox.Show("Error in TokenPasting2");
            }
        }
Example #7
0
        private void AddMethod(ReadOnlyCollection <string> input)
        {
            LexListBuilder ll = new LexListBuilder();

            ll.Add("partial class `Type {", "Type", typeof(REPL));
            foreach (string line in input)
            {
                ll.Add(line);
            }
            ll.Add("}");
            Maker.AddMethodsAndFields(ll.ToLexList(), true);
        }
Example #8
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");
            }
        }
Example #9
0
        static public LexList MakeTheMethod4(
            string TheName, string TheOtherName)
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add(
                @"public int GetValue () 
         { 
           return Alpha.'TheName + Alpha.'TheOtherName + Alpha.'TheName ; 
         }",
                "TheName", TheName,
                "TheOtherName", TheOtherName);
            return(llb.ToLexList());
        }
Example #10
0
        static public void TokenPasting4()
        {
            LexListBuilder llb = new LexListBuilder();

            llb.Add("return First'NameOne'NameTwo'NameThree''Last ; ",
                    "NameOne", "One",
                    "NameTwo", "Two",
                    "NameThree", "Three");
            string s = llb.ToLexList().CodeFormatText(false);

            if (s != "return FirstOneTwoThreeLast;\r\n")
            {
                MessageBox.Show("Error in TokenPasting4");
            }
        }
Example #11
0
        private void MakeFieldInitialiser(List <CompileMethod> currentListOfMethods)
        {
            LexListBuilder lb = new LexListBuilder();

            lb.AddAndPromoteQuotes("public void FieldsInitialiser () { ");
            lb.AddAndPromoteQuotes("if (Fields == null) Fields = new List<object> () ;");
            foreach (var f in (from f in MadeFieldsDict orderby f.Value.Index select f))
            {
                Type theType = f.Value.VarType;
                lb.AddAndPromoteQuotes("`type `name ;  if (Fields.Count == `index) Fields.Add ( (object)`name ) ; ", "type", theType, "name", f.Value.VarName, "index", f.Value.Index);
                // The conditional 'if (Fields.Count == f.Value.Index)' bit means that this initialisation function can be called repeatedly, and only the new ones will be initialised.
            }
            lb.AddAndPromoteQuotes("}");
            LexList ll = lb.ToLexList();

            ll.CrosslinkBrackets();
            CompileNextMethodHeader(ll, true, currentListOfMethods);
        }
Example #12
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");
            }
        }
Example #13
0
        public string RestoreImage(string filename)
        {
            LexListBuilder allMethodsAndFields = new LexListBuilder();

            allMethodsAndFields.Add("partial class `Type {", "Type", typeof(REPL));
            if (filename == "")
            {
                foreach (var s in Directory.GetFiles(Path.GetDirectoryName(Persist.FileName), "*.cs"))
                {
                    Line(Path.GetFileNameWithoutExtension(s));
                }
                return("");
            }
            else
            {
                SaveImage("LastDeleted");
                Maker.Clear();
                Fields = new List <object>();

                List <REPLData.Packet> list = new List <REPLData.Packet>();
                try {
                    using (StreamReader sr = new StreamReader(CodeTextFileName(filename))) {
                        while (true)
                        {
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            List <string> user = ReadBlockOfLines(sr);
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            string        id   = sr.ReadLine();
                            REPLData.Kind kind = REPLData.Kind.Error;
                            switch (id)
                            {
                            case "Reply": kind = REPLData.Kind.Reply; break;

                            case "User": kind = REPLData.Kind.User; break;
                            }
                            if (sr.EndOfStream)
                            {
                                break;
                            }
                            List <string>   reply  = ReadBlockOfLines(sr);
                            REPLData.Packet packet = new REPLData.Packet()
                            {
                                Reply = reply, User = user, ReplyKind = kind
                            };
                            try {
                                switch (ExamineUserInput(user.AsReadOnly()))
                                {
                                case PacketAction.Method:
                                case PacketAction.Field:
                                    foreach (var s in user)
                                    {
                                        allMethodsAndFields.Add(s);
                                    }
                                    break;
                                }
                            } catch (Exception ex) {
                                packet.Reply = new List <string>()
                                {
                                    ex.Message
                                };
                            }
                            list.Add(packet);
                        }
                    }
                } catch (Exception ex) {
                    return("Failed: " + ex.Message);
                }
                ReplPanel.ChangeData(list);
                allMethodsAndFields.Add("}");
                Maker.AddMethodsAndFields(allMethodsAndFields.ToLexList(), true);

                MessageBox.Show(
                    "The image from '" + filename + "' has been restored.\n\n" +
                    "Please remember that only the methods and fields have been restored,\n" +
                    "the contents of the fields have not.\n" +
                    "So all fields are null or 0.", "NOTE!");
                return("");
            }
        }
Example #14
0
 public LexListBuilder Add(LexListBuilder other)
 {
     List.AddRange(other.List); return(this);
 }