예제 #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);
        }
예제 #2
0
파일: Matching.cs 프로젝트: mwh/kernan
 /// <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);
     }
 }
예제 #3
0
파일: Matching.cs 프로젝트: mwh/kernan
 private GraceObject mAsString(EvaluationContext ctx)
 {
     return(GraceString.Create(GraceString.AsNativeString(ctx, lhs) +
                               " | " + GraceString.AsNativeString(ctx, rhs)));
 }
예제 #4
0
파일: Matching.cs 프로젝트: mwh/kernan
 private GraceObject mAsString(EvaluationContext ctx)
 {
     return(GraceString.Create((Success ? "Successful" : "Failed") + "Match["
                               + GraceString.AsNativeString(ctx, Result) + "]"));
 }