/// <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)); } } }
public Value Handler(CallScope args) { if (WantsArg) { if (args.Size < 2) { throw new InvalidOperationException(String.Format("No argument provided for {0}", Desc)); } if (args.Size > 2) { throw new InvalidOperationException(String.Format("To many arguments provided for {0}", Desc)); } if (args[0].Type != ValueTypeEnum.String) { throw new InvalidOperationException(String.Format("Context argument for {0} not a string", Desc)); } On(args[0].AsString, args[1].AsString); } else { if (args.Size < 1) { throw new InvalidOperationException(String.Format("No argument provided for {0}", Desc)); } if (args[0].Type != ValueTypeEnum.String) { throw new InvalidOperationException(String.Format("Context argument for {0} not a string", Desc)); } On(args[0].AsString); } return(NValue.Get(true)); }
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)); } } }
// operator() public Value Call(CallScope args) { if (!args.IsEmpty) { args.PushFront(NValue.StringValue("?expr")); return(Handler(args)); } if (WantsArg) { return(NValue.StringValue(Value)); } else { return(NValue.Get(Handled)); } }