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; }
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); }
//--- 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; }
//--- 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; }
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); }
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; }
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); }
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); }
public override DekiScriptLiteral Convert(DekiScriptType type) { return(this); }
//--- 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)); }
//--- Constructors --- public DekiScriptBadReturnTypeException(Location location, DekiScriptType badType, DekiScriptType[] expectedTypes) : base(location, MakeMessage(badType, expectedTypes)) { this.BadType = badType; this.ExpectedTypes = expectedTypes; }
//--- Constructors --- public DekiScriptInvalidReturnCastException(Location location, DekiScriptType currentType, DekiScriptType newType) : base(location, MakeMessage(currentType, newType)) { this.CurrentType = currentType; this.NewType = newType; }
//--- 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)); }
public static string AsScriptTypeName(DekiScriptType type) { return type.ToString().ToLowerInvariant(); }
//--- 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; }
//--- 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))); }
//--- 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())); }
//--- Constructors --- public DekiScriptInvalidParameterCastException(Location location, DekiScriptParameter parameter, DekiScriptType sourceType) : base(location, MakeMessage(parameter, sourceType)) { this.Parameter = parameter; this.SourceType = sourceType; }
public abstract DekiScriptLiteral Convert(DekiScriptType type);
public override DekiScriptLiteral Convert(DekiScriptType type) { throw new NotImplementedException("undefined value does not have a native value"); }
public static string AsScriptTypeName(DekiScriptType type) { return(type.ToString().ToLowerInvariant()); }
//--- 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()); }
//--- 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); }
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; }