Exemple #1
0
        /// <inheritdoc/>
        public override GraceObject Respond(
            EvaluationContext ctx,
            GraceObject self,
            MethodRequest req
            )
        {
            checkAccessibility(ctx, req);
            var arg = req[1].Arguments[0];

            if (Type != null)
            {
                if (Matching.TryMatch(ctx, Type, arg, out GraceObject result))
                {
                    arg = result;
                }
                else
                {
                    ErrorReporting.RaiseError(ctx, "R2025",
                                              new Dictionary <string, string> {
                        { "field", req[0].Name },
                        { "required", GraceString.AsNativeString(ctx, Type) }
                    },
                                              "TypeError: ${field} can only hold ${required}.");
                }
            }

            var tmp = cell.Value;

            cell.Value = arg;
            return(tmp);
        }
Exemple #2
0
 /// <summary>
 /// Attempt to match a pattern, raising R2025 TypeError on failure.
 /// </summary>
 /// <param name="ctx">Current interpreter</param>
 /// <param name="pattern">Pattern to match against</param>
 /// <param name="target">Object to examine</param>
 /// <param name="name">Name to report in error (e.g. field or parameter name)</param>
 /// <returns></returns>
 public static GraceObject TypeMatch(EvaluationContext ctx, GraceObject pattern, GraceObject target, string name)
 {
     if (Matching.TryMatch(ctx, pattern, target, out var result))
     {
         return(result);
     }
     else
     {
         ErrorReporting.RaiseError(ctx, "R2025",
                                   new Dictionary <string, string> {
             { "field", name },
             { "required", GraceString.AsNativeString(ctx, pattern) }
         },
                                   "TypeError: argument type mismatch");
         return(null);
     }
 }
Exemple #3
0
 private GraceObject mAsString(EvaluationContext ctx)
 {
     return(GraceString.Create(GraceString.AsNativeString(ctx, lhs) +
                               " | " + GraceString.AsNativeString(ctx, rhs)));
 }
Exemple #4
0
 private GraceObject mAsString(EvaluationContext ctx)
 {
     return(GraceString.Create((Success ? "Successful" : "Failed") + "Match["
                               + GraceString.AsNativeString(ctx, Result) + "]"));
 }