/// <summary>Native method implementing the .match Grace method /// for types</summary> /// <remarks>At present, this matching uses only the method /// names in both the object and the type.</remarks> public GraceObject Match(EvaluationContext ctx, GraceObject target) { if (requests == null) { var l = new List <MethodRequest>(); foreach (var m in methods) { var req = new MethodRequest(); foreach (var p in m) { var rp = RequestPart.Nullary(p.Name); req.AddPart(rp); } l.Add(req); } requests = l; } foreach (var req in requests) { if (!target.RespondsTo(req)) { return(Matching.FailedMatch(ctx, target)); } } return(Matching.SuccessfulMatch(ctx, target)); }
/// <summary>Native method representing the match method</summary> /// <param name="ctx">Current interpreter</param> /// <param name="req">Request that obtained this method</param> public GraceObject Match(EvaluationContext ctx, MethodRequest req) { MethodHelper.CheckArity(ctx, req, 1); var target = req[0].Arguments[0]; if (Pattern == null) { var rrr = this.Apply(ctx, MethodRequest.Single("apply(_)", target)); return(Matching.SuccessfulMatch(ctx, rrr)); } var matchResult = Matching.Match(ctx, Pattern, target); if (!Matching.Succeeded(ctx, matchResult)) { return(Matching.FailedMatch(ctx, target)); } var result = matchResult.Request(ctx, MethodRequest.Nullary("result")); if (!explicitPattern) { var res = this.Apply(ctx, MethodRequest.Single("apply(_)", result)); return(Matching.SuccessfulMatch(ctx, res)); } var res2 = this.Apply(ctx, MethodRequest.Single("apply(_)", result)); return(Matching.SuccessfulMatch(ctx, res2)); }
/// <summary>Native method for Grace match</summary> /// <param name="ctx">Current interpreter</param> /// <param name="target">Target of the match</param> private GraceObject mMatch(EvaluationContext ctx, GraceObject target) { if (predicate(target)) { return(Matching.SuccessfulMatch(ctx, target)); } return(Matching.FailedMatch(ctx, target)); }
private static GraceObject mMatch( EvaluationContext ctx, GraceString self, GraceObject target) { return((mEqualsEquals(self, target) == GraceBoolean.True) ? Matching.SuccessfulMatch(ctx, target) : Matching.FailedMatch(ctx, target)); }
/// <summary>Native method for Grace match</summary> /// <param name="ctx">Current interpreter</param> /// <param name="target">Target of the match</param> public GraceObject Match(EvaluationContext ctx, GraceObject target) { var b = target as GraceBoolean; if (b != null && b.Boolean == Boolean) { return(Matching.SuccessfulMatch(ctx, target)); } return(Matching.FailedMatch(ctx, target)); }
/// <summary>Native method for Grace match</summary> /// <param name="ctx">Current interpreter</param> /// <param name="target">Target of the match</param> private GraceObject mMatch(EvaluationContext ctx, GraceObject target) { var gop = target as GraceObjectProxy; if (gop == null) { return(Matching.FailedMatch(ctx, target)); } if (gop.Object is T) { return(Matching.SuccessfulMatch(ctx, target)); } return(Matching.FailedMatch(ctx, target)); }
/// <summary>Native method for Grace match</summary> /// <param name="ctx">Current interpreter</param> /// <param name="req">Request that resolved to this method</param> public GraceObject Match(EvaluationContext ctx, MethodRequest req) { MethodHelper.CheckArity(ctx, req, 1); var target = req[0].Arguments[0]; var gep = target as GraceExceptionPacket; if (gep == null) { return(Matching.FailedMatch(ctx, target)); } if (Parent == null || Children.Contains(gep.KindName)) { return(Matching.SuccessfulMatch(ctx, target)); } return(Matching.FailedMatch(ctx, target)); }