From f343637f217d1eb94d851798124c8f792c35119c Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 17 Feb 2021 14:25:21 +0100 Subject: [PATCH] Rename 'const' to 'firstArgs' in the lua-files --- AspectedRouting/IO/lua/const.lua | 3 -- AspectedRouting/IO/lua/firstArg.lua | 4 +++ AspectedRouting/Language/Functions/Const.cs | 5 ++-- AspectedRouting/Program.cs | 2 +- AspectedRouting/Utils.cs | 31 +++++++++++---------- 5 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 AspectedRouting/IO/lua/const.lua create mode 100644 AspectedRouting/IO/lua/firstArg.lua diff --git a/AspectedRouting/IO/lua/const.lua b/AspectedRouting/IO/lua/const.lua deleted file mode 100644 index 0c9c7fc..0000000 --- a/AspectedRouting/IO/lua/const.lua +++ /dev/null @@ -1,3 +0,0 @@ -function const(a, b) - return a -end \ No newline at end of file diff --git a/AspectedRouting/IO/lua/firstArg.lua b/AspectedRouting/IO/lua/firstArg.lua new file mode 100644 index 0000000..407d2b8 --- /dev/null +++ b/AspectedRouting/IO/lua/firstArg.lua @@ -0,0 +1,4 @@ +function firstArg(a, b) + -- it turns out that 'const' is a reserved token in some lua implementations + return a +end \ No newline at end of file diff --git a/AspectedRouting/Language/Functions/Const.cs b/AspectedRouting/Language/Functions/Const.cs index e7e267f..ee419cd 100644 --- a/AspectedRouting/Language/Functions/Const.cs +++ b/AspectedRouting/Language/Functions/Const.cs @@ -12,16 +12,17 @@ namespace AspectedRouting.Language.Functions public override List ArgNames { get; } = new List{"a","b"}; - public Const() : base("const", true, + public Const() : base("firstArg", true, new[] { Curry.ConstructFrom(new Var("a"), new Var("a"), new Var("b")) } ) { + Funcs.AddBuiltin(this,"const"); } - private Const(IEnumerable types) : base("const", types + private Const(IEnumerable types) : base("firstArg", types ) { } diff --git a/AspectedRouting/Program.cs b/AspectedRouting/Program.cs index 916e577..9cc6ca2 100644 --- a/AspectedRouting/Program.cs +++ b/AspectedRouting/Program.cs @@ -296,7 +296,7 @@ namespace AspectedRouting } File.WriteAllText($"{outputDir}/ProfileMetadata.json", - Utils.GenerateExplanationJson(profiles.Select(p => p.profile)) + Utils.GenerateExplanationJson(profiles.Select(p => p.profile), context) ); if (!args.Contains("--no-repl")) diff --git a/AspectedRouting/Utils.cs b/AspectedRouting/Utils.cs index 2fad1e8..0399136 100644 --- a/AspectedRouting/Utils.cs +++ b/AspectedRouting/Utils.cs @@ -26,8 +26,7 @@ namespace AspectedRouting public static int Multiply(this IEnumerable ints) { var factor = 1; - foreach (var i in ints) - { + foreach (var i in ints) { factor += i; } @@ -36,39 +35,41 @@ namespace AspectedRouting public static T[] SubArray(this T[] data, int index, int length) { - T[] result = new T[length]; + var result = new T[length]; Array.Copy(data, index, result, 0, length); return result; } - + public static T[] SubArray(this T[] data, int index) { return data.SubArray(index, data.Length - index); } /// - /// Generates a JSON file where all the profiles are listed, together with descriptions and other metadata. - /// Useful for other apps, e.g. the routing api to have + /// Generates a JSON file where all the profiles are listed, together with descriptions and other metadata. + /// Useful for other apps, e.g. the routing api to have /// + /// + /// /// /// - public static string GenerateExplanationJson(IEnumerable profiles) + public static string GenerateExplanationJson(IEnumerable profiles, Context context) { var metaItems = new List(); - foreach (var profile in profiles) - { + foreach (var profile in profiles) { var profileName = profile.Name; var author = profile.Author; var profileDescription = profile.Description; - foreach (var behaviour in profile.Behaviours) - { + foreach (var behaviour in profile.Behaviours) { var behaviourDescription = behaviour.Value["description"].Evaluate(new Context()) as string; behaviourDescription ??= ""; - var meta = new Dictionary - { + var keys = string.Join(", ", + profile.AllExpressions(context).PossibleTags().Select(tag => $"\"{tag.Key}\"") + ); + var meta = new Dictionary { {"name", behaviour.Key}, {"type", profileName}, {"author", author}, @@ -77,11 +78,11 @@ namespace AspectedRouting var json = string.Join(",", meta.Select(d => $"\"{d.Key}\": \"{d.Value}\"")); - metaItems.Add("{" + json + "}\n"); + metaItems.Add("{" + json + ", \"usedKeys\": [" + keys + "] }\n"); } } - return "[" + string.Join(",", metaItems) + "]"; + return "[" + string.Join(",\n", metaItems) + "]"; } } } \ No newline at end of file