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

TryParseMember() static private method

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

            var member = Mdx.Member();

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

            string identifierWithBrackets = enumerator.Current.Value;
            string identifierTitle = identifierWithBrackets.Substring(1, identifierWithBrackets.Length - 2);

            member.Titled(identifierTitle);

            while (IsNextTokenValid(enumerator, TokenType.IdentifierSeparator))
            {
                MdxExpressionBase function;
                if (TryParseNavigationFunction(enumerator, out function))
                {
                    member.WithFunction((MdxNavigationFunction)function);
                    continue;
                }

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

                identifierWithBrackets = enumerator.Current.Value;
                identifierTitle = identifierWithBrackets.Substring(1, identifierWithBrackets.Length - 2);

                member.Titled(identifierTitle);

            }

            if (!IsNextTokenValid(enumerator, TokenType.ValueSeparator))
            {
                expression = member;

                enumerator.RemoveLastSavedState();
                return true;
            }

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

            string valueWithBrackets = enumerator.Current.Value;
            string value = valueWithBrackets.Substring(1, valueWithBrackets.Length - 2);

            member.WithValue(value);

            while (IsNextTokenValid(enumerator, TokenType.IdentifierSeparator))
            {
                MdxExpressionBase function;
                if (!TryParseNavigationFunction(enumerator, out function))
                {
                    enumerator.RestoreLastSavedPosition();
                    return false;
                }

                member.WithFunction((MdxNavigationFunction) function);
            }

            expression = member;

            enumerator.RemoveLastSavedState();
            return true;
        }