Beispiel #1
0
        public static ExprOp WrapFunctor(ExprFunc func)
        {
            ExprOp op = new ExprOp(OpKindEnum.FUNCTION);

            op.AsFunction = func;
            return(op);
        }
Beispiel #2
0
        public void MakeFunctor(string name, ExprFunc exprFunc, SymbolKindEnum symbol = SymbolKindEnum.FUNCTION)
        {
            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (exprFunc == null)
            {
                throw new ArgumentNullException("exprFunc");
            }

            // Search optimization
            if (name.EndsWith("_"))
            {
                name = name.Remove(name.Length - 1);
            }

            IDictionary <string, ExprOp> items = GetOrCreate(symbol);

            ExprOp op;

            if (items.TryGetValue(name, out op))
            {
                throw new InvalidOperationException(String.Format("Functor '{0}' is already defined", name));
            }

            items.Add(name, ExprOp.WrapFunctor(exprFunc));
        }
Beispiel #3
0
        /// <summary>
        /// Ported from void process_option(const string& whence, const expr_t::func_t& opt,
        /// </summary>
        public static void ProcessOption(string whence, ExprFunc opt, Scope scope, string arg, string name)
        {
            try
            {
                CallScope args = new CallScope(scope);

                args.PushBack(NValue.Get(whence));
                if (!String.IsNullOrEmpty(arg))
                {
                    args.PushBack(NValue.Get(arg));
                }

                opt(args);
            }
            catch (CountError)
            {
                throw; // DM - error_count is not std::exception and may pass by "catch" block
            }
            catch (Exception)
            {
                if (!String.IsNullOrEmpty(name) && name.StartsWith("-"))
                {
                    throw new Exception(String.Format("While parsing option '{0}'", name));
                }
                else
                {
                    throw new Exception(String.Format("While parsing environent variable '{0}'", name));
                }
            }
        }
Beispiel #4
0
        public void Option_ProcessOption_PassesThroughCountError()
        {
            ExprFunc  func      = s => { throw new CountError(1, String.Empty); };
            MockScope mockScope = new MockScope();

            Assert.Throws <CountError>(() => Option.ProcessOption("whence", func, mockScope, "arg", "name"));
        }
Beispiel #5
0
        public static void ProcessOption(string whence, ExprFunc opt, Scope scope, string arg, string name)
        {
            try
            {
                CallScope args = new CallScope(scope);

                args.PushBack(NValue.Get(whence));
                if (!String.IsNullOrEmpty(arg))
                {
                    args.PushBack(NValue.Get(arg));
                }

                opt(args);
            }
            catch
            {
                if (!String.IsNullOrEmpty(name) && name.StartsWith("-"))
                {
                    throw new Exception(String.Format("While parsing option '{0}'", name));
                }
                else
                {
                    throw new Exception(String.Format("While parsing environent variable '{0}'", name));
                }
            }
        }
Beispiel #6
0
        public void Option_ProcessOption_PassesThroughCountError()
        {
            ExprFunc  func      = s => { throw new CountError(1); };
            MockScope mockScope = new MockScope();

            Option.ProcessOption("whence", func, mockScope, "arg", "name");
        }
Beispiel #7
0
        public void Option_ProcessOption_PopulatesArgsAndCallsFunc()
        {
            OptFunctScopes.Clear();

            MockScope mockScope = new MockScope();
            string    whence    = "whence";
            ExprFunc  opt       = OptFunct;
            string    arg       = "arg";
            string    name      = "name";

            Option.ProcessOption(whence, opt, mockScope, arg, name);

            Assert.AreEqual(1, OptFunctScopes.Count);
            CallScope callScope = OptFunctScopes.First() as CallScope;

            Assert.IsNotNull(callScope);
            Assert.IsNotNull(callScope.Args);
            Assert.AreEqual(2, callScope.Size);
            Assert.AreEqual(whence, callScope[0].ToString());
            Assert.AreEqual(arg, callScope[1].ToString());
        }
Beispiel #8
0
 public static bool IsNullOrEmpty(this ExprFunc exprFunc)
 {
     return(exprFunc == null || exprFunc == Expr.EmptyFunc);
 }
 public virtual LambdaExpression GetExpression(IEnumerable <ExecArgument <Info> > inputs, object mutationReturn = null)
 => IsMutation
     ? (LambdaExpression)ExprFunc.DynamicInvoke(TypeHelpers.GetArgs(ArgsCLRType, Schema.VariableTypes, inputs), mutationReturn)
     : (LambdaExpression)ExprFunc.DynamicInvoke(TypeHelpers.GetArgs(ArgsCLRType, Schema.VariableTypes, inputs));