Catrobat.IDE.Core.Formulas.FormulaInterpreter.CompleteFunctionsBackwards C# (CSharp) Method

CompleteFunctionsBackwards() private method

private CompleteFunctionsBackwards ( IEnumerable tokens ) : IEnumerable
tokens IEnumerable
return IEnumerable
        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;
            }
        }