Rename 'const' to 'firstArgs' in the lua-files

This commit is contained in:
Pieter Vander Vennet 2021-02-17 14:25:21 +01:00
parent 3520c2341b
commit f343637f21
5 changed files with 24 additions and 21 deletions

View file

@ -1,3 +0,0 @@
function const(a, b)
return a
end

View file

@ -0,0 +1,4 @@
function firstArg(a, b)
-- it turns out that 'const' is a reserved token in some lua implementations
return a
end

View file

@ -12,16 +12,17 @@ namespace AspectedRouting.Language.Functions
public override List<string> ArgNames { get; } = new List<string>{"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<Type> types) : base("const", types
private Const(IEnumerable<Type> types) : base("firstArg", types
)
{
}

View file

@ -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"))

View file

@ -26,8 +26,7 @@ namespace AspectedRouting
public static int Multiply(this IEnumerable<int> 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<T>(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<T>(this T[] data, int index)
{
return data.SubArray(index, data.Length - index);
}
/// <summary>
/// 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
/// </summary>
/// <param name="profiles"></param>
/// <param name="context"></param>
/// <param name="select"></param>
/// <returns></returns>
public static string GenerateExplanationJson(IEnumerable<ProfileMetaData> profiles)
public static string GenerateExplanationJson(IEnumerable<ProfileMetaData> profiles, Context context)
{
var metaItems = new List<string>();
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<string, string>
{
var keys = string.Join(", ",
profile.AllExpressions(context).PossibleTags().Select(tag => $"\"{tag.Key}\"")
);
var meta = new Dictionary<string, string> {
{"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) + "]";
}
}
}