//return the idx jump on the valName or -1 if it can't add the substitution
private static int FindSubsAux(Literal var, Literal val, SimpleName valName, IDictionary <string, Substitution> bindings)
{
//first, analyse if the value is a composed name or a single parameter
string valDescription;
int valLiteralCount;
if (val.type == LiteralType.Root)
{
SimpleName auxName = null;
auxName = SimpleWFN.BuildNameFromContainedLiteral(valName, val);
valDescription = auxName.ToString();
valLiteralCount = auxName.literals.Count;
}
else
{
valDescription = val.description;
valLiteralCount = 1;
}
//check if a binding for the same variable already exists
Substitution existingSub = null;
bindings.TryGetValue(var.description, out existingSub);
if (existingSub != null)
{
if (existingSub.SubValue.ToString().RemoveWhiteSpace().EqualsIgnoreCase(valDescription))
{
return(valLiteralCount);
}
else
{
return(-1);
}
}
//if there was no existing binding to the variable
try
{
bindings[var.description] = new Substitution(var.description, valDescription);
return(valLiteralCount);
}
catch (BadSubstitutionException)
{
return(-1);
}
}