コード例 #1
0
 protected void AssertTokenStackIsEmpty()
 {
     if (TokenStack.Any())
     {
         throw new QueryParseException("End of expression expected.");
     }
 }
コード例 #2
0
        protected SortExpression ParseSort()
        {
            SortElementExpression firstElement = ParseSortElement();

            List <SortElementExpression> elements = firstElement.AsList();

            while (TokenStack.Any())
            {
                EatSingleCharacterToken(TokenKind.Comma);

                SortElementExpression nextElement = ParseSortElement();
                elements.Add(nextElement);
            }

            return(new SortExpression(elements));
        }
コード例 #3
0
        protected PaginationQueryStringValueExpression ParsePagination()
        {
            var elements = new List <PaginationElementQueryStringValueExpression>();

            PaginationElementQueryStringValueExpression element = ParsePaginationElement();

            elements.Add(element);

            while (TokenStack.Any())
            {
                EatSingleCharacterToken(TokenKind.Comma);

                element = ParsePaginationElement();
                elements.Add(element);
            }

            return(new PaginationQueryStringValueExpression(elements));
        }
コード例 #4
0
        protected IncludeExpression ParseInclude(int?maximumDepth)
        {
            ResourceFieldChainExpression firstChain = ParseFieldChain(FieldChainRequirements.IsRelationship, "Relationship name expected.");

            List <ResourceFieldChainExpression> chains = firstChain.AsList();

            while (TokenStack.Any())
            {
                EatSingleCharacterToken(TokenKind.Comma);

                ResourceFieldChainExpression nextChain = ParseFieldChain(FieldChainRequirements.IsRelationship, "Relationship name expected.");
                chains.Add(nextChain);
            }

            ValidateMaximumIncludeDepth(maximumDepth, chains);

            return(IncludeChainConverter.FromRelationshipChains(chains));
        }
コード例 #5
0
        protected SparseFieldSetExpression ParseSparseFieldSet()
        {
            var fields = new Dictionary <string, ResourceFieldAttribute>();

            while (TokenStack.Any())
            {
                if (fields.Count > 0)
                {
                    EatSingleCharacterToken(TokenKind.Comma);
                }

                ResourceFieldChainExpression nextChain = ParseFieldChain(FieldChainRequirements.EndsInAttribute, "Field name expected.");
                ResourceFieldAttribute       nextField = nextChain.Fields.Single();
                fields[nextField.PublicName] = nextField;
            }

            return(fields.Any() ? new SparseFieldSetExpression(fields.Values) : null);
        }
コード例 #6
0
        protected SparseFieldSetExpression ParseSparseFieldSet()
        {
            var attributes = new Dictionary <string, AttrAttribute>();

            ResourceFieldChainExpression nextChain = ParseFieldChain(FieldChainRequirements.EndsInAttribute, "Attribute name expected.");
            AttrAttribute nextAttribute            = nextChain.Fields.Cast <AttrAttribute>().Single();

            attributes[nextAttribute.PublicName] = nextAttribute;

            while (TokenStack.Any())
            {
                EatSingleCharacterToken(TokenKind.Comma);

                nextChain     = ParseFieldChain(FieldChainRequirements.EndsInAttribute, "Attribute name expected.");
                nextAttribute = nextChain.Fields.Cast <AttrAttribute>().Single();
                attributes[nextAttribute.PublicName] = nextAttribute;
            }

            return(new SparseFieldSetExpression(attributes.Values));
        }
コード例 #7
0
        private Result ProcessBuffer(StringBuilder buffer)
        {
            string bufferContents = null;

            // Check to see if the current character ends the terminator
            if (TokenStack.Any())
            {
                var peek = TokenStack.Peek();
                bufferContents = buffer.ToString();
                if (peek.Type == TokenType.Complex && bufferContents.EndsWith(peek.Token.Terminator))
                {
                    var terminator = new Result {
                        Type = TokenType.Terminator
                    };
                    terminator.Payload = buffer.ToString(0, buffer.Length - peek.Token.Terminator.Length);
                    return(terminator);
                }
            }

            if (string.IsNullOrEmpty(bufferContents))
            {
                bufferContents = buffer.ToString();
            }

            foreach (var child in _prospectiveTokens)
            {
                var isToken = bufferContents.Last() == child.Identifier.Last() &&
                              bufferContents.EndsWith(child.Identifier);

                var match = CheckForInterpolation(child.Interpolation, bufferContents);

                var isInterpolated = match != null && match.Success;

                if (isToken || isInterpolated)
                {
                    var result = new Result {
                        Token = child
                    };

                    if (child.Interpolation != null)
                    {
                        result.Payload = buffer.ToString(0, bufferContents.IndexOf(child.Interpolation.Start));
                        child.Interpolation.ArgumentInput = match.Value;
                        result.Type = TokenType.Interpolation;
                    }
                    else if (string.IsNullOrEmpty(child.Terminator))
                    {
                        result.Payload = buffer.ToString(0, buffer.Length - child.Identifier.Length);
                        result.Type    = TokenType.Simple;
                    }
                    else
                    {
                        result.Payload = buffer.ToString(0, buffer.Length - child.Identifier.Length);
                        result.Type    = TokenType.Complex;
                    }

                    return(result);
                }
            }

            return(new Result {
                Type = TokenType.NotAToken
            });
        }