o
    tBh/                     @   sZ  d dl mZmZmZmZmZmZmZ d dlm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddl
mBZB ddlCmDZDmEZE ddlFmGZGmHZH dd	lImJZJ d
dlKmLZLmMZM g dZNedZOeeGePf ZQ			d%deQdeRdeeS deRdef
ddZT			d%deQdeRdeeS deRde=f
ddZU			d%deQdeRdeeS deRdef
ddZV			d%deQdeRdeeS deRde9f
ddZWG dd dZXdeBdePfd d!ZYd"eJdePfd#d$ZZdS )&    )CallableDictListOptionalUnionTypeVarcast)partial   )5ArgumentNodeBooleanValueNodeConstArgumentNodeConstDirectiveNodeConstValueNodeDefinitionNodeDirectiveDefinitionNodeDirectiveNodeDocumentNodeEnumTypeDefinitionNodeEnumTypeExtensionNodeEnumValueDefinitionNodeEnumValueNodeFieldDefinitionNode	FieldNodeFloatValueNodeFragmentDefinitionNodeFragmentSpreadNodeInlineFragmentNodeInputObjectTypeDefinitionNodeInputObjectTypeExtensionNodeInputValueDefinitionNodeIntValueNodeInterfaceTypeDefinitionNodeInterfaceTypeExtensionNodeListTypeNodeListValueNodeLocationNameNodeNamedTypeNodeNonNullTypeNodeNullValueNodeObjectFieldNodeObjectTypeDefinitionNodeObjectTypeExtensionNodeObjectValueNodeOperationDefinitionNodeOperationTypeOperationTypeDefinitionNodeScalarTypeDefinitionNodeScalarTypeExtensionNodeSchemaDefinitionNodeSchemaExtensionNodeSelectionNodeSelectionSetNodeStringValueNodeTypeNodeTypeSystemExtensionNodeUnionTypeDefinitionNodeUnionTypeExtensionNode	ValueNodeVariableDefinitionNodeVariableNodeDirectiveLocation)Token)Lexeris_punctuator_token_kind)Source	is_source)	TokenKind   )GraphQLErrorGraphQLSyntaxError)parse
parse_typeparse_valueparse_const_valueTFNsourceno_location
max_tokensallow_legacy_fragment_variablesreturnc                 C   s   t | |||d}| S )a  Given a GraphQL source, parse it into a Document.

    Throws GraphQLError if a syntax error is encountered.

    By default, the parser creates AST nodes that know the location in the source that
    they correspond to. Setting the ``no_location`` parameter to False disables that
    behavior for performance or testing.

    Parser CPU and memory usage is linear to the number of tokens in a document,
    however in extreme cases it becomes quadratic due to memory exhaustion.
    Parsing happens before validation, so even invalid queries can burn lots of
    CPU time and memory. To prevent this, you can set a maximum number of tokens
    allowed within a document using the ``max_tokens`` parameter.

    Legacy feature (will be removed in v3.3):

    If ``allow_legacy_fragment_variables`` is set to ``True``, the parser will
    understand and parse variable definitions contained in a fragment definition.
    They'll be represented in the
    :attr:`~graphql.language.FragmentDefinitionNode.variable_definitions` field
    of the :class:`~graphql.language.FragmentDefinitionNode`.

    The syntax is identical to normal, query-defined variables. For example::

        fragment A($var: Boolean = false) on T  {
          ...
        }
    rQ   rR   rS   )Parserparse_document)rP   rQ   rR   rS   parser rY   n/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/language/parser.pyrK   I   s   "rK   c                 C   s6   t | |||d}|tj |d}|tj |S )ag  Parse the AST for a given string containing a GraphQL value.

    Throws GraphQLError if a syntax error is encountered.

    This is useful within tools that operate upon GraphQL Values directly and in
    isolation of complete GraphQL documents.

    Consider providing the results to the utility function:
    :func:`~graphql.utilities.value_from_ast`.
    rU   F)rV   expect_tokenrG   SOFparse_value_literalEOFrP   rQ   rR   rS   rX   valuerY   rY   rZ   rM   t   s   
rM   c                 C   4   t | |||d}|tj | }|tj |S )zParse the AST for a given string containing a GraphQL constant value.

    Similar to parse_value, but raises a arse error if it encounters a variable.
    The return type will be a constant value.
    rU   )rV   r[   rG   r\   parse_const_value_literalr^   r_   rY   rY   rZ   rN      s   rN   c                 C   ra   )ae  Parse the AST for a given string containing a GraphQL Type.

    Throws GraphQLError if a syntax error is encountered.

    This is useful within tools that operate upon GraphQL Types directly and
    in isolation of complete GraphQL documents.

    Consider providing the results to the utility function:
    :func:`~graphql.utilities.value_from_ast`.
    rU   )rV   r[   rG   r\   parse_type_referencer^   )rP   rQ   rR   rS   rX   type_rY   rY   rZ   rL      s   rL   c                   @   s8  e Zd ZU dZeed< eed< ee ed< eed< eed< 			dd	e	d
edee defddZ
defddZdefddZdddddddddZeeef ed< i eddd d!d"Zeeef ed#< defd$d%Zdefd&d'Zdefd(d)Zdee fd*d+Zdefd,d-Zdefd.d/Z de!fd0d1Z"de#fd2d3Z$de%fd4d5Z&d6edee' fd7d8Z(dd6ede'fd9d:Z)de*fd;d<Z+de,e-e.f fd=d>Z/de0fd?d@Z1defdAdBZ2de3fdCdDZ4e5j6dEe5j7dFe5j8dGe5j9dHe5j:dIe5j;dIe5j<dJe5j=dKiZ>ee5ef edL< d6ede?fdMdNZ@ddOedeAfdPdQZBd6edeCfdRdSZDd6edeEfdTdUZFd6edeGfdVdWZHddOedeIfdXdYZJddOedeKfdZd[ZLddOede?fd\d]ZMd6edefd^d_ZNdeOfd`daZPd6edeeQ fdbdcZRdeeS fdddeZTd6edeQfdfdgZUdeVfdhdiZWde3fdjdkZXdldmdndodpdqdrdsZYeeef edt< deZfdudvZ[defdwdxZ\deeA fdydzZ]de^fd{d|Z_de`fd}d~ZadebfddZcdedfddZedee3 fddZfdeeg fddZhdegfddZideej fddZkdejfddZldemfddZndeofddZpdee3 fddZqderfddZsdeet fddZudetfddZvdefddZwdexfddZydeej fddZzde{fddZ|de}fddZ~defddZdefddZdefddZdefddZdefddZdefddZdee fddZdefddZdedee fddZde5defddZde5defddZde5defddZdeddfddZdedefddZddee defddĄZde5deg ef de5dee fddɄZde5deg ef de5dee fdd˄Zde5deg ef de5dee fdd̈́Zde5deg ef dee fddЄZddd҄ZdS )rV   a  GraphQL AST parser.

    This class is exported only to assist people in implementing their own parsers
    without duplicating too much code and should be used only as last resort for cases
    such as experimental syntax or if certain features couldn't be contributed upstream.

    It's still part of the internal API and is versioned, so any changes to it are never
    considered breaking changes. If you still need to support multiple versions of the
    library, please use the `__version_info__` variable for version detection.
    _lexer_no_location_max_tokens _allow_legacy_fragment_variables_token_counterFNrP   rQ   rR   rS   c                 C   sF   t |r	tt|nttt|}t|| _|| _|| _|| _d| _	d S )Nr   )
rF   r   rE   strrC   re   rf   rg   rh   ri   )selfrP   rQ   rR   rS   rY   rY   rZ   __init__   s   

zParser.__init__rT   c                 C   s    |  tj}t|j| |dS )z0Convert a name lex token into a name parse node.r`   loc)r[   rG   NAMEr'   r`   rn   )rk   tokenrY   rY   rZ   
parse_name   s   zParser.parse_namec                 C   *   | j j}t| tj| jtj| |dS )zDocument: Definition+)definitionsrn   )	re   rp   r   manyrG   r\   parse_definitionr^   rn   rk   startrY   rY   rZ   rW      s
   zParser.parse_documentschema_definitionscalar_type_definitionobject_type_definitioninterface_type_definitionunion_type_definitionenum_type_definitioninput_object_type_definitiondirective_definition)schemascalartype	interfaceunionenuminput	directive*_parse_type_system_definition_method_names)querymutationsubscriptionoperation_definitionfragment_definitiontype_system_extension)fragmentextend$_parse_other_definition_method_namesc                 C   s   |  tjr
|  S |  }|r| j n| jj}|jtj	u rTt
t|j}| j|}|r6t| d|  S |rCt| jj| jjjd| j|}|rTt| d|  S | |)a  Definition: ExecutableDefinition or TypeSystemDefinition/Extension

        ExecutableDefinition: OperationDefinition or FragmentDefinition

        TypeSystemDefinition: SchemaDefinition, TypeDefinition or DirectiveDefinition

        TypeDefinition: ScalarTypeDefinition, ObjectTypeDefinition,
            InterfaceTypeDefinition, UnionTypeDefinition,
            EnumTypeDefinition or InputObjectTypeDefinition
        parse_zLUnexpected description, descriptions are supported only on type definitions.)peekrG   BRACE_Lparse_operation_definitionpeek_descriptionre   	lookaheadrp   kindro   r   rj   r`   r   getgetattrrJ   rP   rw   r   
unexpected)rk   has_descriptionkeyword_token
token_namemethod_namerY   rY   rZ   ru     s,   
zParser.parse_definitionc              	   C   s|   | j j}| tjrttjdg g |  | 	|dS | 
 }| tjr(|  nd}t|||  | d|  | 	|dS )OperationDefinitionN)	operationnamevariable_definitions
directivesselection_setrn   F)re   rp   r   rG   r   r/   r0   QUERYparse_selection_setrn   parse_operation_typero   rq   parse_variable_definitionsparse_directives)rk   rw   r   r   rY   rY   rZ   r   2  s(   z!Parser.parse_operation_definitionc                 C   s2   |  tj}zt|jW S  ty   | |w )z1OperationType: one of query mutation subscription)r[   rG   ro   r0   r`   
ValueErrorr   )rk   operation_tokenrY   rY   rZ   r   I  s   
zParser.parse_operation_typec                 C      |  tj| jtjS )z*VariableDefinitions: (VariableDefinition+))optional_manyrG   PAREN_Lparse_variable_definitionPAREN_Rrk   rY   rY   rZ   r   Q     z!Parser.parse_variable_definitionsc                 C   sL   | j j}t|  | tjo|  | tj	r| 
 nd|  | |dS )zCVariableDefinition: Variable: Type DefaultValue? Directives[Const]?N)variabler   default_valuer   rn   )re   rp   r>   parse_variabler[   rG   COLONrc   expect_optional_tokenEQUALSrb   parse_const_directivesrn   rv   rY   rY   rZ   r   W  s   

z Parser.parse_variable_definitionc                 C   s*   | j j}| tj t|  | |dS )zVariable: $Namer   rn   )re   rp   r[   rG   DOLLARr?   rq   rn   rv   rY   rY   rZ   r   f  s   zParser.parse_variablec                 C   rr   )zSelectionSet: {Selection+})
selectionsrn   )	re   rp   r7   rt   rG   r   parse_selectionBRACE_Rrn   rv   rY   rY   rZ   r   l  s   zParser.parse_selection_setc                 C   s   |  tjr
| j S | j S )z4Selection: Field or FragmentSpread or InlineFragment)r   rG   SPREADparse_fragmentparse_fieldr   rY   rY   rZ   r   v  s   zParser.parse_selectionc              	   C   sl   | j j}|  }| tjr|}|  }nd}|}t||| d| d| 	tj
r.|  nd| |dS )z7Field: Alias? Name Arguments? Directives? SelectionSet?NF)aliasr   	argumentsr   r   rn   )re   rp   rq   r   rG   r   r   parse_argumentsr   r   r   r   rn   )rk   rw   name_or_aliasr   r   rY   rY   rZ   r   |  s   
zParser.parse_fieldis_constc                 C   s4   |r| j n| j}ttg tf |}| tj|tjS )z%Arguments[Const]: (Argument[?Const]+))	parse_const_argumentparse_argumentr   r   r   r   rG   r   r   )rk   r   itemrY   rY   rZ   r     s   zParser.parse_argumentsc                 C   6   | j j}|  }| tj t|| || |dS )z%Argument[Const]: Name : Value[?Const]r   r`   rn   )	re   rp   rq   r[   rG   r   r   r]   rn   rk   r   rw   r   rY   rY   rZ   r     s   zParser.parse_argumentc                 C      t t| dS )z$Argument[Const]: Name : Value[Const]T)r   r   r   r   rY   rY   rZ   r        zParser.parse_const_argumentc                 C   sx   | j j}| tj | d}|s&| tjr&t| 	 | 
d| |dS t|r-|  nd| 
d|  | |dS )zCorresponds to both FragmentSpread and InlineFragment in the spec.

        FragmentSpread: ... FragmentName Directives?
        InlineFragment: ... TypeCondition? Directives? SelectionSet
        onFr   r   rn   N)type_conditionr   r   rn   )re   rp   r[   rG   r   expect_optional_keywordr   ro   r   parse_fragment_namer   rn   r   parse_named_typer   )rk   rw   has_type_conditionrY   rY   rZ   r     s   
zParser.parse_fragmentc              	   C   sr   | j j}| d | jr$t|  |  |  | d| 	 | 
|dS t|  |  | d| 	 | 
|dS )FragmentDefinitionr   F)r   r   r   r   r   rn   )r   r   r   r   rn   )re   rp   expect_keywordrh   r   r   r   parse_type_conditionr   r   rn   rv   rY   rY   rZ   parse_fragment_definition  s$   
z Parser.parse_fragment_definitionc                 C   s   | j jjdkr|  |  S )z!FragmentName: Name but not ``on``r   )re   rp   r`   r   rq   r   rY   rY   rZ   r     s   zParser.parse_fragment_namec                 C   s   |  d |  S )zTypeCondition: NamedTyper   )r   r   r   rY   rY   rZ   r     s   
zParser.parse_type_conditionlistobjectintfloatstring_literalnamed_valuesvariable_value!_parse_value_literal_method_namesc                 C   s2   | j | jjj}|rt| d| |S |  )Nr   )r   r   re   rp   r   r   r   )rk   r   r   rY   rY   rZ   r]     s   zParser.parse_value_literal	_is_constc                 C   s.   | j j}|   t|j|jtjk| |dS )N)r`   blockrn   )	re   rp   advance_lexerr8   r`   r   rG   BLOCK_STRINGrn   rk   r   rp   rY   rY   rZ   parse_string_literal  s   
zParser.parse_string_literalc                 C   4   | j j}t| j|}t| tj|tj| 	|dS )zListValue[Const])valuesrn   )
re   rp   r	   r]   r%   anyrG   	BRACKET_L	BRACKET_Rrn   rk   r   rw   r   rY   rY   rZ   
parse_list  s   zParser.parse_listc                 C   r   )Nr   )	re   rp   rq   r[   rG   r   r+   r]   rn   r   rY   rY   rZ   parse_object_field  s   zParser.parse_object_fieldc                 C   r   )zObjectValue[Const])fieldsrn   )
re   rp   r	   r   r.   r   rG   r   r   rn   r   rY   rY   rZ   parse_object  s   zParser.parse_objectc                 C   $   | j j}|   t|j| |dS Nrm   )re   rp   r   r!   r`   rn   r   rY   rY   rZ   	parse_int     zParser.parse_intc                 C   r   r   )re   rp   r   r   r`   rn   r   rY   rY   rZ   parse_float  r   zParser.parse_floatc                 C   st   | j j}|j}|   |dkrtd| |dS |dkr%td| |dS |dkr1t| |dS t|| |dS )NtrueTrm   falseFnull)rn   )re   rp   r`   r   r   rn   r*   r   )rk   r   rp   r`   rY   rY   rZ   parse_named_values"  s   zParser.parse_named_valuesc                 C   sV   |r'|  tj}| jj}|jtju r"|j}t| jj	|j
d| d| ||  S )NzUnexpected variable '$z' in constant value.)r[   rG   r   re   rp   r   ro   r`   rJ   rP   rw   r   r   )rk   r   variable_tokenrp   var_namerY   rY   rZ   parse_variable_value.  s   

zParser.parse_variable_valuec                 C   r   NT)r   r   r]   r   rY   rY   rZ   rb   <  s   z Parser.parse_const_value_literalc                 C   s4   g }|j }| tjr|| | | tjs|S )z%Directives[Const]: Directive[?Const]+)appendr   rG   ATparse_directive)rk   r   r   r   rY   rY   rZ   r   A  s   zParser.parse_directivesc                 C   s   t tt | dS r   )r   r   r   r   r   rY   rY   rZ   r   I  s   zParser.parse_const_directivesc                 C   s2   | j j}| tj t|  | || |dS )z+Directive[Const]: @ Name Arguments[?Const]?)r   r   rn   )	re   rp   r[   rG   r  r   rq   r   rn   )rk   r   rw   rY   rY   rZ   r  L  s   zParser.parse_directivec                 C   sf   | j j}| tjr|  }| tj t|| 	|d}n| 
 }| tjr1t|| 	|dS |S )z*Type: NamedType or ListType or NonNullType)r   rn   )re   rp   r   rG   r   rc   r[   r   r$   rn   r   BANGr)   )rk   rw   
inner_typerd   rY   rY   rZ   rc   X  s   zParser.parse_type_referencec                 C   s   | j j}t|  | |dS )zNamedType: Namer   )re   rp   r(   rq   rn   rv   rY   rY   rZ   r   f  s   zParser.parse_named_typeschema_extensionscalar_type_extensionobject_type_extensioninterface_type_extensionunion_type_extensionenum_type_extensioninput_object_type_extension)r   r   r   r   r   r   r   "_parse_type_extension_method_namesc                 C   sJ   | j  }|jtjkr | jtt|j	}|r t
| d|  S | |)TypeSystemExtensionr   )re   r   r   rG   ro   r  r   r   rj   r`   r   r   )rk   r   r   rY   rY   rZ   parse_type_system_extensionw  s   


z"Parser.parse_type_system_extensionc                 C   s   |  tjp|  tjS N)r   rG   STRINGr   r   rY   rY   rZ   r     s   zParser.peek_descriptionc                 C   s   |   r|  S dS )zDescription: StringValueN)r   r   r   rY   rY   rZ   parse_description  s   zParser.parse_descriptionc                 C   sL   | j j}|  }| d |  }| tj| jtj	}t
|||| |dS )SchemaDefinitionr   )descriptionr   operation_typesrn   )re   rp   r  r   r   rt   rG   r   parse_operation_type_definitionr   r4   rn   )rk   rw   r  r   r  rY   rY   rZ   parse_schema_definition  s   
zParser.parse_schema_definitionc                 C   s8   | j j}|  }| tj |  }t||| |dS )z2OperationTypeDefinition: OperationType : NamedType)r   r   rn   )	re   rp   r   r[   rG   r   r   r1   rn   )rk   rw   r   rd   rY   rY   rZ   r    s   z&Parser.parse_operation_type_definitionc                 C   s@   | j j}|  }| d |  }|  }t|||| |dS )zAScalarTypeDefinition: Description? scalar Name Directives[Const]?r   r  r   r   rn   )re   rp   r  r   rq   r   r2   rn   rk   rw   r  r   r   rY   rY   rZ   parse_scalar_type_definition  s   
z#Parser.parse_scalar_type_definitionc              	   C   T   | j j}|  }| d |  }|  }|  }|  }t|||||| 	|dS )ObjectTypeDefinitionr   r  r   
interfacesr   r   rn   )
re   rp   r  r   rq   parse_implements_interfacesr   parse_fields_definitionr,   rn   rk   rw   r  r   r  r   r   rY   rY   rZ   parse_object_type_definition     
z#Parser.parse_object_type_definitionc                 C   s   |  dr| tj| jS g S )ImplementsInterfaces
implements)r   delimited_manyrG   AMPr   r   rY   rY   rZ   r    s
   z"Parser.parse_implements_interfacesc                 C   r   )z$FieldsDefinition: {FieldDefinition+})r   rG   r   parse_field_definitionr   r   rY   rY   rZ   r    r   zParser.parse_fields_definitionc              	   C   sV   | j j}|  }|  }|  }| tj |  }| 	 }t
|||||| |dS )FieldDefinition)r  r   r   r   r   rn   )re   rp   r  rq   parse_argument_defsr[   rG   r   rc   r   r   rn   )rk   rw   r  r   argsrd   r   rY   rY   rZ   r'    s   zParser.parse_field_definitionc                 C   r   )z,ArgumentsDefinition: (InputValueDefinition+))r   rG   r   parse_input_value_defr   r   rY   rY   rZ   r)    r   zParser.parse_argument_defsc              	   C   sf   | j j}|  }|  }| tj |  }| tj	r | 
 nd}|  }t|||||| |dS )InputValueDefinitionN)r  r   r   r   r   rn   )re   rp   r  rq   r[   rG   r   rc   r   r   rb   r   r    rn   )rk   rw   r  r   rd   r   r   rY   rY   rZ   r+    s$   

zParser.parse_input_value_defc              	   C   r  )InterfaceTypeDefinitionr   r  )
re   rp   r  r   rq   r  r   r  r"   rn   r   rY   rY   rZ   parse_interface_type_definition  r"  z&Parser.parse_interface_type_definitionc                 C   J   | j j}|  }| d |  }|  }|  }t||||| |dS )UnionTypeDefinitionr   )r  r   r   typesrn   )	re   rp   r  r   rq   r   parse_union_member_typesr;   rn   )rk   rw   r  r   r   r1  rY   rY   rZ   parse_union_type_definition     
z"Parser.parse_union_type_definitionc                 C   s    |  tjr| tj| jS g S )UnionMemberTypes)r   rG   r   r%  PIPEr   r   rY   rY   rZ   r2  #  s
   
zParser.parse_union_member_typesc                 C   r/  )r0  r   )r  r   r   r   rn   )	re   rp   r  r   rq   r   parse_enum_values_definitionr   rn   )rk   rw   r  r   r   r   rY   rY   rZ   parse_enum_type_definition+  r4  z!Parser.parse_enum_type_definitionc                 C   r   )z,EnumValuesDefinition: {EnumValueDefinition+})r   rG   r   parse_enum_value_definitionr   r   rY   rY   rZ   r7  ;  r   z#Parser.parse_enum_values_definitionc                 C   s6   | j j}|  }|  }|  }t|||| |dS )z>EnumValueDefinition: Description? EnumValue Directives[Const]?r  )re   rp   r  parse_enum_value_namer   r   rn   r  rY   rY   rZ   r9  A  s   z"Parser.parse_enum_value_definitionc                 C   s:   | j jjdv rt| j j| j jjt| j j d|  S )z7EnumValue: Name but not ``true``, ``false`` or ``null``)r   r   r   z2 is reserved and cannot be used for an enum value.)re   rp   r`   rJ   rP   rw   get_token_descrq   r   rY   rY   rZ   r:  N  s   zParser.parse_enum_value_namec                 C   r/  )InputObjectTypeDefinitionr   )r  r   r   r   rn   )	re   rp   r  r   rq   r   parse_input_fields_definitionr   rn   )rk   rw   r  r   r   r   rY   rY   rZ   "parse_input_object_type_definitionY  r4  z)Parser.parse_input_object_type_definitionc                 C   r   )z.InputFieldsDefinition: {InputValueDefinition+})r   rG   r   r+  r   r   rY   rY   rZ   r=  i  r   z$Parser.parse_input_fields_definitionc                 C   s\   | j j}| d | d |  }| tj| jtj}|s$|s$| 	 t
||| |dS )SchemaExtensionr   r   )r   r  rn   )re   rp   r   r   r   rG   r   r  r   r   r5   rn   )rk   rw   r   r  rY   rY   rZ   parse_schema_extensiono  s   

zParser.parse_schema_extensionc                 C   sL   | j j}| d | d |  }|  }|s|  t||| |dS )ScalarTypeExtensionr   r   r   )re   rp   r   rq   r   r   r3   rn   )rk   rw   r   r   rY   rY   rZ   parse_scalar_type_extension~  s   

z"Parser.parse_scalar_type_extensionc                 C   h   | j j}| d | d |  }|  }|  }|  }|s(|s(|s(|  t||||| 	|dS )ObjectTypeExtensionr   r   r   r  r   r   rn   )
re   rp   r   rq   r  r   r  r   r-   rn   rk   rw   r   r  r   r   rY   rY   rZ   parse_object_type_extension      

z"Parser.parse_object_type_extensionc                 C   rC  )InterfaceTypeExtensionr   r   rE  )
re   rp   r   rq   r  r   r  r   r#   rn   rF  rY   rY   rZ   parse_interface_type_extension  rH  z%Parser.parse_interface_type_extensionc                 C   Z   | j j}| d | d |  }|  }|  }|s"|s"|  t|||| |dS )UnionTypeExtensionr   r   )r   r   r1  rn   )	re   rp   r   rq   r   r2  r   r<   rn   )rk   rw   r   r   r1  rY   rY   rZ   parse_union_type_extension     

z!Parser.parse_union_type_extensionc                 C   rK  )EnumTypeExtensionr   r   )r   r   r   rn   )	re   rp   r   rq   r   r7  r   r   rn   )rk   rw   r   r   r   rY   rY   rZ   parse_enum_type_extension  rN  z Parser.parse_enum_type_extensionc                 C   rK  )InputObjectTypeExtensionr   r   )r   r   r   rn   )	re   rp   r   rq   r   r=  r   r   rn   )rk   rw   r   r   r   rY   rY   rZ   !parse_input_object_type_extension  rN  z(Parser.parse_input_object_type_extensionc              	   C   sl   | j j}|  }| d | tj |  }|  }| 	d}| d | 
 }t|||||| |dS )DirectiveDefinitionr   
repeatabler   )r  r   r   rT  	locationsrn   )re   rp   r  r   r[   rG   r  rq   r)  r   parse_directive_locationsr   rn   )rk   rw   r  r   r*  rT  rU  rY   rY   rZ   parse_directive_definition  s"   


z!Parser.parse_directive_definitionc                 C   s   |  tj| jS )DirectiveLocations)r%  rG   r6  parse_directive_locationr   rY   rY   rZ   rV    r   z Parser.parse_directive_locationsc                 C   s*   | j j}|  }|jtjv r|S | |r@   )re   rp   rq   r`   rA   __members__r   )rk   rw   r   rY   rY   rZ   rY    s
   
zParser.parse_directive_locationstart_tokenc                 C   s&   | j s| jj}| jj}t|||S dS )zxReturn a location object.

        Used to identify the place in the source that created a given parsed object.
        N)rf   re   
last_tokenrP   r&   )rk   r[  	end_tokenrP   rY   rY   rZ   rn     s
   z
Parser.locr   c                 C   s   | j jj|kS )z.Determine if the next token is of a given kind)re   rp   r   )rk   r   rY   rY   rZ   r     s   zParser.peekc                 C   sF   | j j}|j|kr|   |S t| j j|jdt| dt| d)zExpect the next token to be of the given kind.

        If the next token is of the given kind, return that token after advancing the
        lexer. Otherwise, do not change the parser state and throw an error.
        z	Expected z, found .)	re   rp   r   r   rJ   rP   rw   get_token_kind_descr;  rk   r   rp   rY   rY   rZ   r[     s   
zParser.expect_tokenc                 C   s"   | j j}|j|kr|   dS dS )zExpect the next token optionally to be of the given kind.

        If the next token is of the given kind, return True after advancing the lexer.
        Otherwise, do not change the parser state and return False.
        TF)re   rp   r   r   r`  rY   rY   rZ   r     s
   
zParser.expect_optional_tokenr`   c                 C   sN   | j j}|jtjkr|j|kr|   dS t| j j|j	d| dt
| d)zExpect the next token to be a given keyword.

        If the next token is a given keyword, advance the lexer.
        Otherwise, do not change the parser state and throw an error.
        z
Expected 'z	', found r^  N)re   rp   r   rG   ro   r`   r   rJ   rP   rw   r;  rk   r`   rp   rY   rY   rZ   r   *  s   zParser.expect_keywordc                 C   s.   | j j}|jtjkr|j|kr|   dS dS )zExpect the next token optionally to be a given keyword.

        If the next token is a given keyword, return True after advancing the lexer.
        Otherwise, do not change the parser state and return False.
        TF)re   rp   r   rG   ro   r`   r   ra  rY   rY   rZ   r   :  s
   zParser.expect_optional_keywordat_tokenc                 C   s*   |p| j j}t| j j|jdt| dS )z>Create an error when an unexpected lexed token is encountered.zUnexpected r^  )re   rp   rJ   rP   rw   r;  )rk   rb  rp   rY   rY   rZ   r   G  s   zParser.unexpected	open_kindparse_fn
close_kindc                 C   s:   |  | g }|j}t| j|}| s||  | r|S )aC  Fetch any matching nodes, possibly none.

        Returns a possibly empty list of parse nodes, determined by the ``parse_fn``.
        This list begins with a lex token of ``open_kind`` and ends with a lex token of
        ``close_kind``. Advances the parser to the next lex token after the closing
        token.
        r[   r   r	   r   rk   rc  rd  re  nodesr   r   rY   rY   rZ   r   N  s   


z
Parser.anyc                 C   sB   |  |r| g}|j}t| j |}| s||  | r|S g S )a  Fetch matching nodes, maybe none.

        Returns a list of parse nodes, determined by the ``parse_fn``. It can be empty
        only if the open token is missing, otherwise it will always return a non-empty
        list that begins with a lex token of ``open_kind`` and ends with a lex token of
        ``close_kind``. Advances the parser to the next lex token after the closing
        token.
        )r   r   r	   rg  rY   rY   rZ   r   `  s   

zParser.optional_manyc                 C   s>   |  | | g}|j}t| j|}| s||  | r|S )a9  Fetch matching nodes, at least one.

        Returns a non-empty list of parse nodes, determined by the ``parse_fn``. This
        list begins with a lex token of ``open_kind`` and ends with a lex token of
        ``close_kind``. Advances the parser to the next lex token after the closing
        token.
        rf  rg  rY   rY   rZ   rt   t  s   


zParser.manydelimiter_kindc                 C   s6   t | j|}|  g }|j}	 ||  | s	 |S q)aU  Fetch many delimited nodes.

        Returns a non-empty list of parse nodes, determined by the ``parse_fn``. This
        list may begin with a lex token of ``delimiter_kind`` followed by items
        separated by lex tokens of ``delimiter_kind``. Advances the parser to the next
        lex token after the last item in the list.
        )r	   r   r   )rk   ri  rd  r   rh  r   rY   rY   rZ   r%    s   

zParser.delimited_manyc                 C   sb   | j }| j }|d ur+|jtjkr-|  jd7  _| j|kr/t| jj|j	d| dd S d S d S )Nr
   zDocument contains more than z tokens. Parsing aborted.)
rg   re   advancer   rG   r^   ri   rJ   rP   rw   )rk   rR   rp   rY   rY   rZ   r     s   


zParser.advance_lexerFNF)Fr  )rT   N)__name__
__module____qualname____doc__rC   __annotations__boolr   r   
SourceTyperl   r'   rq   r   rW   r   r   rj   dictfromkeysr   r   ru   r/   r   r0   r   r   r>   r   r   r?   r   r7   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r   rG   r   r   INTFLOATr  r   ro   r   r   r=   r]   r8   r   r%   r   r+   r   r.   r   r!   r   r   r   r   r   r   rb   r   r   r   r   r  r9   rc   r   r  r:   r  r   r  r4   r  r1   r  r2   r  r,   r!  r  r   r  r'  r    r)  r+  r"   r.  r;   r3  r2  r   r8  r   r7  r9  r:  r   r>  r=  r5   r@  r3   rB  r-   rG  r#   rJ  r<   rM  r   rP  r   rR  r   rW  rV  rY  rB   r&   rn   r   r[   r   r   r   rI   r   r   rO   r   r   rt   r%  r   rY   rY   rY   rZ   rV      s:  
 
	
,

	
		










rV   rp   c                 C   s*   | j }t| j|durd| d S d S )z+Describe a token as a string for debugging.Nz '' )r`   r_  r   )rp   r`   rY   rY   rZ   r;    s   r;  r   c                 C   s   t | rd| j dS | jS )z0Describe a token kind as a string for debugging.rw  )rD   r`   )r   rY   rY   rZ   r_    s   r_  rk  )[typingr   r   r   r   r   r   r   	functoolsr	   astr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   directive_locationsrA   rB   lexerrC   rD   rP   rE   rF   
token_kindrG   errorrI   rJ   __all__rO   rj   rr  rq  r   rK   rM   rN   rL   rV   r;  r_  rY   rY   rY   rZ   <module>   s   $ 7
-


       m