Exemplo n.º 1
0
        public void ShouldThrowWhenCurrentTokenIsNotExpressionKind()
        {
            ExpressionLexer lexer    = new ExpressionLexer("null", true, false);
            Action          validate = () => lexer.ValidateToken(ExpressionTokenKind.Question);

            validate.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError(4, "null"));
        }
Exemplo n.º 2
0
        public void ShouldNotThrowWhenCurrentTokenIsExpressionKind()
        {
            ExpressionLexer lexer    = new ExpressionLexer("null", true, false);
            Action          validate = () => lexer.ValidateToken(ExpressionTokenKind.NullLiteral);

            validate.DoesNotThrow();
        }
Exemplo n.º 3
0
        /// <summary>Reads a $select clause.</summary>
        /// <param name="value">Value to read.</param>
        /// <param name="dataServiceProviderWrapper">The provider wrapper for the service.</param>
        /// <returns>A list of paths, each of which is a list of identifiers.</returns>
        private static IList <IList <string> > SplitSelect(string value, DataServiceProviderWrapper dataServiceProviderWrapper)
        {
            Debug.Assert(!String.IsNullOrEmpty(value), "!String.IsNullOrEmpty(value)");

            List <IList <string> > result      = new List <IList <string> >();
            List <string>          currentPath = null;
            ExpressionLexer        lexer       = new ExpressionLexer(value);

            while (lexer.CurrentToken.Kind != ExpressionTokenKind.End)
            {
                string identifier;
                bool   lastSegment = false;
                if (lexer.CurrentToken.Kind == ExpressionTokenKind.Star)
                {
                    identifier = lexer.CurrentToken.Text;
                    lexer.NextToken();
                    lastSegment = true;
                }
                else
                {
                    identifier = lexer.ReadDottedIdentifier(true /*allowEndWithDotStar*/);
                    bool nameIsContainerQualifed;
                    if (dataServiceProviderWrapper.GetNameFromContainerQualifiedName(identifier, out nameIsContainerQualifed) == "*")
                    {
                        lastSegment = true;
                    }
                }

                if (currentPath == null)
                {
                    currentPath = new List <string>();
                    result.Add(currentPath);
                }

                currentPath.Add(identifier);

                // Check whether we're at the end, whether we're drilling in,
                // or whether we're finishing with this path.
                ExpressionTokenKind tokenId = lexer.CurrentToken.Kind;
                if (tokenId != ExpressionTokenKind.End)
                {
                    if (lastSegment || tokenId != ExpressionTokenKind.Slash)
                    {
                        lexer.ValidateToken(ExpressionTokenKind.Comma);
                        currentPath = null;
                    }

                    lexer.NextToken();
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        private static List <List <string> > ReadExpandOrSelect(string value, bool select, IDataService dataService)
        {
            List <List <string> > list  = new List <List <string> >();
            List <string>         list2 = null;
            ExpressionLexer       lexer = new ExpressionLexer(value);

            while (lexer.CurrentToken.Id != TokenId.End)
            {
                string text;
                bool   flag = false;
                if (select && (lexer.CurrentToken.Id == TokenId.Star))
                {
                    text = lexer.CurrentToken.Text;
                    lexer.NextToken();
                    flag = true;
                }
                else if (select)
                {
                    bool flag2;
                    text = lexer.ReadDottedIdentifier(true);
                    if (dataService.Provider.GetNameFromContainerQualifiedName(text, out flag2) == "*")
                    {
                        flag = true;
                    }
                }
                else
                {
                    text = lexer.ReadDottedIdentifier(false);
                }
                if (list2 == null)
                {
                    list2 = new List <string> {
                    };
                }
                list2.Add(text);
                TokenId id = lexer.CurrentToken.Id;
                if (id != TokenId.End)
                {
                    if (flag || (id != TokenId.Slash))
                    {
                        lexer.ValidateToken(TokenId.Comma);
                        list2 = null;
                    }
                    lexer.NextToken();
                }
            }
            return(list);
        }