private IEnumerable<IFormulaToken> CompleteFunctionsBackwards(IEnumerable<IFormulaToken> tokens)
{
foreach (var context in tokens.WithContext())
{
var nextToken = context[0];
var token = context[1];
// attach parentheses to function
if (token is IFormulaFunction)
{
// missing function argument
if (!(nextToken is FormulaNodeParentheses)) yield break;
SetOrigin(token, new[] { token, nextToken });
yield return token;
continue;
}
// yield unattached parentheses
if (nextToken is FormulaNodeParentheses) yield return nextToken;
// yield any other token
if (token != null && !(token is FormulaNodeParentheses)) yield return token;
}
}