/// <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) { var children = new List <SyntaxNode>(); var startLocation = tokenStream.Location; tokenStream.MatchOrThrow(TokenType.BracketLeft); tokenStream.Next(); while (!tokenStream.EndOfStream && !tokenStream.Match(TokenType.BracketRight)) { var childMaker = ValueMakerFactory.CreateMaker(tokenStream.ActiveToken); if (childMaker == null) { throw new GraphQLSyntaxException( tokenStream.Location, $"Unexpected token in list, no value could be parsed. Expected '{TokenType.BracketRight.Description().ToString()}' or an " + $"input object value but receieved '{tokenStream.ActiveToken.Text.ToString()}'"); } var childNode = childMaker.MakeNode(tokenStream); children.Add(childNode); } // ensure we are pointing at an end of list tokenStream.MatchOrThrow(TokenType.BracketRight); tokenStream.Next(); var listNode = new ListValueNode(startLocation); listNode.Children.AddRange(children); return(listNode); }
/// <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) { var maker = ValueMakerFactory.CreateMaker(tokenStream.ActiveToken); if (maker != null) { return(maker.MakeNode(tokenStream)); } GraphQLSyntaxException.ThrowFromExpectation( tokenStream.Location, "<value>", tokenStream.TokenType.Description().ToString()); throw new InvalidOperationException("Critical Failure, this exception should never be reached."); }
/// <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 = ValueMakerFactory.CreateMaker(tokenStream.ActiveToken).MakeNode(tokenStream); } else { tokenStream.MatchOrThrow <NameToken>(); node = new EnumValueNode(tokenStream.Location, tokenStream.ActiveToken.Text); tokenStream.Next(); } return(node); }