o
    if                     @   s   d dl Z d dlZddlmZ ddlmZ eeZG dd dZ	edkrBe
  e	d	d
Zee j D ]Zedejejf  q5dS dS )    N   )lex   )JsonPathLexerErrorc                   @   s   e Zd ZdZd6ddZdd Zg dZdd	iZg d
ee	  Z
g dZdZdZdd Zdd ZdZdd Zdd Zdd Zdd Zdd ZdZdd Zdd  Zd!d" Zd#d$ Zd%d& ZdZd'd( Zd)d* Zd+d, Zd-d. Z d/d0 Z!d1d2 Z"d3d4 Z#d5S )7JsonPathLexerz*
    A Lexical analyzer for JsonPath.
    Fc                 C   s   || _ | jd u rtdd S )NzDocstrings have been removed! By design of PLY, jsonpath-rw requires docstrings. You must not use PYTHONOPTIMIZE=2 or python -OO.)debug__doc__r   )selfr    r
   T/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/vendor/jsonpath_ng/lexer.py__init__   s   
zJsonPathLexer.__init__c                 c   sh    t | | jtd}d|_d|_|| 	 | }|du rn|j|j |_|V  q|jdur2t	ddS )z]
        Maps a string to an iterator over tokens. In other words: [char] -> [token]
        )moduler   errorlogr   NTz.Unexpected EOF in string literal or identifier)
r   r   loggerlatest_newlinestring_valueinputtokenlexposcolr   )r	   string	new_lexertr
   r
   r   tokenize   s   

zJsonPathLexer.tokenize)*.[]()$,:|&~whereWHERE)	DOUBLEDOTNUMBERIDNAMED_OPERATOR))singlequote	exclusive)doublequoter-   )	backquoter-   z\.\.z 	c                 C   s   | j |jd|_|S )z[a-zA-Z_@][a-zA-Z0-9_@\-]*r*   )reserved_wordsgetvaluetyper	   r   r
   r
   r   t_ID?   s   zJsonPathLexer.t_IDc                 C   s   t |j|_|S )z-?\d+)intr2   r4   r
   r
   r   t_NUMBERD   s   zJsonPathLexer.t_NUMBER c                 C   $   |j j|j _d|j _|j d dS )'r8   r,   Nlexerr   string_startr   
push_stater4   r
   r
   r   t_singlequoteL      zJsonPathLexer.t_singlequotec                 C      |j  j|j7  _dS )z[^'\\]+Nr<   r   r2   r4   r
   r
   r   t_singlequote_contentR      z#JsonPathLexer.t_singlequote_contentc                 C      |j  j|jd 7  _dS z\\.r   NrB   r4   r
   r
   r   t_singlequote_escapeV      z"JsonPathLexer.t_singlequote_escapec                 C   &   |j j|_d|_d|j _|j   |S )r:   r*   Nr<   r   r2   r3   	pop_stater4   r
   r
   r   t_singlequote_endZ   
   

zJsonPathLexer.t_singlequote_endc                 C   &   t d|jj|j|jj |jd f )NzSError on line %s, col %s while lexing singlequoted field: Unexpected character: %s r   r   r<   linenor   r   r2   r4   r
   r
   r   t_singlequote_errorb      &z!JsonPathLexer.t_singlequote_errorc                 C   r9   )"r8   r.   Nr;   r4   r
   r
   r   t_doublequoteh   r@   zJsonPathLexer.t_doublequotec                 C   rA   )z[^"\\]+NrB   r4   r
   r
   r   t_doublequote_contentn   rD   z#JsonPathLexer.t_doublequote_contentc                 C   rE   rF   rB   r4   r
   r
   r   t_doublequote_escaper   rH   z"JsonPathLexer.t_doublequote_escapec                 C   rI   )rS   r*   NrJ   r4   r
   r
   r   t_doublequote_endv   rM   zJsonPathLexer.t_doublequote_endc                 C   rN   )NzSError on line %s, col %s while lexing doublequoted field: Unexpected character: %s r   rO   r4   r
   r
   r   t_doublequote_error~   rR   z!JsonPathLexer.t_doublequote_errorc                 C   r9   )`r8   r/   Nr;   r4   r
   r
   r   t_backquote   r@   zJsonPathLexer.t_backquotec                 C   rE   rF   rB   r4   r
   r
   r   t_backquote_escape   rH   z JsonPathLexer.t_backquote_escapec                 C   rA   )z[^`\\]+NrB   r4   r
   r
   r   t_backquote_content   rD   z!JsonPathLexer.t_backquote_contentc                 C   rI   )rY   r+   NrJ   r4   r
   r
   r   t_backquote_end   rM   zJsonPathLexer.t_backquote_endc                 C   rN   )NzTError on line %s, col %s while lexing backquoted operator: Unexpected character: %s r   rO   r4   r
   r
   r   t_backquote_error   rR   zJsonPathLexer.t_backquote_errorc                 C   s   |j  jd7  _|j|j _dS )z\nr   N)r<   rP   r   r   r4   r
   r
   r   	t_newline   s   zJsonPathLexer.t_newlinec                 C   rN   )Nz3Error on line %s, col %s: Unexpected character: %s r   rO   r4   r
   r
   r   t_error   rR   zJsonPathLexer.t_errorN)F)$__name__
__module____qualname__r   r   r   literalsr0   listvaluestokensstatest_DOUBLEDOTt_ignorer5   r7   t_singlequote_ignorer?   rC   rG   rL   rQ   t_doublequote_ignorerT   rU   rV   rW   rX   t_backquote_ignorerZ   r[   r\   r]   r^   r_   r`   r
   r
   r
   r   r      s@    
r   __main__T)r   z%-20s%s)sysloggingply.lexr   
exceptionsr   	getLoggerra   r   r   basicConfigr<   r   stdinreadr   printr2   r3   r
   r
   r
   r   <module>   s    
 
