
    Wh3                        U d dl Zd dlZd dlZd dlZd dlZddlmZ ddl ddl	m
Z
mZmZmZmZ 	 dddddedej                   e   d	ej                   e   d
efdZded
efdZded
efdZ	 	 	 deddddeej*                  e   ef   dededededed
efdZdeded
efdZ	 dfdddededed
efdZded
efdZded
efd Z e       Zd!d"defed#d$eeef   d%eeef   d&ej                   e   d'ej                   e   d(ej                   e   d
efd)Z  e!d*       e!d+      fd,Z"d-eeef   d
e#eef   fd.Z$d-eeef   d
e#eef   fd/Z%ee&d0<   ee&d1<    e$ e'e(e)d2z         jU                  d3            \  Z+Z,ejZ                  j\                  j_                         D  ci c]  \  } }| ja                  d4      | c}} Z1d5je                  d6d7      Z3 e4d8       jU                  d9      Z5d: Z6 G d; d<e7      Z8eeee#eeef   eeef   f   f   Z9ee#e9e:e8ej                   e;   f   e#e9e:e8f   f   Z< e!d!       e!d"      fd=ed>e=e<   d?eeef   d@eeef   d
e>f
dAZ?dg fdBZ@ e4dC      jU                  dD      ZA	  e4dE      jU                  dF      ZB	  e4dG      j                         jU                  dH      ZD e4dI      jU                  dJ      ZE	  e4dK      jU                  dL      ZF	 eFZG	  e4dM      jU                  dN      ZH	  eI       j                         D cg c]  } eK|e      s| c}ZLe=e   e&dO<   	 	 	 	 dgddPdeeef   dQeeef   dRedSej                   e:   dTej                   e:   dUed
efdVZMe8ZNe+ZOe,ZPe5ZQeAZReBZSeDZTeEZUeFZVeGZWeHZX edWeY      ZZ edXeY      ZM edYe      Z[ edZe      Z\ ed[e      Z] ed\e      Z^ ed]e      Z_ ed^e      Z` ed_e       Za ed`e$      Zb edae%      Zc edbe6      Zd edce?      Zeyc c}} w c c}w )h    N   )__diag__)*)_bslash_flatten_escape_regex_range_charsmake_compressed_rereplaced_by_pep8)intExprexprint_exprr   returnc                    |xs |}t                fd}| t        t              j                  d       }n|j	                         }|j                  d       |j                  |d       |z   j                  d  d      S )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.

    Examples:

    .. doctest::

        >>> counted_array(Word(alphas)).parse_string('2 ab cd ef')
        ParseResults(['ab', 'cd'], {})

    - In this parser, the leading integer value is given in binary,
      '10' indicating that 2 values are in the array:

      .. doctest::

        >>> 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')
        ParseResults(['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:

      .. doctest::

         >>> ppc = pyparsing.common
         >>> count_with_metadata = ppc.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())
         ['True', 'True', 'False']
         - items: ['True', 'True', 'False']
         - type: 'bool'
    c                 B    |d   }|r|z  n	t               z  |d d = y Nr   )Empty)sltn
array_exprr   s       K/var/www/html/jupyter_env/lib/python3.12/site-packages/pyparsing/helpers.pycount_field_parse_actionz/counted_array.<locals>.count_field_parse_actionM   s'    aDQqEG3
aD    c                     t        | d         S r   )intr   s    r   <lambda>zcounted_array.<locals>.<lambda>U   s    AaD	 r   arrayLenT)call_during_tryz(len) z...)ForwardWordnumsset_parse_actioncopyset_nameadd_parse_action)r   r   r   r   r   s   `   @r   counted_arrayr(      s    h !GJ t*--.AB,,.Z 5tLj **VD6+=>>r   c                     t               fd}| j                  |d       j                  dt        |       z          S )aI  Helper 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::

    .. testcode::

       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                     |st               z   y t        |      dk(  r	|d   z   y t        |j                               }t	        d |D              z   y )Nr   r   c              3   2   K   | ]  }t        |        y wN)Literal).0tts     r   	<genexpr>zImatch_previous_literal.<locals>.copy_token_to_repeater.<locals>.<genexpr>{   s     /272;/   )r   lenr   as_listAnd)r   r   r   tflatreps       r   copy_token_to_repeaterz6match_previous_literal.<locals>.copy_token_to_repeaterp   sP    57Nq6Q;1Q4K %s////r   TcallDuringTry(prev) )r!   r'   r&   str)r   r7   r6   s     @r   match_previous_literalr<   ]   sA    " )C0 	0ELLSY&'Jr   c                     t               | j                         }|z  fd}| j                  |d       j                  dt	        |       z          S )af  Helper 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:

    .. testcode::

       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.
    c                 j    t        |j                               fd}j                  |d       y )Nc                 h    t        |j                               }|k7  rt        | |d d|       y )Nz	Expected z, found)r   r3   ParseException)r   r   r   theseTokensmatchTokenss       r   must_match_these_tokenszTmatch_previous_expr.<locals>.copy_token_to_repeater.<locals>.must_match_these_tokens   sA    "199;/Kk)$qIk]'+G  *r   Tr8   )r   r3   r$   )r   r   r   rC   rB   r6   s       @r   r7   z3match_previous_expr.<locals>.copy_token_to_repeater   s.    qyy{+	 	4DIr   Tr8   r:   )r!   r%   r'   r&   r;   )r   e2r7   r6   s      @r   match_previous_exprrE      sV    " )C	BBJC
J 	0ELLSY&'Jr   FT)useRegex	asKeywordstrscaseless	use_regex
as_keywordrF   rG   c                   |xs |}|xr |}t        |t              r't        j                  rt        j                  dd       |rd }d }nt        j                  }d }t        | t              r+t        j                  t        |       } | j                         }n't        | t              rt        |       }nt        d      |s
t               S d}	|	t!        |      d	z
  k  r||	   }
t#        ||	d	z   d
       D ]W  \  }} |||
      r||	|z   d	z   =  nEt!        |      t!        |
      kD  s2 ||
|      s<||	|z   d	z   = |j%                  |	|        n |	d	z  }	|	t!        |      d	z
  k  r|r|rt&        j(                  nd}	 t+        d |D              rddj-                  d |D               d}ndj-                  d |D              }|rd| d}t/        ||      }|j1                  dj-                  d |D                     |r3|D ci c]  }|j3                         | c}|j5                  fd       |S dx}}||ft8        || ft:        | |ft<        | | ft>        i||f   tA        fd|D              j1                  dj-                  |            S c c}w # t&        j6                  $ r t        j                  dd       Y w xY w)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.

    :param strs: a string of space-delimited literals, or a collection of
       string literals
    :param caseless: treat all literals as caseless
    :param use_regex: bool - as an optimization, will
       generate a :class:`Regex` object; otherwise, will generate
       a :class:`MatchFirst` object (if ``caseless=True`` or
       ``as_keyword=True``, or if creating a :class:`Regex` raises an exception)
    :param as_keyword: bool - enforce :class:`Keyword`-style matching on the
       generated expressions
    
    Parameters ``asKeyword`` and ``useRegex`` are retained for pre-PEP8
    compatibility, but will be removed in a future release.

    Example:

    .. testcode::

       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:

    .. testoutput::

       [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']]
    zwarn_on_multiple_string_args_to_oneof: More than one string argument passed to one_of, pass choices as a list or space-delimited string   )
stacklevelc                 D    | j                         |j                         k(  S r,   )upperabs     r   r   zone_of.<locals>.<lambda>   s    	QWWY 6 r   c                 \    |j                         j                  | j                               S r,   )rP   
startswithrQ   s     r   r   zone_of.<locals>.<lambda>   s    QWWY11!'')< r   c                 $    |j                  |       S r,   )rU   rQ   s     r   r   zone_of.<locals>.<lambda>   s    Q\\!_ r   z7Invalid argument to one_of, expected string or iterabler   r   Nc              3   8   K   | ]  }t        |      d k(    yw)r   N)r2   r.   syms     r   r0   zone_of.<locals>.<genexpr>  s     4S3s8q=4s   [ c              3   2   K   | ]  }t        |        y wr,   )r   rX   s     r   r0   zone_of.<locals>.<genexpr>
  s     "Uc#<S#A"Ur1   ]|c              3   F   K   | ]  }t        j                  |        y wr,   )reescaperX   s     r   r0   zone_of.<locals>.<genexpr>  s     B3		#Bs   !z\b(?:z)\b)flagsz | c              3   2   K   | ]  }t        |        y wr,   )repr)r.   r   s     r   r0   zone_of.<locals>.<genexpr>  s     #=DG#=r1   c                 0    |d   j                            S r   lower)r   r   r   
symbol_maps      r   r   zone_of.<locals>.<lambda>  s    Z!

5M r   z8Exception creating Regex for one_of, building MatchFirstTc              3   .   K   | ]  } |        y wr,    )r.   rY   parse_element_classs     r   r0   zone_of.<locals>.<genexpr>+  s     B3)#.Bs   )!
isinstancestr_typer   %warn_on_multiple_string_args_to_oneofwarningswarnoperatoreqtypingcastr;   splitIterablelist	TypeErrorNoMatchr2   	enumerateinsertr`   
IGNORECASEalljoinRegexr&   rg   r'   errorCaselessKeywordCaselessLiteralKeywordr-   
MatchFirst)rH   rI   rJ   rK   rF   rG   is_equalmaskssymbolsicurjotherre_flagspattretrY   CASELESSKEYWORDrk   rh   s                      @@r   one_ofr      s   X 'ZI%IH 	8X&::; 	 	 	
 6<;;, $!{{3%**,	D(	#t*QRRy 	
A
c'lQ
aj!'!a%'"23 		HAus#AEAI&5zCH$sE):AEAI&q%(		 FA c'lQ
 )1q	4G44277"UW"UUVVWXxxB'BB vS)H-CLL#=W#==> ;BB3ciik3.B
$$%MNJ Hw	7_	w;w7{#W	
  B'BBKK

7 ' C
 xx 	MMJWX  	s%   B	J! 
J"J! J! !*KKkeyvaluec                 B    t        t        t        | |z                     S )a  Helper 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:

    .. doctest::

       >>> text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
       
       >>> data_word = Word(alphas)
       >>> label = data_word + FollowedBy(':')
       >>> attr_expr = (
       ...    label
       ...    + Suppress(':')
       ...    + OneOrMore(data_word, stop_on=label)
       ...    .set_parse_action(' '.join))
       >>> print(attr_expr[1, ...].parse_string(text).dump())
       ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']

       >>> 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())
       [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
       - color: 'light blue'
       - posn: 'upper left'
       - shape: 'SQUARE'
       - texture: 'burlap'
       [0]:
         ['shape', 'SQUARE']
       [1]:
         ['posn', 'upper left']
       [2]:
         ['color', 'light blue']
       [3]:
         ['texture', 'burlap']

       >>> print(result['shape'])
       SQUARE
       >>> print(result.shape)  # object attribute access works too
       SQUARE
       >>> print(result.as_dict())
       {'shape': 'SQUARE', 'posn': 'upper left', 'color': 'light blue', 'texture': 'burlap'}
    )Dict	OneOrMoreGroup)r   r   s     r   dict_ofr   0  s    l 	%e,-..r   )asString	as_stringr   c                0   |xr |}t               j                  d       }|j                         }d|_         |d      | z    |d      z   }|rd }nd }|j                  |       | j                  |_        |j                  t        j                         |S )a)  Helper 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 a string 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:

    .. testcode::

       src = "this is test <b> bold <i>text</i> </b> normal text "
       for tag in ("b", "i"):
           opener, closer = make_html_tags(tag)
           patt = original_text_for(opener + ... + closer)
           print(patt.search_string(src)[0])

    prints:

    .. testoutput::

       ['<b> bold <i>text</i> </b>']
       ['<i>text</i>']
    c                     |S r,   rj   )r   locr   s      r   r   z#original_text_for.<locals>.<lambda>  s    3 r   F_original_start_original_endc                 4    | |j                   |j                   S r,   )r   r   r   r   r   s      r   r   z#original_text_for.<locals>.<lambda>  s    a(9(9AOO&L r   c                 R    | |j                  d      |j                  d       g|d d  y )Nr   r   popr   s      r   extractTextz&original_text_for.<locals>.extractText  s(    aee-.1GHIAaDr   )r   r$   r%   callPreparseignoreExprssuppress_warningDiagnostics)warn_ungrouped_named_tokens_in_collection)r   r   r   	locMarkerendlocMarker	matchExprr   s          r   original_text_forr   i  s    L %IH(()>?I>>#L %L+,t3l?6SSIL	J {+ ,,I{TTUr   c                 8    t        |       j                  d       S )zkHelper to undo pyparsing's default grouping of And expressions,
    even if all but one are non-empty.
    c                     | d   S r   rj   r   s    r   r   zungroup.<locals>.<lambda>  s
    1Q4 r   )TokenConverterr'   )r   s    r   ungroupr     s     $00@@r   c                     t               j                  d       }t         |d       | d      z    |j                         j	                         d      z         S )a<  
    .. deprecated:: 3.0.0
       Use the :class:`Located` class instead.

    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 ``<TAB>`` characters, you
    may want to call :meth:`ParserElement.parse_with_tabs`

    Example:

    .. testcode::

       wd = Word(alphas)
       res = locatedExpr(wd).search_string("ljsdf123lksdjjf123lkkjj1222")
       for match in res:
           print(match)

    prints:

    .. testoutput::

       [[0, 'ljsdf', 5]]
       [[8, 'lksdjjf', 15]]
       [[18, 'lkkjj', 23]]
    c                     |S r,   rj   )ssllr/   s      r   r   zlocatedExpr.<locals>.<lambda>  s    " r   
locn_startr   locn_end)r   r$   r   r%   leaveWhitespace)r   locators     r   locatedExprr     sW    D g&&'<=G
w-	
*',,.
(
(
*:
6	7 r   ())
ignoreExpropenerclosercontentignore_exprr   c          	         ||k7  r|t         u r|n|}|t         u r
t               }| |k(  rt        d      |t        | t              ret        |t              rTt        j                  t        |       } t        j                  t        |      }t        |       dk(  r|t        |      dk(  rn|8t        t        | t        | |z   t        j                  z   d      z               }nt        t               t        | |z   t        j                  z         z         }n|Lt        t        | t        |        z   t        |       z   t        t        j                  d      z               }nSt        t        t        |        t        |       z   t        t        j                  d      z               }nt        d      t        j                  r|j!                  d        t#               }|6|t%        t'        |       t)        ||z  |z        z   t'        |      z         z  }n2|t%        t'        |       t)        ||z        z   t'        |      z         z  }|j+                  d|  | d       d|_        |S )	a

  Helper method for defining nested lists enclosed in opening and
    closing delimiters (``"("`` and ``")"`` are the default).

    :param opener: str - opening character for a nested list
       (default= ``"("``); can also be a pyparsing expression

    :param closer: str - closing character for a nested list
       (default= ``")"``); can also be a pyparsing expression

    :param content: expression for items within the nested lists

    :param ignore_expr: expression for ignoring opening and closing delimiters
       (default = :class:`quoted_string`)

    Parameter ``ignoreExpr`` 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:

    .. testcode::

       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(DelimitedList(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(f"{func.name} ({func.type}) args: {func.args}")


    prints:

    .. testoutput::

       is_odd (int) args: [['int', 'x']]
       dec_to_hex (int) args: [['char', 'hchar']]
    z.opening and closing strings cannot be the sameNr   )exactzOopening and closing arguments must be strings if no content expression is givenc                 F    | d   j                  t        j                        S r   )stripParserElementDEFAULT_WHITE_CHARSr   s    r   r   znested_expr.<locals>.<lambda>a  s    !A$**]%F%FG r   znested z expression)_NO_IGNORE_EXPR_GIVENquoted_string
ValueErrorrl   rm   rs   rt   r;   r2   Combiner   
CharsNotInr   r   r   r-   r$   r!   r   Suppress
ZeroOrMorer&   errmsg)r   r   r   r   r   r   s         r   nested_exprr     sb   ` [ $.2G$G[Z
**"_
IJJfh'Jvx,H[[f-F[[f-F6{aCK1$4)%!'K( &-2S2S S&'G &$"VOm.O.OOG )%!'K&v./&v./ ))J)JRSTUG &!$V_,&v./()J)JRSTUG a 
 ,,$$G )CVz*s*:W*DEEQWHXX
 	
 	hv&C'M)BBXfEUUVVLL76(6(+67 CJJr   <>c                    t        | t              r| t        | |       } n| j                  t	        t
        t        dz         }|rt        j                         j                  t              }| | d      z   t        t        t        |t        d      z   |z                     z    t        ddg      d      j                  d	       z   |z   }nt         j                         j                  t              t	        t"        d
      z  }| | d      z   t        t        t        |j                  d       t        t        d      |z         z                     z    t        ddg      d      j                  d       z   |z   }t%        t'        d      | z   d
z   d      }|j)                  d d
       |j+                  fd        |ddj-                  j/                  dd      j1                         j3                               z         j)                  d d
      }|_        |_        t7         |             |_        ||fS )zVInternal helper to construct opening and closing tag expressions,
    given a tag name)rI   z_-:tag=/F)defaultemptyc                     |d   dk(  S Nr   r   rj   r   s      r   r   z_makeTags.<locals>.<lambda>      ! r   r   )exclude_charsc                 (    | d   j                         S r   rf   r   s    r   r   z_makeTags.<locals>.<lambda>  s    qtzz| r   c                     |d   dk(  S r   rj   r   s      r   r   z_makeTags.<locals>.<lambda>  r   r   z</)adjacentr   c           	          | j                  ddj                  j                  dd      j                         j	                               z   | j                               S )Nstartr[   : )__setitem__r~   replacetitleru   r%   )r   resnames    r   r   z_makeTags.<locals>.<lambda>  sF    !--bgggooc37==?EEGHH!&&(
 r   endr[   r   r   )rl   rm   r   namer"   alphas	alphanumsdbl_quoted_stringr%   r$   remove_quotesr   r   r   r   Optr   
printablesr   r-   r&   r'   r~   r   r   ru   r   SkipTotag_body)	tagStrxmlsuppress_LTsuppress_GTtagAttrNametagAttrValueopenTagcloseTagr   s	           @r   	_makeTagsr   s  s9    &(#c'2++vy501K
(--/@@OUm:eK(3-$?,$NOPQR (c#w'0AA+  	 %))+<<]KdcO
 
 Um#445KLhsml:;<	 (c#w'0AA+  	  wt}v-3eDHq	^$	

 S1779??ABBhG9A  GKHLhj)GHr   tag_strc                     t        | d      S )al  Helper 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:

    .. testcode::

       text = '<td>More info at the <a href="https://github.com/pyparsing/pyparsing/wiki">pyparsing</a> wiki page</td>'
       # 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 <A> tag (like "href" shown here) are
           # also accessible as named results
           print(link.link_text, '->', link.href)

    prints:

    .. testoutput::

       pyparsing -> https://github.com/pyparsing/pyparsing/wiki
    Fr   r   s    r   make_html_tagsr     s    8 We$$r   c                     t        | d      S )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`
    Tr   r   s    r   make_xml_tagsr    s     Wd##r   any_open_tagany_close_tagz_:zany tag;z-nbsp lt gt amp quot apos cent pound euro copyr   r^   c                  6    dt          dt        t               dS )Nz&(?P<entity>r^   z);)_most_common_entitiesr	   _htmlEntityMaprj   r   r   r   r     s    l013En3U2VVXY r   zcommon HTML entityc                 @    t         j                  |j                        S )zRHelper parser action to replace common HTML entities with their special characters)r  getentityr   s      r   replace_html_entityr    s    ahh''r   c                       e Zd ZdZdZdZy)OpAssoczvEnumeration of operator associativity
    - used in constructing InfixNotationOperatorSpec for :class:`infix_notation`r   rM   N)__name__
__module____qualname____doc__LEFTRIGHTrj   r   r   r  r    s    T DEr   r  	base_exprop_listlparrparc                     G d dt               }d|_        t               }|j                  | j                   d       t        |t              rt        |      }t        |t              rt        |      }||z   |z   j                  d| j                   d      }t        |t              rt        |t              s| t        |      z  }n| |z  }|D ]  }|dz   dd \  }	}
}}t        |	t              rt        j                  |	      }	t        j                  t        |	      }	|
d	k(  r<t        |	t        t        f      rt!        |	      d
k7  rt#        d      |	\  }}| | d}n|	 d}d|
cxk  rd	k  st#        d       t#        d      |t$        j&                  t$        j(                  fvrt#        d      t               j                  |      }t        j                  t        |      }t+        g       }|t$        j&                  u r|
dk(  r |||	z         }t        ||	d   z         }nG|
d
k(  rA|	$ |||	z   |z         }t        ||	|z   d   z         }n |||z         }t        |d         }n|
d	k(  r ||z   |z   z   |z         }t        |||z   |z   |z   d   z         }n|t$        j(                  u r|
dk(  r?t        |	t,              st-        |	      }	 ||	j.                  |z         }t        |	|z         }nw|
d
k(  rB|	# |||	z   |z         }t        ||	|z   d   z         }nM |||z         }t        ||d   z         }n0|
d	k(  r+ ||z   |z   z   |z         }t        ||z   |z   |z   |z         }d|_        |z   }|r7t        |t        t        f      r |j2                  |  n|j3                  |       |||z  j5                  |      z  }|} ||z  }|S )a  Helper method for constructing grammars of expressions made up of
    operators working in a precedence hierarchy.  Operators may be unary
    or binary, left- or right-associative.  Parse actions can also be
    attached to operator expressions. The generated parser will also
    recognize the use of parentheses to override operator precedences
    (see example below).

    Note: if you define a deep operator list, you may see performance
    issues when using infix_notation. See
    :class:`ParserElement.enable_packrat` for a mechanism to potentially
    improve your parser performance.

    Parameters:

    :param base_expr: expression representing the most basic operand to
       be used in the expression
    :param op_list: list of tuples, one for each operator precedence level
       in the expression grammar; each tuple is of the form ``(op_expr,
       num_operands, right_left_assoc, (optional)parse_action)``, where:

       - ``op_expr`` is the pyparsing expression for the operator; may also
         be a string, which will be converted to a Literal; if ``num_operands``
         is 3, ``op_expr`` is a tuple of two expressions, for the two
         operators separating the 3 terms
       - ``num_operands`` is the number of terms for this operator (must be 1,
         2, or 3)
       - ``right_left_assoc`` is the indicator whether the operator is right
         or left associative, using the pyparsing-defined constants
         ``OpAssoc.RIGHT`` and ``OpAssoc.LEFT``.
       - ``parse_action`` is the parse action to be associated with
         expressions matching this operator expression (the parse action
         tuple member may be omitted); if the parse action is passed
         a tuple or list of functions, this is equivalent to calling
         ``set_parse_action(*fn)``
         (:class:`ParserElement.set_parse_action`)

    :param lpar: expression for matching left-parentheses; if passed as a
       str, then will be parsed as ``Suppress(lpar)``. If lpar is passed as
       an expression (such as ``Literal('(')``), then it will be kept in
       the parsed results, and grouped with them. (default= ``Suppress('(')``)
    :param rpar: expression for matching right-parentheses; if passed as a
       str, then will be parsed as ``Suppress(rpar)``. If rpar is passed as
       an expression (such as ``Literal(')')``), then it will be kept in
       the parsed results, and grouped with them. (default= ``Suppress(')')``)

    Example:

    .. testcode::

       # simple example of four-function arithmetic with ints and
       # variable names
       integer = pyparsing_common.signed_integer
       varname = pyparsing_common.identifier

       arith_expr = infix_notation(integer | varname,
           [
           ('-', 1, OpAssoc.RIGHT),
           (one_of('* /'), 2, OpAssoc.LEFT),
           (one_of('+ -'), 2, OpAssoc.LEFT),
           ])

       arith_expr.run_tests('''
           5+3*6
           (5+3)*6
           (5+x)*y
           -2--11
           ''', full_dump=False)

    prints:

    .. testoutput::
       :options: +NORMALIZE_WHITESPACE


       5+3*6
       [[5, '+', [3, '*', 6]]]

       (5+3)*6
       [[[5, '+', 3], '*', 6]]

       (5+x)*y
       [[[5, '+', 'x'], '*', 'y']]

       -2--11
       [[['-', 2], '-', ['-', 11]]]
    c                       e Zd ZddZy)infix_notation.<locals>._FBc                 B    | j                   j                  ||       |g fS r,   )r   	try_parse)selfinstringr   	doActionss       r   	parseImplz%infix_notation.<locals>._FB.parseImple  s    II#.7Nr   NT)r  r  r  r!  rj   r   r   _FBr  d  s    	r   r#  zFollowedBy>_expressionnested_r,   N      rM   z@if numterms=3, opExpr must be a tuple or list of two expressionsz operationsr   z6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)r   .)rM   .F)
FollowedByr  r!   r&   r   rl   r;   r   r   rm   r   _literalStringClassrs   rt   tuplerw   r2   r   r  r  r  r4   r   r   show_in_diagramr$   setName)r  r  r  r  r#  r   r   lastExproperDefopExprarityrightLeftAssocpaopExpr1opExpr2	term_namethisExprmatch_lookaheadr   s                      r   infix_notationr8    s   |j 
 !CL
)CLLINN#;/0$~$~#:$..8H/TUK tX&:dH+Eu[11{*  L-4w->,C)~rfh'"66v>F]F3A:fudm4Fq8H V   &GW")G9K8I!(+.IEQUVV UVV',,!>>QRR"))"4"4Y"?;;w1b'W\\)z"%h&7"8!(VF^";<	!%&)(V*;h*F&GO %h&82CV1L&L MI&)(X*=&>O %hv&6 7I!"%w&1G;hF# "( 2W <x GPP	 w}},z!&#. [F"%fkkH&<"=!&8"34	!%&)(V*;h*F&GO %h&82CV1L&L MI&)(X*=&>O %h&1A&A BI!"%w&1G;hF# "(W"4x"?'"IH"TU	 +0' $i/	"udm,*	**B/**2.i(*33I>>YL\ HCJr   c           	      |   j                  dd        fdfd}fd}fd}t        t               j                  d      j	                               }t               t               j                  |      z   j                  d      }t               j                  |      j                  d      }	t               j                  |      j                  d	      }
|r?t        t        |      |z   t        |	t        |       z   t        |      z         z   |
z         }nDt        t        |      t        |	t        |       z   t        |      z         z   t        |
      z         }|j                  fd
       |j                  fd       | j                  t        t               z          |j                  d      S )av	  
    .. deprecated:: 3.0.0
       Use the :class:`IndentedBlock` class instead.

    Helper method for defining space-delimited indentation blocks,
    such as those used to define block statements in Python source code.

    :param blockStatementExpr: expression defining syntax of statement that
      is repeated within the indented block

    :param indentStack: list created by caller to manage indentation stack
      (multiple ``statementWithIndentedBlock`` expressions within a single
      grammar should share a common ``indentStack``)

    :param indent: boolean indicating whether block must be indented beyond
      the current level; set to ``False`` for block of left-most statements

    A valid block must contain at least one ``blockStatement``.

    (Note that indentedBlock uses internal parse actions which make it
    incompatible with packrat parsing.)

    Example:

    .. testcode::

       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:

    .. testoutput::

       [['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                       d   d d  y Nrj   )backup_stacksindentStacks   r   reset_stackz"indentedBlock.<locals>.reset_stack/  s    &r*Ar   c                     |t        |       k\  ry t        ||       }|d   k7  r"|d   kD  rt        | |d      t        | |d      y )Nr<  zillegal nestingznot a peer entry)r2   colr@   r   r   r   curColr>  s       r   checkPeerIndentz&indentedBlock.<locals>.checkPeerIndent2  sY    A;Q[_$B'$Q+<== A'9:: %r   c                 j    t        ||       }|d   kD  rj                  |       y t        | |d      )Nr<  znot a subentry)rA  appendr@   rB  s       r   checkSubIndentz%indentedBlock.<locals>.checkSubIndent;  s8    QKO#v& A'788r   c                     |t        |       k\  ry t        ||       }r|v st        | |d      |d   k  rj                          y y )Nznot an unindentr<  )r2   rA  r@   r   rB  s       r   checkUnindentz$indentedBlock.<locals>.checkUnindentB  sQ    A;Q+ 5 A'899KO#OO $r   z	 INDENTr[   UNINDENTc                  6     r j                  d      xr d S d S r;  r   )r=  s   r   r   zindentedBlock.<locals>.<lambda>_  s    -!!"%.$ T r   c                             S r,   rj   )rR   rS   cdr?  s       r   r   zindentedBlock.<locals>.<lambda>a  s	    km r   zindented block)rF  r   LineEndset_whitespace_charssuppressr   r$   r&   r   r   r'   set_fail_actionignorer   )blockStatementExprr>  indentr=  rD  rG  rI  NLrJ  PEERUNDENTsmExprr?  s    ` `        @r   indentedBlockr[    s~   t Q(+;9 
7911%8AAC	DBg00@@JJ8TF7##O4==bADW%%m4==jIFGu%7883r7BCD 
 Gu%7883r7BCD&k
 I ;<g	12??+,,r   z/\*(?:[^*]|\*(?!/))*\*\/zC style commentz<!--[\s\S]*?-->zHTML commentz.*zrest of linez//(?:\\\n|[^\n])*z
// commentz2(?:/\*(?:[^*]|\*(?!/))*\*\/)|(?://(?:\\\n|[^\n])*)zC++ style commentz#.*zPython style comment_builtin_exprsallow_trailing_delimdelimcombineminmaxr^  c                $    t        | |||||      S )zT
    .. deprecated:: 3.1.0
       Use the :class:`DelimitedList` class instead.
    r]  )DelimitedList)r   r_  r`  ra  rb  r^  s         r   delimited_listre    s     eWc3=Q r   delimitedListre  countedArraymatchPreviousLiteralmatchPreviousExproneOfdictOforiginalTextFor
nestedExprmakeHTMLTagsmakeXMLTagsreplaceHTMLEntityinfixNotationr,   )FTFr"  ),FNN)fhtml.entitieshtmlrq   r`   sysrs   r[   r   coreutilr   r   r   r	   r
   r   Optionalr(   r<   rE   Unionrv   r;   boolr   r   r   r   r   r   ry   r   r   r   r   r*  r   r  __annotations__r"   r   r   r&   r  r  entitieshtml5itemsrstripr  r   r  r   common_html_entityr  Enumr  InfixNotationOperatorArgTyper   ParseActionInfixNotationOperatorSpecrw   r!   r8  r[  c_style_commenthtml_commentleave_whitespacerest_of_linedbl_slash_commentcpp_style_commentjava_style_commentpython_style_commentvarsvaluesrl   r\  re  opAssoc
anyOpenTaganyCloseTagcommonHTMLEntitycStyleCommenthtmlComment
restOfLinedblSlashCommentcppStyleCommentjavaStyleCommentpythonStyleCommentrd  rf  rg  rh  ri  rj  rk  rl  rm  rn  ro  rp  rq  )kvs   00r   <module>r     s     	 
     04D? /3	D?
D?oom,D? __]+	D?
 D?N" "= "J#m # #P 	E E
$c)
*EE E 	E E E EP6/ 6/} 6/ 6/t ,06EI6
6$(6>B66rA- AM A'm ' 'X  	  ),(+.22G	X 2GX#}$%X#}$%X __]+X /	X .X Xv (0}(3- 8v%3%&%
=-'(%>$3%&$
=-'($   ,T!"++I6 m 04}}/B/B/H/H/JKtq!!((3-"KGOO  Y
(  
(
d   %3eM3$67}c?Q9RRSS   "	$$	& 
$	
 $ '/sm&.sm	JJ+,J ]"
#J ]"
#	J
 JZ ;?b P-j 34==>OP #'(11.A &U|,,.77G./88F  19
(  P&  $V}--.DE  0 v}}'
*Q">A']#  (+ $ $ "'
]"
#m#$  
		
 
	  ( 
% 
##% )  -@!"2MB>'(>@VW $%8:MN &)	(G	,"#46GHlK8
?}m<$%8:MN  .Ag LD's   O;P"P