o
    tBhK                     @   s  d dl mZmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZ dd	lmZ d
dgZG dd deZG dd
 d
Zeejejejejejejejejejejej ej!ej"ej#gZ$dede%fddZ&ejejejejejejejejejej ej!ej#ej"dZ'dddddddddZ(de)de*de*fddZ+d e)de*fd!d"Z,d e)de%fd#d$Z-de)d%e*de%fd&d'Z.d(S ))    )List
NamedTupleOptional   )GraphQLSyntaxError   )Token)dedent_block_string_lines)is_digitis_name_startis_name_continue)Source)	TokenKindLexeris_punctuator_token_kindc                   @   s"   e Zd ZU dZeed< eed< dS )EscapeSequencez6The string value and lexed size of an escape sequence.valuesizeN)__name__
__module____qualname____doc__str__annotations__int r   r   m/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/language/lexer.pyr      s   
 r   c                   @   s.  e Zd ZdZdefddZdefddZdefdd	Zd
e	de
fddZ	d*dede	de	dee
 def
ddZde	defddZde	defddZde	de
defddZde	de
de	fddZde	defddZde	defd d!Zde	defd"d#Zde	defd$d%Zde	defd&d'Zde	defd(d)ZdS )+r   a<  GraphQL Lexer

    A Lexer is a stateful stream generator in that every time it is advanced, it returns
    the next token in the Source. Assuming the source lexes, the final Token emitted by
    the lexer will be of kind EOF, after which the lexer will repeatedly return the same
    EOF token whenever called.
    sourcec                 C   s0   || _ ttjdddd | _| _d\| _| _dS )z:Given a Source object, initialize a Lexer for that source.r   )r   r   N)r   r   r   SOFtoken
last_tokenline
line_start)selfr   r   r   r   __init__   s   zLexer.__init__returnc                 C   s   | j | _|   }| _ |S )z7Advance the token stream to the next non-ignored token.)r   r    	lookahead)r#   r   r   r   r   advance#   s   zLexer.advancec                 C   sV   | j }|jtjkr)	 |jr|j}n| |j}||_||_|}|jtjkr(	 |S q
|S )zJLook ahead and return the next non-ignored token, but do not change state.)	r   kindr   EOFnextread_next_tokenendprevCOMMENT)r#   r   
next_tokenr   r   r   r&   )   s   zLexer.lookaheadlocationc                 C   s   | j j}|t|krtjjS || }d|  krdkr*n n|dkr$dS d| dS tt||r?|||d  dd	dn|}d	|d
S )a-  Print the code point at the given location.

        Prints the code point (or end of file reference) at a given location in a
        source for use in error messages.

        Printable ASCII is printed quoted, while other points are printed in Unicode
        code point form (ie. U+1234).
         ~"z'"''r   utf-16surrogatepasszU+04X)
r   bodylenr   r)   r   ordis_supplementary_code_pointencodedecode)r#   r0   r8   charpointr   r   r   print_code_point_at:   s   	zLexer.print_code_point_atNr(   startr,   r   c                 C   s&   | j }d| | j }t||||||S )z9Create a token with line and column location information.r   )r!   r"   r   )r#   r(   rA   r,   r   r!   colr   r   r   create_tokenT   s   zLexer.create_tokenc                 C   s  | j j}t|}|}||k r|| }|dv r|d7 }q
|dkr.|d7 }|  jd7  _|| _q
|dkrR||d |d  dkrC|d7 }n|d7 }|  jd7  _|| _q
|dkr[| |S |dkru||d |d  d	krp| |S | |S t	|}|r| 
|||d S t|s|d
kr| ||S t|r| |S |dkr||d |d  dkr| 
tj||d S |dkrdnt|st||rd| | dnd| | d}t| j ||| 
tj||S )a  Get the next token from the source starting at the given position.

        This skips over whitespace until it finds the next lexable token, then lexes
        punctuators immediately or calls the appropriate helper function for more
        complicated tokens.
        u    	,﻿r   
r   #r3      ""-.z..r4   zNUnexpected single quote character ('), did you mean to use a double quote (")?zUnexpected character: zInvalid character: )r   r8   r9   r!   r"   read_commentread_block_stringread_string_KIND_FOR_PUNCTgetrC   r
   read_numberr   	read_namer   SPREADis_unicode_scalar_valuer;   r@   r   r)   )r#   rA   r8   body_lengthpositionr>   r(   messager   r   r   r+   \   s\   





zLexer.read_next_tokenc                 C   s   | j j}t|}|d }||k r1|| }|dv rnt|r"|d7 }nt||r,|d7 }nn||k s| tj||||d | S )z*Read a comment token from the source file.r   
r   )r   r8   r9   rS   r;   rC   r   r.   r#   rA   r8   rT   rU   r>   r   r   r   rK      s&   


zLexer.read_comment
first_charc                 C   s  | j j}|}|}d}|dkr|d7 }|||d  }|dkr=|d7 }|||d  }t|r<t| j |d| | dn| ||}|||d  }|dkrkd}|d7 }|||d  }| ||}|||d  }|r|dv rd}|d7 }|||d  }|r|d	v r|d7 }|||d  }| ||}|||d  }|r|dkst|rt| j |d
| | d| |rtj	ntj
||||| S )zReads a number token from the source file.

        This can be either a FloatValue or an IntValue,
        depending on whether a FractionalPart or ExponentPart is encountered.
        FrI   r   0z*Invalid number, unexpected digit after 0: rJ   TEez+-(Invalid number, expected digit but got: )r   r8   r
   r   r@   read_digitsr   rC   r   FLOATINT)r#   rA   rY   r8   rU   r>   is_floatr   r   r   rP      sd   
zLexer.read_numberc                 C   sp   t |st| j|d| | d| jj}t|}|d }||k r6t || r6|d7 }||k r6t || s(|S )zGReturn the new position in the source after reading one or more digits.r\   rJ   r   )r
   r   r   r@   r8   r9   )r#   rA   rY   r8   rT   rU   r   r   r   r]      s   zLexer.read_digitsc           
      C   sL  | j j}t|}|d }|}g }|j}||k r|| }|dkr5||||  | tj||d d|S |dkru||||  ||d |d  dkrc||d |d  dkr^| |n	| 	|n| 
|}	||	j ||	j7 }|}q|d	v rzn%t|r|d7 }nt||r|d7 }nt| j |d
| | d||k st| j |d)z6Read a single-quote string token from the source file.r   r3    \r   urG   {rW   !Invalid character within String: rJ   Unterminated string.)r   r8   r9   appendrC   r   STRINGjoin#read_escaped_unicode_variable_width read_escaped_unicode_fixed_widthread_escaped_characterr   r   rS   r;   r   r@   )
r#   rA   r8   rT   rU   chunk_startr   rg   r>   escaper   r   r   rM     sV   


	



+zLexer.read_stringrU   c                 C   s   | j j}d}d}tdt|| }||k rV|||  }|d7 }|dkrE|dk s=d|  kr1dks>n d|  kr<d	ks>n ntt||S |d
> t|B }|dk rRn||k st| j |d||||   d)Nr   rG      r   }            "Invalid Unicode escape sequence: ''.)r   r8   minr9   r   chrread_hex_digitr   )r#   rU   r8   r?   r   max_sizer>   r   r   r   rj   ;  s*   ,z)Lexer.read_escaped_unicode_variable_widthc                 C   s   | j j}t||d }d|  krdks"n d|  kr dkr)n ntt|dS d|  kr3dkrfn n1||d |d	  d
krft||d	 }d|  krRdkrfn ntt|t| ddddS t| j |d|||d   d)Nr   r   rr   rs   rt      i   i     z\ui   i  r5   r6   ro   rv   rw   )r   r8   read_16_bit_hex_coder   ry   r<   r=   r   )r#   rU   r8   codetrailing_coder   r   r   rk   V  s&   .z&Lexer.read_escaped_unicode_fixed_widthc                 C   sJ   | j j}t||d  }|rt|dS t| j |d|||d   d)Nr   r   z$Invalid character escape sequence: 'rw   )r   r8   _ESCAPED_CHARSrO   r   r   )r#   rU   r8   r   r   r   r   rl   p  s   
zLexer.read_escaped_characterc              	   C   s  | j j}t|}| j}|d }|}d}g }||k r|| }	|	dkrZ||d |d  dkrZ|||| 7 }|| | tj||d dt	|}
|  j
t|d 7  _
|| _|
S |	dkr{||d |d  d	kr{|||| 7 }|d }|d7 }q|	d
v r|||| 7 }|| |	dkr||d |d  dkr|d7 }n|d7 }d}| }}qt|	r|d7 }nt||r|d7 }nt| j |d| | d||k st| j |d)z/Read a block string token from the source file.rG   ra   r3   r   rH   rD   rb   ru   z"""rW   rE   r   re   rJ   rf   )r   r8   r9   r"   rg   rC   r   BLOCK_STRINGri   r	   r!   rS   r;   r   r@   )r#   rA   r8   rT   r"   rU   rm   current_lineblock_linesr>   r   r   r   r   rL   {  s`    
 
 



2zLexer.read_block_stringc                 C   s\   | j j}t|}|d }||k r!|| }t|sn|d7 }||k s| tj||||| S )z7Read an alphanumeric + underscore name from the source.r   )r   r8   r9   r   rC   r   NAMErX   r   r   r   rQ     s   zLexer.read_name)N)r   r   r   r   r   r$   r   r'   r&   r   r   r@   r   r   rC   r+   rK   rP   r]   rM   r   rj   rk   rl   rL   rQ   r   r   r   r   r      s8    
E;6?r(   r%   c                 C   s   | t v S )z`Check whether the given token kind corresponds to a punctuator.

    For internal use only.
    )_punctuator_token_kinds)r(   r   r   r   r     s   )!$&():=@[]rd   rp   |r3   /rb   rD   rE   	)r3   r   rb   bfnrtr8   rU   c                 C   sH   t | | d> t | |d  d> B t | |d  d> B t | |d  B S )a_  Read a 16bit hexadecimal string and return its positive integer value (0-65535).

    Reads four hexadecimal characters and returns the positive integer that 16bit
    hexadecimal string represents. For example, "000f" will return 15, and "dead"
    will return 57005.

    Returns a negative number if any char was not a valid hexadecimal digit.
    ro   r   r}   r   ru   rG   )rz   )r8   rU   r   r   r   r~     s   r~   r>   c                 C   sr   d|   kr
dkrn nt | d S d|   krdkr$n nt | d S d|   kr.dkr7n d
S t | d	 S d
S )a
  Read a hexadecimal character and returns its positive integer value (0-15).

    '0' becomes 0, '9' becomes 9
    'A' becomes 10, 'F' becomes 15
    'a' becomes 10, 'f' becomes 15

    Returns -1 if the provided character code was not a valid hexadecimal digit.
    rZ   90   AF7   ar   W   )r:   r>   r   r   r   rz     s   	rz   c                 C   s0   d|   ko	dkn  pd|   kodkS   S )zCheck whether this is a Unicode scalar value.

    A Unicode scalar value is any Unicode code point except surrogate code
    points. In other words, the inclusive ranges of values 0x0000 to 0xD7FF and
    0xE000 to 0x10FFFF.
     u   ퟿u   u   􏿿r   r   r   r   r   rS   '  s   0rS   r0   c                 C   sV   z d| |   kodkn  od| |d    kodkW S   W S  t y*   Y dS w )z
    Check whether the current location is a supplementary code point.

    The GraphQL specification defines source text as a sequence of unicode scalar
    values (which Unicode defines to exclude surrogate code points).
    u   u   u   r   u   F)
IndexError)r8   r0   r   r   r   r;   1  s   r;   N)/typingr   r   r   errorr   astr   block_stringr	   character_classesr
   r   r   r   r   
token_kindr   __all__r   r   	frozensetBANGDOLLARAMPPAREN_LPAREN_RrR   COLONEQUALSAT	BRACKET_L	BRACKET_RBRACE_LPIPEBRACE_Rr   boolr   rN   r   r   r   r~   rz   rS   r;   r   r   r   r   <module>   st       8	
