Fix serialization of ifDotted
This commit is contained in:
parent
64fd49e33b
commit
4ebddfd807
4 changed files with 33 additions and 22 deletions
|
@ -13,9 +13,8 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
{
|
||||
public partial class LuaSkeleton
|
||||
{
|
||||
internal string ToLua(IExpression bare, string key = "nil")
|
||||
internal string ToLua(IExpression bare, string key = "nil", bool forceFirstArgInDot = false)
|
||||
{
|
||||
|
||||
var collectedMapping = new List<IExpression>();
|
||||
var order = new List<IExpression>();
|
||||
|
||||
|
@ -61,13 +60,9 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
return "member_of(funcName, parameters, tags, result)";
|
||||
}
|
||||
|
||||
|
||||
var collectedList = new List<IExpression>();
|
||||
var func = new List<IExpression>();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (
|
||||
UnApply(
|
||||
UnApply(IsFunc(Funcs.Dot), Assign(func)),
|
||||
|
@ -98,14 +93,9 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
return "\n " + funcName + "({\n " + string.Join(",\n ", luaExprs) +
|
||||
"\n })";
|
||||
}
|
||||
|
||||
|
||||
collectedMapping.Clear();
|
||||
var dottedFunction = new List<IExpression>();
|
||||
|
||||
|
||||
dottedFunction.Clear();
|
||||
|
||||
if (UnApply(
|
||||
UnApply(
|
||||
IsFunc(Funcs.Dot),
|
||||
|
@ -127,6 +117,7 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
"))";
|
||||
}
|
||||
|
||||
|
||||
// The expression might be a function which still expects a string (the value from the tag) as argument
|
||||
if (!(bare is Mapping) &&
|
||||
bare.Types.First() is Curry curr &&
|
||||
|
@ -144,16 +135,36 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
var (f, args) = fArgs.Value;
|
||||
var baseFunc = (Function) f;
|
||||
|
||||
if (baseFunc.Name.Equals(Funcs.Id.Name) ||
|
||||
baseFunc.Name.Equals(Funcs.Dot.Name))
|
||||
if (baseFunc.Name.Equals(Funcs.Id.Name))
|
||||
{
|
||||
// This is an ugly hack
|
||||
return ToLua(args.First());
|
||||
}
|
||||
|
||||
if(baseFunc.Name.Equals(Funcs.Dot.Name))
|
||||
{
|
||||
|
||||
if (args.Count == 1 || forceFirstArgInDot)
|
||||
{
|
||||
return ToLua(args[0]);
|
||||
}
|
||||
|
||||
var argsAsLua = args.Select(arg => ToLua(arg, key)).ToList();
|
||||
var fName = argsAsLua[0];
|
||||
var actualArgs =
|
||||
string.Join(",",argsAsLua.GetRange(1, argsAsLua.Count - 1));
|
||||
return $"{fName}({actualArgs})";
|
||||
}
|
||||
|
||||
AddDep(baseFunc.Name);
|
||||
|
||||
return baseFunc.Name + "(" + string.Join(", ", args.Select(arg => ToLua(arg, key))) + ")";
|
||||
var argExpressions = new List<string>();
|
||||
foreach (var arg in args)
|
||||
{
|
||||
argExpressions.Add(ToLua(arg, key));
|
||||
}
|
||||
|
||||
return baseFunc.Name + "(" + string.Join(", ", argExpressions) + ")";
|
||||
}
|
||||
|
||||
|
||||
|
@ -178,7 +189,6 @@ namespace AspectedRouting.IO.LuaSkeleton
|
|||
return MappingToLua(m).Indent();
|
||||
case Function f:
|
||||
var fName = f.Name.TrimStart('$');
|
||||
|
||||
if (Funcs.Builtins.ContainsKey(fName))
|
||||
{
|
||||
AddDep(f.Name);
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace AspectedRouting.IO.itinero1
|
|||
var paramInLua = _skeleton.ToLua(new Parameter(parameterName));
|
||||
|
||||
|
||||
var exprInLua = _skeleton.ToLua(expression.Optimize());
|
||||
var exprInLua = _skeleton.ToLua(expression.Optimize(), forceFirstArgInDot: true);
|
||||
var resultTypes = expression.Types.Select(t => t.Uncurry().Last());
|
||||
if (resultTypes.Any(t => t.Name.Equals(Typs.Bool.Name)))
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
// this is a profile
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine("Parsing " + fileName);
|
||||
|
||||
return doc.RootElement.ParseAspect(fileName, c);
|
||||
|
@ -240,7 +240,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
if (e.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
var exprs = e.EnumerateArray().Select(json =>
|
||||
Funcs.Either(Funcs.Id, Funcs.Const, json.ParseExpression(context)))
|
||||
Funcs.Either(Funcs.Id, Funcs.Const, json.ParseExpression(context)))
|
||||
.ToList();
|
||||
var list = new Constant(exprs);
|
||||
return Funcs.Either(Funcs.Id, Funcs.ListDot, list);
|
||||
|
@ -330,7 +330,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
return func.Apply(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
args.Add(firstArgument);
|
||||
|
||||
var allExprs = allArgs
|
||||
|
@ -479,7 +479,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
}
|
||||
|
||||
expr = expr.SpecializeToSmallestType();
|
||||
|
||||
|
||||
|
||||
var name = e.Get("name");
|
||||
if (expr.Types.Count() > 1)
|
||||
|
@ -503,6 +503,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Aspect {name} has type {string.Join(",", expr.Types)}");
|
||||
return new AspectMetadata(
|
||||
expr,
|
||||
name,
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace AspectedRouting.IO.jsonParser
|
|||
try
|
||||
{
|
||||
var expr = ParseExpression(prop, c);
|
||||
if (expr.Types.Count() == 0)
|
||||
if (!expr.Types.Any())
|
||||
{
|
||||
throw new Exception($"Could not parse field {property}, no valid typing for expression found");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue