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

TryParseWithDeclaration() static private method

static private TryParseWithDeclaration ( IStatedTwoWayEnumerator enumerator, MdxExpressionBase &expression ) : bool
enumerator IStatedTwoWayEnumerator
expression MdxExpressionBase
return bool
        internal static bool TryParseWithDeclaration(IStatedTwoWayEnumerator<Token> enumerator, out MdxExpressionBase expression)
        {
            enumerator.SavePosition();
            expression = null;

            var declaration = Mdx.Declaration();

            if (!IsNextTokenValid(enumerator, TokenType.Member) &&
                !IsNextTokenValid(enumerator, TokenType.Set))
            {
                enumerator.RestoreLastSavedPosition();
                return false;
            }

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

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

                declaration.Titled(identifierTitle);

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

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

            MdxExpressionBase declarationExpression;
            if (TryParseTuple(enumerator, out declarationExpression))
            {
                declaration.As((MdxTuple) declarationExpression);
            }
            else if (TryParseExpression(enumerator, out declarationExpression))
            {
                declaration.As((MdxExpression) declarationExpression);
            }
            else
            {
                enumerator.RestoreLastSavedPosition();
                return false;
            }

            expression = declaration;
            enumerator.RemoveLastSavedState();
            return true;
        }