Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void StarMustBeLastTokenInDottedIdentifier()
        {
            ExpressionLexer lexer = new ExpressionLexer("m.*.blah", true, false);
            Action          read  = () => lexer.ReadDottedIdentifier(true);

            read.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("3", "m.*.blah"));
        }
Ejemplo n.º 3
0
        public void ShouldThrowWhenGivenStarInDontAcceptStarMode()
        {
            ExpressionLexer lexer = new ExpressionLexer("m.*", true, false);
            Action          read  = () => lexer.ReadDottedIdentifier(false);

            read.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("3", "m.*"));
        }
Ejemplo n.º 4
0
        public void ShouldNotThrowWhenGivenStarInAcceptStarMode()
        {
            ExpressionLexer lexer  = new ExpressionLexer("m.*", true, false);
            string          result = lexer.ReadDottedIdentifier(true);

            Assert.Equal("m.*", result);
        }
Ejemplo n.º 5
0
        public void ShouldThrowWhenNotGivenIdentifierToken()
        {
            ExpressionLexer lexer = new ExpressionLexer("2.43", false, false);
            Action          read  = () => lexer.ReadDottedIdentifier(false);

            read.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("0", "2.43"));
        }
Ejemplo n.º 6
0
        public void ShouldReturnStringIdentifierWhenGivenIdentifierTokenContainingWhitespace()
        {
            ExpressionLexer lexer  = new ExpressionLexer("    m.i.something.k", true, false);
            string          result = lexer.ReadDottedIdentifier(false);

            Assert.Equal("m.i.something.k", result);
        }
Ejemplo n.º 7
0
        public void ShouldReturnStringIdentifierWhenGivenIdentifierTokenContainingDot()
        {
            ExpressionLexer lexer  = new ExpressionLexer("m.i.something.k", true, false);
            string          result = lexer.ReadDottedIdentifier(false);

            result.Should().Be("m.i.something.k");
        }
Ejemplo n.º 8
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);
        }