Exemplo n.º 1
0
        /// <summary>
        /// Processes the stream as far as it needs to to generate a fully qualiffied
        /// <see cref="SyntaxNode" /> based on its internal ruleset. All implementations
        /// are expected to validate the stream is at a location which it can consume
        /// and throw an <see cref="GraphQLSyntaxException" /> as appropriate and consume
        /// the last character in their phrase, leaving the stream primed for the next
        /// maker in the series.
        /// </summary>
        /// <param name="tokenStream">The token stream.</param>
        /// <returns>LexicalToken.</returns>
        public SyntaxNode MakeNode(TokenStream tokenStream)
        {
            SyntaxNode node = null;

            if (tokenStream.Match <NullToken>())
            {
                node = new ScalarValueNode(
                    tokenStream.Location,
                    ScalarValueType.Boolean,
                    ParserConstants.Keywords.Null);
            }
            else
            {
                tokenStream.MatchOrThrow <NameToken>();
                if (tokenStream.Match(ParserConstants.Keywords.True, ParserConstants.Keywords.False))
                {
                    node = new ScalarValueNode(
                        tokenStream.Location,
                        ScalarValueType.Boolean,
                        tokenStream.ActiveToken.Text);
                }
                else
                {
                    GraphQLSyntaxException.ThrowFromExpectation(
                        tokenStream.Location,
                        "{true|false}",
                        tokenStream.ActiveToken.Text.ToString());
                }
            }

            tokenStream.Next();
            return(node);
        }
        /// <summary>
        /// Processes the queue as far as it needs to to generate a fully qualiffied
        /// <see cref="SyntaxNode" /> based on its ruleset.
        /// </summary>
        /// <param name="tokenStream">The token stream.</param>
        /// <returns>LexicalToken.</returns>
        public SyntaxNode MakeNode(TokenStream tokenStream)
        {
            SyntaxNode node;

            if (tokenStream.Match <NullToken>())
            {
                node = new ScalarValueNode(
                    tokenStream.Location,
                    ScalarValueType.String,
                    tokenStream.ActiveToken.Text);
            }
            else
            {
                tokenStream.MatchOrThrow <StringToken>();
                node = new ScalarValueNode(tokenStream.Location, ScalarValueType.String, tokenStream.ActiveToken.Text);
            }

            tokenStream.Next();
            return(node);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="QueryScalarInputValue" /> class.
 /// </summary>
 /// <param name="value">The value parsed from a query document.</param>
 public QueryScalarInputValue(ScalarValueNode value)
     : base(value)
 {
     this.ValueType = value.ValueType;
     this.Value     = value.Value;
 }