K idZddlmZmZddlmZddlmZGddeZ GddeZ Gd d e Z Gd d Z d ZGddZy)a The ``Parser`` tries to convert the available Python code in an easy to read format, something like an abstract syntax tree. The classes who represent this tree, are sitting in the :mod:`parso.tree` module. The Python module ``tokenize`` is a very important part in the ``Parser``, because it splits the code into different words (tokens). Sometimes it looks a bit messy. Sorry for that! You might ask now: "Why didn't you use the ``ast`` module for this? Well, ``ast`` does a very good job understanding proper Python code, but fails to work as soon as there's a single line of broken code. There's one important optimization that needs to be known: Statements are not being parsed completely. ``Statement`` is just a representation of the tokens within the statement. This lowers memory usage and cpu time and reduces the complexity of the ``Parser`` (there's another parser sitting inside ``Statement``, which produces ``Array`` and ``Call``). )DictType)tree)ReservedStringceZdZdZdZy)ParserSyntaxErrorz_ Contains error information about the parser tree. May be raised as an exception. c ||_||_yN)message error_leaf)selfr r s R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/parso/parser.py__init__zParserSyntaxError.__init__&s $N__name__ __module__ __qualname____doc__rrrrr s  %rrceZdZdZdZy)InternalParseErrorz Exception to signal the parser is stuck and error recovery didn't help. Basically this shouldn't happen. It's a sign that something is really wrong. c tj||d|jd|d|||_t|_||_||_y)Nz: type=z, value=z , start_pos=) Exceptionrnamemsgtypevalue start_pos)r rtype_rrs rrzInternalParseError.__init__2sA4UI"? @  "rNrrrrrr+s  #rrceZdZdZy)Stackc.fd}t|S)Nc3KtD]X}|jjD]%}t|tr|j "|'|jj rXyywr )reverseddfa transitions isinstancerris_final) stack_node transitionr s riteratez@Stack._allowed_transition_names_and_token_types..iterate=sa&tn  ",.."<"<)J!*n=(...(( ) "~~.. s A#A+'A+)list)r r,s` r)_allowed_transition_names_and_token_typesz/Stack._allowed_transition_names_and_token_types<s GIrN)rrrr.rrrr"r";s rr"c(eZdZdZedZdZy) StackNodec ||_g|_yr )r&nodes)r r&s rrzStackNode.__init__Ms rc.|jjSr )r& from_ruler s r nonterminalzStackNode.nonterminalQsxx!!!rch|jjd|jd|jdS)N(z, )) __class__rr&r2r5s r__repr__zStackNode.__repr__Us!#~~66$**MMrN)rrrrpropertyr6r;rrrr0r0Ls!""Nrr0cr|jjr |j|S|S#t$rY|SwxYwr )rcontains_syntaxreserved_syntax_stringsKeyError)grammarr rs r_token_to_transitionrBYsE {{"" 2259 9 L   L s ) 66ceZdZUdZiZeeeejfe d<ejZ iZ eeeejfe d<ejZd dZdZdZdZdZd Zd Zy ) BaseParseraIParser engine. A Parser instance contains state pertaining to the current token sequence, and should not be used concurrently by different threads to parse separate token sequences. See python/tokenize.py for how to get input tokens by a string. When a syntax error occurs, error_recovery() is called. node_mapleaf_mapc.||_||_||_yr ) _pgen_grammar_start_nonterminal_error_recovery)r pgen_grammarstart_nonterminalerror_recoverys rrzBaseParser.__init__ws)"3-rc|jj|jd}tt |g|_|D]}|j | |j d}|jjs,tdj|j|jt|j dkDr|jn&|j|j |j"S)Nrzincomplete input)rHnonterminal_to_dfasrIr"r0stack _add_tokenr&r)rrstringrlen_pop convert_noder6r2)r tokens first_dfatokentoss rparsezBaseParser.parse|s&&::4;R;RSTUV Ii012  #E OOE " #**R.C77##)& ELL%//4::" ((#))DDrc|jr td|\}}}}tj||||}t d|)Nz!Error Recovery is not implementedzSyntaxError: invalid syntax)rJNotImplementedErrorr ErrorLeafr)r rZr rrprefixr s rrMzBaseParser.error_recoverysG   %&IJ J.3 +E5)VuiHJ#$A:N Nrcv |j||}|S#t$r|j||}Y|SwxYwr )rEr@ default_node)r r6childrennodes rrWzBaseParser.convert_nodesK <-4==-h7D  <$$[(;D  > ?s 88cB|j}|j}|\}}}}t|||} |djj|} | j|d_| jD]} |jt| |j||||} |dj j| y#t $r@|djj r|jn|j|YyYnt$rtd|||wxYw)z This is the only core function for parsing. Here happens basically everything. Everything is well prepared by the parser generator and we only apply the necessary steps here. rONztoo much input)rHrRrBr&r'r@r)rVrM IndexErrorrnext_dfa dfa_pushesappendr0rgr2) r rZrArRr rrr`r+planpushleafs rrSzBaseParser._add_tokens $$ */'ui)'5%@  TRy}}00< b OO *D LL4 ) *  vyA b t$ 9==))IIK''.  T()95%SS TsB>>ADDc8|jj}t|jdk(r|jd}n0|j |j j |j}|jdjj|y)NrPrrO)rRpoprUr2rWr&r4rl)r r[new_nodes rrVzBaseParser._popsmjjnn syy>Q yy|H(():):CIIFH 2##H-rN) file_inputF)rrrrrErstrrrBaseNode__annotations__NoderbrFLeafrfrr\rMrWrgrSrVrrrrDrDesz 02Hd3T]]++,199L+-Hd3TYY'(-99L. E,O? %@ .rrDN)rtypingrrparsorparso.pgen2.generatorrrrrr-r"r0rBrDrrrr|sV"0% % # # D" N N m.m.r