bBFj]+UddlZddlZddlmZmZmZmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZmZmZmZddlmZddlmZmZmZdd lmZdd lmZmZm Z dd l!m"Z"dd l#m$Z%dd l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.m/Z/iZ0ee1dfe2d<edZ3Gddee3Z4Gdde4Z5dddde1de1fdZ6dS)N)GenericTypeVarUnionDictOptionalAnyIterator)Path)is_pypy)generate_grammar) split_linespython_bytes_to_unicodePythonVersionInfoparse_version_string) DiffParser)tokenize_linestokenize PythonToken)PythonTokenTypes) parser_cache load_moduletry_to_save_module) BaseParser)Parser)ErrorFinderConfig)pep8)FileIOKnownContentFileIO)RefactoringNormalizerNormalizerConfigGrammar_loaded_grammars_NodeTc*eZdZUdZeed<dZeeed<dZ e ed<e j Z eed<edddefd Z dd ddd d ddd d eeefdeejefdedeejefdedef dZdZdZdZdZddZddZdZdS)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_parsertextct|||_||_||_||_t j|d |_ dS)N)token_namespacezutf-8) r _get_token_namespace _pgen_grammar_parser _tokenizer _diff_parserhashlibsha256encode hexdigest_hashed)selfr+ tokenizerr)r*s ;C:\PYTHON\_runtimes\venv\Lib\site-packages\parso/grammar.py__init__zGrammar.__init__'sp-  5577    #'~dkk'&:&:;;EEGG TF)error_recoverypath start_symbolcache diff_cache cache_pathfile_iocoder>r?rBrCreturncD|||tdt|trt|}t|trt|}||j}|r|dkrt d|"|t |}nt||}|r"|jt|j ||} | | S|| }t|}t|d} |r|jtd t|j |j} | j} | j} | | kr| S||j|j| | | } t+|j || | |ot, | | S#t.$rYnwxYw|| }||j|| }|| }|s|r"t+|j ||| |ot, | |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.)rBT)keependsz?You have to define a diff parser to be able to use this option.) old_lines new_lines)picklingrB)r=start_nonterminal)tokens) TypeError isinstancestrr r%NotImplementedErrorrrr>rr7readrr r2rnodelinesr/r1updaterr KeyErrorr0parse)r8rDr=r>r?r@rArBrC module_noderTmodule_cache_itemrInew_noderMp root_nodes r:rWz Grammar.parse1sX >D&t,,D4000   (!6777 $0$>w|$L!04 -3 %%&&,,&&'# #4<(E,1,A'k.8:::: %    ('' LL  )*    GG6G**  6J 6 t|Wi(-(=g+*4 6 6 6 6sF"" F/.F/c6|j}|td|S)Nz"The token namespace should be set.)r' ValueError)r8nss r:r.zGrammar._get_token_namespaces#  " :ABB B r<cd|jtd|||jS)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)r8rSs r: iter_errorszGrammar.iter_errorss5  ( 0NOO O**41NOOOr<cFt||SN)rwalk)r8 base_nodenode_to_str_maps r:refactorzGrammar.refactors$_55::9EEEr<c`||j}|td||S)NzVYou need to specify a normalizer, because there's no default normalizer for this tree.)r(r^create_normalizer)r8normalizer_configs r:_get_normalizerzGrammar._get_normalizersF  $ $ ?  ( "PQQQ 224888r<cV||}||S)zs TODO this is not public, yet. The returned code will be normalized, e.g. PEP8 for Python. )rlrer8rSrk normalizers r: _normalizezGrammar._normalizes* ))*;<< t$$$r<cd||}|||jSrd)rlreissuesrns r:razGrammar._get_normalizer_issuess1))*;<<   r<c|jj}dt |dddz}d|jjd|dS)N z ...<:>)r/nonterminal_to_dfaskeysjoinlist __class____name__)r8 nonterminalstxts r:__repr__zGrammar.__repr__s\)=BBDD hhtL))"1"-..7 N333SSS99r<rd)r~ __module__ __qualname____doc__rP__annotations__r&rrr'rrPEP8NormalizerConfigr(r rr;rbytesosPathLikerr#rWr.rbrhrlrprarr<r:r!r!s<@h'89@@@ c   3L43L3N3N 0NNN7AtHHHSHHHH)-r".2"&48 $rrr#u*%r"+s*+ r  r  S 01rr*0rrrrh P P PFFF999%%%%!!!! :::::r<cbeZdZeZeZdZdede ffd Z de e fdZ dZxZS) PythonGrammarrG version_infobnf_textc~t||jtt||_dS)N)r9r)r*)superr;_tokenize_lines PythonParserrr)r8rrr}s r:r;zPythonGrammar.__init__sC  *"    )r<rEc *t|fd|ji|S)Nr)rr)r8rTkwargss r:rzPythonGrammar._tokenize_liness eNN$2CNvNNNr<c.t||jS)N)r)rr)r8rDs r: _tokenizezPythonGrammar._tokenizes4+<====r<)r~rrrr&rr'r%rrPr;r rrr __classcell__)r}s@r:rrs0022'%)%6)#))))))O(;2GOOOO>>>>>>>r<r)versionr>rr>ct|}t|tdd}|p/tjdd|j|jd}tjtjt|} t|S#t$r t|5}| }dddn #1swxYwYt||}t||cYS#t $r#d|jd|jd }t#|wxYwwxYw) 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 rupythongrammarz.txtNzPython version .z is currently not supported.)rminrrr>r{majorminordirname__file__r"rVopenrRr setdefaultFileNotFoundErrorrQ) rr>passed_version_inforfilefrrmessages r: load_grammarrs/w77*,=a,D,DEEL  27<<)//1C1C1CDD 7<<114 8 8D /%%  / / / /d $q6688 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $$L(;;G#..tW== = = =  / / / /"""L$6$6$6G&g.. .  / /sH# B00 E;D# C+ D#+C/ /D#2C/ 3-D# E#-EE)7r3rtypingrrrrrrr pathlibr parso._compatibilityr parso.pgen2r parso.utilsr rrrparso.python.diffrparso.python.tokenizerrrparso.python.tokenr parso.cacherrr parso.parserrparso.python.parserrrparso.python.errorsr parso.pythonr parso.file_iorrparso.normalizerrr r"rPrr#r!rrrr<r:rs` IIIIIIIIIIIIIIIIII((((((((((((,,,,,,,,,,,,((((((GGGGGGGGGG//////EEEEEEEEEE######66666611111144444444DDDDDDDD)+$sI~&+++   w:w:w:w:w:gfow:w:w:t>>>>>G>>>,$(T&/&/&/S&/s&/&/&/&/&/&/r<