BalticAmadeus.FluentMdx.MdxParser.TryParseFunction C# (CSharp) Method

TryParseFunction() static private method

Performs function syntactical analysis over collection of Token objects using IStatedTwoWayEnumerator{T}.
static private TryParseFunction ( IStatedTwoWayEnumerator enumerator, MdxExpressionBase &expression ) : bool
enumerator IStatedTwoWayEnumerator Extended enumerator of collection of objects.
expression MdxExpressionBase Output parsed function if syntactic analysis was succeeded.
return bool
        internal static bool TryParseFunction(IStatedTwoWayEnumerator<Token> enumerator, out MdxExpressionBase expression)
        {
            enumerator.SavePosition();
            expression = null;

            var function = Mdx.Function();

            do
            {
                if (!IsNextTokenValid(enumerator, TokenType.TitleExpression))
                {
                    enumerator.RestoreLastSavedPosition();
                    return false;
                }

                function.Titled(enumerator.Current.Value);

            } while (IsNextTokenValid(enumerator, TokenType.IdentifierSeparator));

            if (!IsNextTokenValid(enumerator, TokenType.LeftRoundBracket))
            {
                enumerator.RestoreLastSavedPosition();
                return false;
            }

            if (IsNextTokenValid(enumerator, TokenType.RightRoundBracket))
            {
                expression = function;

                enumerator.RemoveLastSavedState();
                return true;
            }

            do
            {
                MdxExpressionBase childExpression;
                if (!TryParseExpression(enumerator, out childExpression))
                {
                    enumerator.RestoreLastSavedPosition();
                    return false;
                }

                function.WithParameters((MdxExpression)childExpression);

            } while (IsNextTokenValid(enumerator, TokenType.MemberSeparator));

            if (!IsNextTokenValid(enumerator, TokenType.RightRoundBracket))
            {
                enumerator.RestoreLastSavedPosition();
                return false;
            }

            expression = function;

            enumerator.RemoveLastSavedState();
            return true;
        }