Ejemplo n.º 1
0
        /// <summary>
        /// Parses a type reference.
        /// <see cref="ITypeNode" />:
        /// - NamedType
        /// - ListType
        /// - NonNullType
        /// </summary>
        /// <param name="context">The parser context.</param>
        private static 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);
        }
Ejemplo n.º 2
0
        public Node ListType()
        {
            var listType = new ListTypeNode()
            {
                AnchorToken = Expect(TokenCategory.LIST)
            };

            Expect(TokenCategory.OF);
            listType.Add(SimpleType());
            return(listType);
        }
Ejemplo n.º 3
0
 protected sealed override ISyntaxVisitorAction Enter(
     ISyntaxNode node,
     ISyntaxVisitorContext context)
 {
     return(node switch
     {
         DocumentNode n => Enter(n, context),
         OperationDefinitionNode n => Enter(n, context),
         VariableDefinitionNode n => Enter(n, context),
         VariableNode n => Enter(n, context),
         SelectionSetNode n => Enter(n, context),
         FieldNode n => Enter(n, context),
         ArgumentNode n => Enter(n, context),
         FragmentSpreadNode n => Enter(n, context),
         InlineFragmentNode n => Enter(n, context),
         FragmentDefinitionNode n => Enter(n, context),
         DirectiveNode n => Enter(n, context),
         NamedTypeNode n => Enter(n, context),
         ListTypeNode n => Enter(n, context),
         NonNullTypeNode n => Enter(n, context),
         ListValueNode n => Enter(n, context),
         ObjectValueNode n => Enter(n, context),
         ObjectFieldNode n => Enter(n, context),
         IValueNode n => Enter(n, context),
         SchemaDefinitionNode n => Enter(n, context),
         OperationTypeDefinitionNode n => Enter(n, context),
         ScalarTypeDefinitionNode n => Enter(n, context),
         ObjectTypeDefinitionNode n => Enter(n, context),
         FieldDefinitionNode n => Enter(n, context),
         InputValueDefinitionNode n => Enter(n, context),
         InterfaceTypeDefinitionNode n => Enter(n, context),
         UnionTypeDefinitionNode n => Enter(n, context),
         EnumTypeDefinitionNode n => Enter(n, context),
         EnumValueDefinitionNode n => Enter(n, context),
         InputObjectTypeDefinitionNode n => Enter(n, context),
         DirectiveDefinitionNode n => Enter(n, context),
         SchemaExtensionNode n => Enter(n, context),
         ScalarTypeExtensionNode n => Enter(n, context),
         ObjectTypeExtensionNode n => Enter(n, context),
         InterfaceTypeExtensionNode n => Enter(n, context),
         UnionTypeExtensionNode n => Enter(n, context),
         EnumTypeExtensionNode n => Enter(n, context),
         InputObjectTypeExtensionNode n => Enter(n, context),
         _ => throw new NotSupportedException()
     });
        /// <summary>
        /// Parses a type reference.
        /// <see cref="ITypeNode" />:
        /// - NamedType
        /// - ListType
        /// - NonNullType
        /// </summary>
        /// <param name="context">The parser context.</param>
        private ITypeNode ParseTypeReference()
        {
            ITypeNode type;
            Location  location;

            if (_reader.Kind == TokenKind.LeftBracket)
            {
                TokenInfo start = Start();

                MoveNext();
                type = ParseTypeReference();
                ExpectRightBracket();

                location = CreateLocation(in start);

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

            if (_reader.Kind == TokenKind.Bang)
            {
                if (type is INullableTypeNode nt)
                {
                    TokenInfo start = Start();
                    MoveNext();
                    location = CreateLocation(in start);

                    return(new NonNullTypeNode
                           (
                               location,
                               nt
                           ));
                }

                Unexpected(TokenKind.Bang);
            }

            return(type);
        }
Ejemplo n.º 5
0
 private IDictionary <string, object?> CreateTypeDto(
     ITypeNode type,
     IDictionary <string, TypeKind> typeKinds)
 {
     return(type switch
     {
         NonNullTypeNode nnt => new Dictionary <string, object?>
         {
             { "kind", TypeKind.NonNull }, { "ofType", CreateTypeDto(nnt.Type, typeKinds) },
         },
         ListTypeNode lt => new Dictionary <string, object?>
         {
             { "kind", TypeKind.List }, { "ofType", CreateTypeDto(lt.Type, typeKinds) },
         },
         NamedTypeNode nt => new Dictionary <string, object?>
         {
             { "kind", typeKinds[nt.Name.Value] }, { "name", nt.Name.Value },
         },
         _ => throw new InvalidOperationException("Invalid Type Structure.")
     });
Ejemplo n.º 6
0
        //-----------------------------------------------------------

        public TypeG Visit(ListTypeNode node)
        {
            dynamic listType;

            Console.WriteLine(node.AnchorToken.Category);
            switch (node.AnchorToken.Lexeme)
            {
            case "integer":
                return(TypeG.INTEGER_LIST);

            case "string":
                return(TypeG.STRING_LIST);

            case "boolean":
                return(TypeG.BOOLEAN_LIST);

            default:
                throw new Exception($"Type {node} has no equivalent list type");
            }

            return(listType);
        }
Ejemplo n.º 7
0
 protected virtual ISyntaxVisitorAction Enter(
     ListTypeNode node,
     ISyntaxVisitorContext context) =>
 DefaultAction;
 protected virtual ISyntaxVisitorAction Leave(
     ListTypeNode node,
     TContext context) =>
 DefaultAction;
Ejemplo n.º 9
0
 protected override void VisitListType(
     ListTypeNode node,
     TContext context)
 {
     VisitType(node.Type, context);
 }
Ejemplo n.º 10
0
 public void Visit(ListTypeNode node)
 {
     Visit((dynamic)Node.fromToken(node.AnchorToken));
     builder.Append("[]");
 }
Ejemplo n.º 11
0
 public Type Visit(ListTypeNode node)
 {
     return(typeMapper[node.AnchorToken.Category].ToListType());
 }
Ejemplo n.º 12
0
 protected override void VisitListType(ListTypeNode node)
 {
     VisitType(node.Type);
 }
Ejemplo n.º 13
0
 protected virtual void VisitListType(ListTypeNode node)
 {
 }