From 8bf77cbc69c78c95c9952a010cd5a42a4aafb67f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 5 Jun 2020 13:37:12 +0200 Subject: [PATCH] Fix to parsing with arguments --- .../IO/jsonParser/JsonParser.ParseAspectProfile.cs | 11 +++++++++-- AspectedRouting/Language/Functions/If.cs | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs b/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs index d81264b..123cb4f 100644 --- a/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs +++ b/AspectedRouting/IO/jsonParser/JsonParser.ParseAspectProfile.cs @@ -323,14 +323,16 @@ namespace AspectedRouting.IO.jsonParser var allExprs = allArgs .Where(kv => !kv.NameEquals("#")) // Leave out comments .ToDictionary(kv => kv.Name, kv => kv.Value.ParseExpression(context)); - + if (allExprs.Count > 1) { if (func.ArgNames == null || func.ArgNames.Count < 2) throw new ArgumentException("{funcName} does not specify argument names"); - foreach (var argName in func.ArgNames) + + foreach (var argName in func.ArgNames.GetRange(1, func.ArgNames.Count - 2)) + // We skip the first argument, that one is already added { args.Add(allExprs[argName]); } @@ -413,6 +415,11 @@ namespace AspectedRouting.IO.jsonParser return eithered; } + if (mapping != null) + { + return mapping; + } + throw new Exception( "No top level reducer found. Did you forget the '$' in the reducing function? Did your forget 'value' to add the mapping?"); diff --git a/AspectedRouting/Language/Functions/If.cs b/AspectedRouting/Language/Functions/If.cs index df894cb..9a93d6f 100644 --- a/AspectedRouting/Language/Functions/If.cs +++ b/AspectedRouting/Language/Functions/If.cs @@ -7,7 +7,8 @@ namespace AspectedRouting.Language.Functions public class If : Function { private static Var a = new Var("a"); - + private static Var b = new Var("b"); + public override string Description { get; } = "Selects either one of the branches, depending on the condition." + "If the `else` branch is not set, `null` is returned in the condition is false."; public override List ArgNames { get; } = new List {"condition", "then", "else"}; @@ -16,7 +17,13 @@ namespace AspectedRouting.Language.Functions new[] { Curry.ConstructFrom(a, Typs.Bool, a, a), - Curry.ConstructFrom(a, Typs.Bool, a) + Curry.ConstructFrom(a, Typs.Bool, a), + + Curry.ConstructFrom(a, + new Curry(b, Typs.Bool), + new Curry(b, a), + new Curry(b, a), + b) } ) {