
    +                    n   S r SrSrSrSSKrSSKJr  SSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SSKrSS	KJr  SS
KJr   SSKJr   SSKJr   SSKJr  SSKJ r J!r!   SSKJ"r#   SSKJ%r%  \%" 5       r&S\&l         S\&l'        \%" 5       r(S\(l         S\(l)        S\(l*        S\(l+        S\(l,        S\(l-        \." \(5       V s/ s H2  o R_                  S5      (       d  U R_                  S5      (       d  M0  U PM4     sn \(l0        S r1\1\(l2        / SQr3\4" \	Rj                  5      SS r6\6S   S:H  r7\7(       a"  \	Rp                  r9\:r;\<r=\:r>\:r?\@\A\B\C\D\4\E\F\G\H\I/rJOG\	R                  r9\LrMS r?/ rJSSKNrNSR                  5        H  rP \JR                  \R" \N\P5      5        M     \T" S \M" S 5       5       5      rUS! rV\R                  \R                  -   rYS"rZ\ZS#-   r[\Y\Z-   r\\<" S$5      r]S%R                  S& \R                   5       5      r`GSS' jra " S( S)\b5      rc " S* S+\c5      rd " S, S-\c5      re " S. S/\e5      rf " S0 S1\b5      rg " S2 S3\h5      ri " S4 S5\h5      rj\ R                  " \j5        S6 rlS7 rmS8 rnS9 roS: rpS; rqS< rr GSS> jrs " S? S@\h5      rt " SA SB\t5      ru " SC SD\t5      rv " SE SF\v5      rw " SG SH\v5      rx " SI SJ\v5      ry " SK SL\y5      rz\yr{\y\tl|         " SM SN\v5      r} " SO SP\y5      r~ " SQ SR\}5      r " SS ST\v5      r " SU SV\v5      r " SW SX\5      r " SY SZ\5      r " S[ S\\v5      r " S] S^\v5      r " S_ S`\v5      r " Sa Sb\v5      r " Sc Sd\v5      r " Se Sf\5      r " Sg Sh\5      r " Si Sj\5      r " Sk Sl\5      r " Sm Sn\5      r " So Sp\5      r " Sq Sr\5      r " Ss St\t5      r " Su Sv\5      r " Sw Sx\5      r " Sy Sz\5      r " S{ S|\5      r " S} S~\t5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\h5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\h5      rS rGSS jrGSS jrS rS rS rS rGSS jrS rGS S jrS rS r\w" 5       GRe                  S5      r\" 5       GRe                  S5      r\" 5       GRe                  S5      r\" 5       GRe                  S5      r\" 5       GRe                  S5      r\" \]SS=S9GRq                  S 5      r\" S5      GRq                  S 5      r\" S5      GRq                  S 5      r\\-  \-  \" SS S9-  r\" \\" S5      -   \-   5      r\y" S5      \" S5      GR}                  S5      -   \" \" \\-  5      5      GR}                  S5      -   S-   rS rS rS rS rS r\" S 5      r \" S 5      r \" S5      \" S5      4S jrS rS rS r\h" 5       \l        GS!S jr\%" 5       r\h" 5       \l        \h" 5       \l        \" S5      \" S5      4S jr\r \" \" S5      S-   5      GRe                  S5      r\" \" S5      S-   5      GRe                  S5      r\" \" S5      S-   \" S5      S-   -  5      GRe                  S5      r\" \{" S5      \R                  5       -   5      GRe                  S5      rSSS\R                  5       4S jrGS S jr\" S5      r\" S5      r\" \" \Y\\S-   5      GRe                  S5      5      u  rr\" \" SR                  5       S5      5      r\" SSR                  \GR                  5       5      -   S-   5      GRe                  S5      rS r\" \" S5      S-   5      GRe                  S5      r \" S5      GRe                  S5      r \" S5      GR                  5       GRe                  S5      r\" S5      GRe                  S5      r \" \" S5      S-   \-  5      GRe                  S5      r \r \" S5      GRe                  S5      r \" \" \" \`SS9\" \" S5      \y" S5      ) -   \" 5       ) -   5      -   5      5      GR                  5       GRe                  S5      r\" \" \R                  5       \-  S%S95      GRe                  S5      r  " S S5      r " S S\h5      r " S S\h5      r " S S\5      r\GR                  GR                  GR                  \GR                  GR                  GR                  -   \GR                  GR                  GR                  -   \GR                  l        \7(       GaI  \" \S\GR                  5        \" \GS \GR                  5        \" \GS\GR                  5        \" \GS\GR                  5        \" \GS\GR                  5        \" \GS\GR                  5        \" \GR                  GS\GR                  GR                  5        \" \GR                  GS\GR                  GR                  5        \" \GR                  GS\GR                  GR                  5        \" \GS\GR                  5        \" \GS	\GR                  5        \" \GS
\GR                  5         " GS GS5      rG\ GS:X  Ga  \~" GS5      Gr\~" GS5      Gr\" \Y\\GS-   5      Gr\" G\GSSGS9GRq                  \5      Gr\" \" G\5      5      GRe                  GS5      GrGSG\-  Gr\" G\GSSGS9GRq                  \5      Gr\" \" G\5      5      GRe                  GS5      GrG\" GS5      G\" GS5      -   G\-   G\" GS5      -   Gr	G\	GR                  GS5        \GR                  GR                  GS5        \GR                  GR                  GS5        \GR                  GR                  GS5        SSGKGr\GR                  GRq                  \" G\GR                  5      5        \GR                  GR                  GS5        gg! \ a
    SSKJr   GNaf = f! \ a
    SSKJr   GNmf = f! \ a    SSKJr  SSKJ r J!r!   GNyf = f! \ a     SSK$J"r#   GN! \ a    Sr#  GNf = ff = f! \ a     " S S5      r% GNf = fs  sn f ! \S a     GM  f = f("  a
  
pyparsing module - Classes and methods to define and execute parsing grammars
=============================================================================

The pyparsing module is an alternative approach to creating and
executing simple grammars, vs. the traditional lex/yacc approach, or the
use of regular expressions.  With pyparsing, you don't need to learn
a new syntax for defining grammars or matching expressions - the parsing
module provides a library of classes that you use to construct the
grammar directly in Python.

Here is a program to parse "Hello, World!" (or any greeting of the form
``"<salutation>, <addressee>!"``), built up using :class:`Word`,
:class:`Literal`, and :class:`And` elements
(the :class:`'+'<ParserElement.__add__>` operators create :class:`And` expressions,
and the strings are auto-converted to :class:`Literal` expressions)::

    from pyparsing import Word, alphas

    # define grammar of a greeting
    greet = Word(alphas) + "," + Word(alphas) + "!"

    hello = "Hello, World!"
    print (hello, "->", greet.parseString(hello))

The program outputs the following::

    Hello, World! -> ['Hello', ',', 'World', '!']

The Python representation of the grammar is quite readable, owing to the
self-explanatory class names, and the use of '+', '|' and '^' operators.

The :class:`ParseResults` object returned from
:class:`ParserElement.parseString` can be
accessed as a nested list, a dictionary, or an object with named
attributes.

The pyparsing module handles some of the problems that are typically
vexing when writing text parsers:

  - extra or missing whitespace (the above program will also handle
    "Hello,World!", "Hello  ,  World  !", etc.)
  - quoted strings
  - embedded comments


Getting Started -
-----------------
Visit the classes :class:`ParserElement` and :class:`ParseResults` to
see the base classes that most other pyparsing
classes inherit from. Use the docstrings for examples of how to:

 - construct literal match expressions from :class:`Literal` and
   :class:`CaselessLiteral` classes
 - construct character word-group expressions using the :class:`Word`
   class
 - see how to create repetitive expressions using :class:`ZeroOrMore`
   and :class:`OneOrMore` classes
 - use :class:`'+'<And>`, :class:`'|'<MatchFirst>`, :class:`'^'<Or>`,
   and :class:`'&'<Each>` operators to combine simple expressions into
   more complex ones
 - associate names with your parsed results using
   :class:`ParserElement.setResultsName`
 - access the parsed data, which is returned as a :class:`ParseResults`
   object
 - find some helpful expression short-cuts like :class:`delimitedList`
   and :class:`oneOf`
 - find more useful common expressions in the :class:`pyparsing_common`
   namespace class
z2.4.7z30 Mar 2020 00:43 UTCz*Paul McGuire <ptmcg@users.sourceforge.net>    N)ref)datetime)
itemgetter)wraps)contextmanager)filterfalse)ifilterfalse)RLock)Iterable)MutableMappingMapping)OrderedDict)SimpleNamespacec                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       %lib/third_party/pyparsing/__init__.pyr   r      s    4r   r   aA  
    A cross-version compatibility configuration for pyparsing features that will be
    released in a future version. By setting values in this configuration to True,
    those features can be enabled in prior versions for compatibility development
    and testing.

     - collect_all_And_tokens - flag to enable fix for Issue #63 that fixes erroneous grouping
       of results names when an And expression is nested within an Or or MatchFirst; set to
       True to enable bugfix released in pyparsing 2.3.0, or False to preserve
       pre-2.3.0 handling of named results
Ta  
Diagnostic configuration (all default to False)
     - warn_multiple_tokens_in_named_alternation - flag to enable warnings when a results
       name is defined on a MatchFirst or Or expression with one or more And subexpressions
       (only warns if __compat__.collect_all_And_tokens is False)
     - warn_ungrouped_named_tokens_in_collection - flag to enable warnings when a results
       name is defined on a containing expression with ungrouped subexpressions that also
       have results names
     - warn_name_set_on_empty_Forward - flag to enable warnings whan a Forward is defined
       with a results name, but has no contents defined
     - warn_on_multiple_string_args_to_oneof - flag to enable warnings whan oneOf is
       incorrectly called with multiple str arguments
     - enable_debug_on_named_expressions - flag to auto-enable debug on all subsequent
       calls to ParserElement.setName()
Fenable_warn_c                  \    S[         l        S[         l        S[         l        S[         l        g NT)__diag__)warn_multiple_tokens_in_named_alternation)warn_ungrouped_named_tokens_in_collectionwarn_name_set_on_empty_Forward%warn_on_multiple_string_args_to_oneofr   r   r   _enable_all_warningsr#      s"    9=H69=H6.2H+59H2r   )t__version____versionTime__
__author__
__compat__r   AndCaselessKeywordCaselessLiteral
CharsNotInCombineDictEachEmpty
FollowedByForward
GoToColumnGroupKeywordLineEnd	LineStartLiteral
PrecededBy
MatchFirstNoMatchNotAny	OneOrMoreOnlyOnceOptionalOrParseBaseExceptionParseElementEnhanceParseExceptionParseExpressionParseFatalExceptionParseResultsParseSyntaxExceptionParserElementQuotedStringRecursiveGrammarExceptionRegexSkipTo	StringEndStringStartSuppressTokenTokenConverterWhiteWordWordEnd	WordStart
ZeroOrMoreChar	alphanumsalphas
alphas8bitanyCloseTag
anyOpenTagcStyleCommentcolcommaSeparatedListcommonHTMLEntitycountedArraycppStyleCommentdblQuotedStringdblSlashCommentdelimitedListdictOfdowncaseTokensemptyhexnumshtmlCommentjavaStyleCommentlinelineEnd	lineStartlinenomakeHTMLTagsmakeXMLTagsmatchOnlyAtColmatchPreviousExprmatchPreviousLiteral
nestedExprnullDebugActionnumsoneOfopAssocoperatorPrecedence
printablespunc8bitpythonStyleCommentquotedStringremoveQuotesreplaceHTMLEntityreplaceWith
restOfLinesglQuotedStringsrange	stringEndstringStarttraceParseActionunicodeStringupcaseTokenswithAttributeindentedBlockoriginalTextForungroupinfixNotationlocatedExpr	withClass
CloseMatchtokenMappyparsing_commonpyparsing_unicodeunicode_setconditionAsParseActionre   c                     [        U [        5      (       a  U $  [        U 5      $ ! [         a_    [        U 5      R	                  [
        R                  " 5       S5      n[        S5      nUR                  S 5        UR                  U5      s $ f = f)zDrop-in replacement for str(obj) that tries to be Unicode
friendly. It first tries str(obj). If that fails with
a UnicodeEncodeError, then it tries unicode(obj). It then
< returns the unicode object | encodes it with the default
encoding | ... >.
xmlcharrefreplacez&#\d+;c                 B    S[        [        U S   SS 5      5      SS  -   $ )Nz\ur      )hexintts    r   <lambda>_ustr.<locals>.<lambda>   s#    C!Qr
O8LQR8P0Pr   )

isinstanceunicodestrUnicodeEncodeErrorencodesysgetdefaultencodingrJ   setParseActiontransformString)objret
xmlcharrefs      r   _ustrr      s     c7##J
	3 s8O! 	3#,%%c&<&<&>@STCy)J%%&PQ--c22	3s   
$ A&BBz6sum len sorted reversed list tuple set any all min maxc              #   $   #    U  H  ov   M     g 7fNr   ).0ys     r   	<genexpr>r     s     +(Qq(s      c                     SnS SR                  5        5       n[        X5       H  u  p4U R                  X45      n M     U $ )z/Escape &, <, >, ", ', etc. in a string of data.z&><"'c              3   2   #    U  H  nS U-   S-   v   M     g7f)&;Nr   )r   ss     r   r   _xml_escape.<locals>.<genexpr>  s     G)FA#'C-)Fs   zamp gt lt quot apos)splitzipreplace)datafrom_symbols
to_symbolsfrom_to_s        r   _xml_escaper     sA     LG)>)D)D)FGJ,3
||E' 4Kr   
0123456789ABCDEFabcdef\    c              #   P   #    U  H  o[         R                  ;  d  M  Uv   M     g 7fr   )string
whitespacer   cs     r   r   r     s     O 01V=N=N4NQQ 0s   &	&c                    ^ ^^ Ub  UOSmU(       a  [         O[        m[        T 5      m [        T 5      UU U4S j5       nU$ )Nzfailed user-defined conditionc                 F   > [        T" XU5      5      (       d	  T" XT5      eg r   )bool)r   lr   exc_typefnmsgs      r   pa"conditionAsParseAction.<locals>.pa$  s&    BqQK  1%% !r   )rD   rB   _trim_arityr   )r   messagefatalr   r   r   s   `   @@r   r   r     s@    ('.MC&+"H	RB
2Y& & Ir   c                   T    \ rS rSrSrSS jr\S 5       rS rS r	S r
SS	 jrS
 rSrg)r@   i+  z7base exception class for all parsing runtime exceptionsNc                 h    X l         Uc  Xl        SU l        OX0l        Xl        X@l        XU4U l        g Nr   )locr   pstrparserElementargs)selfr   r   r   elems        r   __init__ParseBaseException.__init__/  s4    ;HDIHI!$	r   c                 h    U " UR                   UR                  UR                  UR                  5      $ )z
internal factory method to simplify creating one type of ParseException
from another - avoids having __init__ signature conflicts among subclasses
)r   r   r   r   )clspes     r   _from_exception"ParseBaseException._from_exception:  s'     277BFFBFFB,<,<==r   c                     US:X  a   [        U R                  U R                  5      $ US;   a   [        U R                  U R                  5      $ US:X  a   [	        U R                  U R                  5      $ [        U5      e)zsupported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text
rn   )r]   columnrk   )rn   r   r   r]   rk   AttributeError)r   anames     r   __getattr__ParseBaseException.__getattr__B  sf     H$((DII..''txx++f_$)),, ''r   c                 J   U R                   (       a`  U R                  [        U R                   5      :  a  SnO<SU R                   U R                  U R                  S-    -  R                  SS5      nOSnSU R                  XR                  U R
                  U R                  4-  $ )Nz, found end of textz
, found %rr   z\\\r   z%%s%s  (at char %d), (line:%d, col:%d))r   r   lenr   r   rn   r   )r   foundstrs     r   __str__ParseBaseException.__str__Q  s    99xx3tyy>)0(499TXXdhhl+KKTTUZ\`aH7HHh$++t{{KL 	Mr   c                     [        U 5      $ r   r   r   s    r   __repr__ParseBaseException.__repr__[      T{r   c                     U R                   nU R                  S-
  nU(       a  SR                  USU XUS 45      nUR                  5       $ )zrExtracts the exception line from the input string, and marks
the location of the exception with a special symbol.
r   r   N)rk   r   joinstrip)r   markerStringline_strline_columns       r   markInputline ParseBaseException.markInputline]  sR     99kkAoww+ 6 ,{|.D F GH~~r   c                 L    SR                  5       [        [        U 5      5      -   $ )Nzlineno col line)r   dirtyper   s    r   __dir__ParseBaseException.__dir__g  s     &&(3tDz?::r   )r   r   r   r   r   )r   NN)z>!<)r   r   r   r   __doc__r   classmethodr   r   r   r   r  r  r   r   r   r   r@   r@   +  s8    A	% > >(	M	 ;r   r@   c                   ,    \ rS rSrSr\SS j5       rSrg)rB   ij  a  
Exception thrown when parse expressions don't match class;
supported attributes by name are:
- lineno - returns the line number of the exception text
- col - returns the column number of the exception text
- line - returns the line containing the exception text

Example::

    try:
        Word(nums).setName("integer").parseString("ABC")
    except ParseException as pe:
        print(pe)
        print("column: {}".format(pe.col))

prints::

   Expected integer (at char 0), (line:1, col:1)
    column: 1

c                    SSK nUc  [        R                  " 5       n/ n[        U [        5      (       a?  UR                  U R                  5        UR                  SU R                  S-
  -  S-   5        UR                  SR                  [        U 5      R                  U 5      5        US:  Ga  UR                  U R                  US9n[        5       n[        XA* S 5       GHM  u  pgUS   nUR                  R!                  SS5      n	[        U	["        5      (       av  UR$                  R&                  S	;  a  MX  X;   a  M_  UR)                  U	5        [        U	5      n
UR                  S
R                  U
R*                  U
R                  U	5      5        OU	bA  [        U	5      n
UR                  SR                  U
R*                  U
R                  5      5        OIUR$                  nUR&                  S;   a  GM  UR                  SR                  UR&                  5      5        US-  nU(       a  GMN    O   SR-                  U5      $ )a  
Method to take an exception and translate the Python internal traceback into a list
of the pyparsing expressions that caused the exception to be raised.

Parameters:

 - exc - exception raised during parsing (need not be a ParseException, in support
   of Python exceptions that might be raised in a parse action)
 - depth (default=16) - number of levels back in the stack trace to list expression
   and function names; if None, the full stack trace names will be listed; if 0, only
   the failing input line, marker, and exception string will be shown

Returns a multi-line string listing the ParserElements and/or function names in the
exception's stack trace.

Note: the diagnostic output will include string representations of the expressions
that failed to parse. These representations will be more helpful if you use `setName` to
give identifiable names to your expressions. Otherwise they will use the default string
forms, which may be cryptic to read.

explain() is only supported under Python 3.
r   N r   ^z{0}: {1})contextr   )	parseImpl_parseNoCachez{0}.{1} - {2}z{0}.{1})wrapperz<module>z{0}
)inspectr   getrecursionlimitr   r@   appendrk   r]   formatr  r   getinnerframes__traceback__set	enumeratef_localsgetrG   f_codeco_nameaddr   r   )excdepthr  r   callersseenifffrmf_self	self_typecodes               r   explainParseException.explain  s   0 	=))+Ec-..JJsxx JJscggk*S01

:$$T#Y%7%7=>19,,S->->,NG5D"767#34e))&$7fm44zz))1OO ~ HHV$ $VIJJ55i6J6J6?6H6H6< > ? ' $VIJJy//	0D0D090B0B D E ::D||'>> JJu||DLL9:
u9 5< yy~r   r   N)   )r   r   r   r   r	  staticmethodr+  r   r   r   r   rB   rB   j  s    , B Br   rB   c                       \ rS rSrSrSrg)rD   i  zguser-throwable exception thrown when inconsistent parse content
is found; stops all parsing immediatelyr   Nr   r   r   r   r	  r   r   r   r   rD   rD     s
    2r   rD   c                       \ rS rSrSrSrg)rF   i  zjust like :class:`ParseFatalException`, but thrown internally
when an :class:`ErrorStop<And._ErrorStop>` ('-' operator) indicates
that parsing is to stop immediately because an unbacktrackable
syntax error has been found.
r   Nr0  r   r   r   rF   rF     s    
 	r   rF   c                   $    \ rS rSrSrS rS rSrg)rI   i  zaexception thrown by :class:`ParserElement.validate` if the
grammar could be improperly recursive
c                     Xl         g r   parseElementTracer   parseElementLists     r   r   "RecursiveGrammarException.__init__  s    !1r   c                      SU R                   -  $ )NzRecursiveGrammarException: %sr4  r   s    r   r   !RecursiveGrammarException.__str__  s    .1G1GGGr   r4  N)r   r   r   r   r	  r   r   r   r   r   r   rI   rI     s    2Hr   rI   c                   ,    \ rS rSrS rS rS rS rSrg)_ParseResultsWithOffseti  c                     X4U l         g r   tup)r   p1p2s      r   r    _ParseResultsWithOffset.__init__  s    8r   c                      U R                   U   $ r   r>  r   r%  s     r   __getitem__#_ParseResultsWithOffset.__getitem__  s    xx{r   c                 2    [        U R                  S   5      $ Nr   )reprr?  r   s    r   r    _ParseResultsWithOffset.__repr__  s    DHHQK  r   c                 0    U R                   S   U4U l         g rH  r>  rD  s     r   	setOffset!_ParseResultsWithOffset.setOffset  s    HHQK#r   r>  N)	r   r   r   r   r   rE  r   rL  r   r   r   r   r<  r<    s    !$r   r<  c                      \ rS rSrSrS1S jrSSSS\4S jrS r\4S jr	S	 r
S
 rS rS r\rS rS rS rS rS r\(       a	  \r \r \rO\r \r \r S rS rS rS rS rS2S jrS rS rS r S r!S r"S r#S r$S r%S  r&S! r'S3S" jr(S# r)S$ r*S% r+S4S& jr,S' r-S( r.S5S) jr/S* r0S+ r1S, r2S- r3S. r4\5S2S/ j5       r6S0r7g)6rE   i  a  Structured parse results, to provide multiple means of access to
the parsed data:

   - as a list (``len(results)``)
   - by list index (``results[0], results[1]``, etc.)
   - by attribute (``results.<resultsName>`` - see :class:`ParserElement.setResultsName`)

Example::

    integer = Word(nums)
    date_str = (integer.setResultsName("year") + '/'
                    + integer.setResultsName("month") + '/'
                    + integer.setResultsName("day"))
    # equivalent form:
    # date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    # parseString returns a ParseResults object
    result = date_str.parseString("1999/12/31")

    def test(s, fn=repr):
        print("%s -> %s" % (s, fn(eval(s))))
    test("list(result)")
    test("result[0]")
    test("result['month']")
    test("result.day")
    test("'month' in result")
    test("'minutes' in result")
    test("result.dump()", str)

prints::

    list(result) -> ['1999', '/', '12', '/', '31']
    result[0] -> '1999'
    result['month'] -> '12'
    result.day -> '31'
    'month' in result -> True
    'minutes' in result -> False
    result.dump() -> ['1999', '/', '12', '/', '31']
    - day: 31
    - month: 12
    - year: 1999
NTc                 b    [        X5      (       a  U$ [        R                  U 5      nSUl        U$ r   )r   object__new___ParseResults__doinit)r   toklistnameasListmodalretobjs         r   rQ  ParseResults.__new__   s,    g##N$r   c                 F   U R                   (       a  SU l         S U l        S U l        0 U l        X0l        X@l        Uc  / nU" U[        5      (       a  US S  U l        O+U" U[        5      (       a  [        U5      U l        OU/U l        [        5       U l
        Ub  U(       a  U(       d  SU R                  U'   U" U[        5      (       a  [        U5      nX l        U" U[        S 5      [        [        45      (       a	  US S/ 4;   d}  U" U[        5      (       a  U/nU(       aX  U" U[        5      (       a"  [!        [        UR                  5      S5      X'   O[!        [        US   5      S5      X'   X U   l        g  US   X'   g g g g ! ["        [$        [&        4 a    XU'    g f = f)NFr   r   )rR  _ParseResults__name_ParseResults__parent_ParseResults__accumNames_ParseResults__asList_ParseResults__modallist_ParseResults__toklist_generatorTypedict_ParseResults__tokdictr   r   r  
basestringrE   r<  KeyError	TypeError
IndexError)r   rS  rT  rU  rV  r   s         r   r   ParseResults.__init__)  sz   ==!DMDK DM "D"M L'4((!(G^44!%g")!VDN*+!!$'$$$T{KwdZ(FGGGX\^`bdWeLegz22&iG!'<88%<\'J[J[=\^_%`
%<\'RS*=UWX%Y
(,J%-%,QZ
 Mf !%$ %i< -%,T
-s   9F F F c                     [        U[        [        45      (       a  U R                  U   $ XR                  ;  a  U R
                  U   S   S   $ [        U R
                  U    Vs/ s H  o"S   PM	     sn5      $ s  snf )Nr   r   )r   r   slicer`  r\  rc  rE   )r   r%  vs      r   rE  ParseResults.__getitem__P  sq    a#u&&>>!$$)))~~a(,Q//#4>>!3D$E3DaqT3D$EFF$Es   %A:c                    U" U[         5      (       a;  U R                  R                  U[        5       5      U/-   U R                  U'   US   nOjU" U[        [
        45      (       a  X R                  U'   UnOAU R                  R                  U[        5       5      [        US5      /-   U R                  U'   UnU" U[        5      (       a  [        U 5      Ul	        g g rH  )
r<  rc  r  r_  r   rj  r`  rE   wkrefr[  )r   krk  r   subs        r   __setitem__ParseResults.__setitem__Y  s    a011 $ 2 21df = CDNN1A$CC<(( !NN1C $ 2 21df =AXYZ\]A^@_ _DNN1Cc<(( ;CL )r   c           	         [        U[        [        45      (       a  [        U R                  5      nU R                  U	 [        U[        5      (       a  US:  a  X-  n[        XS-   5      n[        [        UR                  U5      6 5      nUR                  5         U R                  R                  5        H7  u  pEU H,  n[        U5       H  u  nu  p[        XX:  -
  5      XW'   M     M.     M9     g U R                  U	 g Nr   r   )r   r   rj  r   r`  r_  rangeindicesreverserc  itemsr  r<  )
r   r%  mylenremovedrT  occurrencesjro  valuepositions
             r   __delitem__ParseResults.__delitem__f  s    a#u&&'Eq! !S!!q5JA!UO5!))E"234GOO%)^^%9%9%;! A09+0F,,E)@T\T`Ha)b 1G ! &<
 q!r   c                     XR                   ;   $ r   )rc  )r   ro  s     r   __contains__ParseResults.__contains__{  s    NN""r   c                 ,    [        U R                  5      $ r   )r   r`  r   s    r   __len__ParseResults.__len__~  s    4>>""r   c                 "    U R                   (       $ r   )r`  r   s    r   __bool__ParseResults.__bool__  s    &'r   c                 ,    [        U R                  5      $ r   iterr`  r   s    r   __iter__ParseResults.__iter__  s    DNN##r   c                 8    [        U R                  S S S2   5      $ Nr   r  r   s    r   __reversed__ParseResults.__reversed__  s    DNN4R4())r   c                     [        U R                  S5      (       a  U R                  R                  5       $ [        U R                  5      $ )Niterkeys)hasattrrc  r  r  r   s    r   	_iterkeysParseResults._iterkeys  s5    4>>:..>>**,,''r   c                 8   ^  U 4S jT R                  5        5       $ )Nc              3   .   >#    U  H
  nTU   v   M     g 7fr   r   r   ro  r   s     r   r   +ParseResults._itervalues.<locals>.<genexpr>  s     2!1AQ!1s   r  r   s   `r   _itervaluesParseResults._itervalues  s    2!122r   c                 8   ^  U 4S jT R                  5        5       $ )Nc              3   0   >#    U  H  oTU   4v   M     g 7fr   r   r  s     r   r   *ParseResults._iteritems.<locals>.<genexpr>  s     7&6DG&6s   r  r   s   `r   
_iteritemsParseResults._iteritems  s    7dnn&677r   c                 4    [        U R                  5       5      $ )zVReturns all named result keys (as a list in Python 2.x, as an iterator in Python 3.x).)r_  r  r   s    r   keysParseResults.keys  s    ((r   c                 4    [        U R                  5       5      $ )zXReturns all named result values (as a list in Python 2.x, as an iterator in Python 3.x).)r_  
itervaluesr   s    r   valuesParseResults.values  s    )**r   c                 4    [        U R                  5       5      $ )zfReturns all named result key-values (as a list of tuples in Python 2.x, as an iterator in Python 3.x).)r_  	iteritemsr   s    r   rx  ParseResults.items  s    ())r   c                 ,    [        U R                  5      $ )zSince keys() returns an iterator, this method is helpful in bypassing
code that looks for the existence of any defined results names.)r   rc  r   s    r   haskeysParseResults.haskeys  s     DNN##r   c                    U(       d  S/nUR                  5        H   u  p4US:X  a	  US   U4nM  [        SU-  5      e   [        US   [        5      (       d  [	        U5      S:X  d	  US   U ;   a  US   nX   nX	 U$ US   nU$ )a  
Removes and returns item at specified index (default= ``last``).
Supports both ``list`` and ``dict`` semantics for ``pop()``. If
passed no argument or an integer argument, it will use ``list``
semantics and pop tokens from the list of parsed tokens. If passed
a non-integer argument (most likely a string), it will use ``dict``
semantics and pop the corresponding value from any defined results
names. A second default return value argument is supported, just as in
``dict.pop()``.

Example::

    def remove_first(tokens):
        tokens.pop(0)
    print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
    print(OneOrMore(Word(nums)).addParseAction(remove_first).parseString("0 123 321")) # -> ['123', '321']

    label = Word(alphas)
    patt = label("LABEL") + OneOrMore(Word(nums))
    print(patt.parseString("AAB 123 321").dump())

    # Use pop() in a parse action to remove named result (note that corresponding value is not
    # removed from list form of results)
    def remove_LABEL(tokens):
        tokens.pop("LABEL")
        return tokens
    patt.addParseAction(remove_LABEL)
    print(patt.parseString("AAB 123 321").dump())

prints::

    ['AAB', '123', '321']
    - LABEL: AAB

    ['AAB', '123', '321']
r   defaultr   z-pop() got an unexpected keyword argument '%s'r   )rx  rf  r   r   r   )r   r   kwargsro  rk  indexr   defaultvalues           r   popParseResults.pop  s    J 4DLLNDAI~Q| ORS STT	 #
 tAw$$t9>7d?GE+CJ7Lr   c                     X;   a  X   $ U$ )a  
Returns named result matching the given key, or if there is no
such name, then returns the given ``defaultValue`` or ``None`` if no
``defaultValue`` is specified.

Similar to ``dict.get()``.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parseString("1999/12/31")
    print(result.get("year")) # -> '1999'
    print(result.get("hour", "not specified")) # -> 'not specified'
    print(result.get("hour")) # -> None
r   )r   keydefaultValues      r   r  ParseResults.get  s    $ ;9r   c                     U R                   R                  X5        U R                  R                  5        H.  u  p4[	        U5       H  u  nu  pg[        XgXq:  -   5      XE'   M     M0     g)a  
Inserts new element at location index in the list of parsed tokens.

Similar to ``list.insert()``.

Example::

    print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']

    # use a parse action to insert the parse location in the front of the parsed results
    def insert_locn(locn, tokens):
        tokens.insert(0, locn)
    print(OneOrMore(Word(nums)).addParseAction(insert_locn).parseString("0 123 321")) # -> [0, '0', '123', '321']
N)r`  insertrc  rx  r  r<  )r   r  insStrrT  r{  ro  r}  r~  s           r   r  ParseResults.insert
  s[     	e,!%!5!5!7D(1+(>$$E!8HL\@]!^ )? "8r   c                 :    U R                   R                  U5        g)a  
Add single element to end of ParseResults list of elements.

Example::

    print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']

    # use a parse action to compute the sum of the parsed integers, and add it to the end
    def append_sum(tokens):
        tokens.append(sum(map(int, tokens)))
    print(OneOrMore(Word(nums)).addParseAction(append_sum).parseString("0 123 321")) # -> ['0', '123', '321', 444]
N)r`  r  )r   items     r   r  ParseResults.append  s     	d#r   c                     [        U[        5      (       a  U R                  U5        gU R                  R	                  U5        g)a  
Add sequence of elements to end of ParseResults list of elements.

Example::

    patt = OneOrMore(Word(alphas))

    # use a parse action to append the reverse of the matched strings, to make a palindrome
    def make_palindrome(tokens):
        tokens.extend(reversed([t[::-1] for t in tokens]))
        return ''.join(tokens)
    print(patt.addParseAction(make_palindrome).parseString("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl'
N)r   rE   __iadd__r`  extend)r   itemseqs     r   r  ParseResults.extend.  s/     g|,,MM'"NN!!'*r   c                 V    U R                   SS2	 U R                  R                  5         g)z'
Clear all elements and results names.
N)r`  rc  clearr   s    r   r  ParseResults.clearA  s      NN1r   c                 ,     X   $ ! [          a     gf = fr   )re  r   rT  s     r   r   ParseResults.__getattr__H  s!    	: 		s    
c                 .    U R                  5       nX!-  nU$ r   )copy)r   otherr   s      r   __add__ParseResults.__add__N  s    iik
r   c                   ^ UR                   (       a  [        U R                  5      mU4S jnUR                   R                  5       nU VVVs/ s H)  u  pEU  H  nU[	        US   U" US   5      5      4PM     M+     nnnnU H6  u  pFX`U'   [        US   [        5      (       d  M#  [        U 5      US   l        M8     U =R                  UR                  -  sl        U R                  R                  UR                  5        U $ s  snnnf )Nc                    > U S:  a  T$ U T-   $ rH  r   )aoffsets    r   r   'ParseResults.__iadd__.<locals>.<lambda>V  s    AE&"Aq6z"Ar   r   r   )rc  r   r`  rx  r<  r   rE   rn  r[  r\  update)	r   r  	addoffset
otheritemsro  vlistrk  otherdictitemsr  s	           @r   r  ParseResults.__iadd__S  s    ??(FAI..0J.8I.8(!%Q  !"9!A$	!A$"PQBG R.8  I&QadL11$)$KAaDM '
 	%//)  !3!34Is   0Dc                 `    [        U[        5      (       a  US:X  a  U R                  5       $ X-   $ rH  )r   r   r  r   r  s     r   __radd__ParseResults.__radd__c  s+    eS!!eqj99; <r   c                 d    S[        U R                  5      < S[        U R                  5      < S3$ )N(, ))rI  r`  rc  r   s    r   r   ParseResults.__repr__k  s    !$..143GHHr   c                 R    SSR                  S U R                   5       5      -   S-   $ )N[r  c              3   x   #    U  H0  n[        U[        5      (       a  [        U5      O
[        U5      v   M2     g 7fr   )r   rE   r   rI  )r   r%  s     r   r   'ParseResults.__str__.<locals>.<genexpr>o  s-     l]kXY:a+F+FuQxDQRGS]ks   8:])r   r`  r   s    r   r   ParseResults.__str__n  s)    TYYl]a]k]klllorrrr   c                     / nU R                    He  nU(       a  U(       a  UR                  U5        [        U[        5      (       a  X#R	                  5       -  nMK  UR                  [        U5      5        Mg     U$ r   )r`  r  r   rE   _asStringListr   )r   sepoutr  s       r   r  ParseResults._asStringListq  sZ    NNDs

3$--))++

5;' # 
r   c                     U R                    Vs/ s H*  n[        U[        5      (       a  UR                  5       OUPM,     sn$ s  snf )a(  
Returns the parse results as a nested list of matching tokens, all converted to strings.

Example::

    patt = OneOrMore(Word(alphas))
    result = patt.parseString("sldkj lsdkj sldkj")
    # even though the result prints in string-like form, it is actually a pyparsing ParseResults
    print(type(result), result) # -> <class 'pyparsing.ParseResults'> ['sldkj', 'lsdkj', 'sldkj']

    # Use asList() to create an actual list
    result_list = result.asList()
    print(type(result_list), result_list) # -> <class 'list'> ['sldkj', 'lsdkj', 'sldkj']
)r`  r   rE   rU  )r   ress     r   rU  ParseResults.asList|  s=     SWR`R`aR`3
3 = =

3FR`aaas   1Ac                    ^ [         (       a  U R                  nOU R                  nU4S jm[        U4S jU" 5        5       5      $ )aD  
Returns the named parse results as a nested dictionary.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parseString('12/31/1999')
    print(type(result), repr(result)) # -> <class 'pyparsing.ParseResults'> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]})

    result_dict = result.asDict()
    print(type(result_dict), repr(result_dict)) # -> <class 'dict'> {'day': '1999', 'year': '12', 'month': '31'}

    # even though a ParseResults supports dict-like access, sometime you just need to have a dict
    import json
    print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable
    print(json.dumps(result.asDict())) # -> {"month": "31", "day": "1999", "year": "12"}
c                    > [        U [        5      (       a>  U R                  5       (       a  U R                  5       $ U  Vs/ s H  nT" U5      PM     sn$ U $ s  snf r   )r   rE   r  asDict)r   rk  toItems     r   r  #ParseResults.asDict.<locals>.toItem  sJ    #|,,;;==::<'/23s!F1Is33
 4s    Ac              3   <   >#    U  H  u  pUT" U5      4v   M     g 7fr   r   )r   ro  rk  r  s      r   r   &ParseResults.asDict.<locals>.<genexpr>  s     9ytqQq	Nys   )PY_3rx  r  rb  )r   item_fnr  s     @r   r  ParseResults.asDict  s6    ( 4jjGnnG	 9wy999r   c                    [        U R                  5      n[        U R                  R	                  5       5      Ul        U R
                  Ul        UR                  R                  U R                  5        U R                  Ul        U$ )z7
Returns a new copy of a :class:`ParseResults` object.
)	rE   r`  rb  rc  rx  r[  r\  r  rZ  )r   r   s     r   r  ParseResults.copy  s`     4>>*T^^1134}} 1 12[[

r   c                    Sn/ n[        S U R                  R                  5        5       5      nUS-   nU(       d  SnSnSnSn	Ub  Un	OU R                  (       a  U R                  n	U	(       d
  U(       a  gSn	XeUSU	S/-  n[	        U R
                  5       H  u  p[        U[        5      (       aO  X;   a&  XkR                  Xz   U=(       a    USL UU5      /-  nME  XkR                  SU=(       a    USL UU5      /-  nMi  SnX;   a  Xz   nU(       d  U(       a  M  Sn[        [        U5      5      nXeUSUSUS	US/	-  nM     XeUS	U	S/-  nSR                  U5      $ )
zw
(Deprecated) Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.
r  c              3   H   #    U  H  u  pU  H  nUS    U4v   M     M     g7fr   Nr   )r   ro  r  rk  s       r   r   %ParseResults.asXML.<locals>.<genexpr>  s.      *6L
#(a Q4)#( $6L    "  r   NITEM<></)rb  rc  rx  rZ  r  r`  r   rE   asXMLr   r   r   )r   doctagnamedItemsOnlyindent	formattednlr  
namedItemsnextLevelIndentselfTagr%  r  resTagxmlBodyTexts                 r   r  ParseResults.asXML  s     *dnn6J6J6L * *
 4- F OBG{{++ FC#../FA#|,,?IIjm&4&G4&5&/1 2 2C
 IId&4&G4&5&/1 2 2C ?']F% !')%*5OS&##04fcC C/ 06 	FD'3//wws|r   c                 t    U R                   R                  5        H  u  p#U H  u  pEXL d  M  Us  s  $    M     g r   )rc  rx  )r   rp  ro  r  rk  r   s         r   __lookupParseResults.__lookup  s6    ,,.HA8H   / r   c                    U R                   (       a  U R                   $ U R                  (       a)  U R                  5       nU(       a  UR                  U 5      $ g[        U 5      S:X  a{  [        U R                  5      S:X  ab  [        [        U R                  R                  5       5      5      S   S   S;   a,  [        [        U R                  R                  5       5      5      $ g)a  
Returns the results name for this token expression. Useful when several
different expressions might match at a particular location.

Example::

    integer = Word(nums)
    ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d")
    house_number_expr = Suppress('#') + Word(nums, alphanums)
    user_data = (Group(house_number_expr)("house_number")
                | Group(ssn_expr)("ssn")
                | Group(integer)("age"))
    user_info = OneOrMore(user_data)

    result = user_info.parseString("22 111-22-3333 #221B")
    for item in result:
        print(item.getName(), ':', item[0])

prints::

    age : 22
    ssn : 111-22-3333
    house_number : 221B
Nr   r   )r   r   )	rZ  r[  _ParseResults__lookupr   rc  nextr  r  r  )r   pars     r   getNameParseResults.getName   s    2 ;;;;]]--/C||D))$i1ndnn%*tDNN11345a8;wFT^^002344r   c                    / nSnU(       a,  UR                  U[        U R                  5       5      -   5        OUR                  S5        U(       Ga  U R                  5       (       a  [	        S U R                  5        5       5      nU H  u  pU(       a  UR                  U5        UR                  U< SU-  < SU< S35        [        U	[        5      (       aG  U	(       a$  UR                  U	R                  XX4S-   S95        M|  UR                  [        U	5      5        M  UR                  [        U	5      5        M     O[        S	 U  5       5      (       a  U n	[        U	5       H~  u  p[        U[        5      (       a8  UR                  S
USU-  U
USUS-   -  UR                  UUUUS-   S94-  5        MR  UR                  S
USU-  U
USUS-   -  [        U5      4-  5        M     SR                  U5      $ )a  
Diagnostic method for listing out the contents of
a :class:`ParseResults`. Accepts an optional ``indent`` argument so
that this string can be embedded in a nested display of other data.

Example::

    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    result = date_str.parseString('12/31/1999')
    print(result.dump())

prints::

    ['12', '/', '31', '/', '1999']
    - day: 1999
    - month: 31
    - year: 12
r  r   c              3   @   #    U  H  u  p[        U5      U4v   M     g 7fr   )r   )r   ro  rk  s      r   r   $ParseResults.dump.<locals>.<genexpr>F  s     D|tqA{|s   r  z- : r   )r  fullinclude_list_depthc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   rE   )r   vvs     r   r   r"  R  s     ADbZL11D   z
%s%s[%d]:
%s%s%s)r  r   rU  r  sortedrx  r   rE   dumprI  anyr  r   )r   r  r$  r%  r&  r  NLrx  ro  rk  r%  r(  s               r   r+  ParseResults.dump(  s   * JJvdkkm 445JJrN||~~Dtzz|DD!DA

2JJvvJK!!\22JJqvvVUastjtv'uvJJuQx0

47+ " ADAAA&q\EA!"l33

#8F=AV_<=<B=AVaZ=P<>GG6IMQ]KQTU: =D =W<X $X Y 

#8F=AV_<=<B=AVaZ=P<A"I<G $G H *& wws|r   c                 T    [         R                   " U R                  5       /UQ70 UD6  g)a  
Pretty-printer for parsed results as a list, using the
`pprint <https://docs.python.org/3/library/pprint.html>`_ module.
Accepts additional positional or keyword args as defined for
`pprint.pprint <https://docs.python.org/3/library/pprint.html#pprint.pprint>`_ .

Example::

    ident = Word(alphas, alphanums)
    num = Word(nums)
    func = Forward()
    term = ident | num | Group('(' + func + ')')
    func <<= ident + Group(Optional(delimitedList(term)))
    result = func.parseString("fna a,b,(fnb c,d,200),100")
    result.pprint(width=40)

prints::

    ['fna',
     ['a',
      'b',
      ['(', 'fnb', ['c', 'd', '200'], ')'],
      '100']]
N)pprintrU  )r   r   r  s      r   r0  ParseResults.pprinti  s     2 	dkkm5d5f5r   c                     U R                   U R                  R                  5       U R                  S L=(       a    U R                  5       =(       d    S U R                  U R
                  44$ r   )r`  rc  r  r[  r\  rZ  r   s    r   __getstate__ParseResults.__getstate__  sT    $$&d*>t}}F$"" 	r   c                     US   U l         US   u  U l        p#U l        0 U l        U R                  R	                  U5        Ub  [        U5      U l        g S U l        g rt  )r`  rc  rZ  r\  r  rn  r[  )r   stater  inAccumNamess       r   __setstate__ParseResults.__setstate__  sT    q9>q64;  .?!#JDM DMr   c                 ^    U R                   U R                  U R                  U R                  4$ r   )r`  rZ  r]  r^  r   s    r   __getnewargs__ParseResults.__getnewargs__  s!    ~~t{{DMM4<<GGr   c                 ^    [        [        U 5      5      [        U R                  5       5      -   $ r   )r  r  r_  r  r   s    r   r  ParseResults.__dir__  s     4:diik!222r   c           	          S nU " / 5      nUR                  5        H=  u  pV[        U[        5      (       a  X@R                  XeS9-  nM-  X@" U/XS" U5      S9-  nM?     Ub  U " U/US9nU$ )z
Helper classmethod to construct a ParseResults from a dict, preserving the
name-value relations as results names. If an optional 'name' argument is
given, a nested ParseResults will be returned
c                      [        U 5        [        (       a  [        U [        [        45      (       + $ [        U [
        5      (       + $ ! [         a     gf = fNF)r  r  r   r   bytesrd  	Exception)r   s    r   is_iterable+ParseResults.from_dict.<locals>.is_iterable  sM    ;S	 4)#U|<<<)#z:::  s   A 
AArT  )rT  rU  )rx  r   r   	from_dict)r   r  rT  rD  r   ro  rk  s          r   rG  ParseResults.from_dict  sx    		; "gKKMDA!W%%}}Q}//sA3Q{1~>>	 "
 se$'C
r   )__accumNames__asList__doinit__modal__name__parent	__tokdict	__toklist)NNTTr   r   )NFr   T)r   TTr   )8r   r   r   r   r	  rQ  r   r   rE  rq  r  r  r  r  __nonzero__r  r  r  r  r  r  r  r  rx  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r   r  rU  r  r  r  r  r  r+  r0  r3  r8  r;  r  r
  rG  r   r   r   r   rE   rE     sI   )T  $$t4T^ %-NG ,6 '"*##(K$*(38 ;=G M 
O	Y	)	+	*$
5 n ._*$+&
  Is	b"":H	;z&P?B68!H3  r   rE   c                 |    UnSU s=:  a  [        U5      :  a  O  OX S-
     S:X  a  S$ XR                  SSU 5      -
  $ )a  Returns current column within a string, counting newlines as line separators.
The first column is number 1.

Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process.  See
:class:`ParserElement.parseString` for more
information on parsing strings containing ``<TAB>`` s, and suggested
methods to maintain a consistent view of the parsed string, the parse
location, and line and column positions within the parsed string.
r   r   r  )r   rfind)r   strgr   s      r   r]   r]     sB     	AC #a& Q1uX%51V3qRUAV;VVr   c                 .    UR                  SSU 5      S-   $ )a  Returns current line number within a string, counting newlines as line separators.
The first line is number 1.

Note - the default parsing behavior is to expand tabs in the input string
before starting the parsing process.  See :class:`ParserElement.parseString`
for more information on parsing strings containing ``<TAB>`` s, and
suggested methods to maintain a consistent view of the parsed string, the
parse location, and line and column positions within the parsed string.
r  r   r   )count)r   rU  s     r   rn   rn     s     ::dAs#a''r   c                 t    UR                  SSU 5      nUR                  SU 5      nUS:  a  XS-   U $ XS-   S $ )zfReturns the line of text containing loc within a string, counting newlines as line separators.
       r  r   r   N)rT  find)r   rU  lastCRnextCRs       r   rk   rk     sK     ZZa%FYYtS!F{QJv&&QJK  r   c           	          [        S[        U5      -   S-   [        U5      -   S[        X5      [        X5      4-  -   5        g )NzMatch z at loc z(%d,%d))printr   rn   r]   )instringr   exprs      r   _defaultStartDebugActionr`    s=    	8eDk!J.s;i6RUK`befibtJu>uuwr   c                 l    [        S[        U5      -   S-   [        UR                  5       5      -   5        g )NzMatched z -> )r]  r   r   rU  )r^  startlocendlocr_  tokss        r   _defaultSuccessDebugActionre    s(    	*uT{
"V
+c$++-.@
@Ar   c                 2    [        S[        U5      -   5        g )NzException raised:)r]  r   )r^  r   r_  r!  s       r   _defaultExceptionDebugActionrg    s    	
c

*+r   c                      g)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nr   )r   s    r   ru   ru     s    r   r   c                 ~  ^ ^^^^	^
 T [         ;   a  U 4S j$ S/m	S/m[        S S S:  a  SS jnSS jmO [        R                  n[        R                  mSnU" SS	9S
   nUS   US   U-   4m
UUU U	UU
4S jnSn [        T S[        T S5      R                  5      nXel        U$ ! [         a    [        T 5      n Nf = f)Nc                    > T" U5      $ r   r   )r   r   r   funcs      r   r   _trim_arity.<locals>.<lambda>  s	    tAwr   r   Fr   )r      c                 f    [         S:X  a  SOSn[        R                  " U* U -   S-
  S9U   nUS S /$ )N)r   rm  r   r   limitr   )system_version	tracebackextract_stack)rr  r  frame_summarys      r   ru  "_trim_arity.<locals>.extract_stack
  s@    )Y6RBF%336'E/A:MNvVM!"1%&&r   c                 @    [         R                  " XS9nUS   nUS S /$ )Nrq  r   r   )rt  
extract_tb)tbrr  framesrv  s       r   ry  _trim_arity.<locals>.extract_tb  s+    ))":F"2JM!"1%&&r      rq  r   r   c                  >  >   T" U TS   S  6 nSTS'   U$ ! [          a|    TS   (       a  e  [        R                  " 5       S   nT" USS9S   S S T:X  d  e   AO'! [         a     Of = f!  Af ! [         a     f f = f= fTS   T::  a  TS==   S-  ss'    M  e f = f)Nr   r   Tr   r   rq  )rf  r   exc_info	NameError)	r   r   rz  ry  
foundArityrk  rr  maxargspa_call_line_synths	      r   r  _trim_arity.<locals>.wrapper   s    DqO, $
1
 a=! \\^B/)"A6r:2A>BTT!  U! "( ! !! "( ! ! 8w&!HMH%sh    B*A*AB
A'$B&A''B*A>,A.-A>.
A;	8A>:A;	;A>>BBz<parse action>r   	__class__r   )	singleArgBuiltinsrs  rt  ru  ry  getattrr   rC  r   )rk  r  ru  	LINE_DIFF	this_liner  	func_namery  r  rr  r  s   ``     @@@@r   r   r     s      &&CEJ bqV#	'
	'
 "//))

 I A&r*I#A,	!y(@A 6 !ID*#D+6??A	 !N	  I	s   ;!B$ $B<;B<c                      \ rS rSrSrSrSr\S 5       r\S 5       r	\
S 5       rSMS jrS	 rS
 rSMS jrSMS jrSNS jrS rS rS rS rS rS rSNS jrS rSOS jrS rS r " S S\5      r\b   " S S\5      r O " S S\5      r 0 r!\"" 5       r#SS/r$SOS  jr%\r&\S! 5       r'Sr(\SPS" j5       r)SMS# jr*\+S4S$ jr,S% r-\+4S& jr.\+S4S' jr/S( r0S) r1S* r2S+ r3S, r4S- r5S. r6S/ r7S0 r8S1 r9S2 r:S3 r;S4 r<S5 r=S6 r>SQS7 jr?S8 r@S9 rAS: rBS; rCS< rDS= rESNS> jrFS? rGS@ rHSA rISB rJSQSC jrKSMSD jrLSE rMSF rNSG rOSH rPSI rQSNSJ jrR   SRSK jrSSLrTg)SrG   iF  z)Abstract base level parser element class.z 
	Fc                     U [         l        g)a  
Overrides the default whitespace chars

Example::

    # default whitespace chars are space, <TAB> and newline
    OneOrMore(Word(alphas)).parseString("abc def\nghi jkl")  # -> ['abc', 'def', 'ghi', 'jkl']

    # change to just treat newline as significant
    ParserElement.setDefaultWhitespaceChars(" \t")
    OneOrMore(Word(alphas)).parseString("abc def\nghi jkl")  # -> ['abc', 'def']
N)rG   DEFAULT_WHITE_CHARScharss    r   setDefaultWhitespaceChars'ParserElement.setDefaultWhitespaceCharsK  s     -2)r   c                     U [         l        g)a  
Set class to be used for inclusion of string literals into a parser.

Example::

    # default literal class used is Literal
    integer = Word(nums)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    date_str.parseString("1999/12/31")  # -> ['1999', '/', '12', '/', '31']


    # change to Suppress
    ParserElement.inlineLiteralsUsing(Suppress)
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

    date_str.parseString("1999/12/31")  # -> ['1999', '12', '31']
N)rG   _literalStringClassr   s    r   inlineLiteralsUsing!ParserElement.inlineLiteralsUsing[  s    ( -0)r   c                 f    UR                   (       a  UR                   nUR                   (       a  M  U$ r   )tb_next)r   rz  s     r   _trim_tracebackParserElement._trim_tracebackq  s"    jjB jjj	r   c                 h   [        5       U l        S U l        S U l        S U l        Xl        SU l        [        [        R                  5      U l
        SU l        SU l        SU l        [        5       U l        SU l        SU l        SU l        SU l        SU l        SU l        S U l        SU l        SU l        g )NTFr   NNN)r_  parseAction
failActionstrReprresultsName
saveAsListskipWhitespacer  rG   r  
whiteCharscopyDefaultWhiteCharsmayReturnEmptykeepTabsignoreExprsdebugstreamlinedmayIndexErrorerrmsgmodalResultsdebugActionsr   callPreparsecallDuringTry)r   savelists     r   r   ParserElement.__init__w  s    6""m??@%)"#6
 ! . "r   c                     [         R                   " U 5      nU R                  SS Ul        U R                  SS Ul        U R                  (       a  [        R
                  Ul        U$ )a  
Make a copy of this :class:`ParserElement`.  Useful for defining
different parse actions for the same parsing pattern, using copies of
the original parse element.

Example::

    integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
    integerK = integer.copy().addParseAction(lambda toks: toks[0] * 1024) + Suppress("K")
    integerM = integer.copy().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")

    print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M"))

prints::

    [5120, 100, 655360, 268435456]

Equivalent form of ``expr.copy()`` is just ``expr()``::

    integerM = integer().addParseAction(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")
N)r  r  r  r  rG   r  r  )r   cpys     r   r  ParserElement.copy  sP    , iio**1-**1-%%*>>CN
r   c                     Xl         SU R                   -   U l        [        R                  (       a  U R	                  5         U $ )a7  
Define name for this expression, makes debugging and exception messages clearer.

Example::

    Word(nums).parseString("ABC")  # -> Exception: Expected W:(0123...) (at char 0), (line:1, col:1)
    Word(nums).setName("integer").parseString("ABC")  # -> Exception: Expected integer (at char 0), (line:1, col:1)
	Expected )rT  r  r   !enable_debug_on_named_expressionssetDebugr  s     r   setNameParserElement.setName  s0     	!DII-55MMOr   c                 $    U R                  X5      $ )a  
Define name for referencing matching tokens as a nested attribute
of the returned parse results.
NOTE: this returns a *copy* of the original :class:`ParserElement` object;
this is so that the client can define a basic element, such as an
integer, and reference it in multiple places with different names.

You can also set results names using the abbreviated syntax,
``expr("name")`` in place of ``expr.setResultsName("name")``
- see :class:`__call__`.

Example::

    date_str = (integer.setResultsName("year") + '/'
                + integer.setResultsName("month") + '/'
                + integer.setResultsName("day"))

    # equivalent form:
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
)_setResultsName)r   rT  listAllMatchess      r   setResultsNameParserElement.setResultsName  s    * ##D99r   c                     U R                  5       nUR                  S5      (       a  US S nSnXl        U(       + Ul        U$ )N*r   T)r  endswithr  r  )r   rT  r  newselfs       r   r  ParserElement._setResultsName  sB    ))+==9D!N"#11r   c                    ^ U(       a#  U R                   mSU4S jjnTUl        X l         U $ [        U R                   S5      (       a  U R                   R                  U l         U $ )zMethod to invoke the Python pdb debugger when this element is
about to be parsed. Set ``breakFlag`` to True to enable, False to
disable.
c                 >   > SS K nUR                  5         T" XX#5      $ rH  )pdb	set_trace)r^  r   	doActionscallPreParser  _parseMethods        r   breaker'ParserElement.setBreak.<locals>.breaker  s    #H9KKr   _originalParseMethodTT)_parser  r  )r   	breakFlagr  r  s      @r   setBreakParserElement.setBreak  sW    
 ;;LL
 ,8G(!K  t{{$:;;"kk>>r   c                     [        U5      S/:X  a	  / U l        U $ [        S U 5       5      (       d  [        S5      e[        [	        [
        [        U5      5      5      U l        UR                  SS5      U l        U $ )a  
Define one or more actions to perform when successfully matching parse element definition.
Parse action fn is a callable method with 0-3 arguments, called as ``fn(s, loc, toks)`` ,
``fn(loc, toks)`` , ``fn(toks)`` , or just ``fn()`` , where:

- s   = the original string being parsed (see note below)
- loc = the location of the matching substring
- toks = a list of the matched tokens, packaged as a :class:`ParseResults` object

If the functions in fns modify the tokens, they can return them as the return
value from fn, and the modified list of tokens will replace the original.
Otherwise, fn does not need to return any value.

If None is passed as the parse action, all previously added parse actions for this
expression are cleared.

Optional keyword arguments:
- callDuringTry = (default= ``False``) indicate if parse action should be run during lookaheads and alternate testing

Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process.  See :class:`parseString for more
information on parsing strings containing ``<TAB>`` s, and suggested
methods to maintain a consistent view of the parsed string, the parse
location, and line and column positions within the parsed string.

Example::

    integer = Word(nums)
    date_str = integer + '/' + integer + '/' + integer

    date_str.parseString("1999/12/31")  # -> ['1999', '/', '12', '/', '31']

    # use parse action to convert to ints at parse time
    integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
    date_str = integer + '/' + integer + '/' + integer

    # note that integer fields are now ints, not strings
    date_str.parseString("1999/12/31")  # -> [1999, '/', 12, '/', 31]
Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   )callable)r   r   s     r   r   /ParserElement.setParseAction.<locals>.<genexpr>  s     2cx||c   zparse actions must be callabler  F)r_  r  allrf  mapr   r  r  r   fnsr  s      r   r   ParserElement.setParseAction  sq    P 9!D 	 2c222 @AA#CT#Y$?@D!'OU!CDr   c           
          U =R                   [        [        [        [        U5      5      5      -  sl         U R                  =(       d    UR                  SS5      U l        U $ )z
Add one or more parse actions to expression's list of parse actions. See :class:`setParseAction`.

See examples in :class:`copy`.
r  F)r  r_  r  r   r  r  r  s      r   addParseActionParserElement.addParseAction  sH     	D[$s)!<==!//U6::ou3Ur   c                     U HE  nU R                   R                  [        X2R                  S5      UR                  SS5      S95        MG     U R                  =(       d    UR                  SS5      U l        U $ )a\  Add a boolean predicate function to expression's list of parse actions. See
:class:`setParseAction` for function call signatures. Unlike ``setParseAction``,
functions passed to ``addCondition`` need to return boolean success/fail of the condition.

Optional keyword arguments:
- message = define a custom message to be used in the raised exception
- fatal   = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException

Example::

    integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
    year_int = integer.copy()
    year_int.addCondition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later")
    date_str = year_int + '/' + integer + '/' + integer

    result = date_str.parseString("1999/12/31")  # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1)
r   r   F)r   r   r  )r  r  r   r  r  )r   r  r  r   s       r   addConditionParserElement.addCondition(  sl    $ B##$:2zzR[G\AGGUZA[%] ^  "//U6::ou3Ur   c                     Xl         U $ )a  Define action to perform if parsing fails at this expression.
Fail acton fn is a callable function that takes the arguments
``fn(s, loc, expr, err)`` where:
- s = string being parsed
- loc = location where expression match was attempted and failed
- expr = the parse expression that failed
- err = the exception thrown
The function returns no value.  It may throw :class:`ParseFatalException`
if it is desired to stop parsing immediately.)r  r   r   s     r   setFailActionParserElement.setFailActionA  s     r   c                     SnU(       a5  SnU R                    H  n  UR                  X5      u  p%SnM     U(       a  M5  U$ ! [         a     M6  f = fNTF)r  r  rB   )r   r^  r   
exprsFoundedummys         r   _skipIgnorablesParserElement._skipIgnorablesN  sc    
J%%%&XXh%<
%)
  & j 
 & s   A
AAc                     U R                   (       a  U R                  X5      nU R                  (       a8  U R                  n[	        U5      nX$:  a  X   U;   a  US-  nX$:  a
  X   U;   a  M  U$ Nr   )r  r  r  r  r   )r   r^  r   wtinstrlens        r   preParseParserElement.preParse[  sd    &&x5CB8}H.X]b%8q .X]b%8 
r   c                 
    U/ 4$ r   r   r   r^  r   r  s       r   r  ParserElement.parseImplg  s    Bwr   c                     U$ r   r   r   r^  r   	tokenlists       r   	postParseParserElement.postParsej  s    r   c           
         Su  pVnU R                   nU(       d  U R                  (       a  U R                  U   (       a  U R                  U   " XU 5         U(       a#  U R                  (       a  U R	                  X5      n	OUn	U	n
U R
                  (       d  U	[        U5      :  a   U R                  XU5      u  p+OU R                  XU5      u  p+OxU(       a#  U R                  (       a  U R	                  X5      n	OUn	U	n
U R
                  (       d  U	[        U5      :  a   U R                  XU5      u  p+OU R                  XU5      u  p+U R                  XU5      n[        XR                  U R                  U R                   S9nU R"                  (       a  U(       d  U R$                  (       a  U(       aq   U R"                   H_  n U" XU5      nUc  M  XLd  M  [        UU R                  U R                  =(       a    [)        U[        [*        45      U R                   S9nMa     OoU R"                   H_  n U" XU5      nUc  M  XLd  M  [        UU R                  U R                  =(       a    [)        U[        [*        45      U R                   S9nMa     U(       a+  U R                  U   (       a  U R                  U   " XX U5        X-4$ ! [         a"    [        U[        U5      U R                  U 5      ef = f! [         aU  nU R                  U   (       a  U R                  U   " UW
X5        U R                  (       a  U R                  UW
X5        e S nAff = f! [         a"    [        U[        U5      U R                  U 5      ef = f! [         a  n[        S5      nUUl        UeS nAff = f! [         a0  nU R                  U   (       a  U R                  U   " XX5        e S nAff = f! [         a  n[        S5      nUUl        UeS nAff = f)N)r   r   r   )rU  rV  z exception raised in parse action)r  r  r  r  r  r  r   r  rg  rB   r  rC  r  rE   r  r  r  r  r  	__cause__r   r_  )r   r^  r   r  r  TRYMATCHFAIL	debuggingpreloctokensStarttokenserr	retTokensr   parse_action_excr!  s                    r   r  ParserElement._parseNoCachen  s   "DZZ	  %!!#&xd;D$5$5!]]89F F$%%3x=)@Y&*nnXy&QV #'..9"MKC  1 1x5 K!!Vs8}%<U"&..9"MKC #nnXyIv6 )9)9$//Y]YjYjk	d.@.@"..&%'y%IF "-&2I(4V6:6F6F=A__=yQ[\beqswdxQy<@<M<M)OI /& **B"!#H9!E )f.E$0262B2B9=9uZX^amos`tMu8<8I8I%K	 +   '!!%(9U~I & Y,Xs8}dkkSWXXY  $$T*%%d+Hk4M??OOHk4E  " U(3x=$++tTTU  * &"01S"TC,<CM"%I& ! ((.))$/tQ	 & ",-OP(8!	"s   AK5 $K 9K5 M 2N, 	NN, N, AN, 2	O),K22K5 5
M?AMM,N
N)N$$N))N, ,
O&6+O!!O&)
P3PPc                 t     U R                  XSS9S   $ ! [         a    [        XU R                  U 5      ef = f)NFr  r   )r  rD   rB   r  r   r^  r   s      r   tryParseParserElement.tryParse  sD    	C;;x;>qAA" 	C TBB	Cs    "7c                 T     U R                  X5        g! [        [        4 a     gf = fr  )r  rB   rg  r  s      r   canParseNextParserElement.canParseNext  s1    	MM((  
+ 		s    ''c                       \ rS rSrS rSrg)ParserElement._UnboundedCachei  c                 8  ^^ 0 m[        5       =U l        mUU4S jnU4S jnU4S jnU4S jn[        R                  " X5      U l        [        R                  " X 5      U l        [        R                  " X05      U l        [        R                  " X@5      U l        g )Nc                 (   > TR                  UT5      $ r   r  r   r  cachenot_in_caches     r   r  3ParserElement._UnboundedCache.__init__.<locals>.get  s    yyl33r   c                    > UTU'   g r   r   )r   r  r}  r  s      r   r  3ParserElement._UnboundedCache.__init__.<locals>.set  s    "c
r   c                 &   > TR                  5         g r   r  r   r  s    r   r  5ParserElement._UnboundedCache.__init__.<locals>.clear  s    r   c                    > [        T5      $ r   r   r   s    r   	cache_len9ParserElement._UnboundedCache.__init__.<locals>.cache_len  s    5z!r   )rP  r  types
MethodTyper  r  r  r  )r   r  r  r  r$  r  r  s        @@r   r   &ParserElement._UnboundedCache.__init__  su    E/5x7D4#" ''2DH''2DH))%6DJ ++I<DLr   r  r  r  r  r  Nr   r   r   r   r   r   r   r   r   _UnboundedCacher    s    	=r   r+  Nc                       \ rS rSrS rSrg)ParserElement._FifoCachei  c                 L  ^^^ [        5       =U l        m[        5       mUU4S jnUU4S jnU4S jnU4S jn[        R                  " X 5      U l        [        R                  " X05      U l        [        R                  " X@5      U l        [        R                  " XP5      U l        g )Nc                 (   > TR                  UT5      $ r   r  r  s     r   r  .ParserElement._FifoCache.__init__.<locals>.get       99S,77r   c                    > UTU'   [        T5      T:  a$   TR                  S5        [        T5      T:  a  M#  g g ! [         a     Nf = frA  )r   popitemre  )r   r  r}  r  sizes      r   r  .ParserElement._FifoCache.__init__.<locals>.set  sK    !&E#Je*t+!!MM%0 e*t+  ( ! !s   ; 
AAc                 &   > TR                  5         g r   r  r   s    r   r  0ParserElement._FifoCache.__init__.<locals>.clear  s    KKMr   c                    > [        T5      $ r   r#  r   s    r   r$  4ParserElement._FifoCache.__init__.<locals>.cache_len      u:%r   )	rP  r  _OrderedDictr&  r'  r  r  r  r  )r   r4  r  r  r  r$  r  r  s    `    @@r   r   !ParserElement._FifoCache.__init__  sw    398;!L$8!"& !++C6 ++C6"--e:
$//	@r   r)  Nr*  r   r   r   
_FifoCacher-        Ar   r=  c                       \ rS rSrS rSrg)r-  i  c                 p  ^^^^ [        5       =U l        m0 m[        R                  " / T5      mUU4S jnUUU4S jnUU4S jnU4S jn[        R
                  " X 5      U l        [        R
                  " X05      U l        [        R
                  " X@5      U l        [        R
                  " XP5      U l	        g )Nc                 (   > TR                  UT5      $ r   r  r  s     r   r  r0    r1  r   c                    > UTU'   [        T5      T:  a1  TR                  TR                  5       S 5        [        T5      T:  a  M1  TR                  U5        g r   )r   r  popleftr  )r   r  r}  r  key_fifor4  s      r   r  r5    sI    !&E#Jh-$.		("2"2"4d; h-$.OOC(r   c                 F   > TR                  5         TR                  5         g r   r  )r   r  rD  s    r   r  r7    s    KKMNN$r   c                    > [        T5      $ r   r#  r   s    r   r$  r9    r:  r   )
rP  r  collectionsdequer&  r'  r  r  r  r  )	r   r4  r  r  r  r$  r  rD  r  s	    `    @@@r   r   r<    s    398;!L&,,R68)%& !++C6 ++C6"--e:
$//	@r   r)  Nr*  r   r   r   r=  r-    r>  r   r   c                    Su  pVXX$U4n[         R                     [         R                  nUR                  U5      n	XR                  L a`  [         R
                  U==   S-  ss'    U R                  XX45      n	UR                  XyS   U	S   R                  5       45        U	sS S S 5        $ [         R
                  U==   S-  ss'   [        U	[        5      (       a  U	eU	S   U	S   R                  5       4sS S S 5        $ ! [         a.  n
UR                  XzR                  " U
R                  6 5        e S n
A
ff = f! , (       d  f       g = f)N)r   r   r   r   )rG   packrat_cache_lockpackrat_cacher  r  packrat_cache_statsr  r  r  r@   r  r   r   rC  )r   r^  r   r  r  HITMISSlookupr  r}  r   s              r   _parseCacheParserElement._parseCache*  s   	#Y?--!//EIIf%E***11$71<7! ..xiVE IIfQxq&AB  .- 11#6!;6eY//KQxq0% .- * IIfllBGG&<= .-s7   AD8&C=8(D8*A	D8=
D5)D00D55D88
Ec                      [         R                  R                  5         S/[        [         R                  5      -  [         R                  S S & g rH  )rG   rK  r  r   rL  r   r   r   
resetCacheParserElement.resetCacheC  s6    ##))+01sS9Z9Z5[/[))!,r   c                     [         R                  (       dd  S[         l        U c  [         R                  5       [         l        O[         R	                  U 5      [         l        [         R
                  [         l        gg)a  Enables "packrat" parsing, which adds memoizing to the parsing logic.
Repeated parse attempts at the same string location (which happens
often in many complex grammars) can immediately return a cached value,
instead of re-executing parsing/validating code.  Memoizing is done of
both valid results and parsing exceptions.

Parameters:

- cache_size_limit - (default= ``128``) - if an integer value is provided
  will limit the size of the packrat cache; if None is passed, then
  the cache size will be unbounded; if 0 is passed, the cache will
  be effectively disabled.

This speedup may break existing programs that use parse actions that
have side-effects.  For this reason, packrat parsing is disabled when
you first import pyparsing.  To activate the packrat feature, your
program must call the class method :class:`ParserElement.enablePackrat`.
For best results, call ``enablePackrat()`` immediately after
importing pyparsing.

Example::

    import pyparsing
    pyparsing.ParserElement.enablePackrat()
TN)rG   _packratEnabledr+  rK  r=  rP  r  )cache_size_limits    r   enablePackratParserElement.enablePackratI  sS    6 ,,,0M)'.;.K.K.M+.;.F.FGW.X+#0#<#<M  -r   c                 N   [         R                  5         U R                  (       d  U R                  5         U R                   H  nUR                  5         M     U R
                  (       d  UR                  5       n U R                  US5      u  pEU(       a7  U R                  X5      n[        5       [        5       -   nUR                  X5        U$ ! [         aK  n[         R                  (       a  e [        USS5      b   U R                  UR                  5      Ul        UeSnAff = f)a3  
Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.

Returns the parsed data as a :class:`ParseResults` object, which may be
accessed as a list, or as a dict or object with attributes if the given parser
includes results names.

If you want the grammar to require that the entire input string be
successfully parsed, then set ``parseAll`` to True (equivalent to ending
the grammar with ``StringEnd()``).

Note: ``parseString`` implicitly calls ``expandtabs()`` on the input string,
in order to report proper column numbers in parse actions.
If the input string contains tabs and
the grammar uses parse actions that use the ``loc`` argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:

- calling ``parseWithTabs`` on your grammar before calling ``parseString``
  (see :class:`parseWithTabs`)
- define your parse action using the full ``(s, loc, toks)`` signature, and
  reference the input string using the parse action's ``s`` argument
- explictly expand the tabs in your input string before calling
  ``parseString``

Example::

    Word('a').parseString('aaaaabaaa')  # -> ['aaaaa']
    Word('a').parseString('aaaaabaaa', parseAll=True)  # -> Exception: Expected end of text
r   r  N)rG   rS  r  
streamliner  r  
expandtabsr  r  r/   rL   r@   verbose_stacktracer  r  r  )r   r^  parseAllr  r   r  ser!  s           r   parseStringParserElement.parseStringl  s    B 	  "OO!!ALLN "}}**,H	++h2KCmmH2Wy{*		(( M " 	// 36B(,(<(<S=N=N(OC%		s   ;AC 
D$ADD$c              #     #    U R                   (       d  U R                  5         U R                   H  nUR                  5         M     U R                  (       d  [	        U5      R                  5       n[        U5      nSnU R                  nU R                  n[        R                  5         Sn	 Xe::  a\  X:  aV   U" X5      n
U" XSS9u  pX:  a+  U	S-  n	XU4v   U(       a  U" X5      nX:  a  UnOUS-  nO	UnOU
S-   n Xe::  a  X:  a  MT  gggg! [         a    W
S-   n N!f = f! [         aK  n[        R                  (       a  e [        USS5      b   U R                  UR                   5      Ul        UeSnAff = f7f)a  
Scan the input string for expression matches.  Each match will return the
matching tokens, start location, and end location.  May be called with optional
``maxMatches`` argument, to clip scanning after 'n' matches are found.  If
``overlap`` is specified, then overlapping matches will be reported.

Note that the start and end locations are reported relative to the string
being parsed.  See :class:`parseString` for more information on parsing
strings with embedded tabs.

Example::

    source = "sldjf123lsdjjkf345sldkjf879lkjsfd987"
    print(source)
    for tokens, start, end in Word(alphas).scanString(source):
        print(' '*start + '^'*(end-start))
        print(' '*start + tokens[0])

prints::

    sldjf123lsdjjkf345sldkjf879lkjsfd987
    ^^^^^
    sldjf
            ^^^^^^^
            lsdjjkf
                      ^^^^^^
                      sldkjf
                               ^^^^^^
                               lkjsfd
r   Fr  r   r  N)r  r[  r  r  r   r\  r   r  r  rG   rS  rB   r@   r]  r  r  r  )r   r^  
maxMatchesoverlapr  r  r   
preparseFnparseFnmatchesr  nextLocr  nextlocr!  s                  r   
scanStringParserElement.scanString  sl    > OO!!ALLN " }}X113Hx=]]
++  "	/g&:)'6F&-hU&SOG }1$g55"&0&?G&}&- #q")C$qj' /g&:/&:/ & % 1*C%  " 	// 36B(,(<(<S=N=N(OC%		sP   B*E<-
D$ 8D 	A D$ E<D!D$  D!!D$ $
E9.AE44E99E<c                    / nSnSU l          U R                  U5       Hu  u  pEnUR                  XU 5        U(       aS  [        U[        5      (       a  X$R                  5       -  nO+[        U[        5      (       a  X$-  nOUR                  U5        UnMw     UR                  XS 5        U Vs/ s H  ow(       d  M  UPM     nnSR                  [        [        [        U5      5      5      $ s  snf ! [         aK  n[        R                  (       a  e [        USS5      b   U R                  UR                   5      Ul        UeSnAff = f)a  
Extension to :class:`scanString`, to modify matching text with modified tokens that may
be returned from a parse action.  To use ``transformString``, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking ``transformString()`` on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action.  ``transformString()`` returns the resulting transformed string.

Example::

    wd = Word(alphas)
    wd.setParseAction(lambda toks: toks[0].title())

    print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york."))

prints::

    Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York.
r   TNr   r  )r  rk  r  r   rE   rU  r_  r   r  r   _flattenr@   rG   r]  r  r  r  )	r   r^  r  lastEr   r   r  or!  s	            r   r   ParserElement.transformString  s   (  	??84a

8!,-!!\22xxz)#At,,

1 5 JJx'(!'cQ1cC'773uhsm455 (! 	// 36B(,(<(<S=N=N(OC%		s1   B!C1 .
C,<C,)C1 ,C1 1
E;AEEc           
      $    [        U R                  X5       VVVs/ s H  u  p4oSPM	     snnn5      $ s  snnnf ! [         aK  n[        R                  (       a  e [        USS5      b   U R                  UR                  5      Ul        UeSnAff = f)a8  
Another extension to :class:`scanString`, simplifying the access to the tokens found
to match the given parse expression.  May be called with optional
``maxMatches`` argument, to clip searching after 'n' matches are found.

Example::

    # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters
    cap_word = Word(alphas.upper(), alphas.lower())

    print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))

    # the sum() builtin can be used to merge results into a single ParseResults object
    print(sum(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")))

prints::

    [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']]
    ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity']
r  N)rE   rk  r@   rG   r]  r  r  r  )r   r^  rd  r   r   r  r!  s          r   searchStringParserElement.searchString   s~    *		$//(2W X2WwqQ2W XYY X! 	// 36B(,(<(<S=N=N(OC%		s"   : 3: : 
BAB

Bc              #   ~   #    SnSnU R                  XS9 H  u  pgnXU v   U(       a  US   v   UnM     XS v   g7f)a  
Generator method to split a string using the given expression as a separator.
May be called with optional ``maxsplit`` argument, to limit the number of splits;
and the optional ``includeSeparators`` argument (default= ``False``), if the separating
matching text should be included in the split results.

Example::

    punc = oneOf(list(".,;:/-!?"))
    print(list(punc.split("This, this?, this sentence, is badly punctuated!")))

prints::

    ['This', ' this', '', ' this sentence', ' is badly punctuated', '']
r   )rd  N)rk  )	r   r^  maxsplitincludeSeparatorssplitslastr   r   r  s	            r   r   ParserElement.split@  sS       xEGA!"" d
D	 F
 uos   ;=c                    U[         L a  [        U 5      $ [        U[        5      (       a  U R	                  U5      n[        U[
        5      (       d'  [        R                  " S[        U5      -  [        SS9  g[        X/5      $ )a  
Implementation of + operator - returns :class:`And`. Adding strings to a ParserElement
converts them to :class:`Literal`s by default.

Example::

    greet = Word(alphas) + "," + Word(alphas) + "!"
    hello = "Hello, World!"
    print (hello, "->", greet.parseString(hello))

prints::

    Hello, World! -> ['Hello', ',', 'World', '!']

``...`` may be used as a parse expression as a short form of :class:`SkipTo`.

    Literal('start') + ... + Literal('end')

is equivalent to:

    Literal('start') + SkipTo('end')("_skipped*") + Literal('end')

Note that the skipped text is returned with '_skipped' as a results name,
and to support having multiple skips in the same parser, the value returned is
a list of all skipped text.
4Cannot combine element of type %s with ParserElementr   
stacklevelN)Ellipsis_PendingSkipr   rd  r  rG   warningswarnr  SyntaxWarningr(   r  s     r   r  ParserElement.__add__Y  sq    6 H%%eZ((,,U3E%//MMPSWX]S^^'A7D=!!r   c                    U[         L a  [        U 5      " S5      U -   $ [        U[        5      (       a  U R	                  U5      n[        U[
        5      (       d'  [        R                  " S[        U5      -  [        SS9  gX-   $ )zP
Implementation of + operator when left operand is not a :class:`ParserElement`
	_skipped*r|  r   r}  N)
r  rK   r   rd  r  rG   r  r  r  r  r  s     r   r  ParserElement.__radd__  su     H$<,t33eZ((,,U3E%//MMPSWX]S^^'A7|r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gU [        R                  5       -   U-   $ )zD
Implementation of - operator, returns :class:`And` with error stop
r|  r   r}  N)
r   rd  r  rG   r  r  r  r  r(   
_ErrorStopr  s     r   __sub__ParserElement.__sub__  sh     eZ((,,U3E%//MMPSWX]S^^'A7cnn&&..r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-
  $ )zP
Implementation of - operator when left operand is not a :class:`ParserElement`
r|  r   r}  Nr   rd  r  rG   r  r  r  r  r  s     r   __rsub__ParserElement.__rsub__  Y     eZ((,,U3E%//MMPSWX]S^^'A7|r   c                   ^ ^ U[         L a  SnO1[        U[        5      (       a  USS [         4:X  a  SUSS -   S-   SS n[        U[        5      (       a  USp2GO	[        U[        5      (       a  [        S U 5       5      nUS	-   SS nUS   c  SUS   4n[        US   [        5      (       aB  US   c<  US   S:X  a  [	        T 5      $ US   S:X  a  [        T 5      $ T US   -  [	        T 5      -   $ [        US   [        5      (       a!  [        US   [        5      (       a	  Uu  p#X2-  nO:[        S
[        US   5      [        US   5      5      e[        S[        U5      5      eUS:  a  [        S5      eUS:  a  [        S5      eX#s=:X  a  S:X  a  O  O[        S5      eU(       aG  UU 4S jmU(       a.  US:X  a  T T" U5      -   nU$ [        T /U-  5      T" U5      -   n U$ T" U5      n U$ US:X  a  T nU$ [        T /U-  5      nU$ )ap  
Implementation of * operator, allows use of ``expr * 3`` in place of
``expr + expr + expr``.  Expressions may also me multiplied by a 2-integer
tuple, similar to ``{min, max}`` multipliers in regular expressions.  Tuples
may also include ``None`` as in:
 - ``expr*(n, None)`` or ``expr*(n, )`` is equivalent
      to ``expr*n + ZeroOrMore(expr)``
      (read as "at least n instances of ``expr``")
 - ``expr*(None, n)`` is equivalent to ``expr*(0, n)``
      (read as "0 to n instances of ``expr``")
 - ``expr*(None, None)`` is equivalent to ``ZeroOrMore(expr)``
 - ``expr*(1, None)`` is equivalent to ``OneOrMore(expr)``

Note that ``expr*(None, n)`` does not raise an exception if
more than n exprs exist in the input stream; that is,
``expr*(None, n)`` does not enforce a maximum number of expr
occurrences.  If this behavior is desired, then write
``expr*(None, n) + ~expr``
)r   NNr   r  r   r   r   c              3   :   #    U  H  o[         La  UOS v   M     g 7fr   )r  )r   rp  s     r   r   (ParserElement.__mul__.<locals>.<genexpr>  s     JEq0!d:Es   NNz8cannot multiply 'ParserElement' and ('%s', '%s') objectsz0cannot multiply 'ParserElement' and '%s' objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuez,cannot multiply ParserElement by 0 or (0, 0)c                 T   > U S:  a  [        TT" U S-
  5      -   5      $ [        T5      $ r  )r>   )nmakeOptionalListr   s    r   r  /ParserElement.__mul__.<locals>.makeOptionalList  s.    q5#D+;AE+B$BCC#D>)r   )
r  r   tupler   rU   r<   rf  r  
ValueErrorr(   )r   r  minElementsoptElementsr   r  s   `    @r   __mul__ParserElement.__mul__  s?   ( HEu%%%){*BU12Y&0"15EeS!!',au%%JEJJE\)2A.EQxE!H%(C((U1X-=8q=%d++8q=$T?*%(?Z-===E!Hc**z%(C/H/H+0(* Z\`afghai\jlpqvwxqylz{{NPTUZP[\\?NOO?_``**KLL*
 !#!1+!>>C 
 tf{236F{6SSC 
 '{3 
	 a 
 4&;./
r   c                 $    U R                  U5      $ r   )r  r  s     r   __rmul__ParserElement.__rmul__  s    ||E""r   c                    U[         L a
  [        U SS9$ [        U[        5      (       a  U R	                  U5      n[        U[
        5      (       d'  [        R                  " S[        U5      -  [        SS9  g[        X/5      $ )z<
Implementation of | operator - returns :class:`MatchFirst`
T)	must_skipr|  r   r}  N)r  r  r   rd  r  rG   r  r  r  r  r9   r  s     r   __or__ParserElement.__or__  ss     H55eZ((,,U3E%//MMPSWX]S^^'A74-((r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zP
Implementation of | operator when left operand is not a :class:`ParserElement`
r|  r   r}  Nr  r  s     r   __ror__ParserElement.__ror__	  r  r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )z4
Implementation of ^ operator - returns :class:`Or`
r|  r   r}  N)	r   rd  r  rG   r  r  r  r  r?   r  s     r   __xor__ParserElement.__xor__	  s^     eZ((,,U3E%//MMPSWX]S^^'A74-  r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zP
Implementation of ^ operator when left operand is not a :class:`ParserElement`
r|  r   r}  Nr  r  s     r   __rxor__ParserElement.__rxor__	  r  r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )z6
Implementation of & operator - returns :class:`Each`
r|  r   r}  N)	r   rd  r  rG   r  r  r  r  r.   r  s     r   __and__ParserElement.__and__&	  s^     eZ((,,U3E%//MMPSWX]S^^'A7TM""r   c                     [        U[        5      (       a  U R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zP
Implementation of & operator when left operand is not a :class:`ParserElement`
r|  r   r}  Nr  r  s     r   __rand__ParserElement.__rand__2	  r  r   c                     [        U 5      $ )z8
Implementation of ~ operator - returns :class:`NotAny`
)r;   r   s    r   
__invert__ParserElement.__invert__>	  s     d|r   c                 F    [        SU R                  R                  -  5      e)Nz%r object is not iterable)rf  r  r   r   s    r   r  ParserElement.__iter__D	  s     3dnn6M6MMNNr   c           
      X    [        U[        5      (       a  U4n[        U5        [	        U5      S:  aR  [
        R                  " SR                  USS [	        U5      S:  a  SR                  [	        U5      5      OS5      5        U [        USS 5      -  nU$ ! [         a    X4n Nf = f)a  
use ``[]`` indexing notation as a short form for expression repetition:
 - ``expr[n]`` is equivalent to ``expr*n``
 - ``expr[m, n]`` is equivalent to ``expr*(m, n)``
 - ``expr[n, ...]`` or ``expr[n,]`` is equivalent
      to ``expr*n + ZeroOrMore(expr)``
      (read as "at least n instances of ``expr``")
 - ``expr[..., n]`` is equivalent to ``expr*(0, n)``
      (read as "0 to n instances of ``expr``")
 - ``expr[...]`` and ``expr[0, ...]`` are equivalent to ``ZeroOrMore(expr)``
 - ``expr[1, ...]`` is equivalent to ``OneOrMore(expr)``
 ``None`` may be used in place of ``...``.

Note that ``expr[..., n]`` and ``expr[m, n]``do not raise an exception
if more than ``n`` ``expr``s exist in the input stream.  If this behavior is
desired, then write ``expr[..., n] + ~expr``.
r   z.only 1 or 2 index arguments supported ({0}{1})Nrm  z	... [{0}]r   )	r   r   r  rf  r   r  r  r  r  )r   r  r   s      r   rE  ParserElement.__getitem__I	  s    (	#s##fI s8a<MMJQQRUVXWXRYSVWZS[^_S_ Q\PbPbcfgjckPlegi j
 U3r7^#
  	*C	s   #B B)(B)c                 J    Ub  U R                  U5      $ U R                  5       $ )a  
Shortcut for :class:`setResultsName`, with ``listAllMatches=False``.

If ``name`` is given with a trailing ``'*'`` character, then ``listAllMatches`` will be
passed as ``True``.

If ``name` is omitted, same as calling :class:`copy`.

Example::

    # these are equivalent
    userdata = Word(alphas).setResultsName("name") + Word(nums + "-").setResultsName("socsecno")
    userdata = Word(alphas)("name") + Word(nums + "-")("socsecno")
)r  r  r  s     r   __call__ParserElement.__call__m	  s'     ''--99;r   c                     [        U 5      $ )zv
Suppresses the output of this :class:`ParserElement`; useful to keep punctuation from
cluttering up returned output.
)rN   r   s    r   suppressParserElement.suppress	  s    
 ~r   c                     SU l         U $ )z
Disables the skipping of whitespace before matching the characters in the
:class:`ParserElement`'s defined pattern.  This is normally only used internally by
the pyparsing module, but may be needed in some whitespace-sensitive grammars.
Fr  r   s    r   leaveWhitespaceParserElement.leaveWhitespace	  s     $r   c                 .    SU l         Xl        SU l        U $ )z(
Overrides the default whitespace chars
TF)r  r  r  )r   r  s     r   setWhitespaceChars ParserElement.setWhitespaceChars	  s     #%*"r   c                     SU l         U $ )z
Overrides default behavior to expand ``<TAB>``s to spaces before parsing the input string.
Must be called before ``parseString`` when the input grammar contains elements that
match ``<TAB>`` characters.
T)r  r   s    r   parseWithTabsParserElement.parseWithTabs	  s     r   c                 ,   [        U[        5      (       a  [        U5      n[        U[        5      (       a,  XR                  ;  a  U R                  R	                  U5        U $ U R                  R	                  [        UR                  5       5      5        U $ )a|  
Define expression to be ignored (e.g., comments) while doing pattern
matching; may be called repeatedly, to define multiple comment or other
ignorable patterns.

Example::

    patt = OneOrMore(Word(alphas))
    patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj']

    patt.ignore(cStyleComment)
    patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd']
)r   rd  rN   r  r  r  r  s     r   ignoreParserElement.ignore	  st     eZ((UOEeX&&,,,  ''.  ##HUZZ\$:;r   c                 v    U=(       d    [         U=(       d    [        U=(       d    [        4U l        SU l        U $ )zD
Enable display of debugging messages while doing pattern matching.
T)r`  re  rg  r  r  )r   startActionsuccessActionexceptionActions       r   setDebugActionsParserElement.setDebugActions	  s8     )D,D*H.H,L0LN 
r   c                 d    U(       a!  U R                  [        [        [        5        U $ SU l        U $ )a  
Enable display of debugging messages while doing pattern matching.
Set ``flag`` to True to enable, False to disable.

Example::

    wd = Word(alphas).setName("alphaword")
    integer = Word(nums).setName("numword")
    term = wd | integer

    # turn on debugging for wd
    wd.setDebug()

    OneOrMore(term).parseString("abc 123 xyz 890")

prints::

    Match alphaword at loc 0(1,1)
    Matched alphaword -> ['abc']
    Match alphaword at loc 3(1,4)
    Exception raised:Expected alphaword (at char 4), (line:1, col:5)
    Match alphaword at loc 7(1,8)
    Matched alphaword -> ['xyz']
    Match alphaword at loc 11(1,12)
    Exception raised:Expected alphaword (at char 12), (line:1, col:13)
    Match alphaword at loc 15(1,16)
    Exception raised:Expected alphaword (at char 15), (line:1, col:16)

The output shown is that produced by the default debug actions - custom debug actions can be
specified using :class:`setDebugActions`. Prior to attempting
to match the ``wd`` expression, the debugging message ``"Match <exprname> at loc <n>(<line>,<col>)"``
is shown. Then if the parse succeeds, a ``"Matched"`` message is shown, or an ``"Exception raised"``
message is shown. Also note the use of :class:`setName` to assign a human-readable name to the expression,
which makes debugging and exception messages easier to understand - for instance, the default
name created for the :class:`Word` expression without calling ``setName`` is ``"W:(ABCD...)"``.
F)r  r`  re  rg  r  )r   flags     r   r  ParserElement.setDebug	  s2    J   !9;UWst  DJr   c                     U R                   $ r   rF  r   s    r   r   ParserElement.__str__	  s    yyr   c                     [        U 5      $ r   r   r   s    r   r   ParserElement.__repr__	  r   r   c                 "    SU l         S U l        U $ r   )r  r  r   s    r   r[  ParserElement.streamline	  s    r   c                     g r   r   r6  s     r   checkRecursionParserElement.checkRecursion	  s    r   c                 &    U R                  / 5        g)zZ
Check defined expressions for valid structure, check for infinite recursive definitions.
N)r  )r   validateTraces     r   validateParserElement.validate	  s     	Br   c                     UR                  5       n U R                  WU5      $ ! [         a;    [        US5       nUR                  5       nSSS5         ME  ! , (       d  f        NT= ff = f! [         aK  n[
        R                  (       a  e [        USS5      b   U R                  UR                  5      Ul	        UeSnAff = f)z
Execute the parse expression on the given file or filename.
If a filename is specified (instead of a file object),
the entire file is opened, read, and closed before parsing.
rNr  )
readr   openr`  r@   rG   r]  r  r  r  )r   file_or_filenamer^  file_contentsfr!  s         r   	parseFileParserElement.parseFile
  s    	),113M		##M8<<	  	)&, ! -,,,	)
 " 	// 36B(,(<(<S=N=N(OC%		s>   % A- A*AA*
A&	!A*&A*-
C7AB==Cc                     XL a  g[        U[        5      (       a  U R                  U5      $ [        U[        5      (       a  [	        U 5      [	        U5      :H  $ gr  )r   rd  rh  rG   varsr  s     r   __eq__ParserElement.__eq__
  sI    =z**<<&&}--:e,,r   c                     X:X  + $ r   r   r  s     r   __ne__ParserElement.__ne__#
      ""r   c                     [        U 5      $ r   )idr   s    r   __hash__ParserElement.__hash__&
  s    $xr   c                 
    X:H  $ r   r   r  s     r   __req__ParserElement.__req__)
  
    }r   c                     X:X  + $ r   r   r  s     r   __rne__ParserElement.__rne__,
  r  r   c                 X     U R                  [        U5      US9  g! [         a     gf = f)ay  
Method for quick testing of a parser against a test string. Good for simple
inline microtests of sub expressions while building up larger parser.

Parameters:
 - testString - to test against this expression for a match
 - parseAll - (default= ``True``) - flag to pass to :class:`parseString` when running tests

Example::

    expr = Word(nums)
    assert expr.matches("100")
r^  TF)r`  r   r@   )r   
testStringr^  s      r   rh  ParserElement.matches/
  s4    	U:.B! 		s    
))c	           
         [        U[        5      (       a?  [        [        [        R
                  UR                  5       R                  5       5      5      n[        U[        5      (       a  [        U5      nUc  [        R                  nUR                  n	/ n
/ nSn[        S5      R                  [        S5      5      R                  [        5      nSnU GH  nUb  UR!                  US5      (       d  U(       a  U(       d  UR#                  U5        M?  U(       d  MH  U(       a  SSR%                  U5      -   OSU/n/ n UR'                  UR)                  U5      5      nU R+                  XS9nU=(       a    U(       + nUb}   U" UU5      nUbP  [        U[,        5      (       a   UR#                  UR/                  5       5        OZUR#                  [	        U5      5        O?UR#                  UR/                  5       5        OUR#                  UR/                  US	95         U(       a/  U(       a  UR#                  S5        U	" SR%                  U5      5        U
R#                  UU45        GM     X4$ ! [0         ag  nUR#                  UR/                  US	95        UR#                  S
R3                  UR4                  [7        U5      R4                  U5      5         SnANSnAff = f! [8         a  n[        U[:        5      (       a  SOSnSU;   aW  UR#                  [=        UR>                  U5      5        UR#                  S[A        UR>                  U5      S-
  -  S-   U-   5        O$UR#                  SUR>                  -  S-   U-   5        UR#                  S[	        U5      -   5        U=(       a    UnUn SnAGNSnAf[0         a5  nUR#                  S[	        U5      -   5        U=(       a    UnUn SnAGNSnAff = f)a+  
Execute the parse expression on a series of test strings, showing each
test, the parsed results or where the parse failed. Quick and easy way to
run a parse expression against a list of sample strings.

Parameters:
 - tests - a list of separate test strings, or a multiline string of test strings
 - parseAll - (default= ``True``) - flag to pass to :class:`parseString` when running tests
 - comment - (default= ``'#'``) - expression for indicating embedded comments in the test
      string; pass None to disable comment filtering
 - fullDump - (default= ``True``) - dump results as list followed by results names in nested outline;
      if False, only dump nested list
 - printResults - (default= ``True``) prints test output to stdout
 - failureTests - (default= ``False``) indicates if these tests are expected to fail parsing
 - postParse - (default= ``None``) optional callback for successful parse results; called as
      `fn(test_string, parse_results)` and returns a string to be added to the test output
 - file - (default=``None``) optional file-like object to which test output will be written;
      if None, will default to ``sys.stdout``

Returns: a (success, results) tuple, where success indicates that all tests succeeded
(or failed if ``failureTests`` is True), and the results contain a list of lines of each
test's output

Example::

    number_expr = pyparsing_common.number.copy()

    result = number_expr.runTests('''
        # unsigned integer
        100
        # negative integer
        -100
        # float with scientific notation
        6.02e23
        # integer with scientific notation
        1e-12
        ''')
    print("Success" if result[0] else "Failed!")

    result = number_expr.runTests('''
        # stray character
        100Z
        # missing leading digit before '.'
        -.100
        # too many '.'
        3.14.159
        ''', failureTests=True)
    print("Success" if result[0] else "Failed!")

prints::

    # unsigned integer
    100
    [100]

    # negative integer
    -100
    [-100]

    # float with scientific notation
    6.02e23
    [6.02e+23]

    # integer with scientific notation
    1e-12
    [1e-12]

    Success

    # stray character
    100Z
       ^
    FAIL: Expected end of text (at char 3), (line:1, col:4)

    # missing leading digit before '.'
    -.100
    ^
    FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1)

    # too many '.'
    3.14.159
        ^
    FAIL: Expected end of text (at char 4), (line:1, col:5)

    Success

Each test string must be on a single line. If you want to test a string that spans multiple
lines, create a test like this::

    expr.runTest(r"this is a test\n of strings that spans \n 3 lines")

(Note that this is a raw string literal, you must include the leading 'r'.)
NT\nr  u   ﻿Fr   r  )r$  z{0} failed: {1}: {2}z(FATAL)r  r   r  zFAIL: zFAIL-EXCEPTION: )!r   rd  r_  r  r   r   rstrip
splitlinesr7   r   stdoutwriter  r   r  r}   rh  r  r   r   lstripr`  rE   r+  rC  r  r   r  r@   rD   rk   r   r]   )r   testsr^  commentfullDumpprintResultsfailureTestsr  fileprint_
allResultscommentssuccessr-  BOMr   r  resultpp_valuer  r   r   r!  s                          r   runTestsParserElement.runTestsC
  s(   @ eZ((SYY(A(A(CDEEgz**g&G<::D
U^**;t+<=DD\RA"wq%'@'@HUV"194$))H--r1ECH";&&qxx}5))!)?  "6,&6(k#,Q#7#/)(LAA #

8==? ; #

3x= 9JJv{{}5
 JJv{{{9:JJrNtyy~&q&k*c f "" % k

6;;H;#=>

#9#@#@ASASUYZ[U\UeUegh#ijjk5 & 	%/4G%H%H	b19JJtBFFA/JJsc"&&!nq&89C?%GHJJsRVV|c1E9:

8c"g-.!2l 

-C89!2lsK   >/K!A I-I-I--
K7AKK!
O7+CN55O7*O22O7)r  r  r  r  r  r  r  r  r  r  r  r  r  rT  r  r   r  r  r  r  r  r  FTr  )   r   )T#TTFNN)Ur   r   r   r   r	  r  r]  r.  r  r  r
  r  r   r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  rP  r+  r;  r=  rK  r
   rJ  rL  rP  r  rS  rV  rX  r`  _MAX_INTrk  r   rs  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  rE  r  r  r  r  r  r  r  r  r   r   r[  r  r  r  r  r  r  r  r  rh  r  r   r   r   r   rG   rG   F  s   3#2 2 0 0*  
#.::.&/b2
UnC=& =, 	A 	A:	A 	A: Ma&1. F\ \ O =  =D8t /7 HT.` 19 @ (05 2$"L
/
HT#)

!

#
O
"H(0)V
 ,##( 69QU`#r   rG   c                   >   ^  \ rS rSrSU 4S jjrS rS rS rSrU =r	$ )r  i
  c                    > [         [        U ]  5         [        U[	        5       -   5      R                  SS5      U l        U R                  U l        Xl        X l	        g )Nr/   ...)
superr  r   r   r/   r   r  rT  anchorr  )r   r_  r  r  s      r   r   _PendingSkip.__init__
  sD    lD*,4%'>*227EBLL	"r   c                   ^  [        U5      R                  S5      " S5      nT R                  (       aF  S nU 4S jnT R                  U" 5       R	                  U5      -   U" 5       R	                  U5      -  U-   $ T R                  U-   U-   $ )Nr"  r  c                     U R                   (       a  U R                   R                  5       S/:X  a  U S	 U R                  SS 5        g g )Nr   r   _skipped)r(  rU  r  r   s    r   r  '_PendingSkip.__add__.<locals>.must_skip
  s:    zzQZZ%6%6%8RD%@!EE*d+ &Ar   c                    > U R                   R                  5       SS  S/:X  a0  U R                  S5      nS[        TR                  5      -   S-   U S'   g g )Nr   r   r(  z	missing <r	  )r(  rU  r  rI  r$  )r   skippedr   s     r   	show_skip'_PendingSkip.__add__.<locals>.show_skip
  sP    ::$$&rs+t3eeJ/G$/$t{{2C$Cc$IAjM 4r   )rK   r  r  r$  r  )r   r  skipperr  r,  s   `    r   r  _PendingSkip.__add__
  s    -''.{;>>,J KK')":":9"EEi..y9:=BC C {{W$u,,r   c                     U R                   $ r   r  r   s    r   r   _PendingSkip.__repr__   s    ||r   c                     [        S5      e)NzBuse of `...` expression without following SkipTo target expression)rC  r   r   s     r   r  _PendingSkip.parseImpl  s    \]]r   )r$  r  rT  r  r  )
r   r   r   r   r   r  r   r  r   __classcell__r  s   @r   r  r  
  s    #- ^ ^r   r  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )rO   i  zQAbstract :class:`ParserElement` subclass, for defining atomic
matching patterns.
c                 (   > [         [        U ]  SS9  g NFr  )r#  rO   r   r   r  s    r   r   Token.__init__  s    eT#U#3r   r   r   r   r   r   r	  r   r   r6  r7  s   @r   rO   rO     s    4 4r   rO   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r/   i  z'An empty token, will always match.
    c                 T   > [         [        U ]  5         SU l        SU l        SU l        g )Nr/   TF)r#  r/   r   rT  r  r  r<  s    r   r   Empty.__init__  s'    eT#%	""r   r  r  rT  r>  r7  s   @r   r/   r/     s    # #r   r/   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r:   i  z#A token that will never match.
    c                 b   > [         [        U ]  5         SU l        SU l        SU l        SU l        g )Nr:   TFzUnmatchable token)r#  r:   r   rT  r  r  r  r<  s    r   r   NoMatch.__init__  s.    gt%'	"")r   c                 0    [        XU R                  U 5      er   )rB   r  r  s       r   r  NoMatch.parseImpl#  s    XDKK>>r   )r  r  r  rT  r  	r   r   r   r   r	  r   r  r   r6  r7  s   @r   r:   r:     s    *? ?r   r:   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r7   i'  a  Token to exactly match a specified string.

Example::

    Literal('blah').parseString('blah')  # -> ['blah']
    Literal('blah').parseString('blahfooblah')  # -> ['blah']
    Literal('blah').parseString('bla')  # -> Exception: Expected "blah"

For case-insensitive matching, use :class:`CaselessLiteral`.

For keyword matching (force word break before and after the matched string),
use :class:`Keyword` or :class:`CaselessKeyword`.
c                   > [         [        U ]  5         Xl        [	        U5      U l         US   U l        S[        U R                  5      -  U l        SU R                  -   U l        SU l        SU l        U R
                  S:X  a  [%        U 5      [        L a  [&        U l        g g g ! [         a(    [        R                  " S[        SS9  [        U l         Nf = f)	Nr   z2null string passed to Literal; use Empty() insteadr   r}  "%s"r  Fr   )r#  r7   r   matchr   matchLenfirstMatchCharrg  r  r  r  r/   r  r   rT  r  r  r  r  _SingleCharLiteralr   matchStringr  s     r   r   Literal.__init__5  s    gt%' 
K(	#"-a.D
 U4::..	!DII-#" ==A$t*"7/DN #8  	#MMN)a9"DN	#s   
B$ $/CCc                     X   U R                   :X  a;  UR                  U R                  U5      (       a  X R                  -   U R                  4$ [	        XU R
                  U 5      er   )rN  
startswithrL  rM  rB   r  r  s       r   r  Literal.parseImplI  sR    =D///H4G4G

TW4X4X&

22XDKK>>r   )r  r  rN  rL  rM  r  r  rT  r  rH  r7  s   @r   r7   r7   '  s    0(? ?r   r7   c                       \ rS rSrSS jrSrg)rO  iN  c                 v    X   U R                   :X  a  US-   U R                  4$ [        XU R                  U 5      er  )rN  rL  rB   r  r  s       r   r  _SingleCharLiteral.parseImplO  s8    =D///7DJJ&&XDKK>>r   r   Nr  r   r   r   r   r  r   r   r   r   rO  rO  N  s    ?r   rO  c                   `   ^  \ rS rSrSr\S-   rS	U 4S jjrS
S jrU 4S jr	\
S 5       rSrU =r$ )r4   iW  a=  Token to exactly match a specified string as a keyword, that is,
it must be immediately followed by a non-keyword character.  Compare
with :class:`Literal`:

 - ``Literal("if")`` will match the leading ``'if'`` in
   ``'ifAndOnlyIf'``.
 - ``Keyword("if")`` will not; it will only match the leading
   ``'if'`` in ``'if x=1'``, or ``'if(y==2)'``

Accepts two optional constructor arguments in addition to the
keyword string:

 - ``identChars`` is a string of characters that would be valid
   identifier characters, defaulting to all alphanumerics + "_" and
   "$"
 - ``caseless`` allows case-insensitive matching, default is ``False``.

Example::

    Keyword("start").parseString("start")  # -> ['start']
    Keyword("start").parseString("starting")  # -> Exception

For case-insensitive matching, use :class:`CaselessKeyword`.
_$c                   > [         [        U ]  5         Uc  [        R                  nXl        [        U5      U l         US   U l        SU R                  -  U l        SU R                  -   U l        SU l        SU l        X0l        U(       a%  UR#                  5       U l        UR#                  5       n['        U5      U l        g ! [         a    [        R                  " S[        SS9   Nf = f)Nr   z2null string passed to Keyword; use Empty() insteadr   r}  rK  r  F)r#  r4   r   DEFAULT_KEYWORD_CHARSrL  r   rM  rN  rg  r  r  r  rT  r  r  r  caselessuppercaselessmatchr  
identChars)r   rQ  ra  r^  r  s       r   r   Keyword.__init__r  s    gt%' 66J 
K(	7"-a.D TZZ'	!DII-#" !,!2!2!4D#))+Jj/  	7MMN'A7	7s   
C $C('C(c                 *   U R                   (       a  XX R                  -    R                  5       U R                  :X  a  U[	        U5      U R                  -
  :  d-  XU R                  -      R                  5       U R
                  ;  aC  US:X  d#  XS-
     R                  5       U R
                  ;  a  X R                  -   U R                  4$ OX   U R                  :X  a  U R                  S:X  d!  UR                  U R                  U5      (       ap  U[	        U5      U R                  -
  :  d  XU R                  -      U R
                  ;  a5  US:X  d  XS-
     U R
                  ;  a  X R                  -   U R                  4$ [        XU R                  U 5      ert  )r^  rM  r_  r`  r   ra  rL  rN  rT  rB   r  r  s       r   r  Keyword.parseImpl  s?   ==cMM1288:d>P>PPH ==$4==%89??AX$1W-335T__L]]*DJJ66 } 3 33]]a'8+>+>tzz3+O+O CMDMM$AA (t}})< =T__ T AX'):$//)Q.

::XDKK>>r   c                 V   > [         [        U ]  5       n[        R                  Ul        U$ r   )r#  r4   r  r]  ra  )r   r   r  s     r   r  Keyword.copy  s$    '4%'44r   c                     U [         l        g)z,Overrides the default Keyword chars
        N)r4   r]  r  s    r   setDefaultKeywordCharsKeyword.setDefaultKeywordChars  s     ).%r   )
r^  r`  r  rN  ra  rL  rM  r  r  rT  rA  r  )r   r   r   r   r	  rW   r]  r   r  r  r.  rh  r   r6  r7  s   @r   r4   r4   W  s8    0 &,**?&
 . .r   r4   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r*   i  aN  Token to match a specified string, ignoring case of letters.
Note: the matched results will always be in the case of the given
match string, NOT the case of the input text.

Example::

    OneOrMore(CaselessLiteral("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD', 'CMD']

(Contrast with example for :class:`CaselessKeyword`.)
c                    > [         [        U ]  UR                  5       5        Xl        SU R                  -  U l        SU R
                  -   U l        g )Nz'%s'r  )r#  r*   r   r_  returnStringrT  r  rP  s     r   r   CaselessLiteral.__init__  sC    ot-k.?.?.AB'T...	!DII-r   c                     XX R                   -    R                  5       U R                  :X  a  X R                   -   U R                  4$ [	        XU R
                  U 5      er   )rM  r_  rL  rl  rB   r  r  s       r   r  CaselessLiteral.parseImpl  sN    mm+,224

B&(9(999XDKK>>r   )r  rT  rl  r  rH  r7  s   @r   r*   r*     s    	.? ?r   r*   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r)   i  z
Caseless version of :class:`Keyword`.

Example::

    OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD']

(Contrast with example for :class:`CaselessLiteral`.)
c                 *   > [         [        U ]  XSS9  g )NTr^  )r#  r)   r   )r   rQ  ra  r  s      r   r   CaselessKeyword.__init__  s    ot-kPT-Ur   r   r   r>  r7  s   @r   r)   r)     s    V Vr   r)   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r   i  a@  A variation on :class:`Literal` which matches "close" matches,
that is, strings with at most 'n' mismatching characters.
:class:`CloseMatch` takes parameters:

 - ``match_string`` - string to be matched
 - ``maxMismatches`` - (``default=1``) maximum number of
   mismatches allowed to count as a match

The results from a successful parse will contain the matched text
from the input string and the following named results:

 - ``mismatches`` - a list of the positions within the
   match_string where mismatches were found
 - ``original`` - the original match_string used to compare
   against the input string

If ``mismatches`` is an empty list, then the match was an exact
match.

Example::

    patt = CloseMatch("ATCATCGAATGGA")
    patt.parseString("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']})
    patt.parseString("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1)

    # exact match
    patt.parseString("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']})

    # close match allowing up to 2 mismatches
    patt = CloseMatch("ATCATCGAATGGA", maxMismatches=2)
    patt.parseString("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']})
c                    > [         [        U ]  5         Xl        Xl        X l        SU R                  U R
                  4-  U l        SU l        SU l        g )Nz&Expected %r (with up to %d mismatches)F)	r#  r   r   rT  match_stringmaxMismatchesr  r  r  )r   rv  rw  r  s      r   r   CloseMatch.__init__  sO    j$(* 	(*>$BSBSUYUgUgAhh"#r   c                    Un[        U5      nU[        U R                  5      -   nXe::  a  U R                  nSn/ n	U R                  n
[        [	        XU U5      5       H2  u  pUu  pX:w  d  M  U	R                  U5        [        U	5      U
:  d  M2    O    US-   n[        XU /5      nX~S'   XS'   X.4$ [        XU R                  U 5      e)Nr   r   original
mismatches)	r   rv  rw  r  r   r  rE   rB   r  )r   r^  r   r  startr  maxlocrv  match_stringlocr{  rw  s_msrcmatresultss                  r   r  CloseMatch.parseImpl  s    x=T..//,,LOJ ..M(1#h66JL2Y(Z$:%%o6:6 )[ &)&s(;'<=&2
#(2%|#XDKK>>r   )r  rv  rw  r  r  rT  )r   r  rH  r7  s   @r   r   r     s    @$? ?r   r   c                   F   ^  \ rS rSrSrSU 4S jjrSS jrU 4S jrSrU =r	$ )	rR   i  a  Token for matching words composed of allowed character sets.
Defined with string containing all allowed initial characters, an
optional string containing allowed body characters (if omitted,
defaults to the initial character set), and an optional minimum,
maximum, and/or exact length.  The default value for ``min`` is
1 (a minimum value < 1 is not valid); the default values for
``max`` and ``exact`` are 0, meaning no maximum or exact
length restriction. An optional ``excludeChars`` parameter can
list characters that might be found in the input ``bodyChars``
string; useful to define a word of all printables except for one or
two characters, for instance.

:class:`srange` is useful for defining custom character set strings
for defining ``Word`` expressions, using range notation from
regular expression character sets.

A common mistake is to use :class:`Word` to match a specific literal
string, as in ``Word("Address")``. Remember that :class:`Word`
uses the string argument to define *sets* of matchable characters.
This expression would match "Add", "AAA", "dAred", or any other word
made up of the characters 'A', 'd', 'r', 'e', and 's'. To match an
exact literal string, use :class:`Literal` or :class:`Keyword`.

pyparsing includes helper strings for building Words:

 - :class:`alphas`
 - :class:`nums`
 - :class:`alphanums`
 - :class:`hexnums`
 - :class:`alphas8bit` (alphabetic characters in ASCII range 128-255
   - accented, tilded, umlauted, etc.)
 - :class:`punc8bit` (non-alphabetic characters in ASCII range
   128-255 - currency, symbols, superscripts, diacriticals, etc.)
 - :class:`printables` (any non-whitespace character)

Example::

    # a word composed of digits
    integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9"))

    # a word with a leading capital, and zero or more lowercase
    capital_word = Word(alphas.upper(), alphas.lower())

    # hostnames are alphanumeric, with leading alpha, and '-'
    hostname = Word(alphas, alphanums + '-')

    # roman numeral (not a strict parser, accepts invalid mix of characters)
    roman = Word("IVXLCDM")

    # any string of non-whitespace characters, except for ','
    csv_value = Word(printables, excludeChars=",")
c                 j  >^ [         [        U ]  5         T(       aH  [        T5      mSR	                  U4S jU 5       5      nU(       a  SR	                  U4S jU 5       5      nXl        [        U5      U l        U(       a  X l        [        U5      U l        OXl        [        U5      U l        US:  U l	        US:  a  [        S5      eX0l        US:  a  X@l        O[        U l        US:  a  XPl        XPl        [        U 5      U l        SU R                  -   U l        SU l        X`l        S	U R
                  U R                  -   ;  GaU  US:X  GaM  US:X  GaE  US:X  Ga=  U R                  U R
                  :X  a  S
['        U R
                  5      -  U l        O[+        U R
                  5      S:X  aA  [,        R.                  " U R
                  5      < S['        U R                  5      < S3U l        O6S['        U R
                  5      < S['        U R                  5      < S3U l        U R$                  (       a  SU R(                  -   S-   U l         [,        R0                  " U R(                  5      U l        U R,                  R2                  U l        [6        U l        g g g g g ! [:         a
    S U l         g f = f)Nr   c              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr   r   r   r   excludeCharss     r   r    Word.__init__.<locals>.<genexpr>G  s     N9a8M9   		c              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr   r   r  s     r   r   r  I  s     #Ry!\<QAAyr  r   r   zZcannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permittedr  Fr  z[%s]+r  z]*z][z\b)r#  rR   r   r  r   initCharsOrig	initCharsbodyCharsOrig	bodyCharsmaxSpecifiedr  minLenmaxLenr  r   rT  r  r  	asKeyword_escapeRegexRangeCharsreStringr   r   escapecompilerL  re_match
_WordRegexr  rC  )	r   r  r  minmaxexactr  r  r  s	          `r   r   Word.__init__C  s*   dD"$|,LN9NNIGG#Ry#RR	&Y!* ^DN!* ^DN!G7yzz7K"DK19KK$K	!DII-""d((4+=+===3!8PSWXPX]bfg]g!!T%7%77 '*@ASAS*T TT''(A--/YYt7I7I-J-CDDVDV-W!Z . 0FdFXFX/Y/EdFXFX/Y!\~~ % 5 =,**T]]3 !%!+% ^hPX8=  s   %J J21J2c                    X   U R                   ;  a  [        XU R                  U 5      eUnUS-  n[        U5      nU R                  nX@R
                  -   n[        Xu5      nX':  a  X   U;   a  US-  nX':  a
  X   U;   a  M  SnX$-
  U R                  :  a  SnORU R                  (       a  X%:  a  X   U;   a  SnO1U R                  (       a   US:  a  XS-
     U;   d  X%:  a
  X   U;   a  SnU(       a  [        XU R                  U 5      eX!XB 4$ )Nr   FTr   )
r  rB   r  r   r  r  r  r  r  r  )	r   r^  r   r  r|  r  	bodycharsr}  throwExceptions	            r   r  Word.parseImpl|  s   =. TBBqx=NN	$V&lx}	91HC lx}	9 ;$!N3>hmy6P!N^^	hqy1Y>~(-9*D!% TBBU'''r   c                 b  >  [         [        U ]  5       $ ! [         a     Of = fU R                  cs  S nU R
                  U R                  :w  a<  SU" U R
                  5      < SU" U R                  5      < S3U l        U R                  $ SU" U R
                  5      -  U l        U R                  $ )Nc                 4    [        U 5      S:  a  U S S S-   $ U $ )N   r"  r#  )r   s    r   
charsAsStr Word.__str__.<locals>.charsAsStr  s"    q6A:Ra55=(Hr   zW:(r  r  zW:(%s))r#  rR   r   rC  r  r  r  )r   r  r  s     r   r   Word.__str__  s    	t,.. 		 << !!T%7%77/9$:L:L/MzZ^ZlZlOmn ||  (*T5G5G*HH||    
"")r  r  r  r  r  r  r  r  r  r  r  rT  r   r  r  r  )Nr   r   r   FNr  
r   r   r   r   r	  r   r  r   r   r6  r7  s   @r   rR   rR     s    3h7,r(8 r   rR   c                       \ rS rSrSS jrSrg)r  i  c                     U R                  X5      nU(       d  [        XU R                  U 5      eUR                  5       nX$R	                  5       4$ r   )r  rB   r  endgroup)r   r^  r   r  r  s        r   r  _WordRegex.parseImpl  s@    x- TBBjjlLLN""r   r   Nr  rY  r   r   r   r  r    s    #r   r  c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )rV   i  zA short-cut class for defining ``Word(characters, exact=1)``,
when defining a match of any single character in a string of
characters.
c                 :  > [         [        U ]  USX#S9  S[        SR	                  U R
                  5      5      -  U l        U(       a  SU R                  -  U l        [        R                  " U R                  5      U l        U R                  R                  U l
        g )Nr   )r  r  r  [%s]r   z\b%s\b)r#  rV   r   r  r   r  r  r   r  rL  r  )r   charsetr  r  r  s       r   r   Char.__init__  sn    dD"7!y"d!78O!PP%5DM**T]]+r   )r   r  r  )FNr>  r7  s   @r   rV   rV     s    & &r   rV   c                   `   ^  \ rS rSrSrS
U 4S jjrSS jrSS jrSS jrU 4S jr	S r
S	rU =r$ )rJ   i  a$  Token for matching strings that match a given regular
expression. Defined with string specifying the regular expression in
a form recognized by the stdlib Python  `re module <https://docs.python.org/3/library/re.html>`_.
If the given regex contains named groups (defined using ``(?P<name>...)``),
these will be preserved as named parse results.

If instead of the Python stdlib re module you wish to use a different RE module
(such as the `regex` module), you can replace it by either building your
Regex object with a compiled RE that was compiled using regex:

Example::

    realnum = Regex(r"[+-]?\d+\.\d*")
    date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
    # ref: https://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
    roman = Regex(r"M{0,4}(CM|CD|D?{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")

    # use regex module instead of stdlib re module to construct a Regex using
    # a compiled regular expression
    import regex
    parser = pp.Regex(regex.compile(r'[0-9]'))

c                   > [         [        U ]  5         [        U[        5      (       ap  U(       d  [
        R                  " S[        SS9  Xl        X l	         [        R                  " U R                  U R                  5      U l
        U R                  U l        OR[        US5      (       a6  [        US5      (       a%  Xl
        UR                  =U l        U l        X l	        O[        S5      eU R                  R                   U l        [%        U 5      U l        SU R&                  -   U l        S	U l        U R#                  S
5      SLU l        X0l        X@l        U R.                  (       a  U R2                  U l        U R0                  (       a  U R6                  U l        gg! [        R                   a    [
        R                  " SU-  [        SS9  e f = f)zThe parameters ``pattern`` and ``flags`` are passed
to the ``re.compile()`` function as-is. See the Python
`re module <https://docs.python.org/3/library/re.html>`_ module for an
explanation of the acceptable patterns and flags.
z0null string passed to Regex; use Empty() insteadr   r}  $invalid pattern (%s) passed to RegexpatternrL  zCRegex may only be constructed with a string or a compiled RE objectr  Fr   N)r#  rJ   r   r   rd  r  r  r  r  flagsr   r  r  errorr  rf  rL  r  r   rT  r  r  r  asGroupListasMatchparseImplAsGroupListr  parseImplAsMatch)r   r  r  r  r  r  s        r   r   Regex.__init__  sd    	eT#%gz**P+; #LJ**T\\4::> $ Wi((WWg-F-FG+2??:DL4=J abb$K	!DII-""mmB/t;&!66DN<<!22DN / 88 DwN+;s   AF 3Gc                     U R                  X5      nU(       d  [        XU R                  U 5      eUR                  5       n[	        UR                  5       5      nUR                  5       nU(       a  UR                  5        H	  u  pxXU'   M     X%4$ r   )r  rB   r  r  rE   r  	groupdictrx  )	r   r^  r   r  r  r   dro  rk  s	            r   r  Regex.parseImpl
  sr    x- TBBjjl6<<>*	A "xr   c                     U R                  X5      nU(       d  [        XU R                  U 5      eUR                  5       nUR	                  5       nX%4$ r   )r  rB   r  r  groupsr   r^  r   r  r  r   s         r   r  Regex.parseImplAsGroupList  sC    x- TBBjjlmmoxr   c                     U R                  X5      nU(       d  [        XU R                  U 5      eUR                  5       nUnX%4$ r   )r  rB   r  r  r  s         r   r  Regex.parseImplAsMatch   s=    x- TBBjjlxr   c                    >  [         [        U ]  5       $ ! [         a     Of = fU R                  c  S[        U R                  5      -  U l        U R                  $ )NzRe:(%s))r#  rJ   r   rC  r  rI  r  r<  s    r   r   Regex.__str__)  sU    	-// 		 <<$tDLL'99DL||r  c                 Z  ^ ^ T R                   (       a$  [        R                  " S[        SS9  [	        5       eT R
                  (       a4  [        T5      (       a$  [        R                  " S[        SS9  [	        5       eT R
                  (       a  U4S jnOUU 4S jnT R                  U5      $ )aQ  
Return Regex with an attached parse action to transform the parsed
result as if called using `re.sub(expr, repl, string) <https://docs.python.org/3/library/re.html#re.sub>`_.

Example::

    make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2</\1>")
    print(make_html.transformString("h1:main title:"))
    # prints "<h1>main title</h1>"
z-cannot use sub() with Regex(asGroupList=True)r   r}  z9cannot use sub() with a callable with Regex(asMatch=True)c                 ,   > U S   R                  T5      $ rH  )expand)r  repls    r   r   Regex.sub.<locals>.paJ  s    ay''--r   c                 B   > TR                   R                  TU S   5      $ rH  )r   rp  )r  r  r   s    r   r   r  M  s    ww{{433r   )r  r  r  r  SyntaxErrorr  r  r  )r   r  r   s   `` r   rp  	Regex.sub4  sw     MMI'A7-<<HTNNMMU'A7-<<.4""2&&r   )r  r  r  r  r  r  rT  r  r  r   r  r  r  )r   FFr  )r   r   r   r   r	  r   r  r  r  r   rp  r   r6  r7  s   @r   rJ   rJ     s,    .+3Z	' 'r   rJ   c                   J   ^  \ rS rSrSr  SU 4S jjrSS jrU 4S jrSrU =r	$ )	rH   iQ  a  
Token for matching strings that are delimited by quoting characters.

Defined with the following parameters:

    - quoteChar - string of one or more characters defining the
      quote delimiting string
    - escChar - character to escape quotes, typically backslash
      (default= ``None``)
    - escQuote - special quote sequence to escape an embedded quote
      string (such as SQL's ``""`` to escape an embedded ``"``)
      (default= ``None``)
    - multiline - boolean indicating whether quotes can span
      multiple lines (default= ``False``)
    - unquoteResults - boolean indicating whether the matched text
      should be unquoted (default= ``True``)
    - endQuoteChar - string of one or more characters defining the
      end of the quote delimited string (default= ``None``  => same as
      quoteChar)
    - convertWhitespaceEscapes - convert escaped whitespace
      (``'\t'``, ``'\n'``, etc.) to actual whitespace
      (default= ``True``)

Example::

    qs = QuotedString('"')
    print(qs.searchString('lsjdf "This is the quote" sldjf'))
    complex_qs = QuotedString('{{', endQuoteChar='}}')
    print(complex_qs.searchString('lsjdf {{This is the "quote"}} sldjf'))
    sql_qs = QuotedString('"', escQuote='""')
    print(sql_qs.searchString('lsjdf "This is the quote with ""embedded"" quotes" sldjf'))

prints::

    [['This is the quote']]
    [['This is the "quote"']]
    [['This is the quote with "embedded" quotes']]
c                   >^  [         [        T ]  5         UR                  5       nU(       d$  [        R
                  " S[        SS9  [        5       eUc  UnO;UR                  5       nU(       d$  [        R
                  " S[        SS9  [        5       eUT l        [        U5      T l
        US   T l        UT l        [        U5      T l        UT l        UT l        UT l        UT l        U(       a  [$        R&                  [$        R(                  -  T l        [$        R,                  " T R                  5      < S[/        T R                  S   5      < US L=(       a    [/        U5      =(       d    S< S3T l        OkST l        [$        R,                  " T R                  5      < S[/        T R                  S   5      < S	US L=(       a    [/        U5      =(       d    S< S3T l        [        T R                  5      S
:  aU  T =R0                  SSR3                  U 4S j[5        [        T R                  5      S
-
  SS5       5       5      -   S-   -  sl        U(       a,  T =R0                  S[$        R,                  " U5      -  -  sl        U(       aT  T =R0                  S[$        R,                  " U5      -  -  sl        [$        R,                  " T R                  5      S-   T l        T =R0                  S[$        R,                  " T R                  5      -  -  sl         [$        R8                  " T R0                  T R*                  5      T l        T R0                  T l        T R$                  R<                  T l        [C        T 5      T l"        ST RD                  -   T l#        ST l$        ST l%        g ! [$        R@                   a)    [        R
                  " ST R0                  -  [        SS9  e f = f)Nz$quoteChar cannot be the empty stringr   r}  z'endQuoteChar cannot be the empty stringr   z(?:[^r   r  z\n\rr   z|(?:z)|(?:c              3      >#    U  HF  n[         R                  " TR                  S U 5      < S[        TR                  U   5      < S3v   MH     g 7f)Nz[^r  )r   r  endQuoteCharr  )r   r%  r   s     r   r   (QuotedString.__init__.<locals>.<genexpr>  sJ      &Y/W! 4699T=N=NrPQ=R3S3I$J[J[\]J^3_'a/Ws   AAr   r  z|(?:%s)z|(?:%s.)z(.)z)*%sr  r  FT)&r#  rH   r   r   r  r  r  r  	quoteCharr   quoteCharLenfirstQuoteCharr  endQuoteCharLenescCharescQuoteunquoteResultsconvertWhitespaceEscapesr   	MULTILINEDOTALLr  r  r  r  r   ru  escCharReplacePatternr  r  rL  r  r  r   rT  r  r  r  )	r   r  r  r  	multiliner  r  r  r  s	   `       r   r   QuotedString.__init__x  s   lD*, OO%	MM@-\]^-$L'--/LGcde!m#"	N'l("<0 ,(@%		1DJ.0ii.G.DTEVEVWXEY.Z/6d/B/fG]^eGf/ljl/loDL DJ24))DNN2K2HIZIZ[\I]2^3:$3F3jKabiKj3pnp3psDL t  !A%LL &Y/4S9J9J5Ka5OQRTV/W&Y Y Y[^_`L
 LLZ"))H*==>LLL[299W+==>L)+4<<)@5)HD&299T->->#??@	jjtzz:DG LLDM GGMMDM $K	!DII-"" xx 	MM@4<<O'A7	s   AN# #=O c                    X   U R                   :H  =(       a    U R                  X5      =(       d    S nU(       d  [        XU R                  U 5      eUR	                  5       nUR                  5       nU R                  (       a  XPR                  U R                  *  n[        U[        5      (       a  SU;   aB  U R                  (       a1  SSSSS.nUR                  5        H  u  pxUR                  Xx5      nM     U R                  (       a"  [        R                   " U R"                  SU5      nU R$                  (       a&  UR                  U R$                  U R&                  5      nX%4$ )Nr   	r  )\tr  z\fz\rz\g<1>)r  r  rB   r  r  r  r  r  r  r   rd  r  rx  r   r  r   rp  r  r  r  )	r   r^  r   r  r  r   ws_mapwslitwschars	            r   r  QuotedString.parseImpl  s   $"5"55V$--:V^Z^ TBBjjllln ''$*>*>)>?C#z**3;4#@#@####	F *0!kk%8 *8 <<&&!;!;XsKC ==++dmmT5F5FGCxr   c                    >  [         [        U ]  5       $ ! [         a     Of = fU R                  c#  SU R
                  < SU R                  < 3U l        U R                  $ )Nzquoted string, starting with z ending with )r#  rH   r   rC  r  r  r  r<  s    r   r   QuotedString.__str__  sW    	t466 		 <<OS~~_c_p_pqDL||r  )r  r  r  r  r  r  r  r  r  r  r  rT  r  r  r  r   r  r  r  r  )NNFTNTr  r  r7  s   @r   rH   rH   Q  s)    %L JORV?#B!F	 	r   rH   c                   F   ^  \ rS rSrSrSU 4S jjrSS jrU 4S jrSrU =r	$ )	r+   i  a  Token for matching words composed of characters *not* in a given
set (will include whitespace in matched characters if not listed in
the provided exclusion set - see example). Defined with string
containing all disallowed characters, and an optional minimum,
maximum, and/or exact length.  The default value for ``min`` is
1 (a minimum value < 1 is not valid); the default values for
``max`` and ``exact`` are 0, meaning no maximum or exact
length restriction.

Example::

    # define a comma-separated-value as anything that is not a ','
    csv_value = CharsNotIn(',')
    print(delimitedList(csv_value).parseString("dkls,lsdkjf,s12 34,@!#,213"))

prints::

    ['dkls', 'lsdkjf', 's12 34', '@!#', '213']
c                 D  > [         [        U ]  5         SU l        Xl        US:  a  [        S5      eX l        US:  a  X0l        O[        U l        US:  a  X@l        X@l        [        U 5      U l
        SU R                  -   U l        U R                  S:H  U l        SU l        g )NFr   zfcannot specify a minimum length < 1; use Optional(CharsNotIn()) if zero-length char group is permittedr   r  )r#  r+   r   r  notCharsr  r  r  r  r   rT  r  r  r  )r   r  r  r  r  r  s        r   r   CharsNotIn.__init__  s    j$(*# 7 ] ^ ^ 7K"DK19KK$K	!DII-#{{a/"r   c                 Z   X   U R                   ;   a  [        XU R                  U 5      eUnUS-  nU R                   n[        X@R                  -   [        U5      5      nX&:  a  X   U;  a  US-  nX&:  a
  X   U;  a  M  X$-
  U R                  :  a  [        XU R                  U 5      eX!XB 4$ r  )r  rB   r  r  r  r   r  )r   r^  r   r  r|  notcharsmaxlens          r   r  CharsNotIn.parseImpl  s    =DMM) TBBq==U[[(#h-8lx}H<1HC lx}H< ;$ TBBU'''r   c                   >  [         [        U ]  5       $ ! [         a     Of = fU R                  cP  [        U R                  5      S:  a#  SU R                  S S -  U l        U R                  $ SU R                  -  U l        U R                  $ )Nr  z
!W:(%s...)z!W:(%s))r#  r+   r   rC  r  r   r  r<  s    r   r   CharsNotIn.__str__%  s    	T244 		 <<4==!A%+dmmBQ.?? ||  )4==8||r  )	r  r  r  r  r  rT  r  r  r  )r   r   r   r  r  r7  s   @r   r+   r+     s    &#2(  r   r+   c                      ^  \ rS rSrSr0 SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&S'S(S)S*S+.ErS/U 4S, jjrS0S- jrS.rU =r	$ )1rQ   i3  a}  Special matching class for matching whitespace.  Normally,
whitespace is ignored by pyparsing grammars.  This class is included
when some whitespace structures are significant.  Define with
a string containing the whitespace characters to be matched; default
is ``" \t\r\n"``.  Also takes optional ``min``,
``max``, and ``exact`` arguments, as defined for the
:class:`Word` class.
r  z<SP>r  z<TAB>r  z<LF>r  z<CR>r  z<FF>    z<NBSP>u    z<OGHAM_SPACE_MARK>u   ᠎z<MONGOLIAN_VOWEL_SEPARATOR>u    z	<EN_QUAD>u    z	<EM_QUAD>u    z
<EN_SPACE>u    z
<EM_SPACE>u    z<THREE-PER-EM_SPACE>u    z<FOUR-PER-EM_SPACE>u    z<SIX-PER-EM_SPACE>u    z<FIGURE_SPACE>u    z<PUNCTUATION_SPACE>z<THIN_SPACE>z<HAIR_SPACE>z<ZERO_WIDTH_SPACE>z<NNBSP>z<MMSP>z<IDEOGRAPHIC_SPACE>)u    u    u   ​u    u    u   　c                   >^  [         [        T ]  5         UT l        T R	                  SR                  U 4S jT R                   5       5      5        SR                  S T R                   5       5      T l        ST l        ST R                  -   T l	        UT l
        US:  a  UT l        O[        T l        US:  a  UT l        UT l
        g g )Nr   c              3   J   >#    U  H  oTR                   ;  d  M  Uv   M     g 7fr   )
matchWhite)r   r   r   s     r   r   !White.__init__.<locals>.<genexpr>X  s     '_?atF^?s   #	#c              3   H   #    U  H  n[         R                  U   v   M     g 7fr   )rQ   	whiteStrsr   s     r   r   r  Z  s     IAU__Q/r  Tr  r   )r#  rQ   r   r  r  r   r  rT  r  r  r  r  r  )r   wsr  r  r  r  s   `    r   r   White.__init__U  s    eT#%'_4??'_ _`WWIII	"!DII-7DK"DK19DKDK r   c                 n   X   U R                   ;  a  [        XU R                  U 5      eUnUS-  nX@R                  -   n[	        U[        U5      5      nX%:  a0  X   U R                   ;   a  US-  nX%:  a  X   U R                   ;   a  M  X$-
  U R                  :  a  [        XU R                  U 5      eX!XB 4$ r  )r  rB   r  r  r  r   r  )r   r^  r   r  r|  r}  s         r   r  White.parseImpli  s    =/ TBBq$VS]+lx}?1HC lx}? ;$ TBBU'''r   )r  r  r  r  r  rT  )z 	
r   r   r   r  )
r   r   r   r   r	  r  r   r  r   r6  r7  s   @r   rQ   rQ   3  s   
f
g
 	f
 	f	

 	f
 	8
 	'
 	0
 	;
 	;
 	<
 	<
 	)
 	(
 	'
  	#!
" 	(#
$ "!'(/
I2 (( (r   rQ   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )_PositionTokeniy  c                 |   > [         [        U ]  5         U R                  R                  U l        SU l        SU l        g r  )r#  r  r   r  r   rT  r  r  r<  s    r   r   _PositionToken.__init__z  s1    nd,.NN++	""r   rB  r   r   r   r   r   r   r6  r7  s   @r   r  r  y  s    # #r   r  c                   <   ^  \ rS rSrSrU 4S jrS rSS jrSrU =r	$ )r2   i  zYToken to advance to a specific column of input text; useful for
tabular report scraping.
c                 6   > [         [        U ]  5         Xl        g r   )r#  r2   r   r]   )r   colnor  s     r   r   GoToColumn.__init__  s    j$(*r   c                 t   [        X!5      U R                   :w  a  [        U5      nU R                  (       a  U R                  X5      nX#:  al  X   R	                  5       (       aU  [        X!5      U R                   :w  a<  US-  nX#:  a2  X   R	                  5       (       a  [        X!5      U R                   :w  a  M<  U$ r  )r]   r   r  r  isspace)r   r^  r   r  s       r   r  GoToColumn.preParse  s    s)8}H**89.X]%:%:%<%<SASW[W_W_A_q .X]%:%:%<%<SASW[W_W_A_
r   c                     [        X!5      nX@R                   :  a  [        XSU 5      eX R                   -   U-
  nXU nXV4$ )NzText not in expected columnr]   rB   )r   r^  r   r  thiscolnewlocr   s          r   r  GoToColumn.parseImpl  sH    c$XX 0MtTTxx')F#{r   )r]   r  )
r   r   r   r   r	  r   r  r  r   r6  r7  s   @r   r2   r2     s     r   r2   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r6   i  ay  Matches if current position is at the beginning of a line within
the parse string

Example::

    test = '''\
    AAA this line
    AAA and this line
      AAA but not this one
    B AAA and definitely not this one
    '''

    for t in (LineStart() + 'AAA' + restOfLine).searchString(test):
        print(t)

prints::

    ['AAA', ' this line']
    ['AAA', ' and this line']

c                 8   > [         [        U ]  5         SU l        g )NzExpected start of line)r#  r6   r   r  r<  s    r   r   LineStart.__init__  s    i').r   c                 V    [        X!5      S:X  a  U/ 4$ [        XU R                  U 5      er  )r]   rB   r  r  s       r   r  LineStart.parseImpl  s+    s"7NXDKK>>r   r  r  rH  r7  s   @r   r6   r6     s    */? ?r   r6   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r5   i  zLMatches if current position is at the end of a line within the
parse string
c                    > [         [        U ]  5         U R                  [        R
                  R                  SS5      5        SU l        g )Nr  r   zExpected end of line)r#  r5   r   r  rG   r  r   r  r<  s    r   r   LineEnd.__init__  s9    gt%' A A I I$PR ST,r   c                     U[        U5      :  a&  X   S:X  a  US-   S4$ [        XU R                  U 5      eU[        U5      :X  a  US-   / 4$ [        XU R                  U 5      e)Nr  r   r   rB   r  r  s       r   r  LineEnd.parseImpl  sf    X}$Qw}$$XDKKFFCM!7B; TBBr   r  r  rH  r7  s   @r   r5   r5     s    -
	C 	Cr   r5   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )rM   i  zDMatches if current position is at the beginning of the parse
string
c                 8   > [         [        U ]  5         SU l        g )NzExpected start of text)r#  rM   r   r  r<  s    r   r   StringStart.__init__  s    k4)+.r   c                 n    US:w  a,  X R                  US5      :w  a  [        XU R                  U 5      eU/ 4$ rH  )r  rB   r  r  s       r   r  StringStart.parseImpl  s6    !8mmHa00$XDKKFFBwr   r  r  rH  r7  s   @r   rM   rM     s    / r   rM   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )rL   i  zBMatches if current position is at the end of the parse string
    c                 8   > [         [        U ]  5         SU l        g )NzExpected end of text)r#  rL   r   r  r<  s    r   r   StringEnd.__init__  s    i'),r   c                     U[        U5      :  a  [        XU R                  U 5      eU[        U5      :X  a  US-   / 4$ U[        U5      :  a  U/ 4$ [        XU R                  U 5      er  r!  r  s       r   r  StringEnd.parseImpl  sc    X TBBCM!7B;3x= 7N TBBr   r  r  rH  r7  s   @r   rL   rL     s    -C Cr   rL   c                   <   ^  \ rS rSrSr\4U 4S jjrSS jrSrU =r	$ )rT   i  a]  Matches if the current position is at the beginning of a Word,
and is not preceded by any character in a given set of
``wordChars`` (default= ``printables``). To emulate the
```` behavior of regular expressions, use
``WordStart(alphanums)``. ``WordStart`` will also match at
the beginning of the string being parsed, or at the beginning of
a line.
c                 X   > [         [        U ]  5         [        U5      U l        SU l        g )NzNot at the start of a word)r#  rT   r   r  	wordCharsr  r   r/  r  s     r   r   WordStart.__init__  s"    i')Y2r   c                     US:w  a>  XS-
     U R                   ;   d  X   U R                   ;  a  [        XU R                  U 5      eU/ 4$ rt  )r/  rB   r  r  s       r   r  WordStart.parseImpl  sF    !8q!T^^3}DNN:$XDKKFFBwr   )r  r/  r  
r   r   r   r   r	  rz   r   r  r   r6  r7  s   @r   rT   rT     s     ", 3
 r   rT   c                   <   ^  \ rS rSrSr\4U 4S jjrSS jrSrU =r	$ )rS   i  aG  Matches if the current position is at the end of a Word, and is
not followed by any character in a given set of ``wordChars``
(default= ``printables``). To emulate the ```` behavior of
regular expressions, use ``WordEnd(alphanums)``. ``WordEnd``
will also match at the end of the string being parsed, or at the end
of a line.
c                 f   > [         [        U ]  5         [        U5      U l        SU l        SU l        g )NFzNot at the end of a word)r#  rS   r   r  r/  r  r  r0  s     r   r   WordEnd.__init__
  s*    gt%'Y#0r   c                     [        U5      nUS:  aC  X$:  a>  X   U R                  ;   d  XS-
     U R                  ;  a  [        XU R                  U 5      eU/ 4$ rt  )r   r/  rB   r  )r   r^  r   r  r  s        r   r  WordEnd.parseImpl  sS    x=a<CN/1W%T^^;$XDKKFFBwr   )r  r  r/  r  r4  r7  s   @r   rS   rS     s     ", 1 r   rS   c                      ^  \ rS rSrSrSU 4S jjrS rS rU 4S jrU 4S jr	U 4S jr
SS	 jrU 4S
 jrSU 4S jjrSrU =r$ )rC   i  zUAbstract subclass of ParserElement, for combining and
post-processing parsed tokens.
c                   >^  [         [        T ]  U5        [        U[        5      (       a  [        U5      n[        U[        5      (       a  T R                  U5      /T l        O[        U[        5      (       a	  U/T l        Oe[        U[        5      (       a?  [        U5      n[        S U 5       5      (       a  U 4S jU 5       n[        U5      T l        O [        U5      T l        ST l        g ! [         a    U/T l         Nf = f)Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   rd  )r   r_  s     r   r   +ParseExpression.__init__.<locals>.<genexpr>)  s     BED:dJ//Er)  c              3   t   >#    U  H-  n[        U[        5      (       a  TR                  U5      OUv   M/     g 7fr   )r   rd  r  )r   r  r   s     r   r   r=  *  s1     hbg]^
1j8Q8Q11!4WXXbgs   58F)r#  rC   r   r   ra  r_  rd  r  exprsrG   r   r,  rf  r  r   r?  r  r  s   `  r   r   ParseExpression.__init__  s    ot-h7e^,,KEeZ((2259:DJ}--DJx((KEBEBBBhbgheDJ%!%[
 "  %#W
%s   C. .DDc                 J    U R                   R                  U5        S U l        U $ r   )r?  r  r  r  s     r   r  ParseExpression.append3  s     

% r   c                     SU l         U R                   Vs/ s H  oR                  5       PM     snU l        U R                   H  nUR                  5         M     U $ s  snf )zuExtends ``leaveWhitespace`` defined in base class, and also invokes ``leaveWhitespace`` on
all contained expressions.F)r  r?  r  r  )r   r  s     r   r  ParseExpression.leaveWhitespace8  sN     $(,

3
1ffh
3
A  4s   Ac                 d  > [        U[        5      (       aU  XR                  ;  aD  [        [        U ]  U5        U R                   H!  nUR                  U R                  S   5        M#     U $ [        [        U ]  U5        U R                   H!  nUR                  U R                  S   5        M#     U $ r  )r   rN   r  r#  rC   r  r?  )r   r  r  r  s      r   r  ParseExpression.ignoreA  s    eX&&,,,ot3E:AHHT--b12 $  /4/6ZZ))"-.  r   c                    >  [         [        U ]  5       $ ! [         a     Of = fU R                  c6  U R
                  R                  < S[        U R                  5      < S3U l        U R                  $ Nz:(r  )	r#  rC   r   rC  r  r  r   r   r?  r<  s    r   r   ParseExpression.__str__M  s_    	$799 		 <<(,(?(?tzzARSDL||r  c                   > [         [        U ]  5         U R                   H  nUR                  5         M     [	        U R                  5      S:X  Ga  U R                  S   n[        X R                  5      (       a  UR                  (       d  UR                  c{  UR                  (       dj  UR                  S S  U R                  S   /-   U l        S U l
        U =R                  UR                  -  sl        U =R                  UR                  -  sl        U R                  S   n[        X R                  5      (       a  UR                  (       d  UR                  cz  UR                  (       di  U R                  S S UR                  S S  -   U l        S U l
        U =R                  UR                  -  sl        U =R                  UR                  -  sl        S[        U 5      -   U l        U $ )Nr   r   r   r   r  )r#  rC   r[  r?  r   r   r  r  r  r  r  r  r  r   r  )r   r  r  r  s      r   r[  ParseExpression.streamlineW  sd   ot/1ALLN  tzz?aJJqME5..11!--))1!KK"[[^tzz!}o=
###u';';;#""u':'::"JJrNE5..11!--))1!KK!ZZ_u{{1~=
###u';';;#""u':'::"!E$K/r   c                     Ub  UO/ S S  U /-   nU R                    H  nUR                  U5        M     U R                  / 5        g r   )r?  r  r  )r   r  tmpr  s       r   r  ParseExpression.validatey  sA     - 9}r1ENAJJsO Br   c                    > [         [        U ]  5       nU R                   Vs/ s H  o"R                  5       PM     snUl        U$ s  snf r   )r#  rC   r  r?  )r   r   r  r  s      r   r  ParseExpression.copy  s:    OT/1'+zz2z!VVXz2	
 3s   Ac           
      V  > [         R                  (       a  U R                   Hq  n[        U[        5      (       d  M  UR
                  (       d  M-  [        R                  " SR                  SU[        U 5      R                  UR
                  5      SS9  Ms     [        [        U ]7  X5      $ )N]{0}: setting results name {1!r} on {2} expression collides with {3!r} on contained expressionr    r   r}  )r   r    r?  r   rG   r  r  r  r  r  r   r#  rC   r  r   rT  r  r  r  s       r   r  ParseExpression._setResultsName  s    ==ZZa//AMMMMM #PPVPV  XCW[W[\`WaWjWjWXWdWdQf ./0   _d;DQQr   )r  r  r?  r  r  r  r   )r   r   r   r   r	  r   r  r  r  r   r[  r  r  r  r   r6  r7  s   @r   rC   rC     s=    ",

 D 
R Rr   rC   c                   n   ^  \ rS rSrSr " S S\5      rSU 4S jjrU 4S jrSS jr	S r
S	 rS
 rSrU =r$ )r(   i  a  
Requires all given :class:`ParseExpression` s to be found in the given order.
Expressions may be separated by whitespace.
May be constructed using the ``'+'`` operator.
May also be constructed using the ``'-'`` operator, which will
suppress backtracking.

Example::

    integer = Word(nums)
    name_expr = OneOrMore(Word(alphas))

    expr = And([integer("id"), name_expr("name"), integer("age")])
    # more easily written as:
    expr = integer("id") + name_expr("name") + integer("age")
c                   (   ^  \ rS rSrU 4S jrSrU =r$ )And._ErrorStopi  c                 p   > [         [        R                  U ]  " U0 UD6  SU l        U R                  5         g )N-)r#  r(   r  r   rT  r  )r   r   r  r  s      r   r   And._ErrorStop.__init__  s.    #..$0$A&ADI  "r   rF  r
  r7  s   @r   r  rX    s    	# 	#r   r  c                 d  > [        U5      nU(       a  [        U;   a  / n[        U5       H}  u  pEU[        L a^  U[        U5      S-
  :  aA  [	        5       XS-      -   R
                  S   nUR                  [        U5      " S5      5        Ma  [        S5      eUR                  U5        M     X1S S & [        [        U ]/  X5        [        S U R
                   5       5      U l        U R                  U R
                  S   R                  5        U R
                  S   R                   U l        SU l        g )Nr   r   r  z0cannot construct And with sequence ending in ...c              3   8   #    U  H  oR                   v   M     g 7fr   r  r   r  s     r   r   And.__init__.<locals>.<genexpr>       !GJq"2"2Jr  r   T)r_  r  r  r   r/   r?  r  rK   rC  r#  r(   r   r  r  r  r  r  r  )r   r?  r  rN  r%  r_  
skipto_argr  s          r   r   And.__init__  s    UX&C$U+8#3u:>)&+g!e&<%C%CB%G


6*#5k#BC'(Z[[JJt$ , !Hc4!%2!!GDJJ!GG

1 8 89"jjm:: r   c                   > U R                   (       a  [        S U R                   S S  5       5      (       a  [        U R                   S S 5       H  u  pUc  M
  [        U[        5      (       d  M!  UR                   (       d  M4  [        UR                   S   [
        5      (       d  MX  UR                   S   U R                   US-      -   UR                   S'   S U R                   US-   '   M     U R                    Vs/ s H	  o"c  M  UPM     snU l         [        [        U ]#  5         [        S U R                    5       5      U l
        U $ s  snf )Nc              3      #    U  HL  n[        U[        5      =(       a0    UR                  =(       a    [        UR                  S    [        5      v   MN     g7fr   N)r   rC   r?  r  r_  s     r   r   !And.streamline.<locals>.<genexpr>  s@      -+q a1gaggg*QWWUW[ZfBgg+s   AAr   r   c              3   8   #    U  H  oR                   v   M     g 7fr   r^  r_  s     r   r   rg    ra  r  )r?  r,  r  r   rC   r  r#  r(   r[  r  r  )r   r%  r  r  s      r   r[  And.streamline  s    :: - JJsO- - -%djj"o6DAy "1o66 !Jqwwr{L,Q,Q&'ggbkDJJq1u4E&E,0

1q5) 7 *.EAaE
c4#%!!GDJJ!GG	 Fs   :EEc                 (   U R                   S   R                  XUSS9u  p$SnU R                   SS   Hy  n[        U[        R                  5      (       a  SnM&  U(       a   UR                  XU5      u  p'OUR                  XU5      u  p'U(       d  UR                  5       (       d  Mu  XG-  nM{     X$4$ ! [
         a    e [         a!  nS Ul        [
        R                  U5      eS nAf[         a"    [        U[        U5      U R                  U 5      ef = f)Nr   Frc  r   T)r?  r  r   r(   r  rF   r@   r  r   rg  r   r  r  )	r   r^  r   r  
resultlist	errorStopr  
exprtokensr   s	            r   r  And.parseImpl  s    **Q-..xiV[.\	ABA!S^^,, 	[&'hhxi&HOC #$((8)"DZ//11(
#  $  , ) C'+B$.>>rBB! [.xXUYZZ[s    B22DC""/Dc                 p    [        U[        5      (       a  U R                  U5      nU R                  U5      $ r   r   rd  r  r  r  s     r   r  And.__iadd__  .    eZ((,,U3E{{5!!r   c                     US S  U /-   nU R                    H'  nUR                  U5        UR                  (       a  M'    g    g r   )r?  r  r  r   r7  subRecCheckListr  s       r   r  And.checkRecursion  s>    *1-6A_-### r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )NrT  {r  c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r_  s     r   r   And.__str__.<locals>.<genexpr>  s     )GJq%((Jr  }r  rT  r  r   r?  r   s    r   r   And.__str__  sQ    4  99<<)GDJJ)G!GG#MDL||r   )r  r?  r  r  r  r  )r   r   r   r   r	  r/   r  r   r[  r  r  r  r   r   r6  r7  s   @r   r(   r(     s7    "#U #!($2"
 r   r(   c                   h   ^  \ rS rSrSrSU 4S jjrU 4S jrSS jrS rS r	S r
SU 4S	 jjrS
rU =r$ )r?   i  a  Requires that at least one :class:`ParseExpression` is found. If
two expressions match, the expression that matches the longest
string will be used. May be constructed using the ``'^'``
operator.

Example::

    # construct Or using '^' operator

    number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums))
    print(number.searchString("123 3.1416 789"))

prints::

    [['123'], ['3.1416'], ['789']]
c                    > [         [        U ]  X5        U R                  (       a"  [	        S U R                   5       5      U l        g SU l        g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r^  r_  s     r   r   Or.__init__.<locals>.<genexpr>       %K
1&6&6
r  T)r#  r?   r   r?  r,  r  r@  s      r   r   Or.__init__  s8    b$ 1::"%%K

%K"KD"&Dr   c                    > [         [        U ]  5         [        R                  (       a!  [        S U R                   5       5      U l        U $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r  r_  s     r   r    Or.streamline.<locals>.<genexpr>       !C
1,,
r  )r#  r?   r[  r'   collect_all_And_tokensr,  r?  r  r<  s    r   r[  Or.streamline  s4    b$"$,,!!C

!CCDOr   c                    SnS n/ nU R                    H'  n UR                  X5      nUR                  X45        M)     U(       a  UR                  [        S5      SS9  U(       d  US   S   n
U
R                  XU5      $ SnU H=  u  pXS   ::  a  Us  $  UR                  XU5      u  pX:  a  X4s  $ XS   :  a  X4nM=  M?     US:w  a  U$ Ub  U R                  Ul        Ue[        XSU 5      e! [         a8  n	S U	l        U	R
                  U:  a  U	nU	R
                  n S n	A	GM   S n	A	GM  S n	A	f[         aD    [        U5      U:  a0  [        U[        U5      UR                  U 5      n[        U5      n GMe   GMi  f = f! [         a8  n	S U	l        U	R
                  U:  a  U	nU	R
                  n S n	A	GM3   S n	A	GM:  S n	A	ff = f)Nr   r   T)r  rw  r   rf   no defined alternatives to match)r?  r  r  rB   r  r   rg  r   r  sortr   r  r   )r   r^  r   r  	maxExcLocmaxExceptionrh  r  loc2r  	best_exprlongestloc1expr1rd  s                  r   r  Or.parseImpl  s   	A*zz(0 y)    LLZ]DL9 $AJqM	 ''yAAG&1:%"N-!&hY!GJD |#z)
*"&* +!  '& *$##{{L 0RTXYYg " ($(!77Y&#&L #I '  .x=9,#1(CM188UY#ZL #HI -.6 & ,(,C%ww*'*$'GG	 +,s6   C/F /
E=9%D,,AE=<E= 
G
%F==Gc                 p    [        U[        5      (       a  U R                  U5      nU R                  U5      $ r   rp  r  s     r   __ixor__Or.__ixor__Z  rr  r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )NrT  rx  z ^ c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r_  s     r   r   Or.__str__.<locals>.<genexpr>d       +IjE!HHjr  r{  r|  r   s    r   r   
Or.__str___  Q    4  99<<+Idjj+I!IICODL||r   c                 ^    US S  U /-   nU R                    H  nUR                  U5        M     g r   r?  r  rt  s       r   r  Or.checkRecursionh  /    *1-6A_- r   c           	      2  > [         R                  (       do  [        R                  (       aZ  [	        S U R
                   5       5      (       a9  [        R                  " SR                  SU[        U 5      R                  5      SS9  [        [        U ]7  X5      $ )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r   r(   r_  s     r   r   %Or._setResultsName.<locals>.<genexpr>p       :z!:a%%zr)  {0}: setting results name {1!r} on {2} expression may only return a single token for an And alternative, in future will return the full list of tokensr   r   r}  )r'   r  r   r   r,  r?  r  r  r  r  r   r#  r?   r  r   rT  r  r  s      r   r  Or._setResultsNamem  sp    11FF:tzz::: NNTf?tDzGZGZO\ 	" R.tDDr   r  r  r  r  r  )r   r   r   r   r	  r   r[  r  r  r   r  r  r   r6  r7  s   @r   r?   r?     s4     ':Zz"
.

E 
Er   r?   c                   h   ^  \ rS rSrSrSU 4S jjrU 4S jrSS jrS rS r	S r
SU 4S	 jjrS
rU =r$ )r9   iz  a  Requires that at least one :class:`ParseExpression` is found. If
two expressions match, the first one listed is the one that will
match. May be constructed using the ``'|'`` operator.

Example::

    # construct MatchFirst using '|' operator

    # watch the order of expressions to match
    number = Word(nums) | Combine(Word(nums) + '.' + Word(nums))
    print(number.searchString("123 3.1416 789")) #  Fail! -> [['123'], ['3'], ['1416'], ['789']]

    # put more selective expression first
    number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums)
    print(number.searchString("123 3.1416 789")) #  Better -> [['123'], ['3.1416'], ['789']]
c                    > [         [        U ]  X5        U R                  (       a"  [	        S U R                   5       5      U l        g SU l        g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r^  r_  s     r   r   &MatchFirst.__init__.<locals>.<genexpr>  r  r  T)r#  r9   r   r?  r,  r  r@  s      r   r   MatchFirst.__init__  s8    j$(9::"%%K

%K"KD"&Dr   c                    > [         [        U ]  5         [        R                  (       a!  [        S U R                   5       5      U l        U $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r  r_  s     r   r   (MatchFirst.streamline.<locals>.<genexpr>  r  r  )r#  r9   r[  r'   r  r,  r?  r  r<  s    r   r[  MatchFirst.streamline  s4    j$*,,,!!C

!CCDOr   c                    SnS nU R                    H  n UR                  XU5      nUs  $    Ub  U R                  Ul        Ue[        XSU 5      e! [         a/  nUR                  U:  a  UnUR                  n S nAMm   S nAMs  S nAf[         aB    [        U5      U:  a/  [        U[        U5      UR                  U 5      n[        U5      n M   M  f = f)Nr   r  )r?  r  rB   r   rg  r   r  r   )	r   r^  r   r  r  r  r  r   r  s	            r   r  MatchFirst.parseImpl  s    	A
.hhxi8
  '#';; ""$X4VX\]] " (77Y&#&L #I '  .x=9,#1(CM188UY#ZL #HI -.s   A
CBACCc                 p    [        U[        5      (       a  U R                  U5      nU R                  U5      $ r   rp  r  s     r   __ior__MatchFirst.__ior__  rr  r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )NrT  rx   | c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r_  s     r   r   %MatchFirst.__str__.<locals>.<genexpr>  r  r  r{  r|  r   s    r   r   MatchFirst.__str__  r  r   c                 ^    US S  U /-   nU R                    H  nUR                  U5        M     g r   r  rt  s       r   r  MatchFirst.checkRecursion  r  r   c           	      2  > [         R                  (       do  [        R                  (       aZ  [	        S U R
                   5       5      (       a9  [        R                  " SR                  SU[        U 5      R                  5      SS9  [        [        U ]7  X5      $ )Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r  r_  s     r   r   -MatchFirst._setResultsName.<locals>.<genexpr>  r  r)  r  r   r   r}  )r'   r  r   r   r,  r?  r  r  r  r  r   r#  r9   r  r  s      r   r  MatchFirst._setResultsName  sp    11FF:tzz::: NNTf?tDzGZGZO\ 	" Z6tLLr   r  r  r  )r   r   r   r   r	  r   r[  r  r  r   r  r  r   r6  r7  s   @r   r9   r9   z  s3     '^0"
.

M 
Mr   r9   c                   R   ^  \ rS rSrSrS	U 4S jjrU 4S jrS	S jrS rS r	Sr
U =r$ )
r.   i  a  Requires all given :class:`ParseExpression` s to be found, but in
any order. Expressions may be separated by whitespace.

May be constructed using the ``'&'`` operator.

Example::

    color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN")
    shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON")
    integer = Word(nums)
    shape_attr = "shape:" + shape_type("shape")
    posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn")
    color_attr = "color:" + color("color")
    size_attr = "size:" + integer("size")

    # use Each (using operator '&') to accept attributes in any order
    # (shape and posn are required, color and size are optional)
    shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr)

    shape_spec.runTests('''
        shape: SQUARE color: BLACK posn: 100, 120
        shape: CIRCLE size: 50 color: BLUE posn: 50,80
        color:GREEN size:20 shape:TRIANGLE posn:20,40
        '''
        )

prints::

    shape: SQUARE color: BLACK posn: 100, 120
    ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']]
    - color: BLACK
    - posn: ['100', ',', '120']
      - x: 100
      - y: 120
    - shape: SQUARE


    shape: CIRCLE size: 50 color: BLUE posn: 50,80
    ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']]
    - color: BLUE
    - posn: ['50', ',', '80']
      - x: 50
      - y: 80
    - shape: CIRCLE
    - size: 50


    color: GREEN size: 20 shape: TRIANGLE posn: 20,40
    ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']]
    - color: GREEN
    - posn: ['20', ',', '40']
      - x: 20
      - y: 40
    - shape: TRIANGLE
    - size: 20
c                    > [         [        U ]  X5        [        S U R                   5       5      U l        SU l        SU l        SU l        g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r^  r_  s     r   r    Each.__init__.<locals>.<genexpr>  ra  r  T)	r#  r.   r   r  r?  r  r  initExprGroupsr  r@  s      r   r   Each.__init__	  s@    dD"53!!GDJJ!GG""r   c                 n   > [         [        U ]  5         [        S U R                   5       5      U l        U $ )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r^  r_  s     r   r   "Each.streamline.<locals>.<genexpr>  ra  r  )r#  r.   r[  r  r?  r  r<  s    r   r[  Each.streamline  s,    dD$&!!GDJJ!GGr   c           	      F   U R                   (       Ga  [        S U R                   5       5      U l        U R                   Vs/ s H&  n[	        U[
        5      (       d  M  UR                  PM(     nnU R                   Vs/ s H4  oDR                  (       d  M  [	        U[
        [        45      (       a  M2  UPM6     nnXV-   U l	        U R                   Vs/ s H&  n[	        U[        5      (       d  M  UR                  PM(     snU l        U R                   Vs/ s H&  n[	        U[        5      (       d  M  UR                  PM(     snU l        U R                   Vs/ s H'  n[	        U[
        [        [        45      (       a  M%  UPM)     snU l        U =R                  U R                  -  sl        SU l         UnU R                  S S  nU R                  S S  n	/ n
SnU(       a  X-   U R                  -   U R                  -   n/ nU Hy  n UR                  X5      nU
R!                  U R                  R#                  [%        U5      U5      5        XH;   a  UR'                  U5        Ma  XI;   a  U	R'                  U5        My  M{     [+        U5      [+        U5      :X  a  SnU(       a  M  U(       a'  SR-                  S U 5       5      n[)        XSU-  5      eXR                   Vs/ s H.  n[	        U[
        5      (       d  M  UR                  U	;   d  M,  UPM0     sn-  n
/ nU
 H)  nUR/                  XU5      u  nnUR!                  U5        M+     [1        U[3        / 5      5      nUU4$ s  snf s  snf s  snf s  snf s  snf ! [(         a    UR!                  U5         GM  f = fs  snf )Nc              3   ~   #    U  H3  n[        U[        5      (       d  M  [        UR                  5      U4v   M5     g 7fr   )r   r>   r  r_  r_  s     r   r   !Each.parseImpl.<locals>.<genexpr>  s)     _AzRSU]G^AFFQs   ==FTr  c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r_  s     r   r   r  8  s     :'Qa'r  z*Missing one or more required elements (%s))r  rb  r?  opt1mapr   r>   r_  r  rJ   	optionalsrU   multioptionalsr<   multirequiredrequiredr  r  r  r  removerB   r   r   r  sumrE   )r   r^  r   r  r  opt1opt2tmpLoctmpReqdtmpOpt
matchOrderkeepMatchingtmpExprsfailedmissingrk  r  finalResultss                     r   r  Each.parseImpl  s   ___DL$(JJJJq*Q2IFAFFJDJ#zzgz!-=-=AjQRU]_dTeFfAzDg![DN37::"[:aAzAZ6166:"[D26**!Y*Q
1i@X&!&&*!YD(,

k
1*QS]_hHi:jQ
kDMMMT///M"'D--"..#
'$*=*==@R@RRHF	)ZZ9F %%dll&6&6r!ua&@A|q)a( %  6{c(m+$ l" ii:'::G 0\_f0fgg 	**]*Q
1h0GqAFFV\L\q*]]

A88H9=LCg&  :|B'78L  Y Kg"[!Yk & %MM!$$%  ^sf   M"M"?M'M'4M'M,0M,M13M1$M6M6M;N;NN;NNc                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )NrT  rx  z & c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r_  s     r   r   Each.__str__.<locals>.<genexpr>K  r  r  r{  r|  r   s    r   r   Each.__str__F  r  r   c                 ^    US S  U /-   nU R                    H  nUR                  U5        M     g r   r  rt  s       r   r  Each.checkRecursionO  r  r   )
r  r  r  r  r  r  r  r  r  r  r  )r   r   r   r   r	  r   r[  r  r   r  r   r6  r7  s   @r   r.   r.     s(    7p
/!b. .r   r.   c                   t   ^  \ rS rSrSrSU 4S jjrSS jrS rU 4S jrU 4S jr	S r
SS	 jrU 4S
 jrSrU =r$ )rA   iU  z^Abstract subclass of :class:`ParserElement`, for combining and
post-processing parsed tokens.
c                 8  > [         [        U ]  U5        [        U[        5      (       aK  [        U R                  [        5      (       a  U R                  U5      nOU R                  [        U5      5      nXl	        S U l
        Ub  UR                  U l        UR                  U l        U R                  UR                  5        UR                  U l        UR                   U l        UR"                  U l        U R$                  R'                  UR$                  5        g g r   )r#  rA   r   r   rd  
issubclassr  rO   r7   r_  r  r  r  r  r  r  r  r  r  r  r   r_  r  r  s      r   r   ParseElementEnhance.__init__Y  s    !41(;dJ''$22E:://5//>	!%!3!3D"&"5"5D##DOO4"&"5"5D"ooDO $ 1 1D##D$4$45 r   c                     U R                   b  U R                   R                  XUSS9$ [        SX R                  U 5      e)NFrc  r   )r_  r  rB   r  r  s       r   r  ParseElementEnhance.parseImplk  s;    99 99##H95#QQ S++t<<r   c                     SU l         U R                  R                  5       U l        U R                  b  U R                  R                  5         U $ rA  )r  r_  r  r  r   s    r   r  #ParseElementEnhance.leaveWhitespaceq  s;    #IINN$	99 II%%'r   c                 t  > [        U[        5      (       aY  XR                  ;  aH  [        [        U ]  U5        U R                  b(  U R                  R                  U R                  S   5        U $ [        [        U ]  U5        U R                  b(  U R                  R                  U R                  S   5        U $ r  )r   rN   r  r#  rA   r  r_  r   r  r  s     r   r  ParseElementEnhance.ignorex  s    eX&&,,,)47>99(II$$T%5%5b%9:
  %t3E:yy$		  !1!1"!56r   c                 z   > [         [        U ]  5         U R                  b  U R                  R                  5         U $ r   )r#  rA   r[  r_  r<  s    r   r[  ParseElementEnhance.streamline  s0    !43599 II  "r   c                     X;   a  [        X/-   5      eUS S  U /-   nU R                  b  U R                  R                  U5        g g r   )rI   r_  r  )r   r7  ru  s      r   r  "ParseElementEnhance.checkRecursion  sK    #+,<v,EFF*1-699 II$$_5 !r   c                     Uc  / nUS S  U /-   nU R                   b  U R                   R                  U5        U R                  / 5        g r   r_  r  r  r   r  rN  s      r   r  ParseElementEnhance.validate  sH     MA$'99 IIs#Br   c                   >  [         [        U ]  5       $ ! [         a     Of = fU R                  cC  U R
                  b6  U R                  R                  < S[        U R
                  5      < S3U l        U R                  $ rI  )	r#  rA   r   rC  r  r_  r  r   r   r<  s    r   r   ParseElementEnhance.__str__  si    	,d;== 		 <<DII$9(,(?(?tyyAQRDL||r  )r  r_  r  r  r  r  r  r  r  r   )r   r   r   r   r	  r   r  r  r  r[  r  r  r   r   r6  r7  s   @r   rA   rA   U  s5    6$=
6  r   rA   c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )r0   i  a&  Lookahead matching of the given parse expression.
``FollowedBy`` does *not* advance the parsing position within
the input string, it only verifies that the specified parse
expression matches at the current position.  ``FollowedBy``
always returns a null token list. If any results names are defined
in the lookahead expression, those *will* be returned for access by
name.

Example::

    # use FollowedBy to match a label only if it is followed by a ':'
    data_word = Word(alphas)
    label = data_word + FollowedBy(':')
    attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))

    OneOrMore(attr_expr).parseString("shape: SQUARE color: BLACK posn: upper left").pprint()

prints::

    [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']]
c                 :   > [         [        U ]  U5        SU l        g r   )r#  r0   r   r  r   r_  r  s     r   r   FollowedBy.__init__  s    j$(."r   c                 J    U R                   R                  XUS9u  pEUS S 2	 X%4$ )Nr  )r_  r  )r   r^  r   r  _r   s         r   r  FollowedBy.parseImpl  s-     !!(9!EFxr   r^  r  rH  r7  s   @r   r0   r0     s    *# r   r0   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )r8   i  a   Lookbehind matching of the given parse expression.
``PrecededBy`` does not advance the parsing position within the
input string, it only verifies that the specified parse expression
matches prior to the current position.  ``PrecededBy`` always
returns a null token list, but if a results name is defined on the
given expression, it is returned.

Parameters:

 - expr - expression that must match prior to the current parse
   location
 - retreat - (default= ``None``) - (int) maximum number of characters
   to lookbehind prior to the current parse location

If the lookbehind expression is a string, Literal, Keyword, or
a Word or CharsNotIn with a specified exact or maximum length, then
the retreat parameter is not required. Otherwise, retreat must be
specified to give a maximum number of characters to look back from
the current parse position for a lookbehind match.

Example::

    # VB-style variable names with type prefixes
    int_var = PrecededBy("#") + pyparsing_common.identifier
    str_var = PrecededBy("$") + pyparsing_common.identifier

c                   > [         [        U ]  U5        U R                  5       R	                  5       U l        SU l        SU l        SU l        [        U[        5      (       a  [        U5      nSU l        O[        U[        [        45      (       a  UR                  nSU l        Oa[        U[        [        45      (       a(  UR                   ["        :w  a  UR                   nSU l        O[        U[$        5      (       a	  SnSU l        X l        S[        U5      -   U l        SU l        U R,                  R/                  S 5        g )NTFr   znot preceded by c                 8    UR                  [        S S 5      5      $ r   )r  rj  r   r   r   s      r   r   %PrecededBy.__init__.<locals>.<lambda>  s    eD$>O0Pr   )r#  r8   r   r_  r  r  r  r  r   r   r   r7   r4   rM  rR   r+   r  r  r  retreatr  r  r  r  )r   r_  r  r  s      r   r   PrecededBy.__init__  s    j$(.IIK//1	""
dC  $iGDJw011mmGDJtZ011dkkX6MkkGDJn--GDJ(3t94# PQr   c                 0   U R                   (       aS  X R                  :  a  [        XU R                  5      eX R                  -
  nU R                  R                  X5      u  pVX&4$ U R                  [        5       -   nU[        SX R                  -
  5      U n[        XU R                  5      n	[        S[        X R                  S-   5      S-   5       H&  n
 UR                  U[        U5      U
-
  5      u  pV  X&4$    U	e! [         a  nUn	 S nAM>  S nAff = frt  )r  r  rB   r  r_  r  rL   r  ru  r  r   r@   )r   r^  r   r  r|  r  r   	test_exprinstring_slice	last_exprr  pbes               r   r  PrecededBy.parseImpl  s    ::\\!$XDKK@@,,&EYY%%h6FA  x 		IK/I%c!S<<-?&@EN&xdkkBI3sLL1,<#=a#?@&--nc.>QTZ>Z[FA  x A   * $ #I$s    C>>
DDD)r  r  r_  r  r  r  r  r   )r   TrH  r7  s   @r   r8   r8     s    6R. r   r8   c                   <   ^  \ rS rSrSrU 4S jrSS jrS rSrU =r	$ )r;   i  ay  Lookahead to disallow matching with the given parse expression.
``NotAny`` does *not* advance the parsing position within the
input string, it only verifies that the specified parse expression
does *not* match at the current position.  Also, ``NotAny`` does
*not* skip over leading whitespace. ``NotAny`` always returns
a null token list.  May be constructed using the '~' operator.

Example::

    AND, OR, NOT = map(CaselessKeyword, "AND OR NOT".split())

    # take care not to mistake keywords for identifiers
    ident = ~(AND | OR | NOT) + Word(alphas)
    boolean_term = Optional(NOT) + ident

    # very crude boolean expression - to support parenthesis groups and
    # operation hierarchy, use infixNotation
    boolean_expr = boolean_term + ZeroOrMore((AND | OR) + boolean_term)

    # integers that are followed by "." are actually floats
    integer = Word(nums) + ~Char(".")
c                    > [         [        U ]  U5        SU l        SU l        S[        U R                  5      -   U l        g )NFTzFound unwanted token, )r#  r;   r   r  r  r   r_  r  r  s     r   r   NotAny.__init__)  s7    fd$T*#".tyy1AAr   c                 x    U R                   R                  X5      (       a  [        XU R                  U 5      eU/ 4$ r   )r_  r  rB   r  r  s       r   r  NotAny.parseImpl0  s3    99!!(00 TBBBwr   c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )NrT  z~{r{  r  rT  r  r   r_  r   s    r   r   NotAny.__str__5  sG    4  99<<%		"22S8DL||r   )r  r  r  r  r  r  r7  s   @r   r;   r;     s    ,B
 r   r;   c                   L   ^  \ rS rSrSU 4S jjrS rSS jrS	U 4S jjrSrU =r	$ )
_MultipleMatchi>  c                    > [         [        U ]  U5        SU l        Un[	        U[
        5      (       a  U R                  U5      nU R                  U5        g r   )r#  r  r   r  r   rd  r  stopOn)r   r_  r!  enderr  s       r   r   _MultipleMatch.__init__?  sG    nd,T2eZ((,,U3EEr   c                 z    [        U[        5      (       a  U R                  U5      nUb
  U) U l        U $ S U l        U $ r   )r   rd  r  	not_ender)r   r"  s     r   r!  _MultipleMatch.stopOnG  s@    eZ((,,U3E#(#4% ;?r   c                    U R                   R                  nU R                  nU R                  S LnU(       a  U R                  R                  nU(       a  W" X5        U" XUSS9u  p( U R
                  (       n	 U(       a  W" X5        U	(       a	  U" X5      n
OUn
U" XU5      u  p+U(       d  UR                  5       (       a  X-  nMN  ! [        [        4 a     X(4$ f = fNFrc  )	r_  r  r  r%  r  r  r  rB   rg  )r   r^  r   r  self_expr_parseself_skip_ignorablescheck_endertry_not_enderr  hasIgnoreExprsr  	tmptokenss               r   r  _MultipleMatch.parseImplM  s    ))**#33nnD0 NN33M ((%hYUS	&*&6&6"6N!(0!1(@F F!09!M	 1 1 3 3'F  
+ 	{	s   (AC CCc           
        > [         R                  (       a  U R                  /[        U R                  S/ 5      -    Hq  n[	        U[
        5      (       d  M  UR                  (       d  M-  [        R                  " SR                  SU[        U 5      R                  UR                  5      SS9  Ms     [        [        U ];  X5      $ )Nr?  rS  r    r   r}  )r   r    r_  r  r   rG   r  r  r  r  r  r   r#  r  r  rT  s       r   r  _MultipleMatch._setResultsNamej  s    ==ii[7499gr#BBa//AMMMMM #PPVPV  XCW[W[\`WaWjWjWXWdWdQf ./0 C ^T:4PPr   )r%  r  r   r  r  )
r   r   r   r   r   r!  r  r  r   r6  r7  s   @r   r  r  >  s    :Q Qr   r  c                       \ rS rSrSrS rSrg)r<   ix  a&  Repetition of one or more of the given expression.

Parameters:
 - expr - expression that must match one or more times
 - stopOn - (default= ``None``) - expression for a terminating sentinel
      (only required if the sentinel would ordinarily match the repetition
      expression)

Example::

    data_word = Word(alphas)
    label = data_word + FollowedBy(':')
    attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))

    text = "shape: SQUARE posn: upper left color: BLACK"
    OneOrMore(attr_expr).parseString(text).pprint()  # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]

    # use stopOn attribute for OneOrMore to avoid reading label string as part of the data
    attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
    OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']]

    # could also be written as
    (attr_expr * (1,)).parseString(text).pprint()
c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )NrT  rx  z}...r  r   s    r   r   OneOrMore.__str__  G    4  99<<tyy!11F:DL||r   r1  N)r   r   r   r   r	  r   r   r   r   r   r<   r<   x  s    2r   r<   c                   F   ^  \ rS rSrSrSU 4S jjrSU 4S jjrS rSrU =r	$ )	rU   i  aO  Optional repetition of zero or more of the given expression.

Parameters:
 - expr - expression that must match zero or more times
 - stopOn - (default= ``None``) - expression for a terminating sentinel
      (only required if the sentinel would ordinarily match the repetition
      expression)

Example: similar to :class:`OneOrMore`
c                 6   > [         [        U ]  XS9  SU l        g )Nr!  T)r#  rU   r   r  )r   r_  r!  r  s      r   r   ZeroOrMore.__init__  s    j$((="r   c                 b   >  [         [        U ]  XU5      $ ! [        [        4 a    U/ 4s $ f = fr   )r#  rU   r  rB   rg  )r   r^  r   r  r  s       r   r  ZeroOrMore.parseImpl  s9    	T4XINN
+ 	7N	s    ..c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )NrT  r  ]...r  r   s    r   r   ZeroOrMore.__str__  r5  r   )r  r  r   r  r  r7  s   @r   rU   rU     s    	# r   rU   c                   $    \ rS rSrS r\rS rSrg)
_NullTokeni  c                     grA  r   r   s    r   r  _NullToken.__bool__  s    r   c                     gr   r   r   s    r   r   _NullToken.__str__  s    r   r   N)r   r   r   r   r  rR  r   r   r   r   r   r@  r@    s    Kr   r@  c                   P   ^  \ rS rSrSr\" 5       r\4U 4S jjrSS jrS r	Sr
U =r$ )r>   i  a  Optional matching of the given expression.

Parameters:
 - expr - expression that must match zero or more times
 - default (optional) - value to be returned if the optional expression is not found.

Example::

    # US postal code can be a 5-digit zip, plus optional 4-digit qualifier
    zip = Combine(Word(nums, exact=5) + Optional('-' + Word(nums, exact=4)))
    zip.runTests('''
        # traditional ZIP code
        12345

        # ZIP+4 form
        12101-0001

        # invalid ZIP
        98765-
        ''')

prints::

    # traditional ZIP code
    12345
    ['12345']

    # ZIP+4 form
    12101-0001
    ['12101-0001']

    # invalid ZIP
    98765-
         ^
    FAIL: Expected end of text (at char 5), (line:1, col:6)
c                 z   > [         [        U ]  USS9  U R                  R                  U l        X l        SU l        g )NFr;  T)r#  r>   r   r_  r  r  r  )r   r_  r  r  s      r   r   Optional.__init__  s6    h&te&<))..#"r   c                 t    U R                   R                  XUSS9u  p$X$4$ ! [        [        4 a    U R                  U R
                  Lae  U R                   R                  (       a9  [        U R                  /5      nU R                  X@R                   R                  '   OU R                  /n X$4$ / n X$4$ f = fr(  )r_  r  rB   rg  r  _Optional__optionalNotMatchedr  rE   )r   r^  r   r  r  s        r   r  Optional.parseImpl  s    
	))**8)RW*XKC { 
+ 	  (A(AA99(()4+<+<*=>F484E4EF99001"//0F { {	s   " B
B70B76B7c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )NrT  r  r  r  r   s    r   r   Optional.__str__  sG    4  99<<tyy!11C7DL||r   )r  r  r  r  r  )r   r   r   r   r	  r@  rI  r   r  r   r   r6  r7  s   @r   r>   r>     s*    #H &<%9 # r   r>   c                   :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )rK   i  a4	  Token for skipping over all undefined text until the matched
expression is found.

Parameters:
 - expr - target expression marking the end of the data to be skipped
 - include - (default= ``False``) if True, the target expression is also parsed
      (the skipped text and target expression are returned as a 2-element list).
 - ignore - (default= ``None``) used to define grammars (typically quoted strings and
      comments) that might contain false matches to the target expression
 - failOn - (default= ``None``) define expressions that are not allowed to be
      included in the skipped test; if found before the target expression is found,
      the SkipTo is not a match

Example::

    report = '''
        Outstanding Issues Report - 1 Jan 2000

           # | Severity | Description                               |  Days Open
        -----+----------+-------------------------------------------+-----------
         101 | Critical | Intermittent system crash                 |          6
          94 | Cosmetic | Spelling error on Login ('log|n')         |         14
          79 | Minor    | System slow when running too many reports |         47
        '''
    integer = Word(nums)
    SEP = Suppress('|')
    # use SkipTo to simply match everything up until the next SEP
    # - ignore quoted strings, so that a '|' character inside a quoted string does not match
    # - parse action will call token.strip() for each matched token, i.e., the description body
    string_data = SkipTo(SEP, ignore=quotedString)
    string_data.setParseAction(tokenMap(str.strip))
    ticket_expr = (integer("issue_num") + SEP
                  + string_data("sev") + SEP
                  + string_data("desc") + SEP
                  + integer("days_open"))

    for tkt in ticket_expr.searchString(report):
        print tkt.dump()

prints::

    ['101', 'Critical', 'Intermittent system crash', '6']
    - days_open: 6
    - desc: Intermittent system crash
    - issue_num: 101
    - sev: Critical
    ['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14']
    - days_open: 14
    - desc: Spelling error on Login ('log|n')
    - issue_num: 94
    - sev: Cosmetic
    ['79', 'Minor', 'System slow when running too many reports', '47']
    - days_open: 47
    - desc: System slow when running too many reports
    - issue_num: 79
    - sev: Minor
c                   > [         [        U ]  U5        X0l        SU l        SU l        X l        SU l        [        U[        5      (       a  U R                  U5      U l        OX@l        S[        U R                  5      -   U l        g )NTFzNo match found for )r#  rK   r   
ignoreExprr  r  includeMatchr  r   rd  r  failOnr   r_  r  )r   r  includer  rQ  r  s        r   r   SkipTo.__init__?  sm    fd$U+ ""#fj))226:DK K+eDII.>>r   c                 R   Un[        U5      nU R                  nU R                  R                  nU R                  b  U R                  R                  OS nU R
                  b  U R
                  R                  OS n	Un
X::  a*  Ub  U" X5      (       a  O0U	b    U	" X5      n
M   U" XSSS9  O[        XU R                  U 5      eU
nXU n[        U5      nU R                  (       a  U" XUSS9u  p-X-  nX,4$ ! [         a     Ma  f = f! [        [        4 a    U
S-  n
 Of = fX::  a  M  N~)Nr   F)r  r  rc  )r   r_  r  rQ  r  rO  r  r@   rB   rg  r  rE   rP  )r   r^  r   r  rb  r  r_  
expr_parseself_failOn_canParseNextself_ignoreExpr_tryParsetmplocskiptext
skipresultr  s                 r   r  SkipTo.parseImplL  sE   x=yyYY%%
?C{{?V4;;#;#;\` ?C?Z4??#;#;`d  '3+H=='3!9(!K 8u5Q  !TBB S)!(+
!(OHCJ3 . 
 #J/ !!  s$   C5 "D 5
DDDD)r  rQ  rO  rP  r  r  r  )FNNr  rH  r7  s   @r   rK   rK     s    8r?- -r   rK   c                   t   ^  \ rS rSrSrSU 4S jjrS rS rS rS r	SS jr
S	 rU 4S
 jrSU 4S jjrSrU =r$ )r1   i{  a  Forward declaration of an expression to be defined later -
used for recursive grammars, such as algebraic infix notation.
When the expression is known, it is assigned to the ``Forward``
variable using the '<<' operator.

Note: take care when assigning to ``Forward`` not to overlook
precedence of operators.

Specifically, '|' has a lower precedence than '<<', so that::

    fwdExpr << a | b | c

will actually be evaluated as::

    (fwdExpr << a) | b | c

thereby leaving b and c out as parseable alternatives.  It is recommended that you
explicitly group the values inserted into the ``Forward``::

    fwdExpr << (a | b | c)

Converting to use the '<<=' operator instead will avoid this problem.

See :class:`ParseResults.pprint` for an example of a recursive
parser created using ``Forward``.
c                 *   > [         [        U ]  USS9  g r:  )r#  r1   r   r  s     r   r   Forward.__init__  s    gt%ee%<r   c                    [        U[        5      (       a  U R                  U5      nXl        S U l        U R                  R
                  U l        U R                  R                  U l        U R                  U R                  R                  5        U R                  R                  U l	        U R                  R                  U l
        U R                  R                  U R                  R                  5        U $ r   )r   rd  r  r_  r  r  r  r  r  r  r  r  r  r  s     r   
__lshift__Forward.__lshift__  s    eZ((,,U3E	!YY44"ii66		 4 45"ii66))..		 5 56r   c                 
    X-  $ r   r   r  s     r   __ilshift__Forward.__ilshift__  r  r   c                     SU l         U $ rA  r  r   s    r   r  Forward.leaveWhitespace  s    #r   c                     U R                   (       d.  SU l         U R                  b  U R                  R                  5         U $ r   )r  r_  r[  r   s    r   r[  Forward.streamline  s2    #Dyy$		$$&r   c                     Uc  / nX;  a1  US S  U /-   nU R                   b  U R                   R                  U5        U R                  / 5        g r   r  r  s      r   r  Forward.validate  sN     M$"dV+Cyy$		""3'Br   c                 x   [        U S5      (       a  U R                  $ U R                  b  U R                  $ SU l        Sn U R                  b  [	        U R                  5      S S nOSnU R
                  R                  S-   U-   U l        U R                  $ ! U R
                  R                  S-   U-   U l        f = f)NrT  z: ...r"  i  Noner#  )r  rT  r  r_  r   r  r   )r   	retStrings     r   r   Forward.__str__  s    4  99<<#<<  		Fyy$!$)),Ud3	"	>>22T9IEDL||  >>22T9IEDLs   (B #B9c                 b   > U R                   b  [        [        U ]  5       $ [        5       nX-  nU$ r   )r_  r#  r1   r  )r   r   r  s     r   r  Forward.copy  s0    99 $,..)CLCJr   c           	         > [         R                  (       aF  U R                  c9  [        R                  " SR                  SU[        U 5      R                  5      SS9  [        [        U ]+  X5      $ )NzR{0}: setting results name {0!r} on {1} expression that has no contained expressionr!   r   r}  )r   r!   r_  r  r  r  r  r   r#  r1   r  r  s      r   r  Forward._setResultsName  s`    22yy  AAGHhHLHLT
H[H[B] *+	, Wd3DIIr   )r_  r  r  r  r  r  r  r   r  )r   r   r   r   r	  r   r`  rc  r  r[  r  r   r  r  r   r6  r7  s   @r   r1   r1   {  s<    4= (	J 	Jr   r1   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )rP   i  zO
Abstract subclass of :class:`ParseExpression`, for converting parsed results.
c                 :   > [         [        U ]  U5        SU l        g rA  )r#  rP   r   r  r  s      r   r   TokenConverter.__init__  s    nd,T2r   r  r  r>  r7  s   @r   rP   rP     s       r   rP   c                   B   ^  \ rS rSrSrSU 4S jjrU 4S jrS rSrU =r	$ )r,   i  a  Converter to concatenate all matching tokens to a single string.
By default, the matching patterns must also be contiguous in the
input string; this can be disabled by specifying
``'adjacent=False'`` in the constructor.

Example::

    real = Word(nums) + '.' + Word(nums)
    print(real.parseString('3.1416')) # -> ['3', '.', '1416']
    # will also erroneously match the following
    print(real.parseString('3. 1416')) # -> ['3', '.', '1416']

    real = Combine(Word(nums) + '.' + Word(nums))
    print(real.parseString('3.1416')) # -> ['3.1416']
    # no match when there are internal spaces
    print(real.parseString('3. 1416')) # -> Exception: Expected W:(0123...)
c                    > [         [        U ]  U5        U(       a  U R                  5         X0l        SU l        X l        SU l        g r   )r#  r,   r   r  adjacentr  
joinStringr  )r   r_  ry  rx  r  s       r   r   Combine.__init__  s;    gt%d+  " "$ r   c                 ~   > U R                   (       a  [        R                  X5        U $ [        [        U ]  U5        U $ r   )rx  rG   r  r#  r,   r  s     r   r  Combine.ignore	  s5    ==  -  '4'.r   c                    UR                  5       nUS S 2	 U[        SR                  UR                  U R                  5      5      /U R
                  S9-  nU R                  (       a  UR                  5       (       a  U/$ U$ )Nr   )rV  )r  rE   r   r  ry  r  r  r  )r   r^  r   r  retTokss        r   r  Combine.postParse  sj    .."AJ<)@)@)Q!R S[_[l[lmm 1 19Nr   )rx  r  ry  r  )r   T)
r   r   r   r   r	  r   r  r  r   r6  r7  s   @r   r,   r,     s    "! r   r,   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r3   i  a  Converter to return the matched tokens as a list - useful for
returning tokens of :class:`ZeroOrMore` and :class:`OneOrMore` expressions.

Example::

    ident = Word(alphas)
    num = Word(nums)
    term = ident | num
    func = ident + Optional(delimitedList(term))
    print(func.parseString("fn a, b, 100"))  # -> ['fn', 'a', 'b', '100']

    func = ident + Group(Optional(delimitedList(term)))
    print(func.parseString("fn a, b, 100"))  # -> ['fn', ['a', 'b', '100']]
c                 :   > [         [        U ]  U5        SU l        g r   )r#  r3   r   r  r  s     r   r   Group.__init__)  s    eT#D)r   c                     U/$ r   r   r  s       r   r  Group.postParse-  s
    {r   r  	r   r   r   r   r	  r   r  r   r6  r7  s   @r   r3   r3     s     r   r3   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r-   i0  a  Converter to return a repetitive expression as a list, but also
as a dictionary. Each element can also be referenced using the first
token in the expression as its key. Useful for tabular report
scraping when the first column can be used as a item key.

Example::

    data_word = Word(alphas)
    label = data_word + FollowedBy(':')
    attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))

    text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
    attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))

    # print attributes as plain groups
    print(OneOrMore(attr_expr).parseString(text).dump())

    # instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names
    result = Dict(OneOrMore(Group(attr_expr))).parseString(text)
    print(result.dump())

    # access named fields as dict entries, or output as dict
    print(result['shape'])
    print(result.asDict())

prints::

    ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']
    [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
    - color: light blue
    - posn: upper left
    - shape: SQUARE
    - texture: burlap
    SQUARE
    {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}

See more examples at :class:`ParseResults` of accessing fields by results name.
c                 :   > [         [        U ]  U5        SU l        g r   )r#  r-   r   r  r  s     r   r   Dict.__init__W  s    dD"4(r   c                 t   [        U5       GH  u  pE[        U5      S:X  a  M  US   n[        U[        5      (       a  [	        US   5      R                  5       n[        U5      S:X  a  [        SU5      X6'   Ml  [        U5      S:X  a+  [        US   [        5      (       d  [        US   U5      X6'   M  UR                  5       nUS	 [        U5      S:w  d*  [        U[        5      (       a%  UR                  5       (       a  [        Xt5      X6'   GM  [        US   U5      X6'   GM     U R                  (       a  U/$ U$ )Nr   r   r   r   )r  r   r   r   r   r   r<  rE   r  r  r  )r   r^  r   r  r%  tokikey	dictvalues           r   r  Dict.postParse[  s   	*FA3x1}q6D$$$SV}**,3x1}"9"a"@	SQz#a&,'G'G"9#a&!"D	HHJ	aLy>Q&:i+N+NS\SdSdSfSf&=i&KIO&=ilA&NIO! +$ ;r   r  r  r7  s   @r   r-   r-   0  s    %L r   r-   c                   $    \ rS rSrSrS rS rSrg)rN   it  a#  Converter for ignoring the results of a parsed expression.

Example::

    source = "a, b, c,d"
    wd = Word(alphas)
    wd_list1 = wd + ZeroOrMore(',' + wd)
    print(wd_list1.parseString(source))

    # often, delimiters that are useful during parsing are just in the
    # way afterward - use Suppress to keep them out of the parsed output
    wd_list2 = wd + ZeroOrMore(Suppress(',') + wd)
    print(wd_list2.parseString(source))

prints::

    ['a', ',', 'b', ',', 'c', ',', 'd']
    ['a', 'b', 'c', 'd']

(See also :class:`delimitedList`.)
c                     / $ r   r   r  s       r   r  Suppress.postParse  s    	r   c                     U $ r   r   r   s    r   r  Suppress.suppress  s    r   r   N)r   r   r   r   r	  r  r  r   r   r   r   rN   rN   t  s    *r   rN   c                   *    \ rS rSrSrS rS rS rSrg)r=   i  zDWrapper for parse actions, to ensure they are only called once.
    c                 2    [        U5      U l        SU l        g rA  )r   r  called)r   
methodCalls     r   r   OnlyOnce.__init__  s    #J/r   c                 r    U R                   (       d  U R                  XU5      nSU l         U$ [        XS5      e)NTr   )r  r  rB   )r   r   r   r   r  s        r   r  OnlyOnce.__call__  s2    {{mmA!,GDKNQ2&&r   c                     SU l         g rA  )r  r   s    r   resetOnlyOnce.reset  s	    r   )r  r  N)	r   r   r   r   r	  r   r  r  r   r   r   r   r=   r=     s    'r   r=   c                 p   ^  [        T 5      m U 4S jn T R                  Ul        U$ ! [         a     U$ f = f)a1  Decorator for debugging parse actions.

When the parse action is called, this decorator will print
``">> entering method-name(line:<current_source_line>, <parse_location>, <matched_tokens>)"``.
When the parse action completes, the decorator will print
``"<<"`` followed by the returned value, or any exception that the parse action raised.

Example::

    wd = Word(alphas)

    @traceParseAction
    def remove_duplicate_chars(tokens):
        return ''.join(sorted(set(''.join(tokens))))

    wds = OneOrMore(wd).setParseAction(remove_duplicate_chars)
    print(wds.parseString("slkdjs sld sldd sdlf sdljf"))

prints::

    >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {}))
    <<leaving remove_duplicate_chars (ret: 'dfjkls')
    ['dfjkls']
c                    > TR                   nU SS  u  p#n[        U 5      S:  a  U S   R                  R                   S-   U-   n[        R                  R                  SU[        X25      X44-  5         T" U 6 n[        R                  R                  SU< S	U< S35        U$ ! [         a.  n[        R                  R                  SU< SU< S35        e S nAff = f)
Nro  r   r   .z">>entering %s(line: '%s', %d, %r)
z
<<leaving z (exception: z)
z (ret: )r   r   r  r   stderrr
  rk   rC  )paArgsthisFuncr   r   r   r   r!  r  s          r   ztraceParseAction.<locals>.z  s    ::+av;?ay**33c9HDH

>(DQRJXYA]]^	V*C 	

xEF
	  	JJ3OP	s   3B" "
C,)CC)r   r   r   )r  r  s   ` r   r   r     sC    2 	AAZZ
 H  Hs   ' 
55,c                 
   [        U 5      S-   [        U5      -   S-   [        U 5      -   S-   nU(       a(  [        U [        X-   5      -   5      R                  U5      $ U [        [	        U5      U -   5      -   R                  U5      $ )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.

Example::

    delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc']
    delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
z [r  r=  )r   r,   rU   r  rN   )r_  delimcombinedlNames       r   rd   rd     sw     4[4%,.4uT{BVKFtj667??GGz(5/D"899BB6JJr   c                   ^ ^ [        5       mUU 4S jnUc   [        [        5      R                  S 5      nOUR	                  5       nUR                  S5        UR                  USS9  UT-   R                  S[        T 5      -   S-   5      $ )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 ``intExpr`` is specified, it should be a pyparsing expression
that produces an integer value.

Example::

    countedArray(Word(alphas)).parseString('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
    binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2))
    countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef')  # -> ['ab', 'cd']
c                    > US   nTU=(       a    [        [        T/U-  5      5      =(       d    [        [        5      -    / $ rH  )r3   r(   rg   )r   r   r   r  	arrayExprr_  s       r   countFieldParseAction+countedArray.<locals>.countFieldParseAction  s6    aDa2E#tfqj/2BeElC	r   c                     [        U S   5      $ rH  )r   r   s    r   r   countedArray.<locals>.<lambda>  s    c!A$ir   arrayLenTr  z(len) r"  )r1   rR   rv   r   r  r  r  r   )r_  intExprr  r  s   `  @r   r`   r`     s|    . 	I t*++,?@,,.OOJ0Ei((E$K)?%)GHHr   c                     / nU  HE  n[        U[        5      (       a  UR                  [        U5      5        M4  UR	                  U5        MG     U$ r   )r   r_  r  rn  r  )Lr   r%  s      r   rn  rn  	  s@    
CaJJx{#JJqM	 
 Jr   c                    ^ [        5       mU4S jnU R                  USS9  TR                  S[        U 5      -   5        T$ )a  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::

    first = Word(nums)
    second = matchPreviousLiteral(first)
    matchExpr = 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:`matchPreviousExpr`. Do *not* use with packrat parsing
enabled.
c                    > U(       aG  [        U5      S:X  a	  TUS   -    g [        UR                  5       5      nT[        S U 5       5      -    g T[	        5       -    g )Nr   r   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r7   r   tts     r   r   DmatchPreviousLiteral.<locals>.copyTokenToRepeater.<locals>.<genexpr>)  s     7272;;r  )r   rn  rU  r(   r/   )r   r   r   tflatreps       r   copyTokenToRepeater1matchPreviousLiteral.<locals>.copyTokenToRepeater"  sJ    1v{qt !,s777757Nr   Tr  (prev) )r1   r  r  r   )r_  r  r  s     @r   rs   rs     sA     )C	 	+4@KK	E$K'(Jr   c                    ^ [        5       mU R                  5       nTU-  mU4S jnU R                  USS9  TR                  S[	        U 5      -   5        T$ )a(  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::

    first = Word(nums)
    second = matchPreviousExpr(first)
    matchExpr = 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                 f   >^ [        UR                  5       5      mU4S jnTR                  USS9  g )Nc                 ^   > [        UR                  5       5      nUT:w  a  [        SSS5      eg )Nr   r   )rn  rU  rB   )r   r   r   theseTokensmatchTokenss       r   mustMatchTheseTokensLmatchPreviousExpr.<locals>.copyTokenToRepeater.<locals>.mustMatchTheseTokensD  s/    "188:.Kk)$RB// *r   Tr  )rn  rU  r   )r   r   r   r  r  r  s       @r   r  .matchPreviousExpr.<locals>.copyTokenToRepeaterB  s.    qxxz*	0 	/tDr   Tr  r  )r1   r  r  r  r   )r_  e2r  r  s      @r   rr   rr   0  sV     )C	BBJCE 	+4@KK	E$K'(Jr   c                     S H  nU R                  U[        U-   5      n M     U R                  SS5      n U R                  SS5      n [        U 5      $ )Nz\^-[]r  r  r  r  )r   _bslashr   )r   r   s     r   r  r  M  sI    IIa1% 			$A			$A8Or   c                 
  ^ [        U[        5      (       a  [        R                  " SSS9  U(       a  S nS nU(       a  [        O[
        mOS nS nU(       a  [        O[        m/ n[        U [        5      (       a  U R                  5       nO;[        U [        5      (       a  [        U 5      nO[        R                  " S[        SS9  U(       d
  [        5       $ U(       d  S	nU[        U5      S
-
  :  au  Xg   n[        XgS
-   S 5       HD  u  pU" X5      (       a
  XgU	-   S
-   	   O1U" X5      (       d  M+  XgU	-   S
-   	 UR                  Xz5          O   US
-  nU[        U5      S
-
  :  a  Mu  U(       d  U(       d  U(       a   [        U5      [        SR!                  U5      5      :X  aB  [#        SSR!                  S U 5       5      -  5      R%                  SR!                  U5      5      $ [#        SR!                  S U 5       5      5      R%                  SR!                  U5      5      $ [)        U4S jU 5       5      R%                  SR!                  U5      5      $ ! [&         a    [        R                  " S[        SS9   NYf = f)a#  Helper to quickly define a set of alternative Literals, 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 - (default= ``False``) - treat all literals as
   caseless
 - useRegex - (default= ``True``) - as an optimization, will
   generate a Regex object; otherwise, will generate
   a :class:`MatchFirst` object (if ``caseless=True`` or ``asKeyword=True``, or if
   creating a :class:`Regex` raises an exception)
 - asKeyword - (default=``False``) - enforce Keyword-style matching on the
   generated expressions

Example::

    comp_oper = oneOf("< = > <= >= !=")
    var = Word(alphas)
    number = Word(nums)
    term = var | number
    comparison_expr = term + comp_oper + term
    print(comparison_expr.searchString("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 oneOf, pass choices as a list or space-delimited stringr   r}  c                 D    U R                  5       UR                  5       :H  $ r   )r_  r  bs     r   r   oneOf.<locals>.<lambda>z  s    	QWWY 6r   c                 \    UR                  5       R                  U R                  5       5      $ r   )r_  rT  r  s     r   r   r  {  s    aggi221779=r   c                 
    X:H  $ r   r   r  s     r   r   r  ~  s    r   c                 $    UR                  U 5      $ r   )rT  r  s     r   r   r    s    all1or   z6Invalid argument to oneOf, expected string or iterabler   r   Nr   r  c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r  r   syms     r   r   oneOf.<locals>.<genexpr>  s     -]U\c.DS.I.IU\r  r  |c              3   N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r   r  r  s     r   r   r    s     %Hbiinns   #%z7Exception creating Regex for oneOf, building MatchFirstc              3   4   >#    U  H  nT" U5      v   M     g 7fr   r   )r   r  parseElementClasss     r   r   r    s     @',,   )r   rd  r  r  r)   r*   r4   r7   r   r   r_  r  r:   r   r  r  r   rJ   r  rC  r9   )strsr^  useRegexr  isequalmaskssymbolsr%  curr|  r  r  s              @r   rw   rw   U  s$   @ (J'' DPQ	S 6=/8Oo&-'0GgG$
##**,	D(	#	#t*N#	3y #g,""*C%g!efo65&&A	*3&&A	*NN1, 7 Q #g,"" 	x	17|s2777#344Vbgg-]U\-]&]]^ffglgqgqrygz{{SXX%H%HHIQQRWR\R\]dReff @@@HHT[I\]]  	1MMS!a1	1s    A(I )>I $JJc                 @    [        [        [        X-   5      5      5      $ )au  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::

    text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
    attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
    print(OneOrMore(attr_expr).parseString(text).dump())

    attr_label = label
    attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)

    # similar to Dict, but simpler call format
    result = dictOf(attr_label, attr_value).parseString(text)
    print(result.dump())
    print(result['shape'])
    print(result.shape)  # object attribute access works too
    print(result.asDict())

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'}
)r-   r<   r3   )r  r}  s     r   re   re     s    J 	%,-..r   c                     [        5       R                  S 5      nUR                  5       nSUl        U" S5      U -   U" S5      -   nU(       a  S nOS nUR                  U5        U R                  Ul        U$ )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 astring containing the original parsed text.

If the optional ``asString`` 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:`originalTextFor` contains expressions with defined
results names, you must set ``asString`` to ``False`` if you
want to preserve those results name values.

Example::

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

prints::

    ['<b> bold <i>text</i> </b>']
    ['<i>text</i>']
c                     U$ r   r   )r   r   r   s      r   r   !originalTextFor.<locals>.<lambda>  s    r   F_original_start_original_endc                 2    XR                   UR                   $ r   )r  r  r  s      r   r   r    s    a(9(91??&Kr   c                 P    XR                  S5      UR                  S5       /US S & g )Nr  r  )r  r  s      r   extractText$originalTextFor.<locals>.extractText  s&    ee-.quu_/EFGAaDr   )r/   r   r  r  r  )r_  asString	locMarkerendlocMarker	matchExprr  s         r   r   r     su    : &&'<=I>>#L %L+,t3l?6SSIK	H[) ,,Ir   c                 8    [        U 5      R                  S 5      $ )zcHelper to undo pyparsing's default grouping of And expressions,
even if all but one are non-empty.
c                     U S   $ rH  r   r   s    r   r   ungroup.<locals>.<lambda>  s    1r   )rP   r  )r_  s    r   r   r     s     $..~>>r   c                     [        5       R                  S 5      n[        U" S5      U " S5      -   UR                  5       R	                  5       " S5      -   5      $ )aq  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 :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                     U$ r   r   r  s      r   r   locatedExpr.<locals>.<lambda>  s    Qr   
locn_startr}  locn_end)r/   r   r3   r  r  )r_  locators     r   r   r     sJ    2 g$$%67G&g69W9W9YZd9eeffr   rg   rm   rl   r   r   z\[]-*.$+^?()~ r  c                     US   S   $ rt  r   r  s      r   r   r   '  s    XYZ[X\]^X_r   z\\0?[xX][0-9a-fA-F]+c                 P    [        [        US   R                  S5      S5      5      $ )Nr   z\0xr-  )unichrr   r  r  s      r   r   r   (  s&    PVWZ[\]^[_[f[fgm[nprWsPtr   z	\\0[0-7]+c                 8    [        [        US   SS  S5      5      $ )Nr   r      )r  r   r  s      r   r   r   )  s!    VCPQRSPTUVUWPXZ[L\E]r   z\]rZ  r  r  negatebodyr  c                    ^ S m SR                  U4S j[        R                  U 5      R                   5       5      $ ! [         a     gf = f)a  Helper to easily define string ranges for use in Word
construction. Borrows syntax from regexp '[]' string range
definitions::

    srange("[0-9]")   -> "0123456789"
    srange("[a-z]")   -> "abcdefghijklmnopqrstuvwxyz"
    srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"

The input string must be enclosed in []'s, and the returned string
is the expanded character set joined into a single string. The
values enclosed in the []'s may be:

 - a single character
 - an escaped character with a leading backslash (such as ``\-``
   or ``\]``)
 - an escaped hex character with a leading ``'\x'``
   (``\x21``, which is a ``'!'`` character) (``\0x##``
   is also supported for backwards compatibility)
 - an escaped octal character with a leading ``'\0'``
   (``\041``, which is a ``'!'`` character)
 - a range of any of the above, separated by a dash (``'a-z'``,
   etc.)
 - any combination of the above (``'aeiouy'``,
   ``'a-zA-Z0-9_$'``, etc.)
c           
          [        U [        5      (       d  U $ SR                  S [        [	        U S   5      [	        U S   5      S-   5       5       5      $ )Nr   c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r  r   s     r   r   +srange.<locals>.<lambda>.<locals>.<genexpr>H  s     K_~Z[FSTII_~r  r   r   )r   rE   r   ru  ord)ps    r   r   srange.<locals>.<lambda>H  sO    :a#>#>!BGGK_dehijklimenpstuvwtxpy|}p}_~KDr   r   c              3   4   >#    U  H  nT" U5      v   M     g 7fr   r   )r   part	_expandeds     r   r   srange.<locals>.<genexpr>J  s     V3U4y3Ur  )r   _reBracketExprr`  r  rC  )r   r  s    @r   r   r   .  sH    4 @IwwV>3M3Ma3P3U3UVVV s   7> 
A
Ac                    ^  U 4S jnU$ )zgHelper method for defining parse actions that require matching at
a specific column in the input text.
c                 B   > [        X5      T:w  a  [        XST-  5      eg )Nzmatched token not at column %dr  )rU  locnrd  r  s      r   	verifyCol!matchOnlyAtCol.<locals>.verifyColR  s(    t?a -MPQ-QRR  r   r   )r  r  s   ` r   rq   rq   N  s    S r   c                    ^  U 4S j$ )a  Helper method for common parse actions that simply return
a literal value.  Especially useful when used with
:class:`transformString<ParserElement.transformString>` ().

Example::

    num = Word(nums).setParseAction(lambda toks: int(toks[0]))
    na = oneOf("N/A NA").setParseAction(replaceWith(math.nan))
    term = na | num

    OneOrMore(term).parseString("324 234 N/A 234") # -> [324, 234, nan, 234]
c                 
   > T/$ r   r   )r   r   r   replStrs      r   r   replaceWith.<locals>.<lambda>d  s    G9r   r   )r  s   `r   r   r   W  s     %$r   c                     US   SS $ )a  Helper parse action for removing quotation marks from parsed
quoted strings.

Example::

    # by default, quotation marks are included in parsed results
    quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"]

    # use removeQuotes to strip quotation marks from parsed results
    quotedString.setParseAction(removeQuotes)
    quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"]
r   r   r   r   r  s      r   r~   r~   f  s     Q4":r   c                    ^ ^ UU 4S jn [        T S[        T S5      R                  5      nX2l        U$ ! [         a    [        T 5      n Nf = f)a  Helper to define a parse action by mapping a function to all
elements of a ParseResults list. If any additional args are passed,
they are forwarded to the given function as additional arguments
after the token, as in
``hex_integer = Word(hexnums).setParseAction(tokenMap(int, 16))``,
which will convert the parsed data to an integer using base 16.

Example (compare the last to example in :class:`ParserElement.transformString`::

    hex_ints = OneOrMore(Word(hexnums)).setParseAction(tokenMap(int, 16))
    hex_ints.runTests('''
        00 11 22 aa FF 0a 0d 1a
        ''')

    upperword = Word(alphas).setParseAction(tokenMap(str.upper))
    OneOrMore(upperword).runTests('''
        my kingdom for a horse
        ''')

    wd = Word(alphas).setParseAction(tokenMap(str.title))
    OneOrMore(wd).setParseAction(' '.join).runTests('''
        now is the winter of our discontent made glorious summer by this sun of york
        ''')

prints::

    00 11 22 aa FF 0a 0d 1a
    [0, 17, 34, 170, 255, 10, 13, 26]

    my kingdom for a horse
    ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE']

    now is the winter of our discontent made glorious summer by this sun of york
    ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York']
c                 B   > U Vs/ s H  nT" U/TQ76 PM     sn$ s  snf r   r   )r   r   r   toknr   rk  s       r   r   tokenMap.<locals>.pa  s%    ./0adT!D!a000s   r   r  )r  r   rC  r   )rk  r   r   r  s   ``  r   r   r   u  sS    H1D*#D+6??A	 KI	  I	s   !4 AAc                 4    [        U 5      R                  5       $ r   r   r_  r   s    r   r   r     s    %(.."2r   c                 4    [        U 5      R                  5       $ r   r   lowerr   s    r   r   r     s    E!HNN$4r   r  r	  c                   ^ [        U [        5      (       a  U m[        X(       + S9n OU R                  m[	        [
        [        S-   5      nU(       a  [        R                  5       R                  [        5      nUU " S5      -   [        [        [        U[        S5      -   U-   5      5      5      -   [        SS/S9" S5      R                  S	 5      -   U-   nO[         R                  5       R                  [        5      [	        ["        S
S9-  nUU " S5      -   [        [        [        UR                  [$        5      [        [        S5      U-   5      -   5      5      5      -   [        SS/S9" S5      R                  S 5      -   U-   n['        [)        S5      U -   S
-   SS9nUR+                  ST-  5        UR-                  U4S j5        U" SSR/                  TR1                  SS5      R3                  5       R5                  5       5      -   5      R+                  ST-  5      nTUl        TUl        [9        U" 5       5      Ul        Xg4$ )zRInternal helper to construct opening and closing tag expressions, given a tag namerr  z_-:tag=/Fr  rg   c                     US   S:H  $ Nr   r$  r   r  s      r   r   _makeTags.<locals>.<lambda>      \]^_\`dg\gr   r	  r  c                     US   S:H  $ r'  r   r  s      r   r   r(    r)  r   r
  )rx  z<%s>c           	         > U R                  SSR                  TR                  SS5      R                  5       R	                  5       5      -   U R                  5       5      $ )Nr|  r   :r  )rq  r   r   titler   r  )r   resnames    r   r   r(    sG    Q]]7RWWW__UXZ]E^EdEdEfElElEn=o3oqrqwqwqy%zr   r  r   r-  r  z</%s>)r   rd  r4   rT  rR   rX   rW   rb   r  r   r~   r-   rU   r3   rN   r>   r}   rz   rf   r,   _Lr  r  r   r   r.  r   r"  rK   tag_body)	tagStrxmlsuppress_LTsuppress_GTtagAttrNametagAttrValueopenTagcloseTagr/  s	           @r   	_makeTagsr:    s    &*%%'2++vy501K
&++-<<\JE]#*U;#+F+U%VWXY cE73G<KKLghi !	! $((*99,G$zhkJllE]#*U;+E+En+U-5hsml6R-S,T &U V WW cE73G<KKLgh	i
 !! r$x&(3.?HOOFW$%z{S(A(G(G(I(O(O(Q RRS[[\cfm\mnHGKHLhj)Gr   c                     [        U S5      $ )a  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::

    text = '<td>More info at the <a href="https://github.com/pyparsing/pyparsing/wiki">pyparsing</a> wiki page</td>'
    # makeHTMLTags returns pyparsing expressions for the opening and
    # closing tags as a 2-tuple
    a, a_end = makeHTMLTags("A")
    link_expr = a + SkipTo(a_end)("link_text") + a_end

    for link in link_expr.searchString(text):
        # attributes in the <A> 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
Fr:  r2  s    r   ro   ro     s    , VU##r   c                     [        U S5      $ )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:`makeHTMLTags`
Tr<  r=  s    r   rp   rp     s     VT""r   c                     ^ U (       a  U SS mOUR                  5       mT VVs/ s H  u  p#X#4PM
     snnmU4S jnU$ s  snnf )a  Helper to create a validating parse action to be used with start
tags created with :class:`makeXMLTags` or
:class:`makeHTMLTags`. Use ``withAttribute`` to qualify
a starting tag with a required attribute value, to avoid false
matches on common tags such as ``<TD>`` or ``<DIV>``.

Call ``withAttribute`` with a series of attribute names and
values. Specify the list of filter attributes names and values as:

 - keyword arguments, as in ``(align="right")``, or
 - as an explicit dict with ``**`` operator, when an attribute
   name is also a Python reserved word, as in ``**{"class":"Customer", "align":"right"}``
 - a list of name-value tuples, as in ``(("ns1:class", "Customer"), ("ns2:align", "right"))``

For attribute names with a namespace prefix, you must use the second
form.  Attribute names are matched insensitive to upper/lower case.

If just testing for ``class`` (with or without a namespace), use
:class:`withClass`.

To verify that the attribute exists, but without specifying a value,
pass ``withAttribute.ANY_VALUE`` as the value.

Example::

    html = '''
        <div>
        Some text
        <div type="grid">1 4 0 1 0</div>
        <div type="graph">1,3 2,3 1,1</div>
        <div>this has no type</div>
        </div>

    '''
    div,div_end = makeHTMLTags("div")

    # only match div tag having a type attribute with value "grid"
    div_grid = div().setParseAction(withAttribute(type="grid"))
    grid_expr = div_grid + SkipTo(div | div_end)("body")
    for grid_header in grid_expr.searchString(html):
        print(grid_header.body)

    # construct a match with any div tag having a type attribute, regardless of the value
    div_any_type = div().setParseAction(withAttribute(type=withAttribute.ANY_VALUE))
    div_expr = div_any_type + SkipTo(div | div_end)("body")
    for div_header in div_expr.searchString(html):
        print(div_header.body)

prints::

    1 4 0 1 0

    1 4 0 1 0
    1,3 2,3 1,1
Nc                    > T HR  u  p4X2;  a  [        XSU-   5      eU[        R                  :w  d  M/  X#   U:w  d  M9  [        XSU< SX#   < SU< S35      e   g )Nzno matching attribute zattribute 'z' has value 'z', must be '')rB   r   	ANY_VALUE)r   r   r  attrName	attrValueattrss        r   r   withAttribute.<locals>.pa/  sd    #(H%$Q+Ch+NOOM3338HI8U$Q-5v7G,T U U	 $)r   )rx  )r   attrDictro  rk  r   rE  s        @r   r   r     sH    p Q  %&aV&EU I 's   ?c                 6    U(       a  SU-  OSn[        S0 X 0D6$ )ae  Simplified version of :class:`withAttribute` when
matching on a div class - made difficult because ``class`` is
a reserved word in Python.

Example::

    html = '''
        <div>
        Some text
        <div class="grid">1 4 0 1 0</div>
        <div class="graph">1,3 2,3 1,1</div>
        <div>this &lt;div&gt; has no class</div>
        </div>

    '''
    div,div_end = makeHTMLTags("div")
    div_grid = div().setParseAction(withClass("grid"))

    grid_expr = div_grid + SkipTo(div | div_end)("body")
    for grid_header in grid_expr.searchString(html):
        print(grid_header.body)

    div_any_type = div().setParseAction(withClass(withAttribute.ANY_VALUE))
    div_expr = div_any_type + SkipTo(div | div_end)("body")
    for div_header in div_expr.searchString(html):
        print(div_header.body)

prints::

    1 4 0 1 0

    1 4 0 1 0
    1,3 2,3 1,1
z%s:classclassr   )r   )	classname	namespace	classattrs      r   r   r   9  s$    F +4
Y&I2I122r   r  r  c           	          " S S[         5      n[        5       nXU-   U-   -  n[        U5       GH  u  pxUS-   SS u  ppU
S:  a  SU	-  OSU	-  nU
S:X  a!  U	b  [        U	5      S	:w  a  [	        S
5      eU	u  p[        5       R                  U5      nU[        R                  :X  a  U
S:X  a$  U" Xi-   5      [        U[        U	5      -   5      -   nGOU
S	:X  aP  U	b)  U" Xi-   U-   5      [        U[        X-   5      -   5      -   nGOhU" Xf-   5      [        U[        U5      -   5      -   nGODU
S:X  a6  U" UW-   U-   W-   U-   5      [        U[        X-   U-   U-   5      -   5      -   nGO[	        S5      eU[        R                  :X  a  U
S:X  aE  [        U	[        5      (       d  [        U	5      n	U" U	R                  U-   5      [        U	U-   5      -   nOU
S	:X  aP  U	b)  U" Xi-   U-   5      [        U[        U	U-   5      -   5      -   nOlU" UU-   5      [        U[        U5      -   5      -   nOHU
S:X  a,  U" UW-   U-   W-   U-   5      [        Xn-   U-   U-   U-   5      -   nO[	        S5      e[	        S5      eU(       a<  [        U[        [        45      (       a  UR                   " U6   OUR!                  U5        UUR                  U5      U-  -  nUnGM     XV-  nU$ )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 infixNotation. See
:class:`ParserElement.enablePackrat` for a mechanism to potentially
improve your parser performance.

Parameters:
 - baseExpr - expression representing the most basic element for the
   nested
 - opList - list of tuples, one for each operator precedence level
   in the expression grammar; each tuple is of the form ``(opExpr,
   numTerms, rightLeftAssoc, parseAction)``, where:

   - opExpr is the pyparsing expression for the operator; may also
     be a string, which will be converted to a Literal; if numTerms
     is 3, opExpr is a tuple of two expressions, for the two
     operators separating the 3 terms
   - numTerms is the number of terms for this operator (must be 1,
     2, or 3)
   - rightLeftAssoc is the indicator whether the operator is right
     or left associative, using the pyparsing-defined constants
     ``opAssoc.RIGHT`` and ``opAssoc.LEFT``.
   - parseAction 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
     ``setParseAction(*fn)``
     (:class:`ParserElement.setParseAction`)
 - lpar - expression for matching left-parentheses
   (default= ``Suppress('(')``)
 - rpar - expression for matching right-parentheses
   (default= ``Suppress(')')``)

Example::

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

    arith_expr = infixNotation(integer | varname,
        [
        ('-', 1, opAssoc.RIGHT),
        (oneOf('* /'), 2, opAssoc.LEFT),
        (oneOf('+ -'), 2, opAssoc.LEFT),
        ])

    arith_expr.runTests('''
        5+3*6
        (5+3)*6
        -2--11
        ''', fullDump=False)

prints::

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

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

    -2--11
    [[['-', 2], '-', ['-', 11]]]
c                       \ rS rSrSS jrSrg)infixNotation.<locals>._FBi  c                 @    U R                   R                  X5        U/ 4$ r   )r_  r  r  s       r   r  $infixNotation.<locals>._FB.parseImpl  s    IIx-7Nr   r   Nr  rY  r   r   r   _FBrO    s    	r   rR  r   Nr  r   z%s termz	%s%s termr   z@if numterms=3, opExpr must be a tuple or list of two expressionsr   z6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)r0   r1   r  r   r  r  rx   LEFTr3   r<   RIGHTr   r>   r_  r  r_  r   )baseExpropListlparrparrR  r   lastExprr%  operDefopExprarityrightLeftAssocr   termNameopExpr1opExpr2thisExprr  s                     r   r   r   c  s   Pj 
 )C#:,-H'
-4x-?!,D)~).9v%f8LA:~V!1 VX X%G9$$X.W\\)z 12U8iPVFW;W5XX	!% #H$5$@ AE(U^_e_pUqJqDr rI #H$7 85IV^L_A_;` `I! G!3h!>!H8!ST$X	':Lw:VYa:a0b%bcd	 !!YZZw}},z!&(33%f-Fh 67%@Q:RR	!% #H$5$@ AE(U^_ehp_pUqJqDr rI #Hx$7 85IV^L_A_;` `I! G!3h!>!H8!ST$X%7(%BW%Lx%WXY	 !!YZZQRR"udm,,(("-((,i''1H<=] (^ CJr   z4"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*"z string enclosed in double quotesz4'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*rA  z string enclosed in single quotesz*quotedString using single or double quotesuzunicode string literalc           
      n   X:X  a  [        S5      eUGc  [        U [        5      (       Gas  [        U[        5      (       Ga]  [        U 5      S:X  a  [        U5      S:X  a  UbF  [	        [        U) [        U U-   [        R                  -   SS9-   5      5      R                  S 5      nGO[        R                  5       [        U U-   [        R                  -   5      R                  S 5      -   nOUbY  [	        [        U) [        U 5      ) -   [        U5      ) -   [        [        R                  SS9-   5      5      R                  S 5      nO`[	        [        [        U 5      ) [        U5      ) -   [        [        R                  SS9-   5      5      R                  S 5      nO[        S5      e[        5       nUb5  U[        [        U 5      [!        X4-  U-  5      -   [        U5      -   5      -  nO1U[        [        U 5      [!        XB-  5      -   [        U5      -   5      -  nUR#                  S	U < U< S
35        U$ )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``)
 - ignoreExpr - expression for ignoring opening and closing
   delimiters (default= :class:`quotedString`)

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 ``ignoreExpr`` 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 quotedString or
a comment expression.  Specify multiple expressions using an
:class:`Or` or :class:`MatchFirst`. The default is
:class:`quotedString`, but if no expressions are to be ignored, then
pass ``None`` for this argument.

Example::

    data_type = oneOf("void int short long char float double")
    decl_data_type = Combine(data_type + Optional(Word('*')))
    ident = Word(alphas+'_', alphanums+'_')
    number = pyparsing_common.number
    arg = Group(decl_data_type + ident)
    LPAR, RPAR = map(Suppress, "()")

    code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment))

    c_function = (decl_data_type("type")
                  + ident("name")
                  + LPAR + Optional(delimitedList(arg), [])("args") + RPAR
                  + code_body("body"))
    c_function.ignore(cStyleComment)

    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.searchString(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 samer   r  c                 (    U S   R                  5       $ rH  r   r   s    r   r   nestedExpr.<locals>.<lambda>:      !A$**,r   c                 (    U S   R                  5       $ rH  rf  r   s    r   r   rg  ?  s    TUVWTXT^T^T`r   c                 (    U S   R                  5       $ rH  rf  r   s    r   r   rg  F  rh  r   c                 (    U S   R                  5       $ rH  rf  r   s    r   r   rg  K  rh  r   zOopening and closing arguments must be strings if no content expression is givenznested z expression)r  r   rd  r   r,   r<   r+   rG   r  r   rg   r  r7   r1   r3   rN   rU   r  )openerclosercontentrO  r   s        r   rt   rt     s-   B IJJfj))j.L.L6{aCK1$4)&y*3=f@F?G@M@a@a?bij4l2l (3  )
 *88N)O   %zz|j;A:B;H;\;\:] /; <J>J`;a bG
 )&y*4;FO3C2D4;FO3C2D 4>m>_>_gh3i2j (k  ) *88N)O	   'y'&/1A4;FO3C2D3=m>_>_gh3i2j (k  ) *88N)O 
 noo
)Chv&J4Dw4N)OORZ[aRbbcchv&CM)BBhvFVVWWKKFF;<Jr   c           	      b  ^^^ TSS mUU4S jmU4S jnU4S jnU4S jn[        [        5       R                  S5      R                  5       [	        5       S9n[        5       [        5       R                  U5      -   R                  S5      n[        5       R                  U5      R                  S	5      n[        5       R                  U5      R                  S
5      n	U(       aF  [        [        U5      U-   [        U[        U 5      -   [        U5      -   [	        5       S9-   U	-   5      n
OB[        [        U5      [        U[        U 5      -   [        U5      -   [	        5       S9-   U	-   5      n
U
R                  U4S j5        U R                  [        [        5       -   5        U
R                  S5      $ )a  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``.

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("(" + Optional(delimitedList(identifier)) + ")") + ":")
    func_body = indentedBlock(stmt, indentStack)
    funcDef = Group(funcDecl + func_body)

    rvalue = Forward()
    funcCall = Group(identifier + "(" + Optional(delimitedList(rvalue)) + ")")
    rvalue << (funcCall | identifier | Word(nums))
    assignment = Group(identifier + "=" + rvalue)
    stmt << (funcDef | assignment | identifier)

    module_body = OneOrMore(stmt)

    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                     > T TS S & g r   r   )backup_stackindentStacks   r   reset_stack"indentedBlock.<locals>.reset_stack  s    %Ar   c                    > U[        U 5      :  a  g [        X5      nUTS   :w  a!  UTS   :  a  [        XS5      e[        XS5      eg )Nr   zillegal nestingznot a peer entry)r   r]   rB   r   r   r   curColrr  s       r   checkPeerIndent&indentedBlock.<locals>.checkPeerIndent  sR    A;Q[_$B'$Q+<== '9:: %r   c                 h   > [        X5      nUTS   :  a  TR                  U5        g [        XS5      e)Nr   znot a subentry)r]   r  rB   rv  s       r   checkSubIndent%indentedBlock.<locals>.checkSubIndent  s4    QKO#v& '788r   c                    > U[        U 5      :  a  g [        X5      nT(       a  UT;   d  [        XS5      eUTS   :  a  TR                  5         g g )Nznot an unindentr   )r   r]   rB   r  rv  s       r   checkUnindent$indentedBlock.<locals>.checkUnindent  sL    A;Qv4 '899KO#OO $r   z	 r8  INDENTr   UNINDENTc                    > T" 5       $ r   r   )r  r  r   r  rs  s       r   r   indentedBlock.<locals>.<lambda>  s    KMr   zindented block)r<   r5   r  r  rL   r/   r   r  r3   r>   r  r  r  )blockStatementExprrr  r  rx  r{  r~  r-  r  PEERUNDENTsmExprrq  rs  s    `         @@r   r   r   V  sl   b q>L&;9 
79//6??A)+	VBg..~>>GGQFW##O4<<R@DW##M2:::FFx| "4%0B*C#Chrl#R[d[fgh    !
 x|"4%0B*C#Chrl#R[d[fgh  ! 9:g	12>>*++r   z#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]z_:zany tagzgt lt amp nbsp quot aposz><& "'z&(?P<entity>r  z);zcommon HTML entityc                 @    [         R                  U R                  5      $ )zRHelper parser action to replace common HTML entities with their special characters)_htmlEntityMapr  entityr   s    r   r   r     s    ahh''r   z/\*(?:[^*]|\*(?!/))*z*/zC style commentz<!--[\s\S]*?-->zHTML commentz.*zrest of linez//(?:\\\n|[^\n])*z
// commentzC++ style commentz#.*zPython style commentr*   		commaItemr%  r^   c            
          \ rS rSrSr\" \5      r \" \5      r	 \
" \5      R                  S5      R                  \5      r \
" \5      R                  S5      R                  \" \S5      5      r \" S5      R                  S5      R                  \5      r \" 5       R                  \	5      S-   \" 5       R                  \	5      -   R                  S	5      r \R)                  S
 5        \\\" \" S5      R-                  5       \-   5      -   -  R                  S5      r \R)                  \5        \" S5      R                  S5      R                  \	5      r \" S5      R                  S5      R                  \	5      r \\-  \-  R7                  5       r \" S5      R                  S5      R                  \	5      r \
" \S-   \S-   5      R                  S5      r  \" S5      R                  S5      r! \" S5      R                  S5      r"\"S\"-   S-  -   R                  S5      r#\" \"S\"-   S-  -   5      S-   \" \"S\"-   S-  -   5      -   R                  S5      r$\$RK                  S 5        S \!-   R                  S!5      r&\'" \#\&-  \$-  R                  S"5      5      R                  S"5      r( \" S#5      R                  S$5      r) \*S9S% j5       r+\*S:S& j5       r,\" S'5      R                  S(5      r- \" S)5      R                  S*5      r. \" S+5      R                  S,5      r/ \0R-                  5       \1R-                  5       -  r2\*S- 5       r3\'" \4" \5" S.5      ) \6" 5       ) -   \
" \7S.S/9-   \" \8" S05      5      -   5      5      R7                  5       R                  S15      r9\:" \" \;Ry                  5       \9-  S2S395      R                  S45      r= \*" \" S5 5      5      r> \*" \" S6 5      5      r?S7r@g8);r   i  ag	  Here are some common low-level expressions that may be useful in
jump-starting parser development:

 - numeric forms (:class:`integers<integer>`, :class:`reals<real>`,
   :class:`scientific notation<sci_real>`)
 - common :class:`programming identifiers<identifier>`
 - network addresses (:class:`MAC<mac_address>`,
   :class:`IPv4<ipv4_address>`, :class:`IPv6<ipv6_address>`)
 - ISO8601 :class:`dates<iso8601_date>` and
   :class:`datetime<iso8601_datetime>`
 - :class:`UUID<uuid>`
 - :class:`comma-separated list<comma_separated_list>`

Parse actions:

 - :class:`convertToInteger`
 - :class:`convertToFloat`
 - :class:`convertToDate`
 - :class:`convertToDatetime`
 - :class:`stripHTMLTags`
 - :class:`upcaseTokens`
 - :class:`downcaseTokens`

Example::

    pyparsing_common.number.runTests('''
        # any int or real number, returned as the appropriate type
        100
        -100
        +100
        3.14159
        6.02e23
        1e-12
        ''')

    pyparsing_common.fnumber.runTests('''
        # any int or real number, returned as float
        100
        -100
        +100
        3.14159
        6.02e23
        1e-12
        ''')

    pyparsing_common.hex_integer.runTests('''
        # hex numbers
        100
        FF
        ''')

    pyparsing_common.fraction.runTests('''
        # fractions
        1/2
        -3/4
        ''')

    pyparsing_common.mixed_integer.runTests('''
        # mixed fractions
        1
        1/2
        -3/4
        1-3/4
        ''')

    import uuid
    pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID))
    pyparsing_common.uuid.runTests('''
        # uuid
        12345678-1234-5678-1234-567812345678
        ''')

prints::

    # any int or real number, returned as the appropriate type
    100
    [100]

    -100
    [-100]

    +100
    [100]

    3.14159
    [3.14159]

    6.02e23
    [6.02e+23]

    1e-12
    [1e-12]

    # any int or real number, returned as float
    100
    [100.0]

    -100
    [-100.0]

    +100
    [100.0]

    3.14159
    [3.14159]

    6.02e23
    [6.02e+23]

    1e-12
    [1e-12]

    # hex numbers
    100
    [256]

    FF
    [255]

    # fractions
    1/2
    [0.5]

    -3/4
    [-0.75]

    # mixed fractions
    1
    [1]

    1/2
    [0.5]

    -3/4
    [-0.75]

    1-3/4
    [1.75]

    # uuid
    12345678-1234-5678-1234-567812345678
    [UUID('12345678-1234-5678-1234-567812345678')]
integerzhex integerr-  z[+-]?\d+zsigned integerr$  fractionc                     U S   U S   -  $ )Nr   r   r   r   s    r   r   pyparsing_common.<lambda>  s    ad1R5jr   rZ  z"fraction or mixed integer-fractionz[+-]?(?:\d+\.\d*|\.\d+)zreal numberz@[+-]?(?:\d+(?:[eE][+-]?\d+)|(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?)z$real number with scientific notationz[+-]?\d+\.?\d*([eE][+-]?\d+)?fnumberr  
identifierzK(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}zIPv4 addressz[0-9a-fA-F]{1,4}hex_integerr-     zfull IPv6 address)r   r}  z::zshort IPv6 addressc                 ,    [        S U  5       5      S:  $ )Nc              3   r   #    U  H-  n[         R                  R                  U5      (       d  M)  S v   M/     g7fr  )r   
_ipv6_partrh  r  s     r   r   ,pyparsing_common.<lambda>.<locals>.<genexpr>  s'     2lqDTD_D_DgDghjDk11qs   (7	7r  )r  r   s    r   r   r    s    s2lq2l/lop/pr   z::ffff:zmixed IPv6 addresszIPv6 addressz:[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}zMAC addressc                    ^  U 4S jnU$ )a  
Helper to create a parse action for converting parsed date string to Python datetime.date

Params -
 - fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%d"``)

Example::

    date_expr = pyparsing_common.iso8601_date.copy()
    date_expr.setParseAction(pyparsing_common.convertToDate())
    print(date_expr.parseString("1999-12-31"))

prints::

    [datetime.date(1999, 12, 31)]
c                    >  [         R                  " US   T5      R                  5       $ ! [         a  n[	        X[        U5      5      eS nAff = frH  )r   strptimedater  rB   r   r   r   r   vefmts       r   cvt_fn.pyparsing_common.convertToDate.<locals>.cvt_fn  sI    4((1s388:: 4$Q3r7334s   '+ 
AA

Ar   r  r  s   ` r   convertToDatepyparsing_common.convertToDate      $	4
 r   c                    ^  U 4S jnU$ )a  Helper to create a parse action for converting parsed
datetime string to Python datetime.datetime

Params -
 - fmt - format to be passed to datetime.strptime (default= ``"%Y-%m-%dT%H:%M:%S.%f"``)

Example::

    dt_expr = pyparsing_common.iso8601_datetime.copy()
    dt_expr.setParseAction(pyparsing_common.convertToDatetime())
    print(dt_expr.parseString("1999-12-31T23:59:59.999"))

prints::

    [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
c                    >  [         R                  " US   T5      $ ! [         a  n[        X[	        U5      5      eS nAff = frH  )r   r  r  rB   r   r  s       r   r  2pyparsing_common.convertToDatetime.<locals>.cvt_fn  s@    4((1s33 4$Q3r7334s    
A<Ar   r  s   ` r   convertToDatetime"pyparsing_common.convertToDatetime  r  r   z7(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?zISO8601 datez(?P<year>\d{4})-(?P<month>\d\d)-(?P<day>\d\d)[T ](?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d(\.\d*)?)?)?(?P<tz>Z|[+-]\d\d:?\d\d)?zISO8601 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}UUIDc                 F    [         R                  R                  US   5      $ )a  Parse action to remove HTML tags from web page HTML source

Example::

    # strip HTML links from normal text
    text = '<td>More info at the <a href="https://github.com/pyparsing/pyparsing/wiki">pyparsing</a> wiki page</td>'
    td, td_end = makeHTMLTags("TD")
    table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end
    print(table_text.parseString(text).body)

Prints::

    More info at the pyparsing wiki page
r   )r   _html_stripperr   )r   r   r  s      r   stripHTMLTagspyparsing_common.stripHTMLTags  s       ..>>vayIIr   r  r*  r  r  r   r%  zcomma separated listc                 4    [        U 5      R                  5       $ r   r  r   s    r   r   r  "  s    58>>3Cr   c                 4    [        U 5      R                  5       $ r   r  r   s    r   r   r  %  s    U1X^^5Er   r   N)z%Y-%m-%d)z%Y-%m-%dT%H:%M:%S.%f)Ar   r   r   r   r	  r   r   convertToIntegerfloatconvertToFloatrR   rv   r  r   r  rh   r  rJ   signed_integerr  r  r>   r  mixed_integerr  realsci_realr[  numberr  rX   rW   r  ipv4_addressr  _full_ipv6_address_short_ipv6_addressr  _mixed_ipv6_addressr,   ipv6_addressmac_addressr.  r  r  iso8601_dateiso8601_datetimeuuidr[   rZ   r  r  r<   r7   r5   rz   rQ   _commasepitemrd   r}   r  comma_separated_listr   rf   r   r   r   r   r   r     s   N`  } e_N 4j  +::;KLGDw-''6EEhsTVFWXKF;'//0@APPQabNV //?#EHXHgHghvHww  A  A  BL  MHT01(3-:P:P:RU]:]1^ ^^gg  iM  NMf  %+,44]CRRSabDLXYaa  cI  J  Y  Y  Zh  iH/ o.::<FG45==iHWWXfgG3fslIO4<<\JJdghppq  AL2*+33MBJ$j(8A'==FFGZ[#J#
2Bf1L$LM!"%jC*4D3N&NOP %W%9:  $$%pq$|3<<=QR.1DDGZZccdrst||  ~L  ML/UV^^_lmKF 0  0 ST\\]klL#  g  h  p  p  qC  D ]FGOOPVWD5((*[-A-A-CCNJ J" Iws|m)0
'3(,Zc(J'K )1u(>'? @ A BLggVaNb  ),2C2C2E4A3BKM*O ++273I+J  e)C DEL7!(+E"FGN7r   r   c                        \ rS rSrS rS rSrg)_lazyclasspropertyi)  c                 T    Xl         UR                  U l        UR                  U l        g r   )r   r	  r   r  s     r   r   _lazyclassproperty.__init__*  s    zzr   c                 D  ^ Tc  [        U5      m[        TS5      (       a'  [        U4S jTR                  SS   5       5      (       a  0 Tl        U R
                  R                  nUTR                  ;  a  U R                  T5      TR                  U'   TR                  U   $ )N_internc              3   V   >#    U  H  nTR                   [        US / 5      L v   M      g7f)r  N)r  r  )r   
superclassr   s     r   r   -_lazyclassproperty.__get__.<locals>.<genexpr>2  s-      .Q@O* /2kkWZQZ\^=_._@Os   &)r   )r  r  r,  __mro__r  r   r   )r   r   r   attrnames     ` r   __get___lazyclassproperty.__get__/  s    ;s)CsI&&# .Q@CAB.Q +Q +QCK77##3;;&$(GGCLCKK!{{8$$r   )r	  r   r   N)r   r   r   r   r   r  r   r   r   r   r  r  )  s    $
	%r   r  c                   l    \ rS rSrSr/ r\S 5       r\S 5       r	\S 5       r
\S 5       r\S 5       rSrg	)
r   i;  a  
A set of Unicode characters, for language-specific strings for
``alphas``, ``nums``, ``alphanums``, and ``printables``.
A unicode_set is defined by a list of ranges in the Unicode character
set, in a class attribute ``_ranges``, such as::

    _ranges = [(0x0020, 0x007e), (0x00a0, 0x00ff),]

A unicode set can also be defined using multiple inheritance of other unicode sets::

    class CJK(Chinese, Japanese, Korean):
        pass
c           	         / nU R                    HE  nU[        L a    O;UR                   H'  nUR                  [	        US   US   S-   5      5        M)     MG     [        [        U5      5       Vs/ s H  n[        U5      PM     sn$ s  snf )Nr   r   r   )r  r   _rangesr  ru  r*  r  r  )r   r   ccrrr   s        r   _get_chars_for_ranges!unicode_set._get_chars_for_rangesK  sv    ++B[ jj

5A2
34 ! 
 $*#c(#34#3aq	#3444s   .Bc                 p    SR                  [        [        R                  U R	                  5       5      5      $ )z+all non-whitespace characters in this ranger   )r   r   r   r  r  r  s    r   rz   unicode_set.printablesU  s'     xxGOOS5N5N5PQRRr   c                 p    SR                  [        [        R                  U R	                  5       5      5      $ )z'all alphabetic characters in this ranger   )r   filterr   isalphar  r  s    r   rX   unicode_set.alphasZ  '     xxw0I0I0KLMMr   c                 p    SR                  [        [        R                  U R	                  5       5      5      $ )z*all numeric digit characters in this ranger   )r   r  r   isdigitr  r  s    r   rv   unicode_set.nums_  r  r   c                 4    U R                   U R                  -   $ )z)all alphanumeric characters in this range)rX   rv   r  s    r   rW   unicode_set.alphanumsd  s     zzCHH$$r   r   N)r   r   r   r   r	  r  r
  r  r  rz   rX   rv   rW   r   r   r   r   r   r   ;  sv     G5 5 S S N N N N % %r   r   c                   X   \ rS rSrSrS\R                  4/r " S S\5      r	 " S S\5      r
 " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\\\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rSrg) r   ij  z>
A namespace class for defining common language unicode_sets.
    c                        \ rS rSrSrSS/rSrg)pyparsing_unicode.Latin1ip  z/Unicode set for Latin-1 Unicode Character Range)r  ~   )      r   Nr   r   r   r   r	  r  r   r   r   r   Latin1r  p      9#%57r   r  c                       \ rS rSrSrS/rSrg)pyparsing_unicode.LatinAit  z/Unicode set for Latin-A Unicode Character Range)   i  r   Nr  r   r   r   LatinAr  t      9#%r   r  c                       \ rS rSrSrS/rSrg)pyparsing_unicode.LatinBix  z/Unicode set for Latin-B Unicode Character Range)i  iO  r   Nr  r   r   r   LatinBr  x  r  r   r  c                        \ rS rSrSr/ SQrSrg)pyparsing_unicode.Greeki|  z.Unicode set for Greek Unicode Character Ranges))ip  i  )i   i  )i  i  )i   iE  )iH  iM  )iP  iW  )iY  )i[  )i]  )i_  i}  )i  i  )i  i  )i  i  )i  i  )i  i  )i  i  )i  i  r   Nr  r   r   r   Greekr  |  s    8
r   r  c                       \ rS rSrSrS/rSrg)pyparsing_unicode.Cyrillici  z0Unicode set for Cyrillic Unicode Character Range)i   i  r   Nr  r   r   r   Cyrillicr    s    :#$r   r  c                        \ rS rSrSrSS/rSrg)pyparsing_unicode.Chinesei  z/Unicode set for Chinese Unicode Character Range) N  i  i 0  i?0  r   Nr  r   r   r   Chineser    r  r   r  c                   ^    \ rS rSrSr/ r " S S\5      r " S S\5      r " S S\5      r	S	r
g
)pyparsing_unicode.Japanesei  z`Unicode set for Japanese Unicode Character Range, combining Kanji, Hiragana, and Katakana rangesc                        \ rS rSrSrSS/rSrg) pyparsing_unicode.Japanese.Kanjii  z-Unicode set for Kanji Unicode Character Range)r   i  r  r   Nr  r   r   r   Kanjir    s    ;')9;Gr   r  c                       \ rS rSrSrS/rSrg)#pyparsing_unicode.Japanese.Hiraganai  z0Unicode set for Hiragana Unicode Character Range)i@0  i0  r   Nr  r   r   r   Hiraganar	    s    >')Gr   r
  c                       \ rS rSrSrS/rSrg)#pyparsing_unicode.Japanese.Katakanai  z1Unicode set for Katakana  Unicode Character Range)i0  i0  r   Nr  r   r   r   Katakanar    s    ?')Gr   r  r   N)r   r   r   r   r	  r  r   r  r
  r  r   r   r   r   Japaneser    s.    j	<K 	<	*{ 	*	*{ 	*r   r  c                        \ rS rSrSr/ SQrSrg)pyparsing_unicode.Koreani  z.Unicode set for Korean Unicode Character Range))i   i  )i   i  )i01  i1  )i`  i  )i  i  r  r   Nr  r   r   r   Koreanr    s
    8r   r  c                       \ rS rSrSrSrg)pyparsing_unicode.CJKi  zTUnicode set for combined Chinese, Japanese, and Korean (CJK) Unicode Character Ranger   Nr0  r   r   r   CJKr    s    ^r   r  c                        \ rS rSrSrSS/rSrg)pyparsing_unicode.Thaii  z,Unicode set for Thai Unicode Character Range)i  i:  )i?  i[  r   Nr  r   r   r   Thair    s    6#%57r   r  c                        \ rS rSrSr/ SQrSrg)pyparsing_unicode.Arabici  z.Unicode set for Arabic Unicode Character Range))i   i  )i  i  )i   i  r   Nr  r   r   r   Arabicr    s
    8Ir   r  c                       \ rS rSrSrS/rSrg)pyparsing_unicode.Hebrewi  z.Unicode set for Hebrew Unicode Character Range)i  i  r   Nr  r   r   r   Hebrewr    s    8#%r   r  c                        \ rS rSrSrSS/rSrg)pyparsing_unicode.Devanagarii  z2Unicode set for Devanagari Unicode Character Range)i 	  i	  )i  i  r   Nr  r   r   r   
Devanagarir    s    <#%56r   r   r   N)r   r   r   r   r	  r   
maxunicoder  r   r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r   r   r   j  s     CNN#$G8 8& && &
 
%; %8+ 8*; * @ @gx 8{ 8J J& &7[ 7r   r   u   العربيةu   中文u   кириллицаu   Ελληνικάu   עִברִיתu	   日本語u   漢字u   カタカナu   ひらがなu	   한국어u	   ไทยu   देवनागरीc                   @    \ rS rSrSr " S S5      r " S S5      rSrg)	pyparsing_testi  z:
namespace class for classes useful in writing unit tests
c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
&pyparsing_test.reset_pyparsing_contexti  a  
Context manager to be used when writing unit tests that modify pyparsing config values:
 - packrat parsing
 - default whitespace characters.
 - default keyword characters
 - literal string auto-conversion class
 - __diag__ settings

Example:
    with reset_pyparsing_context():
        # test that literals used to construct a grammar are automatically suppressed
        ParserElement.inlineLiteralsUsing(Suppress)

        term = Word(alphas) | Word(nums)
        group = Group('(' + term[...] + ')')

        # assert that the '()' characters are not included in the parsed tokens
        self.assertParseAndCheckLisst(group, "(abc 123 def)", ['abc', '123', 'def'])

    # after exiting context manager, literals are converted to Literal expressions again
c                     0 U l         g r   _save_contextr   s    r   r   /pyparsing_test.reset_pyparsing_context.__init__  s
    !#Dr   c                    [         R                  U R                  S'   [        R                  U R                  S'   [         R
                  U R                  S'   [         R                  U R                  S'   [         R                  U R                  S'   [        R                   Vs0 s H  o[        [        U5      _M     snU R                  S'   S[        R                  0U R                  S'   U $ s  snf )	Ndefault_whitespacedefault_keyword_charsliteral_string_classpackrat_enabledpackrat_parser   r  r'   )rG   r  r(  r4   r]  r  rV  r  r   
_all_namesr  r'   r  r  s     r   save+pyparsing_test.reset_pyparsing_context.save  s    7D7X7XD34:A:W:WD67 11 & 5B4Q4QD012?2F2FD/:B:M:M.:M$gh--:M.Dz* )**K*K0D|, K.s   $C/c                    [         R                  U R                  S   :w  a"  [         R                  U R                  S   5        U R                  S   [        l        [         R                  U R                  S   5        U R                  S   R                  5        H  u  p[        [        X5        M     U R                  S   [         l
        U R                  S   [         l        U R                  S   [        l        g )Nr+  r,  r-  r   r.  r/  r'   )rG   r  r(  r  r4   r]  r  rx  setattrr   rV  r  r'   r  )r   rT  r}  s      r   restore.pyparsing_test.reset_pyparsing_context.restore  s     11%%&:;< 77&&';< -1,>,>?V,WG)--""#9:  $11*=CCE$.  F,0,>,>?P,QM)#'#5#5o#FM 040B0B<0PJ-r   c                 "    U R                  5       $ r   )r1  r   s    r   	__enter__0pyparsing_test.reset_pyparsing_context.__enter__
  s    99;r   c                 "    U R                  5       $ r   )r5  r4  s     r   __exit__/pyparsing_test.reset_pyparsing_context.__exit__  s    <<>!r   r'  N)r   r   r   r   r	  r   r1  r5  r8  r;  r   r   r   r   reset_pyparsing_contextr%    s!    	,	$	 	Q&		"r   r=  c                   `    \ rS rSrSr S
S jr SS jr SS jr SS jr\	\
S4S j5       rS	rg)&pyparsing_test.TestParseResultsAssertsi  z[
A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
Nc                     Ub  U R                  X!R                  5       US9  Ub  U R                  X1R                  5       US9  gg)z
Unit test assertion to compare a ParseResults object with an optional expected_list,
and compare any defined results names with an optional expected_dict.
Nr   )assertEqualrU  r  )r   r  expected_listexpected_dictr   s        r   assertParseResultsEquals?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals  sG     (  S I(  S I )r   c                     UR                  USS9nU(       a  [        UR                  5       5        U R                  XcUS9  g)z
Convenience wrapper assert to test a parser element and input string, and assert that
the resulting ParseResults.asList() is equal to the expected_list.
Tr  )rC  r   Nr`  r]  r+  rE  )r   r_  test_stringrC  r   verboser  s          r   assertParseAndCheckList>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   >     %%kD%AFfkkm$))&SV)Wr   c                     UR                  USS9nU(       a  [        UR                  5       5        U R                  XcUS9  g)z
Convenience wrapper assert to test a parser element and input string, and assert that
the resulting ParseResults.asDict() is equal to the expected_dict.
Tr  )rD  r   NrH  )r   r_  rI  rD  r   rJ  r  s          r   assertParseAndCheckDict>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict,  rM  r   c                 b   Uu  pEUb  [        XR5       VVs/ s H  u  pgUS   US   U4PM     nnnU H  u  pn[        S U 5       S5      n[        S U 5       S5      nUb;  U R                  X=(       d    US9   [        U
[        5      (       a  U
e SSS5        Mj  [        S U 5       S5      n[        S U 5       S5      nX4S	:w  a  U R                  U
UUU=(       d    US
9  M  [        SR                  U	5      5        M     U R                  XCb  UOSS9  gs  snnf ! , (       d  f       M  = f)a  
Unit test assertion to evaluate output of ParserElement.runTests(). If a list of
list-dict tuples is given as the expected_parse_results argument, then these are zipped
with the report tuples returned by runTests and evaluated using assertParseResultsEquals.
Finally, asserts that the overall runTests() success value is True.

:param run_tests_report: tuple(bool, [tuple(str, ParseResults or Exception)]) returned from runTests
:param expected_parse_results (optional): [tuple(str, list, dict, Exception)]
Nr   r   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )r   r   r   exps     r   r   Npyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>P  s     IJsC4H   (	(c              3      #    U  H5  n[        U[        5      (       d  M  [        U[        5      (       d  M1  Uv   M7     g 7fr   )r   r  r  rC  rS  s     r   r   rU  S  s2      '/)#t4  9CC9S  C'/s   ??	?)expected_exceptionr   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )r   r_  rS  s     r   r   rU  b       NHS
38MSSHrV  c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )r   rb  rS  s     r   r   rU  e  rZ  rV  r  )rC  rD  r   zno validation for {!r}zfailed runTestsrA  )	r   r  assertRaisesr   rC  rE  r]  r  
assertTrue)r   run_tests_reportexpected_parse_resultsr   run_test_successrun_test_resultsrptexpectedmergedrI  r  fail_msgrX  rC  rD  s                  r   assertRunTestResults;pyparsing_test.TestParseResultsAsserts.assertRunTestResults8  s}    2B.%1 *--=)V)V VSVX.)V   6<1K  $II4 H *.'/
 *& *5!../ASV /   *&)<<&,  =  )-NHNPT) )-NHNPT) *9\I 99 &.;.;$,O	 :  "":"A"A+"NOK 6<P OO _cBS  Y( s   D9D
D.	c              #   f   #    U R                  XS9   S v   S S S 5        g ! , (       d  f       g = f7f)NrA  )r\  )r   r   r   s      r   assertRaisesParseExceptionApyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptionw  s$     ""8"5 655s   1 	1
.1r   r  r   r  )r   r   r   r   r	  rE  rK  rO  rf  r   rB   ri  r   r   r   r   TestParseResultsAssertsr?    sT    	 GK
	J GK
	X GK
	X FJ=	~ 
6D$ 	 
	r   rk  r   N)r   r   r   r   r	  r=  rk  r   r   r   r   r#  r#    s     A" A"Fj jr   r#  __main__selectfromr[  r  )r  columnsr  tablescommandaK  
        # '*' as column list and dotted table name
        select * from SYS.XYZZY

        # caseless match on "SELECT", and casts back to "select"
        SELECT * from XYZZY, ABC

        # list of column names, and mixed case SELECT keyword
        Select AA,BB,CC from Sys.dual

        # multiple tables
        Select A, B, C from Sys.dual, Table2

        # invalid SELECT keyword - should fail
        Xelect A, B, C from Sys.dual

        # incomplete command - should fail
        Select

        # invalid column name - should fail
        Select ^^^ frox Sys.dual

        z]
        100
        -100
        +100
        3.14159
        6.02e23
        1e-12
        z 
        100
        FF
        z6
        12345678-1234-5678-1234-567812345678
        rA  )r   )r  Fr   )FTFr  rQ  (  r	  r$   r%   r&   r   weakrefr   rn  r  r   r  r   rG  r0  rt  r&  r   operatorr   	itertools	functoolsr   
contextlibr   r   ImportErrorr	   _threadr
   	threadingcollections.abcr   r   r   r   r;  ordereddictr   r'   r  r   r   r    r!   r"   r  r  rT  r0  r#   enable_all_warnings__all__r  version_infors  r  maxsizer  r   rd  chrr  r   r   r  r   r*  reversedr_  r  r,  r  r  r  r  maxintxrangeru  __builtin__r   fnamer  r  r   r  ra  r   ascii_uppercaseascii_lowercaserX   rv   rh   rW   r  r   	printablerz   r   rC  r@   rB   rD   rF   rI   rP  r<  rE   registerr]   rn   rk   r`  re  rg  ru   r   rG   r  rO   r/   r:   r7   rO  r0  r  r4   r*   r)   r   rR   r  rV   rJ   rH   r+   rQ   r  r2   r6   r5   rM   rL   rT   rS   rC   r(   r?   r9   r.   rA   r0   r8   r;   r  r<   rU   r@  r>   rK   r1   rP   r,   r3   r-   rN   r=   r   rd   r`   rn  rs   rr   r  rw   re   r   r   r   r  rg   rm   rl   r   r   r   _escapedPunc_escapedHexChar_escapedOctChar_singleChar
_charRanger  r  r   rq   r   r~   r   r   rf   r:  ro   rp   r   rB  r   rx   rS  rT  r   ry   rb   r   r}   r   rt   r   rY   r{   r[   rZ   rb  r   r  r  r_   r   r\   ri   r  r   rc   ra   rj   r|   r[  r  r^   r   r  r   r   r  r  r  r
  r  r4  r  r  r  r  r  r  r  r   r#  r   selectToken	fromTokenident
columnNamecolumnNameList
columnSpec	tableNametableNameList	simpleSQLr  r  r  r  r  r  )nms   0r   <module>r     s\  6E P )9
     
  	         %6% 4(77 %
 


  %)
 !  6; 25: 2*/ '16 .-2 *$(NiNbmmI6N6NRTR_R_`gRhrNi :
  4 , s''(!,aA{{HJFGE c68T5#sCQTVYZ zzHE3. IOOQ	$$W[%%@A R +%(+, 
		&"8"8	8

TM	
b'WWO 0 0OO

=; =;~Z' Zz	, 	
	. 	*H	 H$f $A6 AF    %W
(!xB,	4 DAH]#F ]#@-^= ^B4M 4#E #?e ?%?e %?N? ? $+ !L.e L.\?g ?.Vg VB? B?J]5 ]~# #&: &J'E J'XT5 TnI IVC(E C(L#U # 4? ?>Cn C(. C C" *n .vRm vRrj/ jZxE xEvSM SMlB.? B.JL- L^ $  FH$ HV*  *X7Q( 7Qt! !F > B" BHt  tlhJ! hJT (  +n +ZN ,A> AH~ :v +`K*"IH<:U^n%/N(T?g< goog&k!!+.	i	*m##M2k!!+.	G.a8GGH_`/0??@tu%445]^_,>EYZA[[;#.<=
 < <X FFyYcfqYqOrIs  JC  JC  DJ  JK  K  NQ  Q@%.` 23A 45C #3-"3-#J$0#DJ !( $3L 
x)1#Xc] B #   % WX[^^_gg  iK  L% WX[^^_gg  iK  LuTUX[[VWZ]]^ __f_f  hT  `U 3,"3"3"556>>?WX#t@Q@Q@S fP|,| :;
,-&tFI4D'E'M'Mi'XY 
Kc4::<iHI#((>3F3F3H*II4OPXXYmn (
 56=>FFGXY #&'//? &5\))+33NC
,-55lC 1% 784?/QRZZ[no K"  "6]**+AB  0	$z"D$,T%[07}.=@G	z.J %K#K L MMWZ\ZaZabmZn  #8L,=,=,?-,OY[#\]eefz{ i8 i8X	% %$,%& ,%^H7 H7T '8&@&@&F&F&N&N(9(B(B(K(K(S(S'T(9(B(B(K(K(S(S'T    "
 02C2J2JKy*;*C*CD46G6P6PQ24E4K4KL02C2J2JK|->-G-GH&&	3D3M3M3S3ST&&9J9S9S9\9\]&&9J9S9S9\9\]|->-E-EF|->-C-CD:<M<X<XYr rj z$X.K$V,I&)d"23E"5#t<KKLYJ=45==iHNN*J"5#t<KKLYI=34<<XFM +j.CCiOR_`hRiiI   0 $$ &  %% '    )) + 
 (($)))<="" $ G IX  6556
      4$334  ;;     N jZ  		s   r( r; s -s) 4t 
/t$=t$
t)(r87r8;s
ss&%s&)t
0s99tt
tt
t! t!)t43t4