a
    ;@b_                     @   s   d Z ddlmZmZmZmZ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 g dZG dd deZG dd deZG d	d
 d
eZG dd deZG dd deZdS )z
    pygments.lexers.data
    ~~~~~~~~~~~~~~~~~~~~

    Lexers for data file format.

    :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    )LexerExtendedRegexLexerLexerContextincludebygroups)
TextCommentKeywordNameStringNumberPunctuationLiteralError
Whitespace)	YamlLexer	JsonLexerJsonBareObjectLexerJsonLdLexerc                       s    e Zd ZdZ fddZ  ZS )YamlLexerContextz'Indentation context for the YAML lexer.c                    s.   t  j|i | g | _d| _d| _d | _d S Nr   )super__init__indent_stackindentnext_indentblock_scalar_indent)selfargskwds	__class__ 3lib/python3.9/site-packages/pygments/lexers/data.pyr      s
    zYamlLexerContext.__init__)__name__
__module____qualname____doc__r   __classcell__r#   r#   r!   r$   r      s   r   c                       s  e Zd ZdZdZdgZddgZdgZdd Zd	d
 Z	dhddZ
diddZdd Zdd Zdd Zdd Zdefdefdejfde	ejdfde	ejdfde	ejd fd!e
ed"d#d$fgdefdejfd%ed&fgd'eeed(fgd)eeejeejd(fgd*eed&fd+e
efd,eejfd-e
ed.fgd/eed.fd0efd1eejeed"d2fed3ed4ed5d6eejd7fgd8ejfd9ejfd:ejfd;ejfgd<eejd"d2fd=ejd>fgd?ejd@fdAejdBfdCedDfdEedFfgd0efdefdejfdGejfed3ed5dHeejdIfgedJdKejd.fgdLeejefedJdMejd.fgd%efdNeeej fdOeefdPej fgdQeejd(fdReejd(fgdSefdTefdefd0ejfgedUdVej!fdWefdCed.fgedUdXefdYej!fdZefd[ed.fgdNefdefd\eejd]fdOeed.fgd^eed.fd_ed.fdTefded`fd0e"j#j$fdae"j#j$fgdbeed.fd_ed.fdSefdTefdefd0ejfdcejfgddZ%dj fdfdg	Z&  Z'S )kr   z}
    Lexer for `YAML <http://yaml.org/>`_, a human-friendly data serialization
    language.

    .. versionadded:: 0.11
    ZYAMLZyamlz*.yamlz*.ymlztext/x-yamlc                    s    fdd}|S )zDo not produce empty tokens.c                 3   s.   |  }|sd S |  |fV  | |_d S N)groupstartendposlexermatchcontexttexttoken_classr#   r$   callback-   s
    z%YamlLexer.something.<locals>.callbackr#   r5   r6   r#   r4   r$   	something+   s    zYamlLexer.somethingc                    s    fdd}|S )zReset the indentation levels.c                 3   s>   |  }g |_d|_d|_d |_|  |fV  | |_d S r   )r+   r   r   r   r   r,   r-   r.   r/   r4   r#   r$   r6   7   s    z(YamlLexer.reset_indent.<locals>.callbackr#   r7   r#   r4   r$   reset_indent5   s    zYamlLexer.reset_indentFc                    s    fdd}|S )z"Save a possible indentation level.c                 3   s   |  }d} rjt||_|j|jk r||j|jk r@|j |_q&|j|jkr|||jd  }|d |j }n| jt|7  _|r| |fV  |r| t| j|fV  | |_	d S )N )
r+   lenr   r   r   popr,   r   r-   r.   )r0   r1   r2   r3   Zextrar,   r5   r#   r$   r6   C   s     
z'YamlLexer.save_indent.<locals>.callbackr#   )r5   r,   r6   r#   r=   r$   save_indentA   s    zYamlLexer.save_indentc                    s    fdd}|S )z+Set the previously saved indentation level.c                 3   s^   |  }|j|jk r*|j|j |j|_ s@| jt|7  _| |fV  | |_d S r*   )	r+   r   r   r   appendr;   r,   r-   r.   r/   implicitr5   r#   r$   r6   Y   s    z&YamlLexer.set_indent.<locals>.callbackr#   )r5   rA   r6   r#   r@   r$   
set_indentW   s    	zYamlLexer.set_indentc                    s    fdd}|S )z5Set an explicit indentation level for a block scalar.c                 3   sd   |  }d |_|sd S | d}|rBt|jd}t|}|| |_|r`|  |fV  | |_d S )N   r   )r+   r   maxr   intr,   r-   r.   )r0   r1   r2   r3   Z	incrementcurrent_indentr4   r#   r$   r6   f   s    

z3YamlLexer.set_block_scalar_indent.<locals>.callbackr#   r7   r#   r4   r$   set_block_scalar_indentd   s    z!YamlLexer.set_block_scalar_indentc                    s    fdd}|S )z(Process an empty line in a block scalar.c                 3   s   |  }|jd u s t||jkr6|rx| |fV  nB|d |j }||jd  }| |fV  | |j  |fV  | |_d S r*   )r+   r   r;   r,   r-   r.   )r0   r1   r2   r3   indentationZcontentcontent_token_classindent_token_classr#   r$   r6   w   s    
z9YamlLexer.parse_block_scalar_empty_line.<locals>.callbackr#   )rK   rJ   r6   r#   rI   r$   parse_block_scalar_empty_lineu   s    z'YamlLexer.parse_block_scalar_empty_linec                    s    fdd}|S )z-Process indentation spaces in a block scalar.c                 3   s   |  }|jd u rJt|t|jdkr>|j  |j  d S t||_n&t||jk rp|j  |j  d S |r|  |fV  | |_	d S Nr   )
r+   r   r;   rD   r   stackr<   r,   r-   r.   r/   r4   r#   r$   r6      s    




z5YamlLexer.parse_block_scalar_indent.<locals>.callbackr#   r7   r#   r4   r$   parse_block_scalar_indent   s    z#YamlLexer.parse_block_scalar_indentc                    s    fdd}|S )z-Process indentation spaces in a plain scalar.c                 3   sP   |  }t||jkr.|j  |j  d S |rL|  |fV  | |_d S r*   )r+   r;   r   rN   r<   r,   r-   r.   r/   r4   r#   r$   r6      s    

z5YamlLexer.parse_plain_scalar_indent.<locals>.callbackr#   r7   r#   r4   r$   parse_plain_scalar_indent   s    	z#YamlLexer.parse_plain_scalar_indentz[ ]+(?=#|$)z\n+z#[^\n]*z^%YAML(?=[ ]|$)yaml-directivez^%TAG(?=[ ]|$)tag-directivez^(?:---|\.\.\.)(?=[ ]|$)
block-linez[ ]*(?!\s|$)T)r,   )rS   rH   z\nz#pop:2z([ ]+)([0-9]+\.[0-9]+)ignored-linez;([ ]+)(!|![\w-]*!)([ ]+)(!|!?[\w;/?:@&=+$,.!~*\'()\[\]%-]+)z[ ]*$z[ ]+(?=[?:-](?:[ ]|$))z[?:-](?=[ ]|$)z[ ]*z#popz[ ]*(?=#|$)z[ ]+z ([^#,:?\[\]{}"'\n]+)(:)(?=[ ]|$))rA   descriptorsblock-nodes
flow-nodesz'(?=[^\s?:,\[\]{}#&*!|>\'"%@`-]|[?:-]\S)plain-scalar-in-block-contextz!!<[\w#;/?:@&=+$,.!~*\'()\[\]%-]+>z+!(?:[\w-]+!)?[\w#;/?:@&=+$,.!~*\'()\[\]%-]*z&[\w-]+z\*[\w-]+z
:(?=[ ]|$)z[|>])block-scalar-contentblock-scalar-headerz\[flow-sequencez\{flow-mappingz\'single-quoted-scalarz\"double-quoted-scalarz[?:,]z(?=[^\s?:,\[\]{}#&*!|>\'"%@`])plain-scalar-in-flow-contextflow-collectionz\]z([^,:?\[\]{}"'\n]+)(:)(?=[ ]|$)z\}z^[ ]+$z^[ ]*z[\S\t ]+z([1-9])?[+-]?(?=[ ]|$)z[+-]?([1-9])?(?=[ ]|$)z^[ ]+z[ ]+$quoted-scalar-whitespacesz\'\'z[^\s\']+z\\[0abt\tn\nvfre "\\N_LP]z5\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})z	[^\s"\\]+"z^(?=---|\.\.\.)z#pop:3z[ ]*(?=:[ ]|:$)z	[ ]+(?=#)&plain-scalar-in-block-context-new-linez(?::(?!\s)|[^\s:])+z[ ]*(?=[,:?\[\]{}])z[^\s,:?\[\]{}]+)rootrT   rQ   rR   rH   rS   rU   rV   rW   r`   r[   r\   rY   rZ   ra   r]   r^   rc   rX   r_   Nc                    s    |d u rt |d}t ||S rM   )r   r   get_tokens_unprocessed)r   r3   r2   r!   r#   r$   re     s    
z YamlLexer.get_tokens_unprocessed)F)F)NN)(r%   r&   r'   r(   namealiases	filenames	mimetypesr8   r9   r>   rB   rG   rL   rO   rP   r   r   Singler
   Tag	Namespacer   r   r	   Typer   Z	Indicatorr   ZVariableZLabelr   ConstantZEscaper   ZScalarZPlaintokensre   r)   r#   r#   r!   r$   r      s0  




	










   	r   c                   @   sd   e Zd ZdZdZddgZddgZddgZed	Z	ed
Z
edZedZedZh dZdd ZdS )r   z>
    For JSON data structures.

    .. versionadded:: 1.5
    ZJSONjsonzjson-objectz*.jsonzPipfile.lockzapplication/jsonzapplication/json-objectz-0123456789z.eE+ZtruefalsenullZ0123456789abcdefABCDEFz{}[],>    
	c              	   c   s  d}d}d}d}d}d}d}d}	d}
g }t |D ]\}}|r|rh|| jv r^|d8 }|sfd}qd}d}q0|r|dkrzd}qd}q0|dkrd}q0|dkr0||
tj||
|d  f d}d}d}q0n|r|| jv rq0|r||
t||
| f n|
t||
| fV  d}n|r@|| jv r$q0|
tj	||
| fV  d}n|r|| j
v rVq0n|| jv rhd}q0|r|
tj||
| fV  n|
tj||
| fV  d}d}n,|	r|| jv rq0|
t||
| fV  d}	|}
|dkrd}q0|| jv rd}q0|d	v r|E d
H  |  d}q0|| j
v r>|E d
H  |  d}q0|dkr|D ]L\}}}|tu rn|||fV  n(|tju r|tj|fV  n|t|fV  qL|  d}	q0|| jv r|E d
H  |  d}	q0|E d
H  |  |
t|fV  q0|E d
H  |r|
t||
d
 fV  n|r0|
tj||
d
 fV  nr|rN|
tj||
d
 fV  nT|rl|
tj	||
d
 fV  n6|r|
t||
d
 fV  n|	r|
t||
d
 fV  d
S )zParse JSON data.Fr   rC   u   \Trb   >   tfnN:)	enumeratehexadecimalsr?   r   Doublewhitespacesr   	constantsr	   rn   integersfloatsr   ZFloatZIntegerpunctuationsr   clearr
   rk   r   )r   r3   Z	in_stringZ	in_escapeZin_unicode_escapeZin_whitespaceZin_constantZ	in_numberZin_floatZin_punctuationr,   Zqueuestop	characterZ_startZ_tokenZ_textr#   r#   r$   re     s    










z JsonLexer.get_tokens_unprocessedN)r%   r&   r'   r(   rf   rg   rh   ri   setr   r   r   r}   r   r   re   r#   r#   r#   r$   r     s   
r   c                   @   s    e Zd ZdZdZg Zg Zg ZdS )r   z
    For JSON data structures (with missing object curly braces).

    .. versionadded:: 2.2

    .. deprecated:: 2.8.0

       Behaves the same as `JsonLexer` now.
    ZJSONBareObjectN)r%   r&   r'   r(   rf   rg   rh   ri   r#   r#   r#   r$   r   ~  s
   
r   c                       sF   e Zd ZdZdZddgZdgZdgZdd d	D Z fd
dZ	  Z
S )r   zW
    For `JSON-LD <https://json-ld.org/>`_ linked data.

    .. versionadded:: 2.0
    zJSON-LDZjsonldzjson-ldz*.jsonldzapplication/ld+jsonc                 C   s   h | ]}d | qS )z"@%s"r#   ).0keywordr#   r#   r$   	<setcomp>  s   zJsonLdLexer.<setcomp>)base	containerr2   	directionZgraphidimportZincludedindexrp   languagelistZnestZnoneprefixZ	propagateZ	protectedreverser   typevalueversionZvocabc                 #   sL   t  |D ]:\}}}|tju r:|| jv r:|tj|fV  q|||fV  qd S r*   )r   re   r
   rk   json_ld_keywordsZ	Decorator)r   r3   r,   tokenr   r!   r#   r$   re     s    z"JsonLdLexer.get_tokens_unprocessed)r%   r&   r'   r(   rf   rg   rh   ri   r   re   r)   r#   r#   r!   r$   r     s   r   N)r(   Zpygments.lexerr   r   r   r   r   Zpygments.tokenr   r   r	   r
   r   r   r   r   r   r   __all__r   r   r   r   r   r#   r#   r#   r$   <module>   s   
0    K