
    Mh9)                        U d dl Z d dlZd dlmZmZmZ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mZ d dlmZ d dlmZ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l$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z,m-Z- i a.ee/df         e0d<    ed          Z1 G d dee1                   Z2 G d de2          Z3dddde/de/fdZ4dS )    N)GenericTypeVarUnionDictOptionalAny)Path)is_pypy)generate_grammar)split_linespython_bytes_to_unicodePythonVersionInfoparse_version_string)
DiffParser)tokenize_linestokenize)PythonTokenTypes)parser_cacheload_moduletry_to_save_module)
BaseParser)Parser)ErrorFinderConfig)pep8)FileIOKnownContentFileIO)RefactoringNormalizerNormalizerConfigGrammar_loaded_grammars_NodeTc                   *   e Zd ZU dZeed<   dZee         ed<   dZ	e
ed<    ej                    Zeed<   edddefd	Z	 dd
ddddddddeeef         deej        ef         dedeej        ef         dedefdZd Zd Zd Zd ZddZddZd ZdS )r   z
    :py:func:`parso.load_grammar` returns instances of this class.

    Creating custom none-python grammars by calling this is not supported, yet.

    :param text: A BNF representation of your grammar.
    _start_nonterminalN_error_normalizer_config_token_namespace_default_normalizer_config)parserdiff_parsertextc                    t          ||                                           | _        || _        || _        || _        t          j        |                    d                    	                                | _
        d S )N)token_namespacezutf-8)r   _get_token_namespace_pgen_grammar_parser
_tokenizer_diff_parserhashlibsha256encode	hexdigest_hashed)selfr)   	tokenizerr'   r(   s        M/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/parso/grammar.py__init__zGrammar.__init__'   sp    - 5577
 
 
 #'~dkk'&:&:;;EEGG    TF)error_recoverypathstart_symbolcache
diff_cache
cache_pathfile_iocoder<   r=   r@   rA   returnc                D   |||t          d          t          |t                    rt          |          }t          |t                    rt          |          }|| j        }|r|dk    rt          d          |"|t          |          }nt          ||          }|r"|j        t          | j
        ||          }	|	|	S ||                                }t          |          }t          |d          }
|r| j        t          d          	 t          | j
                 |j                 }|j        }	|j        }||
k    r|	S |                     | j        | j        |	                              ||
	          }t+          | j
        |||
|ot,           |
           |S # t.          $ r Y nw xY w|                     |
          }|                     | j        ||          }|                    |          }|s|r"t+          | j
        |||
|ot,           |
           |S )a  
        If you want to parse a Python file you want to start here, most likely.

        If you need finer grained control over the parsed instance, there will be
        other ways to access it.

        :param str code: A unicode or bytes string. When it's not possible to
            decode bytes to a string, returns a
            :py:class:`UnicodeDecodeError`.
        :param bool error_recovery: If enabled, any code will be returned. If
            it is invalid, it will be returned as an error node. If disabled,
            you will get a ParseError when encountering syntax errors in your
            code.
        :param str start_symbol: The grammar rule (nonterminal) that you want
            to parse. Only allowed to be used when error_recovery is False.
        :param str path: The path to the file you want to open. Only needed for caching.
        :param bool cache: Keeps a copy of the parser tree in RAM and on disk
            if a path is given. Returns the cached trees if the corresponding
            files on disk have not changed. Note that this stores pickle files
            on your file system (e.g. for Linux in ``~/.cache/parso/``).
        :param bool diff_cache: Diffs the cached python module against the new
            code and tries to parse only the parts that have changed. Returns
            the same (changed) module that is found in cache. Using this option
            requires you to not do anything anymore with the cached modules
            under that path, because the contents of it might change. This
            option is still somewhat experimental. If you want stability,
            please don't use it.
        :param bool cache_path: If given saves the parso cache in this
            directory. If not given, defaults to the default cache places on
            each platform.

        :return: A subclass of :py:class:`parso.tree.NodeOrLeaf`. Typically a
            :py:class:`parso.python.tree.Module`.
        Nz%Please provide either code or a path.
file_inputz"This is currently not implemented.)r@   T)keependsz?You have to define a diff parser to be able to use this option.)	old_lines	new_lines)picklingr@   )r;   start_nonterminal)tokens)	TypeError
isinstancestrr	   r#   NotImplementedErrorr   r   r<   r   r5   readr   r   r0   r   nodelinesr-   r/   updater   r
   KeyErrorr.   parse)r6   rB   r;   r<   r=   r>   r?   r@   rA   module_noderR   module_cache_itemrG   new_noderK   p	root_nodes                    r8   rU   zGrammar.parse1   s   X <DLW_CDDDdC   	::Dj#&& 	*j))J2L 	Lll::%&JKKK?| ,,,T488 	#W\-%dlG
SSSK&""<<<>>D&t,,D4000 	  ( !6 7 7 7 $0$>w|$L! 04-3	%%&&,,& &'#     #4<(E,1,A'k.8: : : :  %    ( ''LL)*  
 

 GG6G**	 	6J 	6t|Wi(-(=g+*46 6 6 6 s   F" "
F/.F/c                 6    | j         }|t          d          |S )Nz"The token namespace should be set.)r%   
ValueError)r6   nss     r8   r,   zGrammar._get_token_namespace   s#    ":ABBB	r:   c                 d    | j         t          d          |                     || j                   S )z
        Given a :py:class:`parso.tree.NodeOrLeaf` returns a generator of
        :py:class:`parso.normalizer.Issue` objects. For Python this is
        a list of syntax/indentation errors.
        Nz/No error normalizer specified for this grammar.)r$   r\   _get_normalizer_issues)r6   rQ   s     r8   iter_errorszGrammar.iter_errors   s5     (0NOOO**41NOOOr:   c                 F    t          |                              |          S N)r   walk)r6   	base_nodenode_to_str_maps      r8   refactorzGrammar.refactor   s    $_55::9EEEr:   c                 `    || j         }|t          d          |                    |           S )NzVYou need to specify a normalizer, because there's no default normalizer for this tree.)r&   r\   create_normalizer)r6   normalizer_configs     r8   _get_normalizerzGrammar._get_normalizer   sF    $ $ ? (  "P Q Q Q 224888r:   c                 V    |                      |          }|                    |          S )zs
        TODO this is not public, yet.
        The returned code will be normalized, e.g. PEP8 for Python.
        )rj   rc   r6   rQ   ri   
normalizers       r8   
_normalizezGrammar._normalize   s*    
 ))*;<<
t$$$r:   c                 d    |                      |          }|                    |           |j        S rb   )rj   rc   issuesrl   s       r8   r_   zGrammar._get_normalizer_issues   s1    ))*;<<
  r:   c                     | j         j                                        }d                    t	          |          d d                   dz   }d| j        j        d|dS )N    z ...<:>)r-   nonterminal_to_dfaskeysjoinlist	__class____name__)r6   nonterminalstxts      r8   __repr__zGrammar.__repr__   s\    )=BBDDhhtL))"1"-..7 N333SSS99r:   rb   )r|   
__module____qualname____doc__rN   __annotations__r$   r   r   r%   r   r   PEP8NormalizerConfigr&   r   r   r9   r   bytesosPathLiker   r!   rU   r,   r`   rf   rj   rn   r_   r    r:   r8   r   r      s          <@h'89@@@ c   3L43L3N3N 0NNN7At H H HS H H H H )-r ".2"&48 $r r r#u*%r "+s*+	r
  r  S 01r r *0r r r rh  	P 	P 	PF F F9 9 9% % % %! ! ! !
: : : : :r:   c                   P     e Zd Z e            ZeZdZdede	f fdZ
d Zd Z xZS )PythonGrammarrE   version_infobnf_textc                 ~    t                                          || j        t          t                     || _        d S )N)r7   r'   r(   )superr9   _tokenize_linesPythonParserr   r   )r6   r   r   r{   s      r8   r9   zPythonGrammar.__init__   sC    *"	 	 	
 	
 	
 )r:   c                 *    t          |fd| j        i|S )Nr   )r   r   )r6   rR   kwargss      r8   r   zPythonGrammar._tokenize_lines   s     eNN$2CNvNNNr:   c                 .    t          || j                  S )N)r   )r   r   )r6   rB   s     r8   	_tokenizezPythonGrammar._tokenize   s    4+<====r:   )r|   r   r   r   r$   r   r%   r#   r   rN   r9   r   r   __classcell__)r{   s   @r8   r   r      s        0022'%)%6 )# ) ) ) ) ) )O O O> > > > > > >r:   r   )versionr<   r   r<   c                 r   t          |           }|p/t          j                            dd|j        |j        d          }t          j                            t          j                            t                    |          }	 t          |         S # t          $ r 	 t          |          5 }|                                }ddd           n# 1 swxY w Y   t          ||          }t                              ||          cY S # t          $ r# d|j        d|j        d}t          |          w xY ww xY w)z
    Loads a :py:class:`parso.Grammar`. The default version is the current Python
    version.

    :param str version: A python version string, e.g. ``version='3.8'``.
    :param str path: A path to a grammar file
    pythongrammarz.txtNzPython version .z is currently not supported.)r   r   r<   ry   majorminordirname__file__r    rT   openrP   r   
setdefaultFileNotFoundErrorrO   )r   r<   r   filefr   r   messages           r8   load_grammarr      s    (00L 27<<)//1C1C1CD D 7<<11488D/%% / / /
	/d $q6688$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $L(;;G#..tW=====  	/ 	/ 	/ 	/"""L$6$6$6G &g...		//sH   B 
D6D,CDC	DC	-DD6-D22D6)5r1   r   typingr   r   r   r   r   r   pathlibr	   parso._compatibilityr
   parso.pgen2r   parso.utilsr   r   r   r   parso.python.diffr   parso.python.tokenizer   r   parso.python.tokenr   parso.cacher   r   r   parso.parserr   parso.python.parserr   r   parso.python.errorsr   parso.pythonr   parso.file_ior   r   parso.normalizerr   r   r    rN   r   r!   r   r   r   r   r:   r8   <module>r      sT    				 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?       ( ( ( ( ( ( ( ( ( ( ( (, , , , , , , , , , , , ( ( ( ( ( ( : : : : : : : : / / / / / / E E E E E E E E E E # # # # # # 6 6 6 6 6 6 1 1 1 1 1 1       4 4 4 4 4 4 4 4 D D D D D D D D)+ $sI~& + + +			w: w: w: w: w:gfo w: w: w:t> > > > >G > > >, $(T / / /S /s / / / / / /r:   