Ejemplo n.º 1
0
 private static IEnumerable <Json> Function(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     context.Tick();
     context.LogValue(Json.ArrayParams(Json.String("DEBUG"), json));
     yield return(json);
 }
Ejemplo n.º 2
0
        public IEnumerable <Json> Mash(Json json, IMashContext context)
        {
            context = context.PushStack(this);
            context.Tick();
            var result = new List <Json>();

            try
            {
                foreach (var value in TryBody.Mash(json, context))
                {
                    result.Add(value);
                }
            }
            catch (JsonMasherException ex)
            {
                if (CatchBody != null)
                {
                    foreach (var value in CatchBody.Mash(Json.String(ex.Message), context))
                    {
                        result.Add(value);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public IEnumerable <Json> Mash(Json json, IMashContext context)
        {
            context = context.PushStack(this);
            context.Tick();
            var result = Descriptor switch {
                FunctionName name => CallFunctionName(name, json, context),
                Builtin builtin => RunBuiltin(builtin, json, context),
                _ => throw new InvalidOperationException()
            };

            return(result);
        }
Ejemplo n.º 4
0
 private static IEnumerable <Json> Function_1(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     foreach (var maxValue in mashers[0].Mash(json, context))
     {
         for (int i = 0; i < maxValue.GetNumber(); i++)
         {
             context.Tick();
             yield return(Json.Number(i));
         }
     }
 }
Ejemplo n.º 5
0
 private static IEnumerable <Json> Function(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     if (mashers.Count != 2)
     {
         throw new InvalidOperationException();
     }
     foreach (var t1 in mashers[0].Mash(json, context))
     {
         if (!t1.GetBool())
         {
             context.Tick();
             yield return(Json.False);
         }
         else
         {
             foreach (var t2 in mashers[1].Mash(json, context))
             {
                 context.Tick();
                 yield return(Json.Bool(t2.GetBool()));
             }
         }
     }
 }
Ejemplo n.º 6
0
 private static IEnumerable <Json> Function_3(
     List <IJsonMasherOperator> mashers, Json json, IMashContext context)
 {
     foreach (var startValue in mashers[0].Mash(json, context))
     {
         foreach (var maxValue in mashers[1].Mash(json, context))
         {
             foreach (var stepValue in mashers[2].Mash(json, context))
             {
                 double start = startValue.GetNumber();
                 double max   = maxValue.GetNumber();
                 double step  = stepValue.GetNumber();
                 for (double i = start; i < max; i += step)
                 {
                     context.Tick();
                     yield return(Json.Number(i));
                 }
             }
         }
     }
 }