Пример #1
0
        void Start()
        {
            foreach (var name in SGA.MembAC(typeof(Transform), "p", SuggestionTree.MembK.Any()).Select(mi => mi.Name))
            {
                Debug.Log(name);
            }

            // ----------------------------------------

            var GE = new GrammarEntry()
            {
                StartProd      = TestGrammar.StartProd,
                TR_constructor = (nn) => new StartTU((TestGrammar.StartNode)nn)
            };
            var TLHS = new TranslateLHS()
            {
                preCH_LHS = null,
                scope     = new CH_closedScope()
            };
            var compilat = TranslateEntry.TranslateFully(">> :Transform ..position ", GE, TLHS);
            var MM       = new MemMapper();
            var res      = Evaluate.Eval(compilat, MM);

            Analyz0r.A.JsonifyEval(compilat, MM);
            Analyz0r.A.JsonifyCompilat(compilat);
            Debug.Log("DIIIIIIIIIIIIIIIInGs" + string.Join("--", res.values.Select(_ => _.ToString()).ToArray()));
        }
Пример #2
0
        public static void Test4_still_fanning_and_analyz0r(bool analyz0r = false)
        {
            var lhsCH = new TypedSingleCH <TestcasesLHSType>();

            var FanGE = new GrammarEntry {
                StartProd      = MG.Fan,
                TR_constructor = (nnode) => new FanTU(new adapter_preCH(lhsCH), (MG.FanNode)nnode)
            };
            var trslLHS = new TranslateLHS {
                preCH_LHS = new adapter_preCH(lhsCH),
                scope     = new CH_closedScope()
            };

            var compilat = TranslateEntry.TranslateFully_incomplete_tolerant(" { ..intMem1 -> x <- @4 ->x2  , ..intMem2  <- $x2 }  ", FanGE, trslLHS);

            if (analyz0r)
            {
                Analyz0r.A.JsonifyCompilat(compilat, "_Test4_still_fanning");
            }

            var MM         = new MemMapper();
            var LHS_column = MM.get(lhsCH);

            LHS_column.AddVal(new TestcasesLHSType());
            LHS_column.AddVal(new TestcasesLHSType());
            LHS_column.AddVal(new TestcasesLHSType());
            Evaluate.Eval(compilat, MM);

            if (analyz0r)
            {
                Analyz0r.A.JsonifyEval(compilat, MM, "_Test4_still_fanning");
            }
        }
Пример #3
0
        public static void Test3_Fans_and_Literals()
        {
            var lhsCH = new TypedSingleCH <TestcasesLHSType>();

            var FanGE = new GrammarEntry {
                StartProd      = MG.Fan,
                TR_constructor = (nnode) => new FanTU(new adapter_preCH(lhsCH), (MG.FanNode)nnode)
            };
            var lhsColumn = (ColumnSingle <TestcasesLHSType>)lhsCH.SpawnColumn();

            lhsColumn.AddVal(new TestcasesLHSType(), null);

            CH_closedScope outScope;

            var TR_LHS = new TranslateLHS {
                preCH_LHS = new adapter_preCH(lhsCH),                 // different instance then GrammarEntry - intentional
                scope     = new CH_closedScope()
            };
            var MM = new MemMapper();

            MM.D[lhsCH] = lhsColumn;
            Column res = Evaluate.Eval_incomplete_tolerant(" { ..intMem1 -> x <- @4 ->x2  , ..intMem2  <- $x2 }  ", FanGE, TR_LHS, MM, out outScope);

            Console.WriteLine(" -------------- ");
            foreach (var v in (res as Column <TestcasesLHSType>).valuesT)
            {
                Console.WriteLine(v);
            }

            Console.WriteLine(" ---.---.--.--.---- ");
            foreach (var KV in MM.D)
            {
                Console.WriteLine(KV.Key + " :: " + KV.Value);
            }
        }
Пример #4
0
        public static ShellCommon.EVAL_Resp EVAL_stateless(ShellCommon.EVAL_Req eval_req, bool analyz0r = false)
        {
            // fetch evaluation entry from the current junkjard that is EvaluatorTests_and_random_fux0ring.cs

            GrammarEntry GE = new GrammarEntry {
                StartProd      = MG.ProvStart,
                TR_constructor = NN => new TranslateAndEval.ProvStartTU((MG.ProvStartNode)NN)
            };

            TranslateLHS TLHS = new TranslateLHS {
                preCH_LHS = null,
                scope     = new TranslateAndEval.CH_closedScope()
            };
            Compilat compilat;

            try {
                compilat = TranslateEntry.TranslateFully_incomplete_tolerant(eval_req.expr, GE, TLHS);
            } catch (Exception e) {
                return(new ShellCommon.EVAL_Resp {
                    success = false,
                    msg = "translate ERROR : " + e.Message + "\n" + e.StackTrace,
                    result = new SObject[0]
                });
            }

            if (analyz0r)
            {
                Analyz0r.A.JsonifyCompilat(compilat);
            }

            var MM = new TranslateAndEval.MemMapper();

            TranslateAndEval.Column resultColumn;
            try {
                resultColumn = Evaluate.Eval(compilat, MM);
            } catch (Exception e) {
                return(new ShellCommon.EVAL_Resp {
                    success = false,
                    msg = "eval ERROR : " + e.Message + "\n" + e.StackTrace,
                    result = new SObject[0]
                });
            }

            try {
                if (analyz0r)
                {
                    Analyz0r.A.JsonifyEval(compilat, MM);
                }
            } catch (Exception) {}   // TODO - write a message to the file about how this crashed

            var resp = new ShellCommon.EVAL_Resp {
                success = true,
                msg     = "OK",
                result  = resultColumn.values.ToArray()     // <- current serialization (ShellNetworkGlue.cs) simply does a ToString() for all Objects
            };

            return(resp);
        }
Пример #5
0
    public static Column Eval_incomplete_tolerant(string strExpr, GrammarEntry GE, TranslateLHS trans_LHS, MemMapper MM, out CH_closedScope scope_out)
    {
        var compilat = TranslateEntry.TranslateFully_incomplete_tolerant(strExpr, GE, trans_LHS);

        scope_out = compilat.deltaScope.close();

        #if todo_fixme             // external refs in the scopes still need implementation ( done . todo plug this shit in )
        foreach (var sc_ref in compilat.ownDecls)
        {
            scope_out = (ClosedScope)scope_out.decl(sc_ref);
        }
        #endif
        compilat.run(MM);  // atm the MM keeps references on tmp columns around forever - some pruning mechanism is needed
        VBoxTU last_VBT = compilat.VBoxTrs.Last();
        return(MM.getGen(last_VBT.CH_out));
    }
Пример #6
0
        public static ShellCommon.TYPEINFO_Resp TYPEINFO(ShellCommon.TYPEINFO_Req req)
        {
            // only do this for requests that are valid to be exectuted -> no relaxed grammar

            // thus, most of this is copypasta from Operations_EVAL.cs

            GrammarEntry GE = new GrammarEntry {
                StartProd      = MG.ProvStart,
                TR_constructor = NN => new TranslateAndEval.ProvStartTU((MG.ProvStartNode)NN)
            };

            TranslateLHS TLHS = new TranslateLHS {
                preCH_LHS = null,
                scope     = new TranslateAndEval.CH_closedScope()
            };
            Compilat compilat;

            try {
                compilat = TranslateEntry.TranslateFully_incomplete_tolerant(req.expression, GE, TLHS);
            } catch (Exception e) {
                return(new ShellCommon.TYPEINFO_Resp {
                    success = false,
                    msg = e.Message,
                    // defaults to make serialization easier -- little use in specifying a contract here, as this is likely to change anyway
                    members = new System.Type[0]
                });
            }

            var result_type = compilat.VBoxTrs.Last().CH_out.ttuple.PayT;  // out-Type of last column

            var memIs = result_type
                        .GetMembers()
                        .Where(x => x.MemberType == System.Reflection.MemberTypes.Field || x.MemberType == System.Reflection.MemberTypes.Property)
                        .ToArray();



            return(new ShellCommon.TYPEINFO_Resp {
                success = true,
                msg = "",
                expr_unity_type = result_type,
                unique = true,                      // FIXME : todo
                members = memIs
            });
        }
Пример #7
0
        public static void GreenCameraTest()
        {
        #if NetworklessShell
            Console.WriteLine(" --- GreenCameraTest() ---");
            var go_foo_cam = new GameObject();
            go_foo_cam.AddComponent <Camera>();
            go_foo_cam.GetComponent <Camera>().name = "foo";

            var go_other_cam = new GameObject();
            go_other_cam.AddComponent <Camera>();

            Resources.roots = new [] { go_foo_cam, go_other_cam };


            var query = ">> :Camera .%projectionMatrix <- @[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]";

            var GramE = new GrammarEntry {
                StartProd      = MG.ProvStart,
                TR_constructor = (prov_start_node) => new ProvStartTU((MG.ProvStartNode)prov_start_node)
            };
            var transl_LHS = new TranslateLHS {
                preCH_LHS = null,
                scope     = new CH_closedScope()
            };

            var compilat1 = TranslateEntry.TranslateFully_incomplete_tolerant(query, GramE, transl_LHS);

            var MM  = new MemMapper();
            var res = Evaluate.Eval(compilat1, MM);

            Console.WriteLine(res);
            var query2    = ">> :Camera {.name == @\"foo\"} .projectionMatrix <- @[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]]";
            var compilat2 = TranslateEntry.TranslateFully_incomplete_tolerant(query2, GramE, transl_LHS);

            Analyz0r.A.JsonifyCompilat(compilat2, "_GreenCam_with_fan");

            var res2 = Evaluate.Eval(compilat2, MM);
            Console.WriteLine(res2);

            Analyz0r.A.JsonifyEval(compilat2, MM, "_GreenCam_with_fan");

            Console.WriteLine(" --- GreenCameraTest() done ---");
        #endif
        }
Пример #8
0
    // adding more clusterfuck

    public static ParserComb.NamedNode ScopePartial(
        IEnumerable <PTok> toks,
        GrammarEntry GE,
        TranslateLHS TLHS)
    {
        var matches = ParserComb.Parser <PTok> .RUN_with_rest(GE.StartProd, toks);

        if (!matches.Any())
        {
            throw new Exception("can't parse");
        }
        var match = matches.First();
        // don't care about whether there are unconsumed tokens for the most greedy match, do the scoping for the part that did yield a parse
        NamedNode AST_root = match.N;

        TranslationUnit TU = GE.TR_constructor(AST_root);     // <- TranslationUnit generation from RX_TUs fills in AC_typing callbacks as a side effect

        TU.scope(TLHS.scope);                                 // <- fills eventual holes in preCH chains from scope - if possible ( see AssignTR.scope() )

        // TU is thrown away ,used only for its side effects, the TUs still linger in memory due to references in preCHs - garbage collected when scope and AST_root is dumped
        return(AST_root);
    }
Пример #9
0
    public static NamedNode GetAST_ptokBase(IEnumerable <PTokBase> toksBase)
    {
        var Stripped = toksBase.Where(tok => tok is PTok).Select(tok => (PTok)tok);

        /*
         * todo : this version of scope throws on incomplete parse - should be allowed for interactive
         * also : how to deal with cursor pos beyond the end of an incomplete parse ? ( analog problem to synced walking for Colorize() in the console )
         */
        GrammarEntry GE = new GrammarEntry {
            StartProd = MGRX.ProvStartRX,

            /*
             *  preCH_in :
             *  the first mandatory SG operator acts on an implicit instance of a dummy type ( the PhantomRoot )
             */
            TR_constructor = (NN) => new ProvStartTU_RX((MainGrammarRX.ProvStartNodeRX)NN)
        };
        TranslateLHS TR_lhs = new TranslateLHS {
            preCH_LHS = null,   //new adapter_preCH ( new TypedSingleCH<GameObject>() ) ,
            scope     = new CH_closedScope()
        };

        return(TranslateEntry.ScopePartial(Stripped, GE, TR_lhs));
    }
Пример #10
0
    public static Compilat TranslateFully(string src, GrammarEntry GE, TranslateLHS eval_LHS)
    {
        ParserComb.NamedNode NN = LexxAndParse(src, GE.StartProd);


        var TR         = GE.TR_constructor(NN);
        var deltaScope = new preCH_deltaScope(eval_LHS.scope);
        preCH_deltaScope combinedScope = TR.scope(deltaScope);

        var OPs     = TR.emit().ToArray();
        var VBoxTrs = TR.VBoxTUs;

        // basic compile sanity
        // if ( ! ( VBoxTrs.SelectMany ( vbx => vbx.emit()).Count() == OPs.Length ))throw new Exception();
        // figgn! ... im allgemeinen stimmt das gar nicht der OPSuiGen ist in keiner VBoxTU enthalten, so wie das im Moment generiert wird
        // ---

        return(new Compilat {
            deltaScope = (CH_deltaScope)combinedScope.instantiate(),
            OPs = OPs,
            src = src,
            VBoxTrs = VBoxTrs
        });
    }
Пример #11
0
        public static void Test1()
        {
            //LexxAndRun( ".*foo -> x <- y  -> z " );
            Console.WriteLine(LexxAndParse(".*foo", MG.MemA));
            Console.WriteLine(LexxAndParse(".*foo -> x ", MG.MemAVT));
            Console.WriteLine(LexxAndParse(".*foo -> x ", MGRX.MemAVT_RX));
            Console.WriteLine(LexxAndParse("..str", MGRX.MemAVT_RX));
            Console.WriteLine(LexxAndParse("..str -> foo", MGRX.MemAVT_RX));

            Console.WriteLine(LexxAndParse("..str -> foo", TestMG1.TestStartRX));
            Console.WriteLine("----------- whoooo ------- ");

            Console.WriteLine(LexxAndParse("  <- $XX ", MG.SingleAssign));
            Console.WriteLine(LexxAndParse("  <- $XX -> a -> b ", MG.AssignVT));

            Console.WriteLine(LexxAndParse(" .*foo -> decl1 <- $ARG -> decl2 ", TestMG1.TestStart));


            // -----------------------------------------------------------------

            var MM            = new MemMapper();
            var dollar_arg_CH = new TypedSingleCH <int>();

            // Method I: hack column entries into MM directly
            ColumnSingle <int> dollar_arg_Column = (ColumnSingle <int>)dollar_arg_CH.SpawnColumn();       // todo: maybe provide SpawnColumnT that "kinda-overloads" on the return type

            MM.D[dollar_arg_CH] = dollar_arg_Column;


            dollar_arg_Column.AddVal(3, null);
            dollar_arg_Column.AddVal(4, null);

            // Method II: abuse MemMapper for column creation
            ColumnSingle <TestcasesLHSType> LHS_column;

            LHS_column = MM.get(DummyInstances.TestcasesLHSsingletonTypedCH);                             // TypedSingle<DummyType>

            LHS_column.AddVal(new TestcasesLHSType(), null);
            LHS_column.AddVal(new TestcasesLHSType(), null);
            LHS_column.AddVal(new TestcasesLHSType(), null);

            CH_closedScope scope = new CH_closedScope();

            scope = scope.decl("ARG", dollar_arg_CH);

            CH_closedScope out_scope;



            var TR_LHS = new TranslateLHS {
                preCH_LHS = new adapter_preCH(DummyInstances.TestcasesLHSsingletonTypedCH),
                scope     = scope
            };

            Console.WriteLine("in -> " + LHS_column);
            Column res = Evaluate.Eval_incomplete_tolerant(" ..intMem1 -> decl1 <- $ARG -> decl2 ", DummyInstances.GE_TestStart, TR_LHS, MM, out out_scope);

            foreach (var s in ColumnChainPrttS(
                         res,
                         CH => MM.D[CH]
                         ).Reverse())
            {
                Console.WriteLine(s);
            }
        }
Пример #12
0
 public static ParserComb.NamedNode ScopeAndType(IEnumerable <PTok> toksIN, GrammarEntry GE, TranslateLHS exLHS)
 {
     return(ScopeAndType(toksIN, exLHS.scope, GE.StartProd, GE.TR_constructor));
 }