Exemple #1
0
 public override DekiScriptLiteral Convert(DekiScriptType type)
 {
     switch (type)
     {
     case DekiScriptType.ANY:
     case DekiScriptType.LIST:
         return(this);
     }
     throw new DekiScriptInvalidCastException(Location, ScriptType, type);
 }
 //--- Constructors ---
 public DekiScriptInvocationTargetDescriptor(DreamAccess access, bool isProperty, bool isIdempotent, string name, DekiScriptParameter[] parameters, DekiScriptType returnType, string description, string transform, IDekiScriptInvocationTarget target) {
     this.Access = access;
     this.IsProperty = isProperty;
     this.IsIdempotent = isIdempotent;
     this.Name = name;
     this.Parameters = parameters;
     this.ReturnType = returnType;
     this.Description = description;
     this.Transform = transform;
     this.Target = target;
 }
Exemple #3
0
        public override DekiScriptLiteral Convert(DekiScriptType type)
        {
            switch (type)
            {
            case DekiScriptType.ANY:
            case DekiScriptType.URI:
                return(this);

            case DekiScriptType.STR:
                return(Constant(AsString()));
            }
            throw new DekiScriptInvalidCastException(Location, ScriptType, type);
        }
Exemple #4
0
 //--- Contructors ---
 public DekiScriptParameter(string name, DekiScriptType type, bool optional, string hint)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new NullReferenceException("name");
     }
     this.Name       = name;
     this.ScriptType = type;
     this.Optional   = optional;
     this.Hint       = hint;
     this.NativeType = typeof(object);
     this.Default    = DekiScriptNil.Value;
 }
 //--- Constructors ---
 public DekiScriptScriptFunctionInvocationTarget(DreamAccess access, DekiScriptParameter[] parameters, DekiScriptExpression expr, DekiScriptEnv env, DekiScriptType returnType) {
     if(parameters == null) {
         throw new ArgumentNullException("parameters");
     }
     if(expr == null) {
         throw new ArgumentNullException("expr");
     }
     this.Access = access;
     this.Parameters = parameters;
     this.Expression = expr;
     _env = env;
     _returnType = returnType;
 }
Exemple #6
0
 //--- Constructors ---
 public DekiScriptScriptFunctionInvocationTarget(DreamAccess access, DekiScriptParameter[] parameters, DekiScriptExpression expr, DekiScriptEnv env, DekiScriptType returnType)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     if (expr == null)
     {
         throw new ArgumentNullException("expr");
     }
     this.Access     = access;
     this.Parameters = parameters;
     this.Expression = expr;
     _env            = env;
     _returnType     = returnType;
 }
Exemple #7
0
        public override DekiScriptLiteral Convert(DekiScriptType type)
        {
            switch (type)
            {
            case DekiScriptType.ANY:
            case DekiScriptType.MAP:
                return(this);

            case DekiScriptType.LIST: {
                DekiScriptList result = new DekiScriptList();
                foreach (DekiScriptLiteral value in Value.Values)
                {
                    result.Add(value);
                }
                return(result);
            }
            }
            throw new DekiScriptInvalidCastException(Location, ScriptType, type);
        }
Exemple #8
0
 public DekiScriptParameter(string name, DekiScriptType type, bool optional, string hint, Type nativeType, DekiScriptLiteral @default)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new NullReferenceException("name");
     }
     if (nativeType == null)
     {
         throw new NullReferenceException("nativeType");
     }
     if (@default == null)
     {
         throw new NullReferenceException("default");
     }
     this.Name       = name;
     this.ScriptType = type;
     this.Optional   = optional;
     this.Hint       = hint;
     this.NativeType = nativeType;
     this.Default    = @default;
 }
Exemple #9
0
        public override DekiScriptLiteral Convert(DekiScriptType type)
        {
            switch (type)
            {
            case DekiScriptType.ANY:
            case DekiScriptType.STR:
                return(this);

            case DekiScriptType.BOOL: {
                bool?value = AsBool();
                if (value != null)
                {
                    return(Constant(value.Value));
                }
                break;
            }

            case DekiScriptType.NUM: {
                double?value = AsNumber();
                if (value != null)
                {
                    return(Constant(value.Value));
                }
                break;
            }

            case DekiScriptType.URI: {
                XUri uri = XUri.TryParse(Value);
                if (uri != null)
                {
                    // NOTE (steveb): need a special converstion here to ensure that the produced
                    //                uri is not executed.
                    return(Constant(uri, false));
                }
                break;
            }
            }
            throw new DekiScriptInvalidCastException(Location, ScriptType, type);
        }
Exemple #10
0
        public override DekiScriptLiteral Convert(DekiScriptType type)
        {
            switch (type)
            {
            case DekiScriptType.ANY:
            case DekiScriptType.XML:
                return(this);

            case DekiScriptType.BOOL:
            case DekiScriptType.NUM:
            case DekiScriptType.STR:
            case DekiScriptType.URI: {
                string value = AsString();
                if (value != null)
                {
                    DekiScriptLiteral str = Constant(value);
                    return(str.Convert(type));
                }
                break;
            }
            }
            throw new DekiScriptInvalidCastException(Location, ScriptType, type);
        }
Exemple #11
0
 public override DekiScriptLiteral Convert(DekiScriptType type)
 {
     return(this);
 }
Exemple #12
0
 //--- Class Methods ---
 private static string MakeMessage(DekiScriptType badType, DekiScriptType[] expectedTypes) {
     string[] types = Array.ConvertAll(expectedTypes, type => type.ToString().ToLowerInvariant());
     return string.Format("{0} is not valid; expected {1}", badType.ToString().ToLowerInvariant(), string.Join(" or ", types));
 }
Exemple #13
0
 //--- Constructors ---
 public DekiScriptBadReturnTypeException(Location location, DekiScriptType badType, DekiScriptType[] expectedTypes) : base(location, MakeMessage(badType, expectedTypes)) {
     this.BadType = badType;
     this.ExpectedTypes = expectedTypes;
 }
Exemple #14
0
 //--- Constructors ---
 public DekiScriptInvalidReturnCastException(Location location, DekiScriptType currentType, DekiScriptType newType)
     : base(location, MakeMessage(currentType, newType)) {
     this.CurrentType = currentType;
     this.NewType = newType;
 }
Exemple #15
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptParameter parameter, DekiScriptType sourceType)
 {
     return(string.Format("parameter '{2}' could not convert from '{0}' to '{1}'", sourceType.ToString().ToLowerInvariant(), parameter.ScriptType.ToString().ToLowerInvariant(), parameter.Name));
 }
Exemple #16
0
 public static string AsScriptTypeName(DekiScriptType type) {
     return type.ToString().ToLowerInvariant();
 }
Exemple #17
0
 //--- Contructors ---
 public DekiScriptParameter(string name, DekiScriptType type, bool optional, string hint) {
     if(string.IsNullOrEmpty(name)) {
         throw new NullReferenceException("name");
     }
     this.Name = name;
     this.ScriptType = type;
     this.Optional = optional;
     this.Hint = hint;
     this.NativeType = typeof(object);
     this.Default = DekiScriptNil.Value;
 }
Exemple #18
0
 //--- Class Methods ---
 private static string MakeMessage(DekiScriptType badType, DekiScriptType[] expectedTypes)
 {
     string[] types = Array.ConvertAll(expectedTypes, type => type.ToString().ToLowerInvariant());
     return(string.Format("{0} is not valid; expected {1}", badType.ToString().ToLowerInvariant(), string.Join(" or ", types)));
 }
Exemple #19
0
 //--- Constructors ---
 public DekiScriptBadReturnTypeException(Location location, DekiScriptType badType, DekiScriptType[] expectedTypes) : base(location, MakeMessage(badType, expectedTypes))
 {
     this.BadType       = badType;
     this.ExpectedTypes = expectedTypes;
 }
Exemple #20
0
 //--- Constructors ---
 public DekiScriptInvalidReturnCastException(Location location, DekiScriptType currentType, DekiScriptType newType)
     : base(location, MakeMessage(currentType, newType))
 {
     this.CurrentType = currentType;
     this.NewType     = newType;
 }
Exemple #21
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptType currentType, DekiScriptType newType)
 {
     return(string.Format("return value could not convert from '{0}' to '{1}'", currentType.ToString().ToLowerInvariant(), newType.ToString().ToLowerInvariant()));
 }
Exemple #22
0
 //--- Constructors ---
 public DekiScriptInvalidParameterCastException(Location location, DekiScriptParameter parameter, DekiScriptType sourceType) : base(location, MakeMessage(parameter, sourceType))
 {
     this.Parameter  = parameter;
     this.SourceType = sourceType;
 }
Exemple #23
0
 public abstract DekiScriptLiteral Convert(DekiScriptType type);
Exemple #24
0
 public abstract DekiScriptLiteral Convert(DekiScriptType type);
 //--- Constructors ---
 public DekiScriptInvocationTargetDescriptor(DreamAccess access, bool isProperty, bool isIdempotent, string name, DekiScriptParameter[] parameters, DekiScriptType returnType, string description, string transform, IDekiScriptInvocationTarget target)
 {
     this.Access       = access;
     this.IsProperty   = isProperty;
     this.IsIdempotent = isIdempotent;
     this.Name         = name;
     this.Parameters   = parameters;
     this.ReturnType   = returnType;
     this.Description  = description;
     this.Transform    = transform;
     this.Target       = target;
 }
Exemple #26
0
 public override DekiScriptLiteral Convert(DekiScriptType type)
 {
     throw new NotImplementedException("undefined value does not have a native value");
 }
Exemple #27
0
 public static string AsScriptTypeName(DekiScriptType type)
 {
     return(type.ToString().ToLowerInvariant());
 }
Exemple #28
0
 //--- Constructors ---
 public DekiScriptInvalidParameterCastException(Location location, DekiScriptParameter parameter, DekiScriptType sourceType) : base(location, MakeMessage(parameter, sourceType)) {
     this.Parameter = parameter;
     this.SourceType = sourceType;
 }
Exemple #29
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptType currentType, DekiScriptType newType) {
     return string.Format("return value could not convert from '{0}' to '{1}'", currentType.ToString().ToLowerInvariant(), newType.ToString().ToLowerInvariant());
 }
Exemple #30
0
 //--- Class Methods ---
 protected static string MakeMessage(DekiScriptParameter parameter, DekiScriptType sourceType) {
     return string.Format("parameter '{2}' could not convert from '{0}' to '{1}'", sourceType.ToString().ToLowerInvariant(), parameter.ScriptType.ToString().ToLowerInvariant(), parameter.Name);
 }
Exemple #31
0
 public DekiScriptParameter(string name, DekiScriptType type, bool optional, string hint, Type nativeType, DekiScriptLiteral @default) {
     if(string.IsNullOrEmpty(name)) {
         throw new NullReferenceException("name");
     }
     if(nativeType == null) {
         throw new NullReferenceException("nativeType");
     }
     if(@default == null) {
         throw new NullReferenceException("default");
     }
     this.Name = name;
     this.ScriptType = type;
     this.Optional = optional;
     this.Hint = hint;
     this.NativeType = nativeType;
     this.Default = @default;
 }