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
|
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 collectedMapping = new List<IExpression>();
|
||||||
var order = new List<IExpression>();
|
var order = new List<IExpression>();
|
||||||
|
|
||||||
|
@ -61,13 +60,9 @@ namespace AspectedRouting.IO.LuaSkeleton
|
||||||
return "member_of(funcName, parameters, tags, result)";
|
return "member_of(funcName, parameters, tags, result)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var collectedList = new List<IExpression>();
|
var collectedList = new List<IExpression>();
|
||||||
var func = new List<IExpression>();
|
var func = new List<IExpression>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
UnApply(
|
UnApply(
|
||||||
UnApply(IsFunc(Funcs.Dot), Assign(func)),
|
UnApply(IsFunc(Funcs.Dot), Assign(func)),
|
||||||
|
@ -98,14 +93,9 @@ namespace AspectedRouting.IO.LuaSkeleton
|
||||||
return "\n " + funcName + "({\n " + string.Join(",\n ", luaExprs) +
|
return "\n " + funcName + "({\n " + string.Join(",\n ", luaExprs) +
|
||||||
"\n })";
|
"\n })";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
collectedMapping.Clear();
|
collectedMapping.Clear();
|
||||||
var dottedFunction = new List<IExpression>();
|
var dottedFunction = new List<IExpression>();
|
||||||
|
|
||||||
|
|
||||||
dottedFunction.Clear();
|
dottedFunction.Clear();
|
||||||
|
|
||||||
if (UnApply(
|
if (UnApply(
|
||||||
UnApply(
|
UnApply(
|
||||||
IsFunc(Funcs.Dot),
|
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
|
// The expression might be a function which still expects a string (the value from the tag) as argument
|
||||||
if (!(bare is Mapping) &&
|
if (!(bare is Mapping) &&
|
||||||
bare.Types.First() is Curry curr &&
|
bare.Types.First() is Curry curr &&
|
||||||
|
@ -144,16 +135,36 @@ namespace AspectedRouting.IO.LuaSkeleton
|
||||||
var (f, args) = fArgs.Value;
|
var (f, args) = fArgs.Value;
|
||||||
var baseFunc = (Function) f;
|
var baseFunc = (Function) f;
|
||||||
|
|
||||||
if (baseFunc.Name.Equals(Funcs.Id.Name) ||
|
if (baseFunc.Name.Equals(Funcs.Id.Name))
|
||||||
baseFunc.Name.Equals(Funcs.Dot.Name))
|
|
||||||
{
|
{
|
||||||
// This is an ugly hack
|
// This is an ugly hack
|
||||||
return ToLua(args.First());
|
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);
|
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();
|
return MappingToLua(m).Indent();
|
||||||
case Function f:
|
case Function f:
|
||||||
var fName = f.Name.TrimStart('$');
|
var fName = f.Name.TrimStart('$');
|
||||||
|
|
||||||
if (Funcs.Builtins.ContainsKey(fName))
|
if (Funcs.Builtins.ContainsKey(fName))
|
||||||
{
|
{
|
||||||
AddDep(f.Name);
|
AddDep(f.Name);
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace AspectedRouting.IO.itinero1
|
||||||
var paramInLua = _skeleton.ToLua(new Parameter(parameterName));
|
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());
|
var resultTypes = expression.Types.Select(t => t.Uncurry().Last());
|
||||||
if (resultTypes.Any(t => t.Name.Equals(Typs.Bool.Name)))
|
if (resultTypes.Any(t => t.Name.Equals(Typs.Bool.Name)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
// this is a profile
|
// this is a profile
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Parsing " + fileName);
|
Console.WriteLine("Parsing " + fileName);
|
||||||
|
|
||||||
return doc.RootElement.ParseAspect(fileName, c);
|
return doc.RootElement.ParseAspect(fileName, c);
|
||||||
|
@ -240,7 +240,7 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
if (e.ValueKind == JsonValueKind.Array)
|
if (e.ValueKind == JsonValueKind.Array)
|
||||||
{
|
{
|
||||||
var exprs = e.EnumerateArray().Select(json =>
|
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();
|
.ToList();
|
||||||
var list = new Constant(exprs);
|
var list = new Constant(exprs);
|
||||||
return Funcs.Either(Funcs.Id, Funcs.ListDot, list);
|
return Funcs.Either(Funcs.Id, Funcs.ListDot, list);
|
||||||
|
@ -330,7 +330,7 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
return func.Apply(args);
|
return func.Apply(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
args.Add(firstArgument);
|
args.Add(firstArgument);
|
||||||
|
|
||||||
var allExprs = allArgs
|
var allExprs = allArgs
|
||||||
|
@ -479,7 +479,7 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = expr.SpecializeToSmallestType();
|
expr = expr.SpecializeToSmallestType();
|
||||||
|
|
||||||
|
|
||||||
var name = e.Get("name");
|
var name = e.Get("name");
|
||||||
if (expr.Types.Count() > 1)
|
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(
|
return new AspectMetadata(
|
||||||
expr,
|
expr,
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace AspectedRouting.IO.jsonParser
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var expr = ParseExpression(prop, c);
|
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");
|
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