K iI+pUddlZddlZddlmZmZmZmZmZmZddl m Z ddl m Z ddl mZddlmZmZmZmZddlmZddlmZmZdd lmZdd lmZmZmZdd lm Z dd l!m"Z#dd l$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-ia.ee/dfe0d<edZ1Gddee1Z2Gdde2Z3dddde/de/fdZ4y)N)GenericTypeVarUnionDictOptionalAny)Path)is_pypy)generate_grammar) split_linespython_bytes_to_unicodePythonVersionInfoparse_version_string) DiffParser)tokenize_linestokenize)PythonTokenTypes) parser_cache load_moduletry_to_save_module) BaseParser)Parser)ErrorFinderConfig)pep8)FileIOKnownContentFileIO)RefactoringNormalizerNormalizerConfigGrammar_loaded_grammars_NodeTc(eZdZUdZeed<dZeeed<dZ e ed<e jZ eed<edddefd Z dd ddd d ddd d eeefdeej(efdedeej(efdedef dZdZdZdZdZddZddZdZy)rz :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||j|_||_||_||_t j|jdj|_ y)N)token_namespacezutf-8) r _get_token_namespace _pgen_grammar_parser _tokenizer _diff_parserhashlibsha256encode hexdigest_hashed)selfr) tokenizerr'r(s S/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/parso/grammar.py__init__zGrammar.__init__'sX-  557  #'~~dkk'&:;EEG TF)error_recoverypath start_symbolcache diff_cache cache_pathfile_iocoder<r=r@rAreturnc|| | tdt|tr t|}t|tr t|}| |j}|r|dk7r t d|| t |}n t||}|r(|jt|j||} | | S||j}t|}t|d} |r|j td t|j|j} | j } | j"} | | k(r| S|j|j$|j&| j)| | } t+|j|| | |xrt, | | S|j'| }|j1|j$|| }|j3| }|s|r$t+|j||| |xrt, | |S#t.$rYvwxYw) 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`. z%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 isinstancestrr r#NotImplementedErrorrrr<rr5readr r r0rnodelinesr-r/updaterr KeyErrorr.parse)r6rBr;r<r=r>r?r@rA module_noderRmodule_cache_itemrGnew_noderKp root_nodes r8rUz Grammar.parse1s'X D&t,D40   (!677 $0$>w||$L!044 -33 %&&,,&&&'# #4<<(E,1,A'k.8: ' LL   )*   GG6G* J t||Wi(-(=g+*4 6E  s2 G:: HHc8|j}| td|S)Nz"The token namespace should be set.)r% ValueError)r6nss r8r,zGrammar._get_token_namespaces#  " " :AB B r:ch|j td|j||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. z/No error normalizer specified for this grammar.)r$r\_get_normalizer_issues)r6rQs r8 iter_errorszGrammar.iter_errorss5  ( ( 0NO O**41N1NOOr:c6t|j|SN)rwalk)r6 base_nodenode_to_str_maps r8refactorzGrammar.refactors$_5::9EEr:cZ||j}| td|j|S)NzVYou need to specify a normalizer, because there's no default normalizer for this tree.)r&r\create_normalizer)r6normalizer_configs r8_get_normalizerzGrammar._get_normalizers@  $ $ ? ?  ( "PQQ 22488r:cF|j|}|j|S)zs TODO this is not public, yet. The returned code will be normalized, e.g. PEP8 for Python. )rjrcr6rQri normalizers r8 _normalizezGrammar._normalizes$ ))*;< t$$r:c^|j|}|j||jSrb)rjrcissuesrls r8r_zGrammar._get_normalizer_issuess+))*;<    r:c|jjj}djt |dddz}d|j j d|dS)N z ...<:>)r-nonterminal_to_dfaskeysjoinlist __class____name__)r6 nonterminalstxts r8__repr__zGrammar.__repr__sP))==BBD hhtL)"1-.7 NN33S99r:rb)r| __module__ __qualname____doc__rN__annotations__r$rrr%rrPEP8NormalizerConfigr&rrr9rbytesosPathLikerr!rUr,r`rfrjrnr_rr:r8rrs<@h'89@ c 3L43L3L3N 0N7AtHSH)-r".2"&48 $r#u*%r"++s*+ r  r  S 01rr*0rh PF9%! :r:cJeZdZeZeZdZdede ffd Z dZ dZ xZ S) PythonGrammarrE version_infobnf_textc^t|||jtt||_y)N)r7r'r()superr9_tokenize_lines PythonParserrr)r6rrr{s r8r9zPythonGrammar.__init__s1  **"  )r:c 2t|fd|ji|S)Nr)rr)r6rRkwargss r8rzPythonGrammar._tokenize_linesseN$2C2CNvNNr:c0t||jS)N)r)rr)r6rBs r8 _tokenizezPythonGrammar._tokenizes4+<+<==r:)r|rrrr$rr%r#rrNr9rr __classcell__)r{s@r8rrs702'%)%6)#)O>r:r)versionr<rr<ct|}t|tdd}|xs:tjj dd|j |jd}tjj tjjt|} t|S#t$r t|5}|j}dddn #1swYnxYwt|}tj||cYS#t $r)d|j d|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 rspythongrammarz.txtNzPython version .z is currently not supported.)rminrrr<rymajorminordirname__file__r rTopenrPr setdefaultFileNotFoundErrorrO) rr<passed_version_inforfilefrrmessages r8 load_grammarrs/w7*,=a,DEL  277<<)//1C1CDD 77<<14 8D /%%  / /d $q668 $ $ $$L(;G#..tW= =  /""L$6$6G&g. .  / /s<"B++ E5 D C D C# (D E 2D<<E)5r1rtypingrrrrrrpathlibr parso._compatibilityr parso.pgen2r parso.utilsr r rrparso.python.diffrparso.python.tokenizerrparso.python.tokenr parso.cacherrr parso.parserrparso.python.parserrrparso.python.errorsr parso.pythonr parso.file_iorrparso.normalizerrrr rNrr!rrrrr:r8rs ??((,,(:/EE#614D)+$sI~&+  w:gfow:t>G>,$(T'/S'/s'/r: