bg٘UddlZddlZddlZddlmZddlTddlmZm Z m Z  dXddd e e e fd e e e fd ed ejed ejedede fdZ dYddd e deje deje de fdZd e de fdZd e de fdZ dZdddde eje e fdededededede fdZd e d!e de fd"Z d[dd#d e d$ed%ede fd&Zd e de fd'Zd e de fd(Zd)d*defed+d,e e e fd-e e e fd.eje d/e d0e de f d1Zed2ed3fd4Zd5e e e fdee e ffd6Z d5e e e fdee e ffd7Z!e e"d8<e e"d9<e e#e$e%d:z&d;\Z'Z(d<ej)j*+DZ,e-d=d>.e,zd?z&d@Z/dAZ0GdBdCe1Z2e e e ee e e fe e e fffZ3e ee3ee2eje4fee3ee2ffZ5ed)ed*fdDe dEe6e5dFe e e fdGe e e fde f dHZ7dgfdIZ8e9e-dJdKz&dLZ: e-dM&dNZ; e-dO<&dPZ=e-dQ&dRZ> e9e-dJdKze>z&dSZ? e?Z@ e-dT&dUZA dVeBCDZDe6e e"dW<eZEeZFeZGeZHeZIeZJeZKeZLe ZMe!ZNe'e(cZOZPe/ZQe0ZRe2ZSe7ZTe:ZUe;ZVe=ZWe>ZXe?ZYe@ZZeAZ[dS)\N)__diag__)*)_bslash_flatten_escape_regex_range_chars,F)allow_trailing_delimexprdelimcombineminmaxr returnc t|trt|}dt |t ||r"dt |nd}|st|}||dkrtd|dz}||||krtd|dz}|||z||fz}|r|t|z }|r"t| |S| |S) a/Helper to define a delimited list of expressions - the delimiter defaults to ','. By default, the list elements and delimiters can have intervening whitespace, and comments, but this can be overridden by passing ``combine=True`` in the constructor. If ``combine`` is set to ``True``, the matching tokens are returned as a single token string, with the delimiters included; otherwise, the matching tokens are returned as a list of tokens, with the delimiters suppressed. If ``allow_trailing_delim`` is set to True, then the list may end with a delimiter. Example:: delimited_list(Word(alphas)).parse_string("aa,bb,cc") # -> ['aa', 'bb', 'cc'] delimited_list(Word(hexnums), delim=':', combine=True).parse_string("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE'] z{expr} [{delim} {expr}]...{end}z [{}])r r endNrzmin must be greater than 0z)max must be greater than, or equal to min) isinstancestr_type ParserElement_literalStringClassformatstrcopy streamlineSuppress ValueErrorOptCombineset_name)r r r rrr dlNamedelimited_list_exprs b/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pyparsing/helpers.pydelimited_listr$sY4$!!70066 . 5 5 '')) * *%jj*> FGNN3u:: & & &B6F    779:: : q  ?sczzHII I q%$,S!99*s5zz)4*++44V<<<"++F333)intExprint_exprr&cb|p|}tfd}|)ttd}n|}|d||d|zdtzdzS) a~Helper to define a counted list of expressions. This helper defines a pattern of the form:: integer expr expr expr... where the leading integer tells how many expr expressions follow. The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed. If ``int_expr`` is specified, it should be a pyparsing expression that produces an integer value. Example:: counted_array(Word(alphas)).parse_string('2 ab cd ef') # -> ['ab', 'cd'] # in this parser, the leading integer value is given in binary, # '10' indicating that 2 values are in the array binary_constant = Word('01').set_parse_action(lambda t: int(t[0], 2)) counted_array(Word(alphas), int_expr=binary_constant).parse_string('10 ab cd ef') # -> ['ab', 'cd'] # if other fields must be parsed after the count but before the # list items, give the fields results names and they will # be preserved in the returned ParseResults: count_with_metadata = integer + Word(alphas)("type") typed_array = counted_array(Word(alphanums), int_expr=count_with_metadata)("items") result = typed_array.parse_string("3 bool True True False") print(result.dump()) # prints # ['True', 'True', 'False'] # - items: ['True', 'True', 'False'] # - type: 'bool' cR|d}|r|zn tz|dd=dSNr)Empty)sltn array_exprr s r#count_field_parse_actionz/counted_array..count_field_parse_actionss6 aDQ3qEGG3 aaaDDDr%Nc,t|dSr*)intr.s r#zcounted_array..{sAaD r%arrayLenT)call_during_tryz(len) z...)ForwardWordnumsset_parse_actionrr add_parse_actionr)r r'r&r1r0s` @r# counted_arrayr=GsR!GJt**--.A.ABB,,.. Z    5tLLL j * *8c$ii+?%+G H HHr%ctfd}||ddt|zS)a9Helper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = match_previous_literal(first) match_expr = first + ":" + second will match ``"1:1"``, but not ``"1:2"``. Because this matches a previous literal, will also match the leading ``"1:1"`` in ``"1:10"``. If this is not desired, use :class:`match_previous_expr`. Do *not* use with packrat parsing enabled. c|r_t|dkr |dzdSt|}td|DzdSt zdS)Nrrc34K|]}t|VdSN)Literal).0tts r# zImatch_previous_literal..copy_token_to_repeater..s(77272;;777777r%)lenras_listAndr+)r,r-r.tflatreps r#copy_token_to_repeaterz6match_previous_literal..copy_token_to_repeaters{  1vv{{qt !--s77777777777 577NNNNr%T callDuringTry(prev) )r8r<r r)r rKrJs @r#match_previous_literalrOse ))C      0EEELLSYY&''' Jr%ct|}|zfd}||ddt |zS)aWHelper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = match_previous_expr(first) match_expr = first + ":" + second will match ``"1:1"``, but not ``"1:2"``. Because this matches by expressions, will *not* match the leading ``"1:1"`` in ``"1:10"``; the expressions are evaluated first, and then compared, so ``"1"`` is compared with ``"10"``. Do *not* use with packrat parsing enabled. ct|fd}|ddS)Nct|}|kr%t||d|dS)NzExpected {}, found{})rrGParseExceptionr)r,r-r. theseTokens matchTokenss r#must_match_these_tokenszTmatch_previous_expr..copy_token_to_repeater..must_match_these_tokenssU"199;;//Kk))$q077 [QQ*)r%TrL)rrGr;)r,r-r.rVrUrJs @r#rKz3match_previous_expr..copy_token_to_repeatersTqyy{{++       4DIIIIIr%TrLrN)r8rr<r r)r e2rKrJs @r#match_previous_exprrXs ))C BBJC J J J J J 0EEELLSYY&''' Jr%T)useRegex asKeywordstrscaseless use_regex as_keywordrYrZc |p|}|o|}t|tr(tjrtdd|rd}d}|rt ntnd}d}|rtntg}t|tr| }n4t|trt|}ntd|stStd |Drd } | t!|d z kr|| } t#|| d zd D]I\} } || | r || | zd z=n3|| | r!|| | zd z=|| | nJ| d z } | t!|d z k|r#|r t&jnd } t+d |Dr3ddd|D}ndd|D}|rd|}t1|| d|}|r$d|D|fd|S#t&j$rtddYnwxYwt9fd|Dd|S)a Helper to quickly define a set of alternative :class:`Literal` s, and makes sure to do longest-first testing when there is a conflict, regardless of the input order, but returns a :class:`MatchFirst` for best performance. Parameters: - ``strs`` - a string of space-delimited literals, or a collection of string literals - ``caseless`` - treat all literals as caseless - (default= ``False``) - ``use_regex`` - as an optimization, will generate a :class:`Regex` object; otherwise, will generate a :class:`MatchFirst` object (if ``caseless=True`` or ``asKeyword=True``, or if creating a :class:`Regex` raises an exception) - (default= ``True``) - ``as_keyword`` - enforce :class:`Keyword`-style matching on the generated expressions - (default= ``False``) - ``asKeyword`` and ``useRegex`` are retained for pre-PEP8 compatibility, but will be removed in a future release Example:: comp_oper = one_of("< = > <= >= !=") var = Word(alphas) number = Word(nums) term = var | number comparison_expr = term + comp_oper + term print(comparison_expr.search_string("B = 12 AA=23 B<=AA AA>12")) prints:: [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']] z`More than one string argument passed to one_of, pass choices as a list or space-delimited string) stacklevelcV||kSrA)upperabs r#r5zone_of..sqwwyyAGGII5r%ct||SrA)rc startswithrds r#r5zone_of..s$QWWYY11!''))<<r%c||kSrArds r#r5zone_of..s qAvr%c,||SrA)rhrds r#r5zone_of..sQ\\!__r%z7Invalid argument to one_of, expected string or iterablec3<K|]}t|dkVdSrNrFrCsyms r#rEzone_of..s, + +C3s88a< + + + + + +r%rrNc3<K|]}t|dkVdSrmrnros r#rEzone_of..&s,44S3s88q=444444r%z[{}]rc34K|]}t|VdSrA)rros r#rEzone_of..)s+NNs5c::NNNNNNr%|c3>K|]}tj|VdSrA)reescaperos r#rEzone_of..,s*BB3 #BBBBBBr%z \b(?:{})\b)flagsz | c8i|]}||Srjlowerros r# zone_of..7s"BBB3ciikk3BBBr%cD|dSr*ry)r,r-r. symbol_maps r#r5zone_of..8sZ! 5Mr%z8Exception creating Regex for one_of, building MatchFirstc3.K|]}|VdSrArj)rCrpparseElementClasss r#rEzone_of..Bs/@@'',,@@@@@@r%)rrr%warn_on_multiple_string_args_to_oneofwarningswarnCaselessKeywordCaselessLiteralKeywordrBsplitIterablelist TypeErrorNoMatchanyrF enumerateinsertru IGNORECASEallrjoinRegexr r<error MatchFirst)r[r\r]r^rYrZisequalmaskssymbolsicurjotherre_flagspattretrr}s @@r#one_ofrsR'ZI%IH 8X&&  :    ;    >55<</8MOOo%%,,'0=GGgG$!!S**,, D( # #St**QRRR yy + +7 + + +++  #g,,"""!*C%ga!egg&677  575#&&A *EU3&&A *NN1e,,,E Q#g,,""")18 q 44G44444 C}}GGNNgNNNNNxxBB'BBBBB 2$++D11H---66uzz'7J7JKKC OCB'BBB $$%M%M%M%MNNNJx    MMJWX        @@@@@@@ @ @ I I 7  s3C J+KKkeyvaluecZttt||zS)aHelper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the :class:`Dict`, :class:`ZeroOrMore`, and :class:`Group` tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the :class:`Dict` results can include named token fields. Example:: text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join)) print(attr_expr[1, ...].parse_string(text).dump()) attr_label = label attr_value = Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join) # similar to Dict, but simpler call format result = dict_of(attr_label, attr_value).parse_string(text) print(result.dump()) print(result['shape']) print(result.shape) # object attribute access works too print(result.as_dict()) prints:: [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: 'light blue' - posn: 'upper left' - shape: 'SQUARE' - texture: 'burlap' SQUARE SQUARE {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'} )Dict OneOrMoreGroup)rrs r#dict_ofrGs'J  %e ,,-- . ..r%)asString as_stringrcN|o|}td}|}d|_|d|z|dz}|rd}nd}|||j|_|t j|S)aHelper to return the original, untokenized text for a given expression. Useful to restore the parsed fields of an HTML start tag into the raw tag text itself, or to revert separate tokens with intervening whitespace back to the original matching input text. By default, returns astring containing the original parsed text. If the optional ``as_string`` argument is passed as ``False``, then the return value is a :class:`ParseResults` containing any results names that were originally matched, and a single token containing the original matched text from the input string. So if the expression passed to :class:`original_text_for` contains expressions with defined results names, you must set ``as_string`` to ``False`` if you want to preserve those results name values. The ``asString`` pre-PEP8 argument is retained for compatibility, but will be removed in a future release. Example:: src = "this is test bold text normal text " for tag in ("b", "i"): opener, closer = make_html_tags(tag) patt = original_text_for(opener + SkipTo(closer) + closer) print(patt.search_string(src)[0]) prints:: [' bold text '] ['text'] c|SrArj)r,locr.s r#r5z#original_text_for..s3r%F_original_start _original_endc*||j|jSrA)rrr,r-r.s r#r5z#original_text_for..sa(9AO(K&Lr%cr||d|dg|dd<dS)Nrrpoprs r# extractTextz&original_text_for..extractTexts9aee-..1G1GGHIAaaaDDDr%)r+r;r callPreparse ignoreExprssuppress_warning Diagnostics)warn_ungrouped_named_tokens_in_collection)r rr locMarker endlocMarker matchExprrs r#original_text_forrosD%IH(()>)>??I>>##L %L +,,t3ll?6S6SSIJLL  J J J{+++ ,I {TUUU r%cHt|dS)zkHelper to undo pyparsing's default grouping of And expressions, even if all but one are non-empty. c|dSr*rjr4s r#r5zungroup..s 1Q4r%)TokenConverterr<)r s r#ungrouprs" $   0 0 @ @@r%ctd}t|d|dz|dzS)a (DEPRECATED - future code should use the Located class) Helper to decorate a returned token with its starting and ending locations in the input string. This helper adds the following results names: - ``locn_start`` - location where matched expression begins - ``locn_end`` - location where matched expression ends - ``value`` - the actual parsed results Be careful if the input text contains ```` characters, you may want to call :class:`ParserElement.parseWithTabs` Example:: wd = Word(alphas) for match in locatedExpr(wd).searchString("ljsdf123lksdjjf123lkkjj1222"): print(match) prints:: [[0, 'ljsdf', 5]] [[8, 'lksdjjf', 15]] [[18, 'lkkjj', 23]] c|SrArj)ssllrDs r#r5zlocatedExpr..s"r% locn_startrlocn_end)r+r;rrleaveWhitespace)r locators r# locatedExprrst6gg&&'<'<==G   $w--  *',,.. ( ( * *: 6 6 7  r%()) ignoreExpropenerclosercontent ignore_exprrc ||kr|tkr|n|}||krtd|t|trt|trt |dkrt |dkr|Ut t |t||ztj zdz d}n;t t||ztj z dz}n|pt t |t|zt|zttj dz d}n{t t t|t|zttj dz d}ntd t}|F|tt!|t#||z|zzt!|zz}nB|tt!|t#||zzt!|zz}|d ||d |S) a& Helper method for defining nested lists enclosed in opening and closing delimiters (``"("`` and ``")"`` are the default). Parameters: - ``opener`` - opening character for a nested list (default= ``"("``); can also be a pyparsing expression - ``closer`` - closing character for a nested list (default= ``")"``); can also be a pyparsing expression - ``content`` - expression for items within the nested lists (default= ``None``) - ``ignore_expr`` - expression for ignoring opening and closing delimiters (default= :class:`quoted_string`) - ``ignoreExpr`` - this pre-PEP8 argument is retained for compatibility but will be removed in a future release If an expression is not provided for the content argument, the nested expression will capture all whitespace-delimited content between delimiters as a list of separate values. Use the ``ignore_expr`` argument to define expressions that may contain opening or closing characters that should not be treated as opening or closing characters for nesting, such as quoted_string or a comment expression. Specify multiple expressions using an :class:`Or` or :class:`MatchFirst`. The default is :class:`quoted_string`, but if no expressions are to be ignored, then pass ``None`` for this argument. Example:: data_type = one_of("void int short long char float double") decl_data_type = Combine(data_type + Opt(Word('*'))) ident = Word(alphas+'_', alphanums+'_') number = pyparsing_common.number arg = Group(decl_data_type + ident) LPAR, RPAR = map(Suppress, "()") code_body = nested_expr('{', '}', ignore_expr=(quoted_string | c_style_comment)) c_function = (decl_data_type("type") + ident("name") + LPAR + Opt(delimited_list(arg), [])("args") + RPAR + code_body("body")) c_function.ignore(c_style_comment) source_code = ''' int is_odd(int x) { return (x%2); } int dec_to_hex(char hchar) { if (hchar >= '0' && hchar <= '9') { return (ord(hchar)-ord('0')); } else { return (10+ord(hchar)-ord('A')); } } ''' for func in c_function.search_string(source_code): print("%(name)s (%(type)s) args: %(args)s" % func) prints:: is_odd (int) args: [['int', 'x']] dec_to_hex (int) args: [['char', 'hchar']] z.opening and closing strings cannot be the sameNr)exactc6|dSr*stripr4s r#r5znested_expr..(1r%c6|dSr*rr4s r#r5znested_expr..,rr%c6|dSr*rr4s r#r5znested_expr..6rr%c6|dSr*rr4s r#r5znested_expr..>rr%zOopening and closing arguments must be strings if no content expression is givenznested z expression) quoted_stringrrrrFrr CharsNotInrDEFAULT_WHITE_CHARSr;emptyrrBr8rr ZeroOrMorer )rrrrrrs r# nested_exprrsT[  $.-//$A$A[[z  IJJJ fh ' '% Jvx,H,H% 6{{aCKK1$4$4)%!'K( &-2S S&''&'='=>>G$jjllZ-*KK..&&'='=>>?GG)%!'K&v./&v./))JRSTTTU'&'='=>>G&!$V__,&v./()JRSTTTU '&'='=>> Ga  ))C  V  z*s*:W*DEE EQWHXHX X    hv&&C'M)B)BBXfEUEUUVVVLLLVVVVV<=== Jr%<>c t|tr|t|| }n|jt t t dz}|rt t}||dzttt|tdz|zztddgd d z|z}nt  tt t"d z}||dzttt| d ttd|zzztddgd d z|z}t%t'd|zd zd}|dz|fd|ddddzdz}|_|_t7||_||fS)zRInternal helper to construct opening and closing tag expressions, given a tag name)r\z_-:tag=/F)defaultrc|ddkSNrrrjrs r#r5z_makeTags..^! r%r) exclude_charsc6|dSr*ryr4s r#r5z_makeTags..lsqtzz||r%c|ddkSrrjrs r#r5z_makeTags..rrr%zc |ddddz|S)Nstartr: ) __setitem__rreplacetitlerr)r.resnames r#r5z_makeTags..{sY!-- bgggooc377==??EEGGHH H!&&((  r%rrrrz)rrrnamer9alphas alphanumsdbl_quoted_stringrr; remove_quotesrrrrrr printablesrrBr r<rrrrrSkipTotag_body) tagStrxml suppress_LT suppress_GT tagAttrName tagAttrValueopenTagcloseTagrs @r# _makeTagsrNs&(##c'222+vy5011K  (--//@@OO fUmm :eK(3--$?,$NOOPPQQ R(c#w'''00AA++     %))++<<]KKd cO O O   fUmm #445K5KLLhsmml:;;< (c#w'''00AA++    wt}}v-3eDDDH Vg%&&&      x S117799??AABBBhw !! GKHLhhjj))G H r%tag_strc"t|dS)aPHelper to construct opening and closing tag expressions for HTML, given a tag name. Matches tags in either upper or lower case, attributes with namespaces and with quoted or unquoted values. Example:: text = 'More info at the pyparsing wiki page' # make_html_tags returns pyparsing expressions for the opening and # closing tags as a 2-tuple a, a_end = make_html_tags("A") link_expr = a + SkipTo(a_end)("link_text") + a_end for link in link_expr.search_string(text): # attributes in the tag (like "href" shown here) are # also accessible as named results print(link.link_text, '->', link.href) prints:: pyparsing -> https://github.com/pyparsing/pyparsing/wiki Frrs r#make_html_tagsr s0 We $ $$r%c"t|dS)zHelper to construct opening and closing tag expressions for XML, given a tag name. Matches tags only in the given upper/lower case. Example: similar to :class:`make_html_tags` Trr s r# make_xml_tagsr s Wd # ##r% any_open_tag any_close_tagz_:zany tagc@i|]\}}|d|S);)rstrip)rCkvs r#r{r{s(KKKtq!!((3--KKKr%z &(?Prsz);zcommon HTML entityc@t|jS)zRHelper parser action to replace common HTML entities with their special characters)_htmlEntityMapgetentityr4s r#replace_html_entityrs   ah ' ''r%ceZdZdZdZdS)OpAssocrr`N)__name__ __module__ __qualname__LEFTRIGHTrjr%r#rrs D EEEr%r base_exprop_listlparrparc ZGddt}d|_t}t|trt |}t|trt |}t|t rt|t s|t ||z|zz}n |||z|zz}t|D]V\}}|dzdd\} } } } t| trt | } | dkrZt| ttfrt| dkrtd | \} }d | |}nd | }d | cxkrdksntd | t jt jfvrtdt|}| t jur| d kr)||| zt || dzz}n| dkrW| /||| z|zt || |zdzz}nc|||zt |dz}n=| dkr@||| z|z|z|zt |t)| |z|z|zzz}n| t jur| d krKt| t*st+| } || j|zt | |zz}n| dkrX| .||| z|zt || |zdzz}na|||zt ||dzz}n9| dkr3||| z|z|z|zt || z|z|z|zz}| r._FBTc@|j|||gfSrA)r try_parse)selfinstringr doActionss r# parseImplz%infix_notation.._FB.parseImpl(s# I  # . . .7Nr%NT)rrrr,rjr%r#_FBr&'s(      r%r.z FollowedBy>rANr`z@if numterms=3, opExpr must be a tuple or list of two expressionsz {}{} termz{} termrz6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)r.)r`.) FollowedByrr8rrrrrrrrtuplerrFrrrrrr rrr r;setName)r r!r"r#r.rlastExprroperDefopExprarityrightLeftAssocpaopExpr1opExpr2 term_namethisExprrs r#infix_notationr>sbj !CL ))C$~~$~~ tX & &3:dH+E+E3uTCZ$%6777s T 12((<< 7-4w->,C)~r fh ' ' ?"66v>>F A::fudm44 F q8H8H V & GW#**7G< > >QRR R#II..y99 W\ ) )zzC6 122U8fVn;T5U5UU !% #Hv$5$@ A AE FX$5v#>>EE!II!$Hx$7 8 85&AQ;R;R RII!Cw&1G;hF(Yw/AG/Kh/V%W%WWXXY w} , ,zz!&#..) [[FC h 677%@Q:R:RR !% #Hv$5$@ A AE FX$5v#>>EE!II!$Hx$7 8 85 8F#33<<!II!Cw&1G;hF(W,x7'AHLMMN   /"udm,, /* *B///**2...i(*33I>>>HC Jr%c  ddfd fd}fd}fd}ttd}t t |zd}t |d} t |d } |rStt||zt| t|zt|zz| z} n\tt|t| t|zt|zzt| z} | fd | fd | ttz| d S) a (DEPRECATED - use IndentedBlock class instead) Helper method for defining space-delimited indentation blocks, such as those used to define block statements in Python source code. Parameters: - ``blockStatementExpr`` - expression defining syntax of statement that is repeated within the indented block - ``indentStack`` - list created by caller to manage indentation stack (multiple ``statementWithIndentedBlock`` expressions within a single grammar should share a common ``indentStack``) - ``indent`` - boolean indicating whether block must be indented beyond the current level; set to ``False`` for block of left-most statements (default= ``True``) A valid block must contain at least one ``blockStatement``. (Note that indentedBlock uses internal parse actions which make it incompatible with packrat parsing.) Example:: data = ''' def A(z): A1 B = 100 G = A2 A2 A3 B def BB(a,b,c): BB1 def BBA(): bba1 bba2 bba3 C D def spam(x,y): def eggs(z): pass ''' indentStack = [1] stmt = Forward() identifier = Word(alphas, alphanums) funcDecl = ("def" + identifier + Group("(" + Opt(delimitedList(identifier)) + ")") + ":") func_body = indentedBlock(stmt, indentStack) funcDef = Group(funcDecl + func_body) rvalue = Forward() funcCall = Group(identifier + "(" + Opt(delimitedList(rvalue)) + ")") rvalue << (funcCall | identifier | Word(nums)) assignment = Group(identifier + "=" + rvalue) stmt << (funcDef | assignment | identifier) module_body = stmt[1, ...] parseTree = module_body.parseString(data) parseTree.pprint() prints:: [['def', 'A', ['(', 'z', ')'], ':', [['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]], 'B', ['def', 'BB', ['(', 'a', 'b', 'c', ')'], ':', [['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]], 'C', 'D', ['def', 'spam', ['(', 'x', 'y', ')'], ':', [[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]] Nc"ddd<dSNrj) backup_stacks indentStacksr# reset_stackz"indentedBlock..reset_stacks&r* AAAr%c|t|krdSt||}|dkr.|dkrt||dt||ddS)NrBzillegal nestingznot a peer entry)rFcolrSr,r-r.curColrDs r#checkPeerIndentz&indentedBlock..checkPeerIndentsp A;; FQ [_ $ $ B''$Q+<=== A'9:: : % $r%ct||}|dkr|dSt||d)NrBznot a subentry)rGappendrSrHs r#checkSubIndentz%indentedBlock..checkSubIndentsLQ KO # #   v & & & & & A'788 8r%c|t|krdSt||}r|vst||d|dkrdSdS)Nznot an unindentrB)rFrGrSrrHs r# checkUnindentz$indentedBlock..checkUnindentsv A;; FQ :+ 5 5 A'899 9 KO # # OO      $ #r%z INDENTrUNINDENTc:rdodndSrAr)rCsr#r5zindentedBlock..s"-I !!"%%.$Tr%cSrArj)rerfcdrEs r#r5zindentedBlock..s kkmmr%zindented block)rLrLineEndset_whitespace_charssuppressr+r;r rrr<set_fail_actionignorer) blockStatementExprrDindentrCrJrMrONLrPPEERUNDENTsmExprrEs ` ` @r# indentedBlockra{sXlQQQ(((++++++;;;;;99999 79911%88AACC D DBgg00@@@ J J8 T TF 77 # #O 4 4 = =b A AD WW % %m 4 4 = =j I IF   GG u%78883r77BCC D    GGu%78883r77BCC D&kk    IIII ;;;;<<<g 1222 ??+ , ,,r%z/\*(?:[^*]|\*(?!/))*z*/zC style commentzz HTML commentz.*z rest of linez//(?:\\\n|[^\n])*z // commentzC++ style commentz#.*zPython style commentc<g|]}t|t|Srj)rr)rCrs r# rc%s7''' *Q ">">''''r%_builtin_exprs)r FNNrA)FTFr-)\ html.entitieshtmlrutypingrrcoreutilrrrUnionrrboolOptionalr3r$r=rOrXrrrrrrrrrrTupler r __annotations__r9rrr r rentitieshtml5itemsrrrcommon_html_entityrEnumrInfixNotationOperatorArgType ParseActionInfixNotationOperatorSpecListr>rarc_style_comment html_commentleave_whitespace rest_of_linedbl_slash_commentcpp_style_commentjava_style_commentpython_style_commentvarsvaluesrd delimitedList countedArraymatchPreviousLiteralmatchPreviousExproneOfdictOforiginalTextFor nestedExpr makeHTMLTags makeXMLTags anyOpenTag anyCloseTagcommonHTMLEntityreplaceHTMLEntityopAssoc infixNotation cStyleComment htmlComment restOfLinedblSlashCommentcppStyleCommentjavaStyleCommentpythonStyleCommentrjr%r#rs& >>>>>>>>>>(+ $ $ 64"'646464 ]" #64 m# $6464   64   646464646464v049I/3 9I9I9I 9Iom,9I_] + 9I  9I9I9I9Ix=B!m! !!!!L | ||| $c) *||| |  ||||||~%/%/}%/%/%/%/%/R,02EI222 2$(2>B22222jA-AMAAAA m     H),(+.2!. } !.  }}} #}$ %} #}$ %}_] +} }  }}}}}@(0x}}((3--7777t% 3 % &% =- '(%%%%6$ 3 % &$ =- '($$$$,nDT!""++I66 mLKt}/B/H/H/J/JKKKU>CHH^,D,DDtKLLUU ((( d %3eM3$67}c?Q9RRSS " $  $ &  $    $'/hsmm&.hsmm bbb + ,b ]" #b ]" # b  bbbbJ;?bL-L-L-L-`'%% 7884?@@II$u'((11.AA &uU||,,..77GG E.//88FF1G E !""T),== ( P&$uV}}--.DEE0 ''tvv}}''']#   -' #    &  K%'     ##%)r%