Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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");
            }
        }