コード例 #1
0
        /// <summary>
        /// Parses a type reference.
        /// <see cref="ITypeNode" />:
        /// - NamedType
        /// - ListType
        /// - NonNullType
        /// </summary>
        /// <param name="context">The parser context.</param>
        private ITypeNode ParseTypeReference(ParserContext context)
        {
            SyntaxToken start = context.Current;
            ITypeNode   type;
            Location    location;

            if (context.Skip(TokenKind.LeftBracket))
            {
                type = ParseTypeReference(context);
                context.ExpectRightBracket();
                location = context.CreateLocation(start);

                type = new ListTypeNode(location, type);
            }
            else
            {
                type = ParseNamedType(context);
            }

            if (context.Skip(TokenKind.Bang))
            {
                if (type is INullableType nt)
                {
                    return(new NonNullTypeNode
                           (
                               context.CreateLocation(start),
                               nt
                           ));
                }
                context.Unexpected(context.Current.Previous);
            }

            return(type);
        }
コード例 #2
0
        private UnionTypeExtensionNode ParseUnionTypeExtension(ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectExtendKeyword();
            context.ExpectUnionKeyword();
            NameNode             name       = context.ParseName();
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <NamedTypeNode> types =
                ParseUnionMemberTypes(context);
            Location location = context.CreateLocation(start);

            if (directives.Count == 0 && types.Count == 0)
            {
                throw context.Unexpected(start);
            }

            return(new UnionTypeExtensionNode
                   (
                       location,
                       name,
                       directives,
                       types
                   ));
        }
コード例 #3
0
        private EnumTypeExtensionNode ParseEnumTypeExtension(ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectExtendKeyword();
            context.ExpectEnumKeyword();
            NameNode             name       = context.ParseName();
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <EnumValueDefinitionNode> values =
                ParseEnumValuesDefinition(context);
            Location location = context.CreateLocation(start);

            if (directives.Count == 0 && values.Count == 0)
            {
                throw context.Unexpected(start);
            }

            return(new EnumTypeExtensionNode
                   (
                       location,
                       name,
                       directives,
                       values
                   ));
        }
コード例 #4
0
        private InputObjectTypeExtensionNode ParseInputObjectTypeExtension(ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectExtendKeyword();
            context.ExpectInputKeyword();
            NameNode             name       = context.ParseName();
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <InputValueDefinitionNode> fields =
                ParseInputFieldsDefinition(context);
            Location location = context.CreateLocation(start);

            if (directives.Count == 0 && fields.Count == 0)
            {
                throw context.Unexpected(start);
            }

            return(new InputObjectTypeExtensionNode
                   (
                       location,
                       name,
                       directives,
                       fields
                   ));
        }
コード例 #5
0
ファイル: Parser.Values.cs プロジェクト: xgame92/hotchocolate
        private static IValueNode ParseEnumValue(ParserContext context)
        {
            SyntaxToken start    = context.Current;
            Location    location = context.CreateLocation(start);

            context.MoveNext();

            switch (start.Value)
            {
            case Keywords.True:
                return(new BooleanValueNode(location, true));

            case Keywords.False:
                return(new BooleanValueNode(location, false));

            case Keywords.Null:
                return(new NullValueNode(location));
            }

            return(new EnumValueNode
                   (
                       location,
                       start.Value
                   ));
        }
コード例 #6
0
ファイル: Parser.Values.cs プロジェクト: xgame92/hotchocolate
        private static IValueNode ParseScalarValue(ParserContext context)
        {
            if (context.Current.IsString())
            {
                return(ParseStringLiteral(context));
            }

            SyntaxToken start    = context.ExpectScalarValue();
            Location    location = context.CreateLocation(start);

            if (start.Kind == TokenKind.Float)
            {
                return(new FloatValueNode
                       (
                           location,
                           start.Value
                       ));
            }

            if (start.Kind == TokenKind.Integer)
            {
                return(new IntValueNode
                       (
                           location,
                           start.Value
                       ));
            }

            throw context.Unexpected(start);
        }
コード例 #7
0
        /// <summary>
        /// Parse schema definition extension.
        /// <see cref="SchemaExtensionNode" />:
        /// * - extend schema Directives[Const]? { OperationTypeDefinition+ }
        /// * - extend schema Directives[Const]
        /// </summary>
        /// <param name="context">The parser context.</param>
        private SchemaExtensionNode ParseSchemaExtension(ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectExtendKeyword();
            context.ExpectSchemaKeyword();

            List <DirectiveNode> directives =
                ParseDirectives(context, true);

            List <OperationTypeDefinitionNode> operationTypeDefinitions =
                ParseOperationTypeDefinitions(context);

            if (directives.Count == 0 && operationTypeDefinitions.Count == 0)
            {
                throw context.Unexpected(start);
            }

            Location location = context.CreateLocation(start);

            return(new SchemaExtensionNode
                   (
                       location,
                       directives,
                       operationTypeDefinitions
                   ));
        }
コード例 #8
0
        /// <summary>
        /// Parses an object type definition.
        /// <see cref="ObjectTypeDefinitionNode" />:
        /// Description?
        /// type Name ImplementsInterfaces? Directives[isConstant=true]? FieldsDefinition?
        /// </summary>
        /// <param name="context">The parser context.</param>
        private ObjectTypeDefinitionNode ParseObjectTypeDefinition(
            ParserContext context)
        {
            SyntaxToken     start       = context.Current;
            StringValueNode description = ParseDescription(context);

            context.ExpectTypeKeyword();
            NameNode             name       = ParseName(context);
            List <NamedTypeNode> interfaces =
                ParseImplementsInterfaces(context);
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <FieldDefinitionNode> fields =
                ParseFieldsDefinition(context);
            Location location = context.CreateLocation(start);

            return(new ObjectTypeDefinitionNode
                   (
                       location,
                       name,
                       description,
                       directives,
                       interfaces,
                       fields
                   ));
        }
コード例 #9
0
        private ObjectTypeExtensionNode ParseObjectTypeExtension(ParserContext context)
        {
            SyntaxToken start = context.Current;

            context.ExpectExtendKeyword();
            context.ExpectTypeKeyword();
            NameNode             name       = context.ParseName();
            List <NamedTypeNode> interfaces =
                ParseImplementsInterfaces(context);
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            List <FieldDefinitionNode> fields =
                ParseFieldsDefinition(context);
            Location location = context.CreateLocation(start);

            if (interfaces.Count == 0 &&
                directives.Count == 0 &&
                fields.Count == 0)
            {
                throw context.Unexpected(start);
            }

            return(new ObjectTypeExtensionNode
                   (
                       location,
                       name,
                       directives,
                       interfaces,
                       fields
                   ));
        }
コード例 #10
0
        /// <summary>
        /// Parses a interface type or object type field definition.
        /// <see cref="FieldDefinitionNode" />:
        /// Description?
        /// Name ArgumentsDefinition? : Type Directives[isConstant=true]?
        /// </summary>
        /// <param name="context">The parser context.</param>
        private FieldDefinitionNode ParseFieldDefinition(
            ParserContext context)
        {
            SyntaxToken     start       = context.Current;
            StringValueNode description = ParseDescription(context);
            NameNode        name        = ParseName(context);
            List <InputValueDefinitionNode> arguments =
                ParseArgumentDefinitions(context);

            context.ExpectColon();
            ITypeNode            type       = ParseTypeReference(context);
            List <DirectiveNode> directives =
                ParseDirectives(context, true);
            Location location = context.CreateLocation(start);

            return(new FieldDefinitionNode
                   (
                       location,
                       name,
                       description,
                       arguments,
                       type,
                       directives
                   ));
        }
コード例 #11
0
ファイル: Parser.Values.cs プロジェクト: rstaib/hotchocolate
        private StringValueNode ParseStringLiteral(ParserContext context)
        {
            SyntaxToken start    = context.ExpectString();
            bool        isBlock  = start.Kind == TokenKind.BlockString;
            Location    location = context.CreateLocation(start);

            return(new StringValueNode(location, start.Value, isBlock));
        }
コード例 #12
0
        internal static NameNode ParseName(ParserContext context)
        {
            SyntaxToken token    = context.ExpectName();
            Location    location = context.CreateLocation(token);

            return(new NameNode
                   (
                       location,
                       token.Value
                   ));
        }
コード例 #13
0
        /// <summary>
        /// Parses a named type.
        /// <see cref="NamedTypeNode" />:
        /// Name
        /// </summary>
        /// <param name="context">The parser context.</param>
        private NamedTypeNode ParseNamedType(ParserContext context)
        {
            SyntaxToken start    = context.Current;
            NameNode    name     = context.ParseName();
            Location    location = context.CreateLocation(start);

            return(new NamedTypeNode
                   (
                       location,
                       name
                   ));
        }
コード例 #14
0
        private static NameNode ParseJsonName(ParserContext context)
        {
            SyntaxToken token = context.Current.Kind == TokenKind.String
                ? context.ExpectString()
                : context.ExpectName();

            Location location = context.CreateLocation(token);

            return(new NameNode
                   (
                       location,
                       token.Value
                   ));
        }
コード例 #15
0
ファイル: Parser.Values.cs プロジェクト: rstaib/hotchocolate
        /// <summary>
        /// Parses an object value.
        /// <see cref="ObjectValueNode" />:
        /// - { }
        /// - { Value[isConstant]+ }
        /// </summary>
        /// <param name="context">The parser context.</param>
        /// <param name="isConstant">
        /// Defines if only constant values are allowed;
        /// otherwise, variables are allowed.
        /// </param>
        private ObjectValueNode ParseObject(ParserContext context, bool isConstant)
        {
            SyntaxToken            start  = context.Current;
            List <ObjectFieldNode> fields = ParseMany(context,
                                                      TokenKind.LeftBrace,
                                                      c => ParseObjectField(c, isConstant),
                                                      TokenKind.RightBrace);
            Location location = context.CreateLocation(start);

            return(new ObjectValueNode
                   (
                       location,
                       fields
                   ));
        }
コード例 #16
0
ファイル: Parser.Values.cs プロジェクト: rstaib/hotchocolate
        /// <summary>
        /// Parses a list value.
        /// <see cref="ListValueNode" />:
        /// - [ ]
        /// - [ Value[isConstant]+ ]
        /// </summary>
        /// <param name="context">The parser context.</param>
        /// <param name="isConstant">
        /// Defines if only constant values are allowed;
        /// otherwise, variables are allowed.
        /// </param>
        private ListValueNode ParseList(ParserContext context, bool isConstant)
        {
            SyntaxToken       start = context.Current;
            List <IValueNode> items = isConstant
                ? ParseMany(context, TokenKind.LeftBracket,
                            ParseConstantValue, TokenKind.RightBracket)
                : ParseMany(context, TokenKind.LeftBracket,
                            c => ParseValueLiteral(c, false), TokenKind.RightBracket);
            Location location = context.CreateLocation(start);

            return(new ListValueNode
                   (
                       location,
                       items
                   ));
        }
コード例 #17
0
ファイル: Parser.Values.cs プロジェクト: rstaib/hotchocolate
        private ObjectFieldNode ParseObjectField(ParserContext context, bool isConstant)
        {
            SyntaxToken start = context.Current;
            NameNode    name  = ParseName(context);

            context.ExpectColon();
            IValueNode value    = ParseValueLiteral(context, isConstant);
            Location   location = context.CreateLocation(start);

            return(new ObjectFieldNode
                   (
                       location,
                       name,
                       value
                   ));
        }
コード例 #18
0
        private DocumentNode ParseDocument(ISource source, SyntaxToken start, ParserOptions options)
        {
            List <IDefinitionNode> definitions = new List <IDefinitionNode>();
            ParserContext          context     = new ParserContext(source, start, options);

            context.MoveNext();

            while (!context.IsEndOfFile())
            {
                definitions.Add(ParseDefinition(context));
            }

            Location location = context.CreateLocation(start);

            return(new DocumentNode(location, definitions.AsReadOnly()));
        }
コード例 #19
0
        /// <summary>
        /// Parses an operation type definition.
        /// <see cref="OperationTypeDefinitionNode" />:
        /// OperationType : NamedType
        /// </summary>
        /// <param name="context">The parser context.</param>
        private OperationTypeDefinitionNode ParseOperationTypeDefinition(
            ParserContext context)
        {
            SyntaxToken   start     = context.Current;
            OperationType operation = ParseOperationType(context);

            context.ExpectColon();
            NamedTypeNode type     = ParseNamedType(context);
            Location      location = context.CreateLocation(start);

            return(new OperationTypeDefinitionNode
                   (
                       location,
                       operation,
                       type
                   ));
        }