
                           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Jr  SS	KJr   SS
KJr  / SQr\" \R8                  5      SS r\S   S:H  r\(       a   \R>                  r \!r"\#r$\!r%\&\'\(\)\*\\+\,\-\.\//r0OG\Rb                  r \2r3S r%/ r0SSK4r4SRk                  5        H  r6 \0Ro                  \8" \4\65      5        M     \:" S \3" S5       5       5      r;S r< " S S\=5      r>\R~                  \R                  -   rASrB\BS-   rC\A\B-   rD\#" S5      rESR                  S \R                   5       5      rH " S S\I5      rJ " S S\J5      rK " S S\J5      rL " S S \L5      rM " S! S"\I5      rN " S# S$\=5      rO " S% S&\=5      rP\R                  " \P5        S' rRS( rSS) rTS* rUS+ rVS, rWS- rX SS/ jrY " S0 S1\=5      rZ " S2 S3\Z5      r[ " S4 S5\[5      r\ " S6 S7\[5      r] " S8 S9\[5      r^\^r_\^\Zl`         " S: S;\[5      ra " S< S=\^5      rb " S> S?\a5      rc " S@ SA\[5      rd " SB SC\[5      re " SD SE\[5      rf " SF SG\[5      rg " SH SI\[5      rh " SJ SK\[5      ri " SL SM\[5      rj " SN SO\j5      rk " SP SQ\j5      rl " SR SS\j5      rm " ST SU\j5      rn " SV SW\j5      ro " SX SY\j5      rp " SZ S[\j5      rq " S\ S]\Z5      rr " S^ S_\r5      rs " S` Sa\r5      rt " Sb Sc\r5      ru " Sd Se\r5      rv " Sf Sg\Z5      rw " Sh Si\w5      rx " Sj Sk\w5      ry " Sl Sm\w5      rz " Sn So\z5      r{ " Sp Sq\z5      r| " Sr Ss\=5      r}\}" 5       r~ " St Su\w5      r " Sv Sw\w5      r " Sx Sy\w5      r " Sz S{\5      r " S| S}\w5      r " S~ S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\=5      rS rSS jrSS jrS rS rS rS rSS jrS rSS jrS rS r\\" 5       GR+                  S5      r\l" 5       GR+                  S5      r\m" 5       GR+                  S5      r\n" 5       GR+                  S5      r\o" 5       GR+                  S5      r\e" \ESS.S9GR7                  S 5      r\f" S5      GR7                  S 5      r\f" S5      GR7                  S 5      r\\-  \-  \h" SSS9-  r\" \\" S5      -   \-   5      r\^" S5      \" S5      GRC                  S5      -   \" \{" \\-  5      5      GRC                  S5      -   S-   rS rS rS rS rS r\" S 5      r \" S 5      r S rS rS rS r\=" 5       \l        SS jr\>" 5       r\=" 5       \l        \=" 5       \l        \" S5      \" S5      4S jr\r \" \f" S5      S-   5      GR+                  S5      r\" \f" S5      S-   5      GR+                  S5      r\" \f" S5      S-   \f" S5      S-   -  5      GR+                  S5      r\" \_" S5      \R                  5       -   5      GR+                  S5      rSSS\R                  5       4S jrSS jr\" S5      r\" S5      r\" \e" \A\DS-   5      GR+                  S5      5      u  rr\" \" SRk                  5       S5      5      r\f" SSR                  \GR                  5       5      -   S-   5      GR+                  S5      rS r\" \f" S5      S-   5      GR+                  S5      r \f" S5      GR+                  S5      r \f" S5      GR                  5       GR+                  S5      r\f" S5      GR+                  S5      r \" \f" S5      S-   \-  5      GR+                  S5      r \r \f" S5      GR+                  S5      r \" \{" \e" \HSS9\" \e" S5      \^" S5      ) -   \m" 5       ) -   5      -   5      5      GR                  5       GR+                  S5      r\" \" \R                  5       \-  SS95      GR+                  S5      r  " S S5      r\S:X  Gac  \b" S5      r\b" S5      r\e" \A\DS-   5      r\" \SSS9GR7                  \5      r\" \" \5      5      GR+                  S5      rS\-  r\" \SSS9GR7                  \5      r\" \" \5      5      GR+                  S5      r\" S5      \" S5      -   \-   \" S5      -   r\GR                  S5        \GR                  GR                  S5        \GR                  GR                  S5        \GR                  GR                  S5        SSKr\GR                  GR7                  \" \GR                  5      5        \GR                  GR                  S5        gg! \ a
    SSKJr   G	NZf = f! \ a    SSKJr  SS	KJr   G	Nff = f! \ a     SS
KJr   G	Ns! \ a    Sr  G	Nf = ff = f! \9 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 
C{"<salutation>, <addressee>!"}), built up using L{Word}, L{Literal}, and L{And} elements 
(L{'+'<ParserElement.__add__>} operator gives L{And} expressions, strings are auto-converted to
L{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 L{ParseResults} object returned from L{ParserElement.parseString<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 L{ParserElement} and L{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 L{Literal} and L{CaselessLiteral} classes
 - construct character word-group expressions using the L{Word} class
 - see how to create repetitive expressions using L{ZeroOrMore} and L{OneOrMore} classes
 - use L{'+'<And>}, L{'|'<MatchFirst>}, L{'^'<Or>}, and L{'&'<Each>} operators to combine simple expressions into more complex ones
 - associate names with your parsed results using L{ParserElement.setResultsName}
 - find some helpful expression short-cuts like L{delimitedList} and L{oneOf}
 - find more useful common expressions in the L{pyparsing_common} namespace class
z2.2.2z29 Sep 2018 15:58 UTC    N)ref)datetime)RLock)Iterable)MutableMapping)OrderedDict)iAndCaselessKeywordCaselessLiteral
CharsNotInCombineDictEachEmpty
FollowedByForward
GoToColumnGroupKeywordLineEnd	LineStartLiteral
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	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   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    -platform/bq/third_party/pyparsing/__init__.py<lambda>_ustr.<locals>.<lambda>   s#    C!Qr
O8LQR8P0P    )

isinstanceunicodestrUnicodeEncodeErrorencodesysgetdefaultencodingr*   setParseActiontransformString)objret
xmlcharrefs      r|   _ustrr      s    
 c'""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N ).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     C%B#a%)%Bs   zamp gt lt quot apos)splitzipreplace)datafrom_symbols
to_symbolsfrom_to_s        r|   _xml_escaper      sA     LC%:%@%@%BCJ2	||E' 3Kr   c                       \ rS rSrSrg)
_Constants   r   N)__name__
__module____qualname____firstlineno____static_attributes__r   r   r|   r   r      s    r   r   
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                   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       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   )locmsg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
rM   )r<   columnrJ   )rM   r   r   r<   rJ   AttributeError)r   anames     r|   __getattr__ParseBaseException.__getattr__   sf     X488TYY00(($))--vo499.. ''r   c                 d    SU R                   U R                  U R                  U R                  4-  $ )Nz"%s (at char %d), (line:%d, col:%d))r   r   rM   r   r   s    r|   __str__ParseBaseException.__str__   s-    3((DHHdkk4;;@A 	A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)rJ   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__  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	% > >(A	 ;r   r    c                       \ rS rSrSrSrg)r"   i  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
r   Nr   r   r   r   r   r   r   r   r|   r"   r"     s    $ 	r   r"   c                       \ rS rSrSrSrg)r$   i  zguser-throwable exception thrown when inconsistent parse content
is found; stops all parsing immediatelyr   Nr   r   r   r|   r$   r$     s
    2r   r$   c                       \ rS rSrSrSrg)r&   i  zjust like L{ParseFatalException}, but thrown internally when an
L{ErrorStop<And._ErrorStop>} ('-' operator) indicates that parsing is to stop 
immediately because an unbacktrackable syntax error has been foundr   Nr   r   r   r|   r&   r&     s    M 	r   r&   c                   $    \ rS rSrSrS rS rSrg)r)   i2  zZexception thrown by L{ParserElement.validate} if the grammar could be improperly recursivec                     Xl         g r   parseElementTracer   parseElementLists     r|   r   "RecursiveGrammarException.__init__4  s    !1r   c                      SU R                   -  $ )NzRecursiveGrammarException: %sr   r   s    r|   r   !RecursiveGrammarException.__str__7  s    .1G1GGGr   r   N)r   r   r   r   r   r   r   r   r   r   r|   r)   r)   2  s    d2Hr   r)   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    7r   c                      U R                   U   $ r   r   r   is     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 r   r   r   s     r|   	setOffset!_ParseResultsWithOffset.setOffsetA  s    HHQK?r   r   N)	r   r   r   r   r   r   r   r  r   r   r   r|   r   r   :  s    !#r   r   c                   r   \ rS rSrSrS0S 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S1S jrS rS rS r S r!S r"S r#S r$S r%S  r&S! r'S2S" jr(S# r)S$ r*S% r+S3S& jr,S' r-S( r.S4S) jr/S* r0S+ r1S, r2S- r3S. r4S/r5g)5r%   iD  a  
Structured parse results, to provide multiple means of access to the parsed data:
   - as a list (C{len(results)})
   - by list index (C{results[0], results[1]}, etc.)
   - by attribute (C{results.<resultsName>} - see L{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$ NT)r   object__new___ParseResults__doinit)r   toklistnameasListmodalretobjs         r|   r	  ParseResults.__new__k  s,    g##N$r   c                 <   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;   dx  U" U[        5      (       a  U/nU(       aS  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   )r
  _ParseResults__name_ParseResults__parent_ParseResults__accumNames_ParseResults__asList_ParseResults__modallist_ParseResults__toklist_generatorTypedict_ParseResults__tokdictry   r   r   
basestringr%   r   copyKeyError	TypeError
IndexError)r   r  r  r  r  r   s         r|   r   ParseResults.__init__t  st   ==!DMDK DM "D"M L'4((!(G^44!%g")!VDN*+!!$'$s##T{KwdZ(FGGGX\]_`bWcLcgj11 'kG!',77%<W\\^A%N
%<\'RS*=UVW%X
(,J%-%,QZ
 Md !%$ %Yz: -%,T
-s   4E? ?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 )Nrw   r   )r   ry   slicer  r  r  r%   )r   r   vs      r|   r   ParseResults.__getitem__  sq    q3u+''>>!$$)))~~a(,Q//#DNN14E$G4Eqd4E$GHH$Gs   %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 r   )
r   r  getr  ry   r#  r  r%   wkrefr  )r   kr$  r   subs        r|   __setitem__ParseResults.__setitem__  s    a/00 $ 2 21TV <s BDNN1A$C3u+&& !NN1C $ 2 21TV <@WXYZ[@\?] ]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   ry   r#  lenr  r  rangeindicesreverser  items	enumerater   )
r   r   mylenremovedr  occurrencesjr)  valuepositions
             r|   __delitem__ParseResults.__delitem__  s    aU$$)Eq! !S!!q5JA!qSM5!))E"234GOO$(NN$8$8$:  A09+0F,,E)@T\T`Ha)b 1G ! %;
 q!r   c                     XR                   ;   $ r   )r  )r   r)  s     r|   __contains__ParseResults.__contains__  s    NN""r   c                 ,    [        U R                  5      $ r   )r/  r  r   s    r|   __len__ParseResults.__len__  s    T^^ 55r   c                 "    U R                   (       $ r   )r  r   s    r|   __bool__ParseResults.__bool__  s    %79r   c                 ,    [        U R                  5      $ r   iterr  r   s    r|   __iter__ParseResults.__iter__  s    t~~!77r   c                 8    [        U R                  S S S2   5      $ Nrw   rG  r   s    r|   __reversed__ParseResults.__reversed__  s    T4>>$B$+?%AAr   c                     [        U R                  S5      (       a  U R                  R                  5       $ [        U R                  5      $ )Niterkeys)hasattrr  rP  rH  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   r)  r   s     r|   r   +ParseResults._itervalues.<locals>.<genexpr>  s     2!1AQ!1s   rR  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   rV  s     r|   r   *ParseResults._iteritems.<locals>.<genexpr>  s     7&6DG&6s   rX  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  rP  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|   r3  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.)boolr  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=C{last}).
Supports both C{list} and C{dict} semantics for C{pop()}. If passed no
argument or an integer argument, it will use C{list} semantics
and pop tokens from the list of parsed tokens. If passed a 
non-integer argument (most likely a string), it will use C{dict}
semantics and pop the corresponding value from any defined 
results names. A second default return value argument is 
supported, just as in C{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']
rw   defaultr   z-pop() got an unexpected keyword argument '%s'r   )r3  r  r   ry   r/  )r   r   kwargsr)  r$  indexr   defaultvalues           r|   popParseResults.pop  s    D 4D<<>CAI~Q| ORS STT	 "
 tAw$$D	QQ4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 C{defaultValue} or C{None} if no
C{defaultValue} is specified.

Similar to C{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.get3  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 C{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  insertr  r3  r4  r   )r   rq  insStrr  r7  r)  r9  r:  s           r|   rz  ParseResults.insertI  s[     	e, $ 4 4 6D(1+(>$$E!8HL\@]!^ )? !7r   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  append)r   items     r|   r~  ParseResults.append]  s     	d#r   c                 n    [        U[        5      (       a  X-  n 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   r%   r  extend)r   itemseqs     r|   r  ParseResults.extendk  s*     g|,,ODNN!!'*r   c                 V    U R                   SS2	 U R                  R                  5         g)z'
Clear all elements and results names.
N)r  r  clearr   s    r|   r  ParseResults.clear}  s      NN1r   c                 ,     X   $ ! [          a     gf = fr   )r  r  r  r%   )r   r  r$  s      r|   r   ParseResults.__getattr__  s!    	: 		s    
c                 .    U R                  5       nX!-  nU$ r   )r  )r   otherr   s      r|   __add__ParseResults.__add__  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-   $ r   r   )aoffsets    r|   r}   'ParseResults.__iadd__.<locals>.<lambda>  s    AaC&"=QvX"=r   r   r   )r  r/  r  r3  r   r   r%   r(  r  r  update)	r   r  	addoffset
otheritemsr)  vlistr$  otherdictitemsr  s	           @r|   __iadd__ParseResults.__iadd__  s    ??(F=I..0J1;L1;IQU  !"9!A$y1"OQEJ R1;  L%Qad<00$)$KAaDM &
 	%//)  %"4"46Ls   0Dc                 `    [        U[        5      (       a  US:X  a  U R                  5       $ X-   $ r   )r   ry   r  r   r  s     r|   __radd__ParseResults.__radd__  s+    eC  UaZ99; <r   c                 d    S[        U R                  5      < S[        U R                  5      < S3$ )N(, ))r   r  r  r   s    r|   r   ParseResults.__repr__  s    "DNN4dDNN6LNNr   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   r%   r   r   )r   r   s     r|   r   'ParseResults.__str__.<locals>.<genexpr>  s-     l]kXY:a+F+FuQxDQRGS]ks   8:])r   r  r   s    r|   r   ParseResults.__str__  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   r%   _asStringListr   )r   sepoutr  s       r|   r  ParseResults._asStringList  sZ    NNDs

34//))++

E$K) # 
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   r%   r  )r   ress     r|   r  ParseResults.asList  s=     RVQ_Q_`Q_#
3| < <

#EQ_```s   1Ac                    ^ [         (       a  U R                  nOU R                  nU4S jm[        U4S jU" 5        5       5      $ )aK  
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   r%   rl  asDict)r   r$  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   r)  r$  r  s      r|   r   &ParseResults.asDict.<locals>.<genexpr>  s     7YcaQvayMYs   )PY_3r3  rh  r  )r   item_fnr  s     @r|   r  ParseResults.asDict  s6    & 4jjGnnG	 7WY777r   c                     [        U R                  5      nU R                  R                  5       Ul        U R                  Ul        UR
                  R                  U R
                  5        U R                  Ul        U$ )z1
Returns a new copy of a C{ParseResults} object.
)r%   r  r  r  r  r  r  r  )r   r   s     r|   r  ParseResults.copy  s[     DNN,++-}}!2!24[[

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.

c              3   H   #    U  H  u  pU  H  nUS    U4v   M     M     g7fr   Nr   )r   r)  r  r$  s       r|   r   %ParseResults.asXML.<locals>.<genexpr>  s/      L4JyEJ Q4(EJ #4J    "  r   NITEM<></)r  r  r3  r  r4  r  r   r%   asXMLr   r   r   )r   doctagnamedItemsOnlyindent	formattednlr  
namedItemsnextLevelIndentselfTagr   r  resTagxmlBodyTexts                 r|   r  ParseResults.asXML  s     LDNN4H4H4J L L
 4- F OBG{{++ VS'300t~~.EA#l++?YYz}(6(I6T>(7(13 4 4C
 YYt(6(I6T>(7(13 4 4C ?']F% !')%*5_c630;04fcD D/ /6 	VT7C11wws|r   c                 t    U R                   R                  5        H  u  p#U H  u  pEXL d  M  Us  s  $    M     g r   )r  r3  )r   r*  r)  r  r$  r   s         r|   __lookupParseResults.__lookup;  s6    ~~++-GA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   rw   )	r  r  _ParseResults__lookupr/  r  nextrH  re  ra  )r   pars     r|   getNameParseResults.getNameB  s    , ;;;;]]--/C||D))$i1n4>>"a'D..01215a8FBT^^002344r   c                    / nSnUR                  U[        U R                  5       5      -   5        U(       Ga  U R                  5       (       a  [	        S U R                  5        5       5      nU H  u  pxU(       a  UR                  U5        UR                  U< SU-  < SU< S35        [        U[        5      (       aH  U(       a%  UR                  UR                  XS-   5      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      (       a6  UR                  SUSU-  XSUS-   -  U
R                  XS-   5      4-  5        MP  UR                  SUSU-  XSUS-   -  [        U
5      4-  5        M}     S	R                  U5      $ )
a  
Diagnostic method for listing out the contents of a C{ParseResults}.
Accepts an optional C{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  c              3   @   #    U  H  u  p[        U5      U4v   M     g 7fr   )r   )r   r)  r$  s      r|   r   $ParseResults.dump.<locals>.<genexpr>~  s     ClsqA{ls   r  z- z: r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   r%   )r   vvs     r|   r   r    s     @4RZ<004   z
%s%s[%d]:
%s%s%sr   )r~  r   r  rl  sortedr3  r   r%   dumpr   anyr4  r   )r   r  depthfullr  NLr3  r)  r$  r   r  s              r|   r  ParseResults.dumpg  s   $ 

F5//1||~~CdjjlCC CA

2JJU
Q GI!!L11JJvAg(>@JJuQx0

47+ ! @4@@@%aLDA!"\22

#8FD%LRS\`bghibi\jlnlslstz  BC  |C  mD  <F  $F  G

#8FD%LRS\`bghibi\jlqrtlu;v#vw	 ) wws|r   c                 T    [         R                   " U R                  5       /UQ70 UD6  g)ae  
Pretty-printer for parsed results as a list, using the C{pprint} module.
Accepts additional positional or keyword args as defined for the 
C{pprint.pprint} method. (U{http://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)pprintr  )r   r   rp  s      r|   r  ParseResults.pprint  s     * 	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  r  r  r  r  r  r   s    r|   __getstate__ParseResults.__getstate__  sT    >>&&(==,@HD$$;;!# 	#r   c                     US   U l         US   u  U l        nnU l        0 U l        U R                  R	                  U5        Ub  [        U5      U l        g S U l        g r.  )r  r  r  r  r  r(  r  )r   stater  inAccumNamess       r|   __setstate__ParseResults.__setstate__  s]    q a				  .?!#JDM DMr   c                 ^    U R                   U R                  U R                  U R                  4$ r   )r  r  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  ra  r   s    r|   r   ParseResults.__dir__  s     DJ$tyy{"334r   )__accumNames__asList__doinit__modal__name__parent	__tokdict	__toklist)NNTTr   r   )NFr   T)r   r   T)6r   r   r   r   r   r	  r   r   r   r+  r;  r>  rA  rD  __nonzero__rI  rM  rR  rY  r^  r  ra  re  r3  rP  rd  rh  rl  rs  r'  rz  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%   D  s/   %L !%4DU_ %-NI -7 '"*# 69K7A(38 MOY M 
O	Y	)	+	*$
2 h ,_($+$
  Os	a !8F	;z#J+Z60#!H5r   r%   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 L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
on parsing strings containing C{<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<     s?     	A#c!fq5T!11RsWWT1c=R7RRr   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 L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
on parsing strings containing C{<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   r  s     r|   rM   rM     s     ::d1S!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)r  find)r   r  lastCRnextCRs       r|   rJ   rJ     sJ     ZZa%FYYtS!F{1HV$$1HI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   rM   r<   )instringr   exprs      r|   _defaultStartDebugActionr    s=    	HuT{"Z/%*<yVTWMacfgjctKv?vvxr   c                 l    [        S[        U5      -   S-   [        UR                  5       5      -   5        g )NzMatched z -> )r  r   r   r  )r  startlocendlocr  tokss        r|   _defaultSuccessDebugActionr    s(    	:d#f,s4;;=/AABr   c                 2    [        S[        U5      -   5        g )NzException raised:)r  r   )r  r   r  excs       r|   _defaultExceptionDebugActionr    s    	s+,r   c                      g)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nr   )r   s    r|   rT   rT     s    r   rv   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   lr{   funcs      r|   r}   _trim_arity.<locals>.<lambda>  s	    T!Wr   r   Frv   )rr      c                 f    [         S:X  a  SOSn[        R                  " U* U -   S-
  S9U   nUS S /$ )N)rr   r   r   r   limitrv   )system_version	tracebackextract_stack)r%  r  frame_summarys      r|   r(  "_trim_arity.<locals>.extract_stack  s?    )W4R"F%336'%-/J6RM!"1%&&r   c                 @    [         R                  " XS9nUS   nUS S /$ )Nr$  rw   rv   )r'  
extract_tb)tbr%  framesr)  s       r|   r,  _trim_arity.<locals>.extract_tb  s+    ))":F"2JM!"1%&&r      r$  rw   r   c                     >   T" U TS   S  6 nSTS'   U$ ! [          aZ    TS   (       a  e  [        R                  " 5       S   nT" USS9S   S S T:X  d  e  AO! Af = fTS   T::  a  TS==   S-  ss'    Mv  e f = f)Nr   r   Trw   rv   r$  )r  r   exc_info)	r   r   r-  r,  
foundArityr  r%  maxargspa_call_line_synths	      r|   wrapper_trim_arity.<locals>.wrapper-  s    DqO, $
1
 a= \\^B/)"A6r:2A>BTT!  U B8w&!HMHs&    A:*AA:AA:8A:z<parse action>r   	__class__)r   )	singleArgBuiltinsr&  r'  r(  r,  getattrr   	Exceptionr   )r  r4  r(  	LINE_DIFF	this_liner6  	func_namer,  r3  r%  r5  s   ``     @@@@r|   _trim_arityr?    s      $$CEJ bqU"	'
	'
 "//))

 I A&r*I#A,	!Y(>? 0 !ID*#D+6??A	 !N	  I	s   ;!B$ $B<;B<c                   z  ^  \ rS rSrSrSrSr\S 5       r\S 5       r	SHS jr
S rS	 rSHS
 jrSIS jrS rS rS rS rS rS rSIS jrS rSJS 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!SJS jr"\r#\S 5       r$Sr%\SKS j5       r&SHS  jr'\(S4S! jr)S" r*\(4S# jr+\(S4S$ jr,S% r-S& r.S' r/S( r0S) r1S* r2S+ r3S, r4S- r5S. r6S/ r7S0 r8S1 r9SLS2 jr:S3 r;S4 r<S5 r=S6 r>S7 r?S8 r@SIS9 jrAS: rBS; rCS< rDS= rE/ 4S> jrFSHS? jrGU 4S@ jrHSA rISB rJSC rKSD rLSISE jrMSMSF jrNSGrOU =rP$ )Nr'   iO  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)r'   DEFAULT_WHITE_CHARScharss    r|   setDefaultWhitespaceChars'ParserElement.setDefaultWhitespaceCharsT  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)r'   _literalStringClass)r   s    r|   inlineLiteralsUsing!ParserElement.inlineLiteralsUsingc  s    & -0)r   c                 V   [        5       U l        S U l        S U l        S U l        Xl        SU l        [        R                  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'   rB  
whiteCharscopyDefaultWhiteCharsmayReturnEmptykeepTabsignoreExprsdebugstreamlinedmayIndexErrorerrmsgmodalResultsdebugActionsrecallPreparsecallDuringTry)r   savelists     r|   r   ParserElement.__init__x  s    6""';;%)"#6
 ! 0 "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 C{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 C{expr.copy()} is just C{expr()}::
    integerM = integer().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M")
N)r  rL  rV  rS  r'   rB  rR  )r   cpys     r|   r  ParserElement.copy  sQ      ii**1-**1-%%*>>CN
r   c                     Xl         SU R                   -   U l        [        U S5      (       a  U R                  U R                  l        U $ )a6  
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 	exception)r  rZ  rQ  rg  r   r   r  s     r|   setNameParserElement.setName  s;     	!DII-4$$!%DNNr   c                     U R                  5       nUR                  S5      (       a  USS nSnXl        U(       + Ul        U$ )a  
Define name for referencing matching tokens as a nested attribute
of the returned parse results.
NOTE: this returns a *copy* of the original C{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,
C{expr("name")} in place of C{expr.setResultsName("name")} - 
see L{I{__call__}<__call__>}.

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

    # equivalent form:
    date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
*Nrw   T)r  endswithrO  r[  )r   r  listAllMatchesnewselfs       r|   setResultsNameParserElement.setResultsName  sD    ( ))+==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 C{breakFlag} to True to enable, False to
disable.
c                 >   > SS K nUR                  5         T" XX#5      $ r   )pdb	set_trace)r  r   	doActionscallPreParsert  _parseMethods        r|   breaker'ParserElement.setBreak.<locals>.breaker  s    #XIMMr   _originalParseMethodTT)_parser{  rQ  )r   	breakFlagry  rx  s      @r|   setBreakParserElement.setBreak  sW    
 ;;LN ,8G(!K  t{{#9::"kk>>r   c                     [        [        [        [        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 C{fn(s,loc,toks)},
C{fn(loc,toks)}, C{fn(toks)}, or just C{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 C{L{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.

Optional keyword arguments:
 - callDuringTry = (default=C{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 L{I{parseString}<parseString>} for more information
on parsing strings containing C{<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]
r_  F)r  mapr?  rL  r'  r_  r   fnsrp  s      r|   r   ParserElement.setParseAction  s5    D  Kc ;<#ZZ?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 L{I{setParseAction}<setParseAction>}.

See examples in L{I{copy}<copy>}.
r_  F)rL  r  r  r?  r_  r'  r  s      r|   addParseActionParserElement.addParseAction  sH     	D[$s)!<==!//U6::ou3Ur   c                 "  ^^^ UR                  SS5      mUR                  SS5      (       a  [        O[        mU H&  mUUU4S jnU R                  R	                  U5        M(     U R
                  =(       d    UR                  SS5      U l        U $ )ak  Add a boolean predicate function to expression's list of parse actions. See 
L{I{setParseAction}<setParseAction>} for function call signatures. Unlike C{setParseAction}, 
functions passed to C{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)
messagezfailed user-defined conditionfatalFc                 X   > [        [        T5      " XU5      5      (       d	  T" XT5      eg r   )rk  r?  )r   r  r{   exc_typefnr   s      r|   pa&ParserElement.addCondition.<locals>.pa&  s+    KOA233"1s++ 4r   r_  )r'  r$   r"   rL  r~  r_  )r   r  rp  r  r  r  r   s       @@@r|   addConditionParserElement.addCondition  sx    " jj$CD*0**We*D*D&.B, ##B'	 
 "//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
C{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 C{L{ParseFatalException}}
if it is desired to stop parsing immediately.)rM  )r   r  s     r|   setFailActionParserElement.setFailAction-  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)rV  r}  r"   )r   r  r   
exprsFoundedummys         r|   _skipIgnorablesParserElement._skipIgnorables:  sc    
J%%$%HHh$=	%)
  & 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   )rV  r  rQ  rR  r/  )r   r  r   wtinstrlens        r|   preParseParserElement.preParseG  sd    &&7CB8}H.X]b%8q .X]b%8 
r   c                 
    U/ 4$ r   r   r   r  r   rv  s       r|   	parseImplParserElement.parseImplS  s    Bwr   c                     U$ r   r   r   r  r   	tokenlists       r|   	postParseParserElement.postParseV  s    r   c           
         U R                   nU(       d  U R                  (       ao  U R                  S   (       a  U R                  S   " XU 5        U(       a#  U R                  (       a  U R	                  X5      nOUnUn  U 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(       aj   U R"                   HX  nU" XU
5      nUc  M  [        UU R                  U R                  =(       a    ['        U[        [(        45      U R                   S9n
MZ     OhU R"                   HX  nU" XU
5      nUc  M  [        UU R                  U R                  =(       a    ['        U[        [(        45      U R                   S9n
MZ     U(       a+  U R                  S   (       a  U R                  S   " XX U
5        X*4$ ! [         a"    [        U[        U5      U R                  U 5      ef = f! [         aS  n	U R                  S   (       a  U R                  S   " XX	5        U R                  (       a  U R                  XX	5        e S n	A	ff = f! [         a"    [        U[        U5      U R                  U 5      ef = f! [         a0  n	U R                  S   (       a  U R                  S   " XX	5        e S n	A	ff = f)Nr   rv   )r  r  r   )rW  rM  r\  r^  r  r  r   r"   r/  rZ  r    rY  r  r%   rO  rP  r[  rL  r_  r   r  )r   r  r   rv  rw  	debuggingpreloctokensStarttokenserr	retTokensr  s               r|   _parseNoCacheParserElement._parseNoCacheZ  s   jj	!!!$!!!$hT; 1 17 KW!%9!NJC  1 17 K!!Vs8}%<W!%9!NJC "^^XyJ
8 &*:*:4??Z^ZkZkm	d.@.@"..!#XI!G!-(4f6:6F6F=A__=wQ[\bdpqucvQw<@<M<M)PI / **B	CF)$0&262B2B9=9sZX^`lmq_rMs8<8I8I%L	 + !!!$!!!$hS	S~m " W((CM4;;PTVVW% $$Q'%%a((L??OOXDG  " W((CM4;;PTVVW$ * ))!,))!,hTP	sP   ?I> #L 8L< AL< >,J**J- -
L
7ALL
,L9<
M6+M11M6c                 t     U R                  XSS9S   $ ! [         a    [        XU R                  U 5      ef = f)NF)rv  r   )r}  r$   r"   rZ  r   r  r   s      r|   tryParseParserElement.tryParse  sD    	D;;;@CC" 	D (dCC	Ds    "7c                 T     U R                  X5        g! [        [        4 a     gf = fr  )r  r"   r   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   rv  cachenot_in_caches     r|   r'  3ParserElement._UnboundedCache.__init__.<locals>.get  s    yyl33r   c                    > UTU'   g r   r   )r   rv  r9  r  s      r|   set3ParserElement._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   )r  r  types
MethodTyper'  r  r  rA  )r   r'  r  r  r  r  r  s        @@r|   r   &ParserElement._UnboundedCache.__init__  su    E/5x7D4#" ''2DH''2DH))%6DJ ++I<DLr   rA  r  r'  r  r  Nr   r   r   r   r   r   r   r   r|   _UnboundedCacher    s    	=r   r  c                       \ 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NF)r/  popitemr  )r   rv  r9  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   )	r  r  _OrderedDictr  r  r'  r  r  rA  )r   r  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'  r    r  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/  rs  popleftr~  )r   rv  r9  r  key_fifor  s      r|   r  r    sI    !&E#Jh-$.		("2"2"4d; h-$.OOC(r   c                 F   > TR                  5         TR                  5         g r   r  )r   r  r  s    r|   r  r    s    KKMNN$r   c                    > [        T5      $ r   r  r  s    r|   r  r    r  r   )
r  r  collectionsdequer  r  r'  r  r  rA  )	r   r  r'  r  r  r  r  r  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   )r'   packrat_cache_lockpackrat_cacher'  r  packrat_cache_statsr  r  r  r    r8  r   r   r;  )r   r  r   rv  rw  HITMISSlookupr  r9  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a%(--/2% .- * 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 r   )r'   r  r  r/  r  r   r   r|   
resetCacheParserElement.resetCache  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=C{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 C{ParserElement.enablePackrat()}.  If
your program uses C{psyco} to "compile as you go", you must call
C{enablePackrat} before calling C{psyco.full()}.  If you do not do this,
Python will crash.  For best results, call C{enablePackrat()} immediately
after importing pyparsing.

Example::
    import pyparsing
    pyparsing.ParserElement.enablePackrat()
TN)r'   _packratEnabledr  r  r  r  r}  )cache_size_limits    r|   enablePackratParserElement.enablePackrat%  sS    6 ,,,0M)'.;.K.K.M+.;.F.FGW.X+#0#<#<M  -r   c                    [         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$ ! [         a  n[         R                  (       a  e UeSnAff = f)a  
Execute the parse expression with the given string.
This is the main interface to the client code, once the complete
expression has been built.

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

Note: C{parseString} implicitly calls C{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 C{loc} argument to index into the
string being parsed, you can ensure you have a consistent view of the input
string by:
 - calling C{parseWithTabs} on your grammar before calling C{parseString}
   (see L{I{parseWithTabs}<parseWithTabs>})
 - define your parse action using the full C{(s,loc,toks)} signature, and
   reference the input string using the parse action's C{s} argument
 - explictly expand the tabs in your input string before calling
   C{parseString}

Example::
    Word('a').parseString('aaaaabaaa')  # -> ['aaaaa']
    Word('a').parseString('aaaaabaaa', parseAll=True)  # -> Exception: Expected end of text
r   N)r'   r  rX  
streamlinerV  rU  
expandtabsr}  r  r   r,   r    verbose_stacktrace)r   r  parseAllr  r   r  ser  s           r|   parseStringParserElement.parseStringH  s    6 	  "OO!!ALLN "}}**,H	++x4KCmmX4Wy{*		8* M " 	// 		s   ;AC 
C6C11C6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! [         a  n[        R                  (       a  e 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
C{maxMatches} argument, to clip scanning after 'n' matches are found.  If
C{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 L{I{parseString}<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rw  r   N)rX  r  rV  rU  r   r  r/  r  r}  r'   r  r"   r    r  )r   r  
maxMatchesoverlapr  r  r   
preparseFnparseFnmatchesr  nextLocr  nextlocr  s                  r|   
scanStringParserElement.scanStringz  sD    < OO!!ALLN " }}X113Hx=]]
++  "	/g&:''8F%,hU%TNG }1$g55"&0(&AG&}&- #q")C$Qh' /g&:/&:/ & # (C#  " 	// 		sO   B*E-
D$ 8D 	A D$ ED!D$  D!!D$ $
E.EEEc                 6   / 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 ! [         a  n[        R                  (       a  e UeSnAff = f)a  
Extension to C{L{scanString}}, to modify matching text with modified tokens that may
be returned from a parse action.  To use C{transformString}, define a grammar and
attach a parse action to it that modifies the returned token list.
Invoking C{transformString()} on a target string will then scan for matches,
and replace the matched text patterns according to the logic in the parse
action.  C{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   )rU  r  r~  r   r%   r  r  r   r  r   _flattenr    r'   r  )	r   r  r  lastEr{   r   r  or  s	            r|   r   ParserElement.transformString  s    "  	(4A

H1-/!!L11xxz)#Ad++

1 5 JJx'(!'cQ1cC'773uXc]344 (! 	// 		s0   B!C1 .
C,<C,)C1 ,C1 1
D;DD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 ! [         a  n[        R                  (       a  e UeSnAff = f)a5  
Another extension to C{L{scanString}}, simplifying the access to the tokens found
to match the given parse expression.  May be called with optional
C{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']
N)r%   r  r    r'   r  )r   r  r  r{   r   r  r  s          r|   searchStringParserElement.searchString  sV    $	(1X Z1XA!1X Z[[ Z! 	// 		s!   : 3: : 
A!AA!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 C{maxsplit} argument, to limit the number of splits;
and the optional C{includeSeparators} argument (default=C{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   )r  N)r  )	r   r  maxsplitincludeSeparatorssplitslastr{   r   r  s	            r|   r   ParserElement.split  sS      __X_CEA"" d
D	 D
 uos   ;=c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )aF  
Implementation of + operator - returns C{L{And}}. Adding strings to a ParserElement
converts them to L{Literal}s by default.

Example::
    greet = Word(alphas) + "," + Word(alphas) + "!"
    hello = "Hello, World!"
    print (hello, "->", greet.parseString(hello))
Prints::
    Hello, World! -> ['Hello', ',', 'World', '!']
4Cannot combine element of type %s with ParserElementrv   
stacklevelN)	r   r  r'   rH  warningswarnr   SyntaxWarningr	   r  s     r|   r  ParserElement.__add__  s^     uj**!55u>E5-11MMPSWX]S^^!a1dO%%r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-   $ )zM
Implementation of + operator when left operand is not a C{L{ParserElement}}
r'  rv   r(  Nr   r  r'   rH  r*  r+  r   r,  r  s     r|   r  ParserElement.__radd__1  Y     uj**!55u>E5-11MMPSWX]S^^!a1|r   c                    [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gU [        R                  5       -   U-   $ )zA
Implementation of - operator, returns C{L{And}} with error stop
r'  rv   r(  N)
r   r  r'   rH  r*  r+  r   r,  r	   
_ErrorStopr  s     r|   __sub__ParserElement.__sub__=  sh     uj**!55u>E5-11MMPSWX]S^^!a1cnn&&..r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-
  $ )zM
Implementation of - operator when left operand is not a C{L{ParserElement}}
r'  rv   r(  Nr/  r  s     r|   __rsub__ParserElement.__rsub__I  r1  r   c                 p  ^ ^ [        U[        5      (       a  USp2O[        U[        5      (       a  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$ )a]  
Implementation of * operator, allows use of C{expr * 3} in place of
C{expr + expr + expr}.  Expressions may also me multiplied by a 2-integer
tuple, similar to C{{min,max}} multipliers in regular expressions.  Tuples
may also include C{None} as in:
 - C{expr*(n,None)} or C{expr*(n,)} is equivalent
      to C{expr*n + L{ZeroOrMore}(expr)}
      (read as "at least n instances of C{expr}")
 - C{expr*(None,n)} is equivalent to C{expr*(0,n)}
      (read as "0 to n instances of C{expr}")
 - C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
 - C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}

Note that C{expr*(None,n)} does not raise an exception if
more than n exprs exist in the input stream; that is,
C{expr*(None,n)} does not enforce a maximum number of expr
occurrences.  If this behavior is desired, then write
C{expr*(None,n) + ~expr}
r   )NNNrv   r   z7cannot 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.    Q3#D+;AaC+@$@AA#D>)r   )	r   ry   tupler5   r   r  r   
ValueErrorr	   )r   r  minElementsoptElementsr   r<  s   `    @r|   __mul__ParserElement.__mul__U  s   ( eC  ',Qe$$\)2A.EQxE!H%(3''E!H,<8q=%d++8q=$T?*a=:d+;;;E!HS))jq#.F.F+0(* Y[_`efg`h[ijnotuvowjxyyNPTUZP[\\?NOO?_``**JKK*
 !#!1+!>>C 
 tf[014D[4QQC 
 '{3 
	 a 
 4&,-
r   c                 $    U R                  U5      $ r   )rB  r  s     r|   __rmul__ParserElement.__rmul__  s    ||E""r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )z9
Implementation of | operator - returns C{L{MatchFirst}}
r'  rv   r(  N)	r   r  r'   rH  r*  r+  r   r,  r   r  s     r|   __or__ParserElement.__or__  s^     uj**!55u>E5-11MMPSWX]S^^!a1T?,,r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zM
Implementation of | operator when left operand is not a C{L{ParserElement}}
r'  rv   r(  Nr/  r  s     r|   __ror__ParserElement.__ror__  r1  r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )z1
Implementation of ^ operator - returns C{L{Or}}
r'  rv   r(  N)	r   r  r'   rH  r*  r+  r   r,  r   r  s     r|   __xor__ParserElement.__xor__  s^     uj**!55u>E5-11MMPSWX]S^^!a1T?$$r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zM
Implementation of ^ operator when left operand is not a C{L{ParserElement}}
r'  rv   r(  Nr/  r  s     r|   __rxor__ParserElement.__rxor__  r1  r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  g[        X/5      $ )z3
Implementation of & operator - returns C{L{Each}}
r'  rv   r(  N)	r   r  r'   rH  r*  r+  r   r,  r   r  s     r|   __and__ParserElement.__and__  s^     uj**!55u>E5-11MMPSWX]S^^!a1t_&&r   c                     [        U[        5      (       a  [        R                  U5      n[        U[        5      (       d'  [        R
                  " S[        U5      -  [        SS9  gX-  $ )zM
Implementation of & operator when left operand is not a C{L{ParserElement}}
r'  rv   r(  Nr/  r  s     r|   __rand__ParserElement.__rand__  r1  r   c                     [        U 5      $ )z5
Implementation of ~ operator - returns C{L{NotAny}}
)r   r   s    r|   
__invert__ParserElement.__invert__  s     t~r   c                 J    Ub  U R                  U5      $ U R                  5       $ )a  
Shortcut for C{L{setResultsName}}, with C{listAllMatches=False}.

If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
passed as C{True}.
   
If C{name} is omitted, same as calling C{L{copy}}.

Example::
    # these are equivalent
    userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
    userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")             
)rp  r  rh  s     r|   __call__ParserElement.__call__  s'     &&t,,99;r   c                     [        U 5      $ )zp
Suppresses the output of this C{ParserElement}; useful to keep punctuation from
cluttering up returned output.
)r.   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
C{ParserElement}'s defined pattern.  This is normally only used internally by
the pyparsing module, but may be needed in some whitespace-sensitive grammars.
FrQ  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)rQ  rR  rS  )r   rD  s     r|   setWhitespaceChars ParserElement.setWhitespaceChars  s     #%*"r   c                     SU l         U $ )z
Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
Must be called before C{parseString} when the input grammar contains elements that
match C{<TAB>} characters.
T)rU  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   r  r.   rV  r~  r  r  s     r|   ignoreParserElement.ignore  st     eZ((UOEuh((,,,  ''.  ##Xuzz|%=?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  r  r  r\  rW  )r   startActionsuccessActionexceptionActions       r|   setDebugActionsParserElement.setDebugActions6  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 C{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 L{setDebugActions}. Prior to attempting
to match the C{wd} expression, the debugging message C{"Match <exprname> at loc <n>(<line>,<col>)"}
is shown. Then if the parse succeeds, a C{"Matched"} message is shown, or an C{"Exception raised"}
message is shown. Also note the use of L{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 C{Word} expression without calling C{setName} is C{"W:(ABCD...)"}.
F)rs  r  r  r  rW  )r   flags     r|   setDebugParserElement.setDebug@  s2    F   ":<VXtv  DJr   c                     U R                   $ r   r  r   s    r|   r   ParserElement.__str__i  s    yyr   c                     [        U 5      $ r   r   r   s    r|   r   ParserElement.__repr__l  r   r   c                 "    SU l         S U l        U $ r  )rX  rN  r   s    r|   r  ParserElement.streamlineo  s    r   c                     g r   r   r   s     r|   checkRecursionParserElement.checkRecursiont  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.validatew  s     	R!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! [         a  n[
        R                  (       a  e 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.
rN)readr   openr  r    r'   r  )r   file_or_filenamer	  file_contentsfr  s         r|   	parseFileParserElement.parseFile}  s    	),113M	##M8<<	  	)&, ! -,,,	)
 " 	// 		s=   % A- A*AA*
A&	!A*&A*-
B7BBc                    > [        U[        5      (       a!  XL =(       d    [        U 5      [        U5      :H  $ [        U[        5      (       a  U R	                  U5      $ [        [        U 5      U:H  $ r   )r   r'   varsr  r  superr   r  r8  s     r|   __eq__ParserElement.__eq__  sX    e]++==DJ$u+$==z**<<&&t,e33r   c                     X:X  + $ r   r   r  s     r|   __ne__ParserElement.__ne__      ""r   c                 *    [        [        U 5      5      $ r   )hashidr   s    r|   __hash__ParserElement.__hash__  s    BtH~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)a{  
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=C{True}) - flag to pass to C{L{parseString}} when running tests
    
Example::
    expr = Word(nums)
    assert expr.matches("100")
r	  TF)r  r   r    )r   
testStringr	  s      r|   r  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/ n/ nSn	U H  n
Ub  UR                  U
S5      (       d  U(       a  U
(       d  UR                  U
5        M>  U
(       d  MG  SR                  U5      U
/n/ n U
R                  SS5      n
U R                  XS9nUR                  UR                  US95        U	=(       a    U(       + n	U(       a2  U(       a  UR                  S	5        [+        SR                  U5      5        UR                  X45        M     X4$ ! [         a  n[        U[         5      (       a  SOS	nSU
;   aW  UR                  [#        UR$                  U
5      5        UR                  S
['        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N&SnAf[(         a5  nUR                  S[	        U5      -   5        U	=(       a    Un	Un SnAGNcS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=C{True}) - flag to pass to C{L{parseString}} when running tests           
 - comment - (default=C{'#'}) - expression for indicating embedded comments in the test 
      string; pass None to disable comment filtering
 - fullDump - (default=C{True}) - dump results as list followed by results names in nested outline;
      if False, only dump nested list
 - printResults - (default=C{True}) prints test output to stdout
 - failureTests - (default=C{False}) indicates if these tests are expected to fail parsing

Returns: a (success, results) tuple, where success indicates that all tests succeeded
(or failed if C{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'.)
TNFr  \nr  )r  z(FATAL)r    r   ^zFAIL: zFAIL-EXCEPTION: )r   r  r  r  r   r   rstrip
splitlinesr   r  r~  r   r   r  r  r    r$   rJ   r   r<   r;  r  )r   testsr	  commentfullDumpprintResultsfailureTests
allResultscommentssuccessr{   r  resultr   r  r  s                   r|   runTestsParserElement.runTests  s   n eZ((SYY(A(A(CDEEgz**g&G
A"wq%'@'@HUV"99X&*CHIIeD)))!)?

6;;H;56!6,&6  JJrNdiin%qk*C F ""- & 	%/4G%H%H	b19JJtBFFA/JJsCqM!O4s:UBCJJs266zC/%78

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

-C89!2ls&   AE;;
JCIJ*JJ)r}  r_  r^  rS  rW  r\  rZ  rM  rV  rU  rY  rT  r[  r  rL  r]  rO  rP  rQ  rN  rX  rR  FTr|  )   r   )T#TTF)Qr   r   r   r   r   rB  r  staticmethodrE  rI  r   r  ri  rp  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  _MAX_INTr  r   r  r   r  r  r4  r7  rB  rE  rH  rK  rN  rQ  rT  rW  rZ  r]  r`  rd  rg  rj  rm  rs  rw  r   r   r  r  r  r  r  r  r  r  r  r  r  r   __classcell__r8  s   @r|   r'   r'   O  s   3#2 2 0 0(#..8$$L6
END=& =, 	A 	A:	A 	A: Ma&3. F\ \ O =  =D0d 08 EN)V 2: 6 (05 ,&(

/
BH#
-

%

'
& .'R
 ') "(4##&A# A#r   r'   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r/   i<	  zL
Abstract C{ParserElement} subclass, for defining atomic matching patterns.
c                 (   > [         [        U ]  SS9  g NFr`  )r  r/   r   r   r8  s    r|   r   Token.__init__@	  s    eD"U"4r   r   r   r   r   r   r   r   r   r  r  s   @r|   r/   r/   <	  s    5 5r   r/   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   iD	  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   r  rT  rY  r  s    r|   r   Empty.__init__H	  s'    eD"$	""r   rY  rT  r  r  r  s   @r|   r   r   D	  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   iO	  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   r  rT  rY  rZ  r  s    r|   r   NoMatch.__init__S	  s.    gd$&	"")r   c                 0    [        XU R                  U 5      er   )r"   rZ  r  s       r|   r  NoMatch.parseImplZ	  s    XDKK>>r   )rZ  rY  rT  r  r  	r   r   r   r   r   r   r  r   r  r  s   @r|   r   r   O	  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^	  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 L{CaselessLiteral}.

For keyword matching (force word break before and after the matched string),
use L{Keyword} or L{CaselessKeyword}.
c                 T  > [         [        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        g ! [         a(    [        R                  " S[        SS9  [        U l         Nqf = f)Nr   z2null string passed to Literal; use Empty() insteadrv   r(  "%s"rf  F)r  r   r   matchr/  matchLenfirstMatchCharr   r*  r+  r,  r   r8  r   r  rZ  rT  rY  r   matchStringr8  s     r|   r   Literal.__init__l	  s    gd$& 
K(	#"-a.D
 U4::..	!DII-#"  	#MMN)a9"DN	#s   
A5 5/B'&B'c                     X   U R                   :X  aK  U R                  S:X  d!  UR                  U R                  U5      (       a  X R                  -   U R                  4$ [	        XU R
                  U 5      er  )r  r  
startswithr  r"   rZ  r  s       r|   r  Literal.parseImpl	  s]    MT000]]A!4!4TZZ!D!D}}$djj00XDKK>>r   )r8  rZ  r  r  r  rY  rT  r  r  r  r  s   @r|   r   r   ^	  s    #&? ?r   r   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$ )r   i	  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 C{L{Literal}}:
 - C{Literal("if")} will match the leading C{'if'} in C{'ifAndOnlyIf'}.
 - C{Keyword("if")} will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'}
Accepts two optional constructor arguments in addition to the keyword string:
 - C{identChars} is a string of characters that would be valid identifier characters,
      defaulting to all alphanumerics + "_" and "$"
 - C{caseless} allows case-insensitive matching, default is C{False}.
   
Example::
    Keyword("start").parseString("start")  # -> ['start']
    Keyword("start").parseString("starting")  # -> Exception

For case-insensitive matching, use L{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() insteadrv   r(  r  rf  F)r  r   r   DEFAULT_KEYWORD_CHARSr  r/  r  r  r   r*  r+  r,  r  rZ  rT  rY  caselessuppercaselessmatchr  
identChars)r   r  r  r  r8  s       r|   r   Keyword.__init__	  s    gd$& 66J 
K(	9"-a.D TZZ'	!DII-#" !,!2!2!4D#))+Jj/  	9MMN)a9	9s   
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r.  )r  r  r  r  r/  r  r  r  r  r"   rZ  r  s       r|   r  Keyword.parseImpl	  s>   ==MM 1399;t?Q?QQXt}}44T]]AR8S8Y8Y8[cgcrcr8r(h1uo335T__L==($**44!4!44!X%8%8C%H%HHdmm33xDMM@Q7RZ^ZiZi7iX!e_DOOC==($**44XDKK>>r   c                 V   > [         [        U ]  5       n[        R                  Ul        U$ r   )r  r   r  r  r  )r   r   r8  s     r|   r  Keyword.copy	  s$    '$$&44r   c                     U [         l        g)z,Overrides the default Keyword chars
        N)r   r  rC  s    r|   setDefaultKeywordCharsKeyword.setDefaultKeywordChars	  s     ).%r   )
r  r  rZ  r  r  r  r  rY  rT  r  r  r  )r   r   r   r   r   r6   r  r   r  r  r  r  r   r  r  s   @r|   r   r   	  s7      &dN**?
 . .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	  aL  
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 L{CaselessKeyword}.)
c                    > [         [        U ]  UR                  5       5        Xl        SU R                  -  U l        SU R
                  -   U l        g )Nz'%s'rf  )r  r   r   r  returnStringr  rZ  r  s     r|   r   CaselessLiteral.__init__	  sC    od,k.?.?.AC'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   )r  r  r  r  r"   rZ  r  s       r|   r  CaselessLiteral.parseImpl	  sN    ]]*,224

B}}$d&7&777XDKK>>r   )rZ  r  r  r  r  r  s   @r|   r   r   	  s    	.? ?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	  z
Caseless version of L{Keyword}.

Example::
    OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD']
    
(Contrast with example for L{CaselessLiteral}.)
c                 *   > [         [        U ]  XSS9  g )NTr  )r  r
   r   )r   r  r  r8  s      r|   r   CaselessKeyword.__init__	  s    od,kPT,Vr   c                 N   XX R                   -    R                  5       U R                  :X  ac  U[        U5      U R                   -
  :  d-  XU R                   -      R                  5       U R                  ;  a  X R                   -   U R
                  4$ [        XU R                  U 5      er   )r  r  r  r/  r  r  r"   rZ  r  s       r|   r  CaselessKeyword.parseImpl	  s    C-/5574;M;MMS]4==00H=N4O4U4U4W_c_n_n4n}}$djj00XDKK>>r   r   r   r  r  r  s   @r|   r
   r
   	  s    W? ?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$ )ro   i	  a$  
A variation on L{Literal} which matches "close" matches, that is, 
strings with at most 'n' mismatching characters. C{CloseMatch} takes parameters:
 - C{match_string} - string to be matched
 - C{maxMismatches} - (C{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:
 - C{mismatches} - a list of the positions within the match_string where mismatches were found
 - C{original} - the original match_string used to compare against the input string

If C{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  ro   r   r  match_stringmaxMismatchesrZ  rY  rT  )r   r  r  r8  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 R                  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U R                  US'   XS'   X.4$ [        XU R                  U 5      e)Nr   r   original
mismatches)	r/  r  r  r4  r   r~  r%   r"   rZ  )r   r  r   rv  startr  maxlocr  match_stringlocr  r  s_msrcmatresultss                  r|   r  CloseMatch.parseImpl
  s    x=T..//,,LOJ ..M'0X&5I4K\K\1]'^#:%%o6:6 (_ &)&s(;'<=&*&7&7
#(2%|#XDKK>>r   )rZ  r  r  rY  rT  r  )r   r  r  r  s   @r|   ro   ro   	  s    0$? ?r   ro   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	$ )	r2   i.
  al  
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 C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{exact}
are 0, meaning no maximum or exact length restriction. An optional
C{excludeChars} parameter can list characters that might be found in 
the input C{bodyChars} string; useful to define a word of all printables
except for one or two characters, for instance.

L{srange} is useful for defining custom character set strings for defining 
C{Word} expressions, using range notation from regular expression character sets.

A common mistake is to use C{Word} to match a specific literal string, as in 
C{Word("Address")}. Remember that C{Word} uses the string argument to define
I{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 L{Literal} or L{Keyword}.

pyparsing includes helper strings for building Words:
 - L{alphas}
 - L{nums}
 - L{alphanums}
 - L{hexnums}
 - L{alphas8bit} (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.)
 - L{punc8bit} (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.)
 - L{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                   >^ [         [        U ]  5         T(       a=  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a/  US:X  Ga'  US:X  Ga  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        g g g g g ! [2         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>`
  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  b
  s     #Ry!\<QAAyr  r   r   zZcannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permittedrf  Fr  z[%s]+r  z]*z][z\b)r  r2   r   r   initCharsOrigr  	initCharsbodyCharsOrig	bodyCharsmaxSpecifiedr?  minLenmaxLenr  r   r  rZ  rY  	asKeyword_escapeRegexRangeCharsreStringr/  r]  escapecompiler;  )	r   r  r  minmaxexactr  r  r8  s	          `r|   r   Word.__init__]
  s   d4!#N9NNIGG#Ry#RR	&Y!* ^DN!* ^DN!G7yzz7K"DK19KK$K	!DII-""d((););;;aCQRFW\^_W_!!T%7%77 '*@ASAS*T TT''(A-')yy1C1C'D&<T=O=O&P!S . (>d>P>P'Q&<T=O=O&P!S ~~ %dmm 3E 9**dmm5 X`F;  s   %I- -J Jc                    U R                   (       aZ  U R                   R                  X5      nU(       d  [        XU R                  U 5      eUR	                  5       nX$R                  5       4$ X   U R                  ;  a  [        XU R                  U 5      eUnUS-  n[        U5      nU R                  nXPR                  -   n[        X5      nX(:  a  X   U;   a  US-  nX(:  a
  X   U;   a  M  Sn	X%-
  U R                  :  a  Sn	U R                  (       a  X&:  a
  X   U;   a  Sn	U 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!XR 4$ )Nr   FTr   )r]  r  r"   rZ  endgroupr  r/  r  r  r   r  r  r  )
r   r  r   rv  r  r  r  	bodycharsr  throwExceptions
             r|   r  Word.parseImpl
  sS   77WW]]80F$XDKKFF**,C&&$..0 TBBqx=NN	$f(lx}	91HC lx}	9 ;$!NHMY4N!N>>aH1W-:QYQ^bkQk!% 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   s    r|   
charsAsStr Word.__str__.<locals>.charsAsStr
  s"    q6!8Ra5;&Hr   zW:(,r  zW:(%s))r  r2   r   r;  rN  r  r  )r   r.  r8  s     r|   r   Word.__str__
  s    	d+-- 		 << ##t'9'99/9$:L:L/MzZ^ZlZlOmo ||  (*T5G5G*HH||    
"")r  r  r  rZ  r  r  r  r  rY  r  r  r]  r  rN  )Nr   r   r   FNr  
r   r   r   r   r   r   r  r   r   r  r  s   @r|   r2   r2   .
  s    -\4l!(F r   r2   c                   |   ^  \ rS rSrSr\" \R                  " S5      5      rS	U 4S jjr	S
S jr
U 4S jrS rSrU =r$ )r*   i
  ah  
Token for matching strings that match a given regular expression.
Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module.
If the given regex contains named groups (defined using C{(?P<name>...)}), these will be preserved as 
named parse results.

Example::
    realnum = Regex(r"[+-]?\d+\.\d*")
    date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
    # ref: http://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?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")
z[A-Z]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        ON[        U[        R                  5      (       a$  Xl
        [        U5      =U l        U l        X l	        O[!        S5      e[#        U 5      U l        SU R$                  -   U l        SU l        SU l        X0l        X@l        g	! [        R                   a    [
        R                  " SU-  [        SS9  e f = f)
zThe parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags.z0null string passed to Regex; use Empty() insteadrv   r(  $invalid pattern (%s) passed to RegexzCRegex may only be constructed with a string or a compiled RE objectrf  FTN)r  r*   r   r   r  r*  r+  r,  patternflagsr]  r  r  errorcompiledREtyper   r?  r   r  rZ  rY  rT  asGroupListasMatch)r   r7  r8  r;  r<  r8  s        r|   r   Regex.__init__
  s   eD"$gz**P%!5 #LJ**T\\4::> $ !5!566GL)DLMJ bcc$K	!DII-""&' 88 DwN!a1s   AD& &3Ec                    U R                   R                  X5      nU(       d  [        XU R                  U 5      eUR	                  5       nUR                  5       nU R                  (       a  UnX&4$ U R                  (       a  UR                  5       nX&4$ [        UR                  5       5      nU(       a  U H	  nXW   Xg'   M     X&4$ r   )r]  r  r"   rZ  r%  	groupdictr<  r;  groupsr%   r&  )r   r  r   rv  r  dr   r)  s           r|   r  Regex.parseImpl
  s    x, TBBjjl<<C w --/C w	 v||~.CATCF wr   c                    >  [         [        U ]  5       $ ! [         a     Of = fU R                  c  S[        U R                  5      -  U l        U R                  $ )NzRe:(%s))r  r*   r   r;  rN  r   r7  r  s    r|   r   Regex.__str__  sU    	t,.. 		 <<$tDLL'99DL||r2  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      $ )z}
Return Regex with an attached parse action to transform the parsed
result as if called using C{re.sub(expr, repl, string)}.
z-cannot use sub() with Regex(asGroupList=True)rv   r(  z9cannot use sub() with a callable with Regex(asMatch=True)c                 ,   > U S   R                  T5      $ r   )expand)r  repls    r|   r  Regex.sub.<locals>.pa,  s    ay''--r   c                 B   > TR                   R                  TU S   5      $ r   )r]  r*  )r  rH  r   s    r|   r  rI  /  s    ww{{433r   )r;  r*  r+  r,  SyntaxErrorr<  callabler  )r   rH  r  s   `` r|   r*  	Regex.sub  sw    
 MMI(Q8-<<HTNNMMU(Q8-<<.4""2&&r   )r;  r<  rZ  r8  rY  rT  r  r7  r]  r  rN  )r   FFr  )r   r   r   r   r   r   r]  r  r:  r   r  r   r*  r   r  r  s   @r|   r*   r*   
  s7     "**W-.N"H$	' '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	$ )	r(   i3  aS  
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=C{None})
    - escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=C{None})
    - multiline - boolean indicating whether quotes can span multiple lines (default=C{False})
    - unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True})
    - endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar)
    - convertWhitespaceEscapes - convert escaped whitespace (C{'\t'}, C{'\n'}, etc.) to actual whitespace (default=C{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 5      T l         ST R@                  -   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 stringrv   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>u  sJ      &S-Q 4699T=N=NrPQ=R3S/EdFWFWXYFZ/[']-Qs   AArw   r  z|(?:%s)z|(?:%s.)z(.)z)*%sr6  rf  FT)$r  r(   r   r   r*  r+  r,  rK  	quoteCharr/  quoteCharLenfirstQuoteCharrQ  endQuoteCharLenescCharescQuoteunquoteResultsconvertWhitespaceEscapesr]  	MULTILINEDOTALLr8  r  r  r7  r   r0  escCharReplacePatternr  r  r9  r   r  rZ  rY  rT  )	r   rS  rW  rX  	multilinerY  rQ  rZ  r8  s	   `       r|   r   QuotedString.__init__L  s   l4)+ OO%	MM@Z[\-$L'--/LGabc!m#"	N'l("<0 ,(@%		1DJ))DNN+():):1)=>$&J+A'+JPbPTDL
 DJ))DNN+():):1)=>$&J+A'+JPbPTDL t  !A%LL &S-23t7H7H3I!3KAb-Q&S S SUXYL
 LLZ"))H*==>LLL[299W+==>L)+4<<)@)FD&299T->->#??@	jjtzz:DG LLDM $K	!DII-"" xx 	MM@4<<O!-	s   AN =Oc                    X   U R                   :H  =(       a    U R                  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$ )N\	r  )\tr  z\fz\rz\g<1>)rU  r]  r  r"   rZ  r%  r&  rY  rT  rV  r   r  rZ  r3  r   rW  r*  r]  rX  rQ  )	r   r  r   rv  r  r   ws_mapwslitwschars	            r|   r  QuotedString.parseImpl  s   $"5"55U$''--:U]Y] TBBjjllln '')=)=(=>C#j))3;4#@#@ $ $ $ $	F )/!kk%8 )7 <<&&!;!;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  r(   r   r;  rN  rS  rQ  r  s    r|   r   QuotedString.__str__  sW    	d355 		 <<OS~~_c_p_pqDL||r2  )rZ  rQ  rV  rZ  rW  r]  rX  rU  r8  rY  rT  r  r7  rS  rT  r]  r  rN  rY  )NNFTNTr  r3  r  s   @r|   r(   r(   3  s    0?#B!F	 	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	$ )	r   i  a  
Token for matching words composed of characters I{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 C{min} is 1 (a
minimum value < 1 is not valid); the default values for C{max} and C{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   rf  )r  r   r   rQ  notCharsr?  r  r  r  r   r  rZ  rT  rY  )r   rn  r   r!  r"  r8  s        r|   r   CharsNotIn.__init__  s    j')# 7  F  G  G7K"DK19KK$K	!DII- $q 0"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  )rn  r"   rZ  r   r  r/  r  )r   r  r   rv  r  notcharsmaxlens          r|   r  CharsNotIn.parseImpl  s    =DMM) TBBq==eKK'X8l}H,1HC l}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   r;  rN  r/  rn  r  s    r|   r   CharsNotIn.__str__  s    	T244 		 <<4==!A%+dmmBQ.?? ||  )4==8||r2  )	rZ  r  rY  rT  r  r  rn  rQ  rN  )r   r   r   r  r3  r  s   @r|   r   r     s    #0(" r   r   c                   J   ^  \ rS rSrSrSSSSSS.rSU 4S	 jjrSS
 jrSrU =r	$ )r1   i  aw  
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 C{" \t\r\n"}.  Also takes optional C{min}, C{max}, and C{exact} arguments,
as defined for the C{L{Word}} class.
z<SPC>z<TAB>z<LF>z<CR>z<FF>)r  rb  r  rd  rc  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>  s     (`OqPTP_P_G_Os   #	#c              3   H   #    U  H  n[         R                  U   v   M     g 7fr   )r1   	whiteStrsr   s     r|   r   rz    s     IAU__Q/r  Trf  r   )r  r1   r   ry  rg  r   rR  r  rT  rZ  r  r  r  )r   wsr   r!  r"  r8  s   `    r|   r   White.__init__  s    eD"$(`DOO(`!`b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  )ry  r"   rZ  r  r   r/  r  )r   r  r   rv  r  r  s         r|   r  White.parseImpl&  s    $//1 TBBq$fc(m-lx}?1HC lx}? ;$ TBBU'''r   )rZ  ry  r  rT  r  r  )z 	
r   r   r   r  )
r   r   r   r   r   r|  r   r  r   r  r  s   @r|   r1   r1     s/     
I (( (r   r1   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )_PositionTokeni6  c                 |   > [         [        U ]  5         U R                  R                  U l        SU l        SU l        g r  )r  r  r   r8  r   r  rT  rY  r  s    r|   r   _PositionToken.__init__7  s1    nT+-..))	""r   r  r   r   r   r   r   r   r  r  s   @r|   r  r  6  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	$ )r   i=  zZ
Token to advance to a specific column of input text; useful for tabular report scraping.
c                 6   > [         [        U ]  5         Xl        g r   )r  r   r   r<   )r   colnor8  s     r|   r   GoToColumn.__init__A  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/  rV  r  isspace)r   r  r   r  s       r|   r  GoToColumn.preParseE  s    s(8}H**H;.X]%:%:%<%<cAUY]YaYaAaq .X]%:%:%<%<cAUY]YaYaAa
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<   r"   )r   r  r   rv  thiscolnewlocr   s          r|   r  GoToColumn.parseImplN  sI    s&XX (1NPTVVxx')V%{r   )r<   r  )
r   r   r   r   r   r   r  r  r   r  r  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   iW  a  
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  r   r   rZ  r  s    r|   r   LineStart.__init__l  s    i&(.r   c                 V    [        X!5      S:X  a  U/ 4$ [        XU R                  U 5      er  )r<   r"   rZ  r  s       r|   r  LineStart.parseImplp  s+    s"7NXDKK>>r   rZ  r  r  r  s   @r|   r   r   W  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   iu  zM
Matches 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  r   r   rg  r'   rB  r   rZ  r  s    r|   r   LineEnd.__init__y  s9    gd$&!B!B!J!J4PR!SU,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/  r"   rZ  r  s       r|   r  LineEnd.parseImpl~  sf    s8}}$1ud{"$XDKKFFCM!q5"9 TBBr   r  r  r  r  s   @r|   r   r   u  s    -
	C 	C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  zE
Matches 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  r-   r   rZ  r  s    r|   r   StringStart.__init__  s    k$(*.r   c                 n    US:w  a,  X R                  US5      :w  a  [        XU R                  U 5      eU/ 4$ r   )r  r"   rZ  r  s       r|   r  StringStart.parseImpl  s6    !8mmXq22$XDKKFFBwr   r  r  r  r  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?
Matches 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  r,   r   rZ  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!q5"93x= 7N TBBr   r  r  r  r  s   @r|   r,   r,     s    -C Cr   r,   c                   <   ^  \ rS rSrSr\4U 4S jjrSS jrSrU =r	$ )r4   i  aX  
Matches if the current position is at the beginning of a Word, and
is not preceded by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{} behavior of regular expressions,
use C{WordStart(alphanums)}. C{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  r4   r   r  	wordCharsrZ  r   r  r8  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$ r.  )r  r"   rZ  r  s       r|   r  WordStart.parseImpl  sE    !8Q4>>1T^^3$XDKKFFBwr   )rZ  r  r  
r   r   r   r   r   rY   r   r  r   r  r  s   @r|   r4   r4     s     $. 3
 r   r4   c                   <   ^  \ rS rSrSr\4U 4S jjrSS jrSrU =r	$ )r3   i  aB  
Matches if the current position is at the end of a Word, and
is not followed by any character in a given set of C{wordChars}
(default=C{printables}). To emulate the C{} behavior of regular expressions,
use C{WordEnd(alphanums)}. C{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  r3   r   r  r  rQ  rZ  r  s     r|   r   WordEnd.__init__  s*    gd$&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$ r.  )r/  r  r"   rZ  )r   r  r   rv  r  s        r|   r  WordEnd.parseImpl  sR    x=A:#,/Qt~~5$XDKKFFBwr   )rZ  rQ  r  r  r  r  s   @r|   r3   r3     s     $. 1 r   r3   c                      ^  \ rS rSrSrSU 4S jjrS rS rS rU 4S jr	U 4S jr
U 4S	 jrSU 4S
 jjr/ 4S jrU 4S jrSrU =r$ )r#   i  zV
Abstract subclass of ParserElement, for combining and post-processing parsed tokens.
c                   > [         [        U ]  U5        [        U[        5      (       a  [        U5      n[        U[        5      (       a  [        R                  U5      /U l	        Os[        U[        5      (       aM  [        U5      n[        S U 5       5      (       a  [        [        R                  U5      n[        U5      U l	        O [        U5      U l	        SU l        g ! [         a    U/U l	         Nf = f)Nc              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   r  )r   r  s     r|   r   +ParseExpression.__init__.<locals>.<genexpr>  s     BED:dJ//Er  F)r  r#   r   r   r  r  r  r'   rH  exprsr   allr  r  r^  r   r  r`  r8  s      r|   r   ParseExpression.__init__  s    od,X6un..KEuj**(<<eEGDJ**KEBEBBBM==uEeDJ'!5]
 "  '$Y
's   	C! !C65C6c                      U R                   U   $ r   )r  r   s     r|   r   ParseExpression.__getitem__  s    zz!}r   c                 J    U R                   R                  U5        S U l        U $ r   )r  r~  rN  r  s     r|   r~  ParseExpression.append  s     

5"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 )zsExtends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
all contained expressions.F)rQ  r  r  rd  )r   r  s     r|   rd  ParseExpression.leaveWhitespace  sN     $)-5Avvx5
A  6s   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 $ rL  )r   r.   rV  r  r#   rm  r  )r   r  r  r8  s      r|   rm  ParseExpression.ignore  s    uh((,,,4e=AHHd..r24 $  ?D0%9ZZ$**2.0  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  r#   r   r;  rN  r8  r   r   r  r  s    r|   r   ParseExpression.__str__
  s_    	688 		 <<)-)@)@%

BSUDL||r2  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 $ )Nrv   r   r   rw   rf  )r  r#   r  r  r/  r   r8  rL  rO  rW  rN  rT  rY  r   rZ  )r   r  r  r8  s      r|   r  ParseExpression.streamline  se   od.0ALLN  _!JJqMEUNN44''##+kk"[[^

1.??
###u';';;#""u':'::"JJrNEUNN44''##+kk!ZZ_u{{1~=
###u';';;#""u':'::"!E$K/r   c                 .   > [         [        U ]  X5      nU$ r   )r  r#   rp  )r   r  rn  r   r8  s       r|   rp  ParseExpression.setResultsName6  s    OD8M
r   c                     U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.validate:  s:    Av%AJJsO R!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  r#   r  r  )r   r   r  r8  s      r|   r  ParseExpression.copy@  s:    OD.0'+zz2z!VVXz2	
 3s   A)r^  rZ  r  rQ  rN  r  )r   r   r   r   r   r   r   r~  rd  rm  r   r  rp  r  r  r   r  r  s   @r|   r#   r#     sE    "(

 D ') " r   r#   c                   b   ^  \ rS rSrSr " S S\5      rSU 4S jjrSS jrS r	S r
S	 rS
rU =r$ )r	   iE  a  
Requires all given C{ParseExpression}s to be found in the given order.
Expressions may be separated by whitespace.
May be constructed using the C{'+'} operator.
May also be constructed using the C{'-'} 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._ErrorStopiU  c                 p   > [         [        R                  U ]  " U0 UD6  SU l        U R                  5         g )N-)r  r	   r3  r   r  rd  )r   r   rp  r8  s      r|   r   And._ErrorStop.__init__V  s.    #../@@DI  "r   rz  r  r  s   @r|   r3  r  U  s    	# 	#r   r3  c                   > [         [        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 )Nc              3   8   #    U  H  oR                   v   M     g 7fr   rT  r   r  s     r|   r   And.__init__.<locals>.<genexpr>]       !GJq"2"2J   r   T)
r  r	   r   r  r  rT  rg  rR  rQ  r^  r  s      r|   r   And.__init__[  sc    c$ 1!!GDJJ!GGA!9!9;"jjm:: r   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   Fr  r   T)r  r}  r   r	   r3  r&   r    __traceback__r   r   r/  rZ  rl  )	r   r  r   rv  
resultlist	errorStopr  
exprtokensr   s	            r|   r  And.parseImplb  s    **Q-..yW\.^	ABA!S^^,, 	[&'hhy&JOC #$((H9"FZ//11(
#  $  , ) C'+B$.>>rBB! [.xXUYZZ[s    B22DC""/Dc                 x    [        U[        5      (       a  [        R                  U5      nU R	                  U5      $ r   r   r  r'   rH  r~  r  s     r|   r  And.__iadd__{  .    uj**!55u>E{{E##r   c                     US S  U /-   nU R                    H'  nUR                  U5        UR                  (       a  M'    g    g r   )r  r  rT  r   r   subRecCheckListr  s       r|   r  And.checkRecursion  s>    *1-$8Ao/### r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )Nr  {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  }rQ  r  rN  r   r  r   s    r|   r   And.__str__  sQ    499<<)GDJJ)G!GG#MDL||r   )r^  rT  rQ  rN  r  )r   r   r   r   r   r   r3  r   r  r  r  r   r   r  r  s   @r|   r	   r	   E  s2    #U #!2$
 r   r	   c                   L   ^  \ rS rSrSrS	U 4S jjrS
S jrS rS rS r	Sr
U =r$ )r   i  a  
Requires that at least one C{ParseExpression} is found.
If two expressions match, the expression that matches the longest string will be used.
May be constructed using the C{'^'} 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  rT  r  s      r|   r   Or.__init__  s8    b0::"%%K

%K"KD"&D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 S9  U H  u  p UR                  XU5      s  $    Ub  U R                  Ul        Ue[        XSU 5      e! [         a6  n	S U	l        U	R
                  U:  a  U	nU	R
                  n S n	A	M   S n	A	M  S n	A	f[         aD    [        U5      U:  a0  [        U[        U5      UR                  U 5      n[        U5      n GM
   GM  f = f! [         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f = f)Nrw   c                     U S   * $ r   r   )xs    r|   r}   Or.parseImpl.<locals>.<lambda>  s
    !ur   )rv   no defined alternatives to match)r  r  r~  r"   r  r   r   r/  rZ  sortr}  r   )r   r  r   rv  	maxExcLocmaxExceptionr  r  loc2r  _s              r|   r  Or.parseImpl  sP   	A*zz82 y)   LL_L-,88XI??  ##{{L 0RTXYY9 " ($(!77Y&#&L #I '  .x=9,#1(3x=RV#WL #HI -. & ,(,C%ww*'*$'GG	 +,s6   BD%
D" %CAD"!D"%
E'/%E""E'c                 x    [        U[        5      (       a  [        R                  U5      nU R	                  U5      $ r   r  r  s     r|   __ixor__Or.__ixor__  r  r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )Nr  r  z ^ c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r  s     r|   r   Or.__str__.<locals>.<genexpr>       +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  r  s       r|   r  Or.checkRecursion  /    *1-$8Ao/ r   rT  rN  r  r  )r   r   r   r   r   r   r  r  r   r  r   r  r  s   @r|   r   r     s(    '#ZL$
0 0r   r   c                   L   ^  \ rS rSrSrS	U 4S jjrS
S jrS rS rS r	Sr
U =r$ )r   i  a  
Requires that at least one C{ParseExpression} is found.
If two expressions match, the first one listed is the one that will match.
May be constructed using the C{'|'} 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  r   r   r  r  rT  r  s      r|   r   MatchFirst.__init__  s8    j'8::"%%K

%K"KD"&D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)Nrw   r  )r  r}  r"   r   r   r/  rZ  r   )	r   r  r   rv  r   r  r  r   r  s	            r|   r  MatchFirst.parseImpl  s    	A
.hhy:
  '#';; ""$X4VX\]] " (77Y&#&L #I '  .x=9,#1(3x=RV#WL #HI -.s   A
CBACCc                 x    [        U[        5      (       a  [        R                  U5      nU R	                  U5      $ r   r  r  s     r|   __ior__MatchFirst.__ior__  r  r   c                     [        U S5      (       a  U R                  $ U R                  c-  SSR                  S U R                   5       5      -   S-   U l        U R                  $ )Nr  r   | 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  r  s       r|   r  MatchFirst.checkRecursion  r  r   r  r  r  )r   r   r   r   r   r   r  r  r   r  r   r  r  s   @r|   r   r     s'     '^0$
0 0r   r   c                   F   ^  \ rS rSrSrSU 4S jjrSS jrS rS rSr	U =r
$ )	r   i$  a  
Requires all given C{ParseExpression}s to be found, but in any order.
Expressions may be separated by whitespace.
May be constructed using the C{'&'} 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        g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r  r  s     r|   r    Each.__init__.<locals>.<genexpr>\  r  r  T)r  r   r   r  r  rT  rQ  initExprGroupsr  s      r|   r   Each.__init__Z  s9    d4!%2!!GDJJ!GG""r   c           	      :   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 H.  oDR                  (       d  M  [	        U[
        5      (       a  M,  UPM0     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+     [/        U[1        / 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>b  s)     ]
1jQRS[F\AFFA
s   ==FTr  c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r  s     r|   r   r,    s     :'Qa'r  z*Missing one or more required elements (%s))r(  r  r  opt1mapr   r   r  rT  	optionalsr5   multioptionalsr   multirequiredrequiredr  r~  r'  r  remover"   r/  r   r}  sumr%   )r   r  r   rv  r  opt1opt2tmpLoctmpReqdtmpOpt
matchOrderkeepMatchingtmpExprsfailedmissingr  r
  finalResultss                     r|   r  Each.parseImpl`  s   ]

]]DL%)ZZKZ:a3IVQVVZDK $

^
1.>.>QzRST\G]Q
D^![DN48JJ"\Jq*QzBZFAFFJ"\D37::!Z:aAiAX6166:!ZD)-jA:aR\]fHg;hajDMMMT///M"'D--"..#
'$*=*==@R@RRHF	)ZZ;F %%dll&6&6r!uQ&?@|q)a( %  6{c(m+$ l" ii:'::G .Z]d.dff 	**\*Q
1X0Fq166U[K[q*\\

A((8	:KCg&  :|B'78L  Y L^"\!Zj & %MM!$$%  ]sf   MM?M!M!.M!M&*M&M+-M+$M0;M0 M5N5NN5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                  $ )Nr  r  z & c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r  s     r|   r   Each.__str__.<locals>.<genexpr>  r  r  r  r  r   s    r|   r   Each.__str__  r  r   c                 ^    US S  U /-   nU R                    H  nUR                  U5        M     g r   r  r  s       r|   r  Each.checkRecursion  r  r   )	r(  rT  r0  r1  r.  r/  r2  rQ  rN  r  )r   r   r   r   r   r   r  r   r  r   r  r  s   @r|   r   r   $  s#    4j#/!b0 0r   r   c                   v   ^  \ 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
/ 4S	 jrU 4S
 jrSrU =r$ )r!   i  zY
Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens.
c                 P  > [         [        U ]  U5        [        U[        5      (       aW  [        [        R                  [        5      (       a  [        R                  U5      nO[        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  r!   r   r   r  
issubclassr'   rH  r/   r   r  rN  rY  rT  rg  rR  rQ  rP  r^  rV  r  r   r  r`  r8  s      r|   r   ParseElementEnhance.__init__  s    !$0:tZ))-;;UCC$88>$88G	!%!3!3D"&"5"5D##T__6"&"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)NFr  r   )r  r}  r"   rZ  r  s       r|   r  ParseElementEnhance.parseImpl  s;    99 99##XIE#SS CD99r   c                     SU l         U R                  R                  5       U l        U R                  b  U R                  R                  5         U $ r  )rQ  r  r  rd  r   s    r|   rd  #ParseElementEnhance.leaveWhitespace  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 $ rL  )r   r.   rV  r  r!   rm  r  r  s     r|   rm  ParseElementEnhance.ignore  s    uh((,,,*D8%A99(II$$d&6&6r&:<
  &4e=yy$		  $"2"22"68r   c                 z   > [         [        U ]  5         U R                  b  U R                  R                  5         U $ r   )r  r!   r  r  r  s    r|   r  ParseElementEnhance.streamline  s0    !$24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   )r)   r  r  )r   r   r  s      r|   r  "ParseElementEnhance.checkRecursion  sK    #+-=f-DFF*1-$899 II$$o7 !r   c                     US S  U /-   nU R                   b  U R                   R                  U5        U R                  / 5        g r   r  r  r  r   r  r  s      r|   r  ParseElementEnhance.validate  s=    Av%99 IIs#R!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                  $ r  )	r  r!   r   r;  rN  r  r8  r   r   r  s    r|   r   ParseElementEnhance.__str__  si    	,T:<< 		 <<DII$9)-)@)@%		BRTDL||r2  )r^  r  rY  rT  rP  rQ  rN  r  r  )r   r   r   r   r   r   r  rd  rm  r  r  r  r   r   r  r  s   @r|   r!   r!     s:    6$:
8 ') " 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  a  
Lookahead matching of the given parse expression.  C{FollowedBy}
does I{not} advance the parsing position within the input string, it only
verifies that the specified parse expression matches at the current
position.  C{FollowedBy} always returns a null token list.

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  r   r   rT  r   r  r8  s     r|   r   FollowedBy.__init__  s    j'-"r   c                 @    U R                   R                  X5        U/ 4$ r   )r  r  r  s       r|   r  FollowedBy.parseImpl  s    		H+Bwr   r  r  r  r  s   @r|   r   r     s     # r   r   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  a  
Lookahead to disallow matching with the given parse expression.  C{NotAny}
does I{not} advance the parsing position within the input string, it only
verifies that the specified parse expression does I{not} match at the current
position.  Also, C{NotAny} does I{not} skip over leading whitespace. C{NotAny}
always returns a null token list.  May be constructed using the '~' operator.

Example::
    
c                    > [         [        U ]  U5        SU l        SU l        S[        U R                  5      -   U l        g )NFTzFound unwanted token, )r  r   r   rQ  rT  r   r  rZ  r^  s     r|   r   NotAny.__init__  s7    fT#D)#".uTYY/??r   c                 x    U R                   R                  X5      (       a  [        XU R                  U 5      eU/ 4$ r   )r  r  r"   rZ  r  s       r|   r  NotAny.parseImpl  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                  $ )Nr  z~{r  rQ  r  rN  r   r  r   s    r|   r   NotAny.__str__  sG    499<<%		"22S8DL||r   )rZ  rT  rQ  rN  r  r3  r  s   @r|   r   r     s    	@
 r   r   c                   6   ^  \ rS rSrSU 4S jjrSS jrSrU =r$ )_MultipleMatchi'  c                    > [         [        U ]  U5        SU l        Un[	        U[
        5      (       a  [        R                  U5      nUb	  U) U l        g S U l        g r  )	r  rk  r   rP  r   r  r'   rH  	not_ender)r   r  stopOnenderr8  s       r|   r   _MultipleMatch.__init__(  sO    nd,T2eZ((!55e<E#(#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NFr  )	r  r}  r  rm  r  rV  rl  r"   r   )r   r  r   rv  self_expr_parseself_skip_ignorablescheck_endertry_not_enderr  hasIgnoreExprsr  	tmptokenss               r|   r  _MultipleMatch.parseImpl0  s    ))**#33nnD0 NN33M ((%xieU	&*&6&6"6N!(0!18BF F!0(I!O	 1 1 3 3'F  z* 	{	s   (AC CC)rm  rP  r   r  )r   r   r   r   r   r  r   r  r  s   @r|   rk  rk  '  s    ? r   rk  c                       \ rS rSrSrS rSrg)r   iM  a3  
Repetition of one or more of the given expression.

Parameters:
 - expr - expression that must match one or more times
 - stopOn - (default=C{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                  $ )Nr  r  z}...rh  r   s    r|   r   OneOrMore.__str__g  G    499<<tyy!11F:DL||r   )rN  N)r   r   r   r   r   r   r   r   r   r|   r   r   M  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	$ )	r5   ip  aS  
Optional repetition of zero or more of the given expression.

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

Example: similar to L{OneOrMore}
c                 6   > [         [        U ]  XS9  SU l        g )N)rn  T)r  r5   r   rT  )r   r  rn  r8  s      r|   r   ZeroOrMore.__init__|  s    j''<"r   c                 b   >  [         [        U ]  XU5      $ ! [        [        4 a    U/ 4s $ f = fr   )r  r5   r  r"   r   )r   r  r   rv  r8  s       r|   r  ZeroOrMore.parseImpl  s9    	T4XINNz* 	7N	s    ..c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )Nr  r  ]...rh  r   s    r|   r   ZeroOrMore.__str__  r}  r   r  r   r  r3  r  s   @r|   r5   r5   p  s    
# r   r5   c                   $    \ rS rSrS r\rS rSrg)
_NullTokeni  c                     gr  r   r   s    r|   rD  _NullToken.__bool__      r   c                     gr   r   r   s    r|   r   _NullToken.__str__  s    r   r   N)r   r   r   r   rD  r  r   r   r   r   r|   r  r    s    Kr   r  c                   B   ^  \ rS rSrS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  rP  rw  rT  )r   r  ro  r8  s      r|   r   Optional.__init__  s6    ht%te%=))..#"r   c                 h    U R                   R                  XUSS9u  p$X$4$ ! [        [        4 a    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rr  )r  r}  r"   r   rw  _optionalNotMatchedrO  r%   )r   r  r   rv  r  s        r|   r  Optional.parseImpl  s    
	))**H9SX*ZKC { z* 	  (;;99(()D,=,=*?@F484E4EF99001#002F { {	s   " BB1*B10B1c                     [        U S5      (       a  U R                  $ U R                  c   S[        U R                  5      -   S-   U l        U R                  $ )Nr  r  r  rh  r   s    r|   r   Optional.__str__  sG    499<<tyy!11C7DL||r   )rw  rT  rP  rN  r  )r   r   r   r   r   r  r   r  r   r   r  r  s   @r|   r   r     s"    !D ': # 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  a7	  
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=C{False}) if True, the target expression is also parsed 
      (the skipped text and target expression are returned as a 2-element list).
 - ignore - (default=C{None}) used to define grammars (typically quoted strings and 
      comments) that might contain false matches to the target expression
 - failOn - (default=C{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  [        R                  U5      U l        OX@l        S[        U R                  5      -   U l        g )NTFzNo match found for )r  r+   r   
ignoreExprrT  rY  includeMatchrP  r   r  r'   rH  failOnr   r  rZ  )r   r  includerm  r  r8  s        r|   r   SkipTo.__init__  sm    vt&/ ""#fj))';;FCDK K+E$)),<<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)rv  rw  r  )r/  r  r}  r  r  r  r  r    r"   r   rZ  r%   r  )r   r  r   rv  r  r  r  
expr_parseself_failOn_canParseNextself_ignoreExpr_tryParsetmplocskiptext
skipresultr	  s                 r|   r  SkipTo.parseImpl  sE   x=yyYY%%
?C{{?V4;;#;#;\` ?C?Z4??#;#;`d  '3+H=='3!9(!K 8u5Q  !TBB S)!(+
!(yeLHCJ3 . 
 #J/ !!  s$   C5 "D 5
DDDD)rZ  r  r  r  rY  rT  rP  )FNNr  r  r  s   @r|   r+   r+     s    5l=- -r   r+   c                   f   ^  \ rS rSrSrSU 4S jjrS rS rS rS r	/ 4S jr
S	 rU 4S
 jrSrU =r$ )r   iJ  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 C{Forward} variable using the '<<' operator.

Note: take care when assigning to C{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 C{Forward}::
    fwdExpr << (a | b | c)
Converting to use the '<<=' operator instead will avoid this problem.

See L{ParseResults.pprint} for an example of a recursive parser created using
C{Forward}.
c                 *   > [         [        U ]  USS9  g r  )r  r   r   r  s     r|   r   Forward.__init__]  s    gd$ee$=r   c                    [        U[        5      (       a  [        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   r  r'   rH  r  rN  rY  rT  rg  rR  rQ  rP  rV  r  r  s     r|   
__lshift__Forward.__lshift__`  s    uj**!55e<E	!YY44"ii66!5!57"ii66))..		 5 56r   c                 
    X-  $ r   r   r  s     r|   __ilshift__Forward.__ilshift__m  r  r   c                     SU l         U $ r  rc  r   s    r|   rd  Forward.leaveWhitespacep  s    #r   c                     U R                   (       d.  SU l         U R                  b  U R                  R                  5         U $ r  )rX  r  r  r   s    r|   r  Forward.streamlinet  s2    #Dyy$		$$&r   c                     X;  a1  US S  U /-   nU R                   b  U R                   R                  U5        U R                  / 5        g r   rW  rX  s      r|   r  Forward.validate{  sC    $"D6)Cyy$		""3'Br   c                 n    [        U S5      (       a  U R                  $ U R                  R                  S-   $ )Nr  z: ...)rQ  r  r8  r   _revertClass_ForwardNoRecurser  r   )r   	retStrings     r|   r   Forward.__str__  s.    499~~&&00r   c                 b   > U R                   b  [        [        U ]  5       $ [        5       nX-  nU$ r   )r  r  r   r  )r   r   r8  s     r|   r  Forward.copy  s0    99 +--)CLCJr   )	r8  r  r  rY  rT  rP  rQ  rN  rX  r   )r   r   r   r   r   r   r  r  rd  r  r  r   r  r   r  r  s   @r|   r   r   J  s:    $> ')  :" r   r   c                       \ rS rSrS rSrg)r  i  c                     g)Nr-  r   r   s    r|   r   _ForwardNoRecurse.__str__  r  r   r   N)r   r   r   r   r   r   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$ )r0   i  zI
Abstract subclass of C{ParseExpression}, for converting parsed results.
c                 :   > [         [        U ]  U5        SU l        g r  )r  r0   r   rP  rJ  s      r|   r   TokenConverter.__init__  s    nT+T3r   rP  r  r  r  s   @r|   r0   r0     s       r   r0   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 C{'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   rd  adjacentrQ  
joinStringr^  )r   r  r  r  r8  s       r|   r   Combine.__init__  s;    gd$d,  " "$ r   c                 ~   > U R                   (       a  [        R                  X5        U $ [        [        U ]  U5        U $ r   )r  r'   rm  r  r   r  s     r|   rm  Combine.ignore  s5    ==  -  7D(%1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   )r  )r  r%   r   r  r  r[  rO  rl  )r   r  r   r  retTokss        r|   r  Combine.postParse  sj    .."AJ<"'')*A*A$//*R"S U]a]n]noo 1 1;Nr   )r  r^  r  rQ  )r   T)
r   r   r   r   r   r   rm  r  r   r  r  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$ )r   i  a  
Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{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  r   r   rP  r^  s     r|   r   Group.__init__  s    eD"D*r   c                     U/$ r   r   r  s       r|   r  Group.postParse  s
    }r   r  	r   r   r   r   r   r   r  r   r  r  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$ )r   i  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 L{ParseResults} of accessing fields by results name.
c                 :   > [         [        U ]  U5        SU l        g r  )r  r   r   rP  r^  s     r|   r   Dict.__init__  s    d4!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   rv   )r4  r/  r   ry   r   r   r   r%   r  rl  rO  )r   r  r   r  r   tokikey	dictvalues           r|   r  Dict.postParse  s   y)EA3x1}q6D$s##SV}**,3x{"9"Q"?	S1ZA|%D%D"9#a&"C	HHJ	aLy>A%*Y|*L*LQZQbQbQdQd&=i&JIO&=il1&MIO! *$ = r   r  r  r  s   @r|   r   r     s    "F r   r   c                   $    \ rS rSrSrS rS rSrg)r.   i)  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 L{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|   r.   r.   )  s    $r   r.   c                   *    \ rS rSrSrS rS rS rSrg)r   iC  zA
Wrapper for parse actions, to ensure they are only called once.
c                 2    [        U5      U l        SU l        g r  )r?  rL  called)r   
methodCalls     r|   r   OnlyOnce.__init__G  s    #J/r   c                 r    U R                   (       d  U R                  XU5      nSU l         U$ [        XS5      e)NTr   )r  rL  r"   )r   r   r  r{   r
  s        r|   r]  OnlyOnce.__call__J  s2    {{mmA*GDKNQ$$r   c                     SU l         g r  )r  r   s    r|   resetOnlyOnce.resetP  s	    r   )rL  r  N)	r   r   r   r   r   r   r]  r  r   r   r   r|   r   r   C  s    %r   r   c                 p   ^  [        T 5      m U 4S jn T R                  Ul        U$ ! [         a     U$ f = f)a4  
Decorator for debugging parse actions. 

When the parse action is called, this decorator will print C{">> entering I{method-name}(line:I{current_source_line}, I{parse_location}, I{matched_tokens})".}
When the parse action completes, the decorator will print C{"<<"} 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)
Nr"  rr   r   .z">>entering %s(line: '%s', %d, %r)
z
<<leaving z (exception: z)
z (ret: )r   r/  r8  r   stderrwriterJ   r;  )paArgsthisFuncr   r  r{   r   r  r  s          r|   ztraceParseAction.<locals>.zi  s    ::rsAv;q=ay**33c9HDH

?8DQRIVWBZZ\	V*C 	

EG
	  	JJ(3OQ	s   3B" "
C,)CC)r?  r   r   )r  r  s   ` r|   re   re   S  sC    * 	AAZZ
 H  Hs   ' 
55r0  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 C{combine=True} in the constructor.
If C{combine} is set to C{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   r5   ri  r.   )r  delimcombinedlNames       r|   rC   rC     sx     4[eEl*3.uT{:6AFz5<99;CCFKK
He$5$<>>HHPPr   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 C{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      -    / $ r   )r   r	   rF   )r   r  r{   r;  	arrayExprr  s       r|   countFieldParseAction+countedArray.<locals>.countFieldParseAction  s6    aDa0E#tfQh-0@E%LA	r   c                     [        U S   5      $ r   )ry   rz   s    r|   r}   countedArray.<locals>.<lambda>  s    S1Yr   arrayLenTr_  z(len) r-  )r   r2   rU   r   r  ri  r  r   )r  intExprr  r  s   `  @r|   r?   r?     s|    $ 	I t*++,>?,,.OOJ0Ey **8eDk+AE+IJJr   c                     / nU  HE  n[        U[        5      (       a  UR                  [        U5      5        M4  UR	                  U5        MG     U$ r   )r   r  r  r  r~  )Lr   r   s      r|   r  r    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 C{"1:1"}, but not C{"1:2"}.  Because this matches a
previous literal, will also match the leading C{"1:1"} in C{"1:10"}.
If this is not desired, use C{matchPreviousExpr}.
Do I{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   )r   r   tts     r|   r   DmatchPreviousLiteral.<locals>.copyTokenToRepeater.<locals>.<genexpr>  s     7272;;r  )r/  r  r  r	   r   )r   r  r{   tflatreps       r|   copyTokenToRepeater1matchPreviousLiteral.<locals>.copyTokenToRepeater  sJ    1v{qt !,s777757Nr   Tr  (prev) )r   r  ri  r   )r  r	  r  s     @r|   rR   rR     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 C{"1:1"}, but not C{"1:2"}.  Because this matches by
expressions, will I{not} match the leading C{"1:1"} in C{"1:10"};
the expressions are evaluated first, and then compared, so
C{"1"} is compared with C{"10"}.
Do I{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   )r  r  r"   )r   r  r{   theseTokensmatchTokenss       r|   mustMatchTheseTokensLmatchPreviousExpr.<locals>.copyTokenToRepeater.<locals>.mustMatchTheseTokens  s/    "188:.K{*$R"-- +r   Tr  )r  r  r   )r   r  r{   r  r  r  s       @r|   r	  .matchPreviousExpr.<locals>.copyTokenToRepeater  s.    qxxz*	. 	0Fr   Tr  r  )r   r  r  ri  r   )r  e2r	  r  s      @r|   rQ   rQ     sV     )C	BBJCG 	+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  rb  re  )r   _bslashr   )r   r   s     r|   r  r    sI    IIa	" 			$uA			$uA8Or   Tc                 j  ^
 U(       a  S nS n[         m
OS nS n[        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       $ SnU[        U5      S	-
  :  aw  XV   n[        XVS	-   S
 5       HF  u  pU" X5      (       a
  XVU-   S	-   	   O3U" Xy5      (       d  M+  XVU-   S	-   	 UR                  Xi5        U	n  O   US	-  nU[        U5      S	-
  :  a  Mw  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 C{L{MatchFirst}} for best performance.

Parameters:
 - strs - a string of space-delimited literals, or a collection of string literals
 - caseless - (default=C{False}) - treat all literals as caseless
 - useRegex - (default=C{True}) - as an optimization, will generate a Regex
      object; otherwise, will generate a C{MatchFirst} object (if C{caseless=True}, or
      if creating a C{Regex} raises an exception)

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']]
c                 D    U R                  5       UR                  5       :H  $ r   )r  r  bs     r|   r}   oneOf.<locals>.<lambda>  s    	QWWY 6r   c                 \    UR                  5       R                  U R                  5       5      $ r   )r  r  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   )r  r  s     r|   r}   r    s    all1or   z6Invalid argument to oneOf, expected string or iterablerv   r(  r   r   Nr   z[%s]c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r  r   syms     r|   r   oneOf.<locals>.<genexpr>8  s     .^V]s/Ec/J/JV]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     &I#ryy~~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"  A  s     @',,   )r   r   r   r  r   r   r  r*  r+  r,  r   r/  r4  rz  r   r*   ri  r;  r   )strsr  useRegexisequalmaskssymbolsr   curr8  r  r&  s             @r|   rV   rV     s   . 6=+&-#G$z""**,	D(	#	#t*N!	-y	A
c'l1n
j 1/GA$$aCEN$$aCENq' 0 FA c'l1n
 	17|S!122frww.^V].^'^^`hhinisist{i|}}chh&I&IIKSSTYT^T^_fTghh @@@HHT[I\]]  	1MMS!a1	1s   0A(H >H $H21H2c                 @    [        [        [        X-   5      5      5      $ )ah  
Helper to easily and clearly define a dictionary by specifying the respective patterns
for the key and value.  Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{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 C{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   r5   r   )rv  r9  s     r|   rD   rD   C  s    B US[2466r   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$ )a9  
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 C{asString} argument is passed as C{False}, then the return value is a 
C{L{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 C{L{originalTextFor}} contains expressions with defined
results names, you must set C{asString} to C{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    sr   F_original_start_original_endc                 2    XR                   UR                   $ r   )r2  r3  r   r  r{   s      r|   r}   r1    s    A&7&7$Hr   c                 P    XR                  S5      UR                  S5       /US S & g )Nr2  r3  )rs  r5  s      r|   extractText$originalTextFor.<locals>.extractText  s&    ee-.quu_/EFGAaDr   )r   r   r  r^  rV  )r  asString	locMarkerendlocMarker	matchExprr7  s         r|   rj   rj   f  su    0 &&':;I>>#L %L+,t3l?6SSIH	H[) ,,Ir   c                 8    [        U 5      R                  S 5      $ )zd
Helper to undo pyparsing's default grouping of And expressions, even
if all but one are non-empty.
c                     U S   $ r   r   rz   s    r|   r}   ungroup.<locals>.<lambda>  s    !r   )r0   r   )r  s    r|   rk   rk     s    
 $..}==r   c                     [        5       R                  S 5      n[        U" S5      U " S5      -   UR                  5       R	                  5       " S5      -   5      $ )ai  
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 C{<TAB>} characters, you may want to call
C{L{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   r5  s      r|   r}   locatedExpr.<locals>.<lambda>  s    1r   
locn_startr9  locn_end)r   r   r   r  rd  )r  locators     r|   rm   rm     sI    ( g$$_5G&g69W9W9YZd9eeffr   rF   rL   rK   rd   rc   z\[]-*.$+^?()~ r"  c                     US   S   $ r.  r   r5  s      r|   r}   r}     s    WXYZW[\]W^r   z\\0?[xX][0-9a-fA-F]+c                 P    [        [        US   R                  S5      S5      5      $ )Nr   z\0x   )unichrry   lstripr5  s      r|   r}   r}     s%    VTWXYZ[X\XcXcdjXklnToMpr   z	\\0[0-7]+c                 8    [        [        US   SS  S5      5      $ )Nr   r      )rJ  ry   r5  s      r|   r}   r}     s    &QqTRSRTXVWBYr   z\]r  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 C{\-} or C{\]})
 - an escaped hex character with a leading C{'\x'} (C{\x21}, which is a C{'!'} character) 
     (C{\0x##} is also supported for backwards compatibility) 
 - an escaped octal character with a leading C{'\0'} (C{\041}, which is a C{'!'} character)
 - a range of any of the above, separated by a dash (C{'a-z'}, etc.)
 - any combination of the above (C{'aeiouy'}, C{'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   )rJ  r   s     r|   r   +srange.<locals>.<lambda>.<locals>.<genexpr>  s     J{^zYZ6RS99^zr  r   r   )r   r%   r   r0  ord)ps    r|   r}   srange.<locals>.<lambda>  sO    :a#=#=!{277J{^cdghijkhldmnqrsturvnwxyny^zJ{C{{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>  s     V3U4y3Ur'  )r   _reBracketExprr  rO  r;  )r   rY  s    @r|   rb   rb     sH    $ |IwwV>3M3Ma3P3U3UVVV s   7> 
A
Ac                    ^  U 4S jnU$ )zh
Helper 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  )r  locnr  r;  s      r|   	verifyCol!matchOnlyAtCol.<locals>.verifyCol  s'    t>Q +Ka+OPP r   r   )r;  r_  s   ` r|   rP   rP     s    
Q r   c                    ^  U 4S j$ )a  
Helper method for common parse actions that simply return a literal value.  Especially
useful when used with C{L{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>  s    'r   r   )rc  s   `r|   r_   r_     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   rw   r   r5  s      r|   r]   r]     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 C{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 L{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   r  s       r|   r  tokenMap.<locals>.pa  s%    ./0adT!D!a000s   r   r8  )r:  r   r;  r   )r  r   r  r>  s   ``  r|   rp   rp     sS    @1D*#D+6??A	 KI	  I	s   !4 AAc                 4    [        U 5      R                  5       $ r   r   r  rz   s    r|   r}   r}   "  s    %(.."2r   c                 4    [        U 5      R                  5       $ r   r   lowerrz   s    r|   r}   r}   %  s    E!HNN$4r   c                 ~   [        U [        5      (       a  U n[        X(       + S9n OU R                  n[	        [
        [        S-   5      nU(       a  [        R                  5       R                  [        5      n[        S5      U " S5      -   [        [        [        U[        S5      -   U-   5      5      5      -   [        SS/S9R!                  S	5      R                  S
 5      -   [        S5      -   nOSR#                  S [$         5       5      n[&        R                  5       R                  [        5      [	        U5      -  n[        S5      U " S5      -   [        [        [        UR                  [(        5      [        [        S5      U-   5      -   5      5      5      -   [        SS/S9R!                  S	5      R                  S 5      -   [        S5      -   n[+        [-        S5      U -   S-   5      nUR!                  SSR#                  UR/                  SS5      R1                  5       R3                  5       5      -   5      R5                  SU-  5      nUR!                  SSR#                  UR/                  SS5      R1                  5       R3                  5       5      -   5      R5                  SU-  5      nX%l        X'l        XW4$ )zRInternal helper to construct opening and closing tag expressions, given a tag namer  z_-:r  tag=/Fro  rF   c                     US   S:H  $ Nr   rr  r   r5  s      r|   r}   _makeTags.<locals>.<lambda>5      bcdebfhkbkr   r  r   c              3   4   #    U  H  oS ;  d  M
  Uv   M     g7f)r  Nr   r   s     r|   r   _makeTags.<locals>.<genexpr>7  s     'N:a#:s   		c                     US   S:H  $ ru  r   r5  s      r|   r}   rv  <  rw  r   r  r  :r  z<%s>r%  z</%s>)r   r  r   r  r2   r7   r6   rA   r  r   r]   r.   r   r5   r   r   rp  r   rY   r\   rE   r   _Lr   titler   ri  rp  )tagStrxmlresnametagAttrNametagAttrValueopenTagprintablesLessRAbrackcloseTags           r|   	_makeTagsr  (  sU   &$$'2++vio.K&++-<<lL3-&-/Z{Xc]'B\'Q STUVeW-<<WETTUklmowx{o|} !#'N:'N N#((*99<IDQfLgg3-&-/Z{'A'A.'Q(3-,68(9 !; < == eW-<<WETTUklm pxx{o|} r$x&(3./H$$WRWWW__S5M5S5S5U5[5[5]-^%^_gghnqxhxyG&&uRWWW__S5M5S5S5U5[5[5]-^'^_gghoryhyzHKL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="http://pyparsing.wikispaces.com">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 -> http://pyparsing.wikispaces.com
Fr  r~  s    r|   rN   rN   E  s    " fe%%r   c                     [        U S5      $ )z
Helper 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 L{makeHTMLTags}
Tr  r  s    r|   rO   rO   X  s     fd$$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 C{L{makeXMLTags}} or C{L{makeHTMLTags}}. Use C{withAttribute} to qualify a starting tag
with a required attribute value, to avoid false matches on common tags such as
C{<TD>} or C{<DIV>}.

Call C{withAttribute} with a series of attribute names and values. Specify the list
of filter attributes names and values as:
 - keyword arguments, as in C{(align="right")}, or
 - as an explicit dict with C{**} operator, when an attribute name is also a Python
      reserved word, as in C{**{"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 C{class} (with or without a namespace), use C{L{withClass}}.

To verify that the attribute exists, but without specifying a value, pass
C{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 '')r"   rh   	ANY_VALUE)r   r  r  attrName	attrValueattrss        r|   r  withAttribute.<locals>.pa  sd    "'H%$Q)AH)LMMM3338HI8U$Qq-5v7G*T U U	 #(r   )r3  )r   attrDictr)  r$  r  r  s        @r|   rh   rh   a  sH    d Q #$esqaUe$EU I %s   ?c                 6    U(       a  SU-  OSn[        S0 X 0D6$ )as  
Simplified version of C{L{withAttribute}} when matching on a div class - made
difficult because C{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   )rh   )	classname	namespace	classattrs      r|   rn   rn     s$    @ +4
Y&I3I233r   r  r  c           	         [        5       nXU-   U-   -  n[        U5       GH  u  pgU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'  [        XX-   5      [        U[        U5      -   5      -   nGOU	S:X  aV  Ub,  [        XX-   U-   5      [        U[        X-   5      -   5      -   nGOn[        XU-   5      [        U[        U5      -   5      -   nGOGU	S:X  a0  [        UW-   U-   W-   U-   5      [        X]-   U-   U-   U-   5      -   nGO[        S
5      eU
[
        R                  :X  a  U	S	:X  aG  [        U[        5      (       d  [        U5      n[        UR                  U-   5      [        X-   5      -   nOU	S:X  aT  Ub+  [        XX-   U-   5      [        U[        X-   5      -   5      -   nOq[        X_-   5      [        U[        U5      -   5      -   nOKU	S:X  a/  [        UW-   U-   W-   U-   5      [        X]-   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     XE-  nU$ )ah	  
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 L{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 C{opAssoc.RIGHT} and C{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 C{setParseAction(*fn)} (L{ParserElement.setParseAction})
 - lpar - expression for matching left-parentheses (default=C{Suppress('(')})
 - rpar - expression for matching right-parentheses (default=C{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]]]
r   Nr,  rr   z%s termz	%s%s termrv   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)r   r4  r/  r?  ri  rW   LEFTr   r   r   RIGHTr   r   r  r>  r  r   )baseExpropListlparrparr   lastExprr   operDefopExprarityrightLeftAssocr  termNameopExpr1opExpr2thisExprr<  s                    r|   rl   rl     s   z )C3J-/Hv&	*1G*;Ra)@&^).9v%f8LA:~V!1 !cdd%G9$$X.W\\)z&x'89E8iY_NaCa<cc	!% *8+<x+G H5RZ]fhnhy]{R{K} }I *8+< =xR[\dReGe@g gI!&x''9H'Dw'NQY'YZ!8#5#@7#JX#UWX	 !!YZZw}},z!&(33%f-F&v{{X'=>HYA[[	!% *8+<x+G H5RZ]fhnhy]{R{K} }I *8+> ?%T]_gTiIiBk kI!&x''9H'Dw'NQY'YZ!8#5#@7#JX#UWX	 !!YZZQRR"udm,,(("-((,y((2X=?[ '\ 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]+)))*r  z string enclosed in single quotesz*quotedString using single or double quotesuzunicode string literalc           
      j   X:X  a  [        S5      eUGc  [        U [        5      (       Gaq  [        U[        5      (       Ga[  [        U 5      S:X  a  [        U5      S:X  a  UbE  [	        [        U) [        X-   [        R                  -   SS9-   5      5      R                  S 5      nGO [        R                  5       [        X-   [        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=C{"("}); can also be a pyparsing expression
 - closer - closing character for a nested list (default=C{")"}); can also be a pyparsing expression
 - content - expression for items within the nested lists (default=C{None})
 - ignoreExpr - expression for ignoring opening and closing delimiters (default=C{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 C{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 C{L{Or}} or C{L{MatchFirst}}.
The default is L{quotedString}, but if no expressions are to be ignored,
then pass C{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   rF  c                 (    U S   R                  5       $ r   r   rz   s    r|   r}   nestedExpr.<locals>.<lambda>      !A$**,r   c                 (    U S   R                  5       $ r   r  rz   s    r|   r}   r    r  r   c                 (    U S   R                  5       $ r   r  rz   s    r|   r}   r    r  r   c                 (    U S   R                  5       $ r   r  rz   s    r|   r}   r    r  r   zOopening and closing arguments must be strings if no content expression is givenznested z expression)r?  r   r  r/  r   r   r   r'   rB  r   rF   r  r   r   r   r.   r5   ri  )openerclosercontentr  r   s        r|   rS   rS   B  s   t IJJfZ((Zz-J-J6{aCKN)&y*$.v}]=^=^/^ef$g2h (i  ""0.1F"G   %zz|Jv}]EfEf7f -""0.1F"G HG )&y*%,V_$4258?7G2H$.}/P/PWX$Y2Z ([  " #1.1F"G 
  'y'&/1AWV_DT1T$.}/P/PWX$Y2Z ([  ""0.1F"G  noo
)Cx'*j6F6P*RRU]^dUeeggx'*cm*EERXIYY[[KKF6:;Jr   c           	        ^ U4S jnU4S jnU4S jn[        [        5       R                  S5      R                  5       5      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(       a?  [        [        U5      U-   [        U[        U 5      -   [        U5      -   5      -   U	-   5      n
O8[        [        U5      [        U[        U 5      -   [        U5      -   5      -   5      n
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
        the current level; set to False for block of left-most statements
        (default=C{True})

A valid block must contain at least one C{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']]]]]]] 
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 )Nrw   zillegal nestingznot a peer entry)r/  r<   r$   r"   r   r  r{   curColindentStacks       r|   checkPeerIndent&indentedBlock.<locals>.checkPeerIndent  sR    A;Q[_$B')!.?@@ %788 %r   c                 h   > [        X5      nUTS   :  a  TR                  U5        g [        XS5      e)Nrw   znot a subentry)r<   r~  r"   r  s       r|   checkSubIndent%indentedBlock.<locals>.checkSubIndent  s4    QKO#( %566r   c                    > U[        U 5      :  a  g [        X5      nT(       a  UTS   :  a	  UTS   ::  d  [        XS5      eTR                  5         g )Nrw   r#  znot an unindent)r/  r<   r"   rs  r  s       r|   checkUnindent$indentedBlock.<locals>.checkUnindent  sK    A;QvB7FkRTo<U %677r   z	 INDENTr   UNINDENTzindented block)r   r   rg  r`  r   r   ri  r   r   rm  r  )blockStatementExprr  r  r  r  r  r  r  PEERUNDENTsmExprs    `         r|   ri   ri     s4   \97 
79//6??A	BBg..~>>GGQFW##O4<<R@DW##M2:::FF.@(A!AHRL!PRTV\] ^ u%7888B<GIK M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'  entityrz   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 commentr   		commaItemrs  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);rq   i4  a	  
Here are some common low-level expressions that may be useful in jump-starting parser development:
 - numeric forms (L{integers<integer>}, L{reals<real>}, L{scientific notation<sci_real>})
 - common L{programming identifiers<identifier>}
 - network addresses (L{MAC<mac_address>}, L{IPv4<ipv4_address>}, L{IPv6<ipv6_address>})
 - ISO8601 L{dates<iso8601_date>} and L{datetime<iso8601_datetime>}
 - L{UUID<uuid>}
 - L{comma-separated list<comma_separated_list>}
Parse actions:
 - C{L{convertToInteger}}
 - C{L{convertToFloat}}
 - C{L{convertToDate}}
 - C{L{convertToDatetime}}
 - C{L{stripHTMLTags}}
 - C{L{upcaseTokens}}
 - C{L{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 integerrI  z[+-]?\d+zsigned integerrr  fractionc                     U S   U S   -  $ )Nr   rw   r   rz   s    r|   r}   pyparsing_common.<lambda>  s    ad1R5jr   r  z"fraction or mixed integer-fractionz[+-]?\d+\.\d*zreal numberz+[+-]?\d+([eE][+-]?\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   r0  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  )rq   
_ipv6_partr  r  s     r|   r   ,pyparsing_common.<lambda>.<locals>.<genexpr>  s'     2lqDTD_D_DgDghjDk11qs   (7	7rM  )r4  rz   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=C{"%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r   )r   strptimedater?  r"   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=C{"%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r   )r   r  r?  r"   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="http://pyparsing.wikispaces.com">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) # -> 'More info at the pyparsing wiki page'
r   )rq   _html_stripperr   )r   r  r  s      r|   stripHTMLTagspyparsing_common.stripHTMLTags+  s      ..>>vayIIr   r0  r  r  r  r   rs  zcomma separated listc                 4    [        U 5      R                  5       $ r   rk  rz   s    r|   r}   r  ?  s    58>>3Cr   c                 4    [        U 5      R                  5       $ r   rm  rz   s    r|   r}   r  B  s    U1X^^5Er   r   N)z%Y-%m-%d)z%Y-%m-%dT%H:%M:%S.%f)Ar   r   r   r   r   rp   ry   convertToIntegerfloatconvertToFloatr2   rU   ri  r   r  rG   r  r*   signed_integerr  r  r   r`  mixed_integerr4  realsci_realr  numberr  r7   r6   r  ipv4_addressr  _full_ipv6_address_short_ipv6_addressr  _mixed_ipv6_addressr   ipv6_addressmac_addressr  r  r  iso8601_dateiso8601_datetimeuuidr:   r9   r  r  r   r   r   rY   r1   _commasepitemrC   r\   r  comma_separated_listrg   rE   r   r   r   r|   rq   rq   4  s   EN  } e_N 4j  +::;KLGDw-''6EEhsSUFVWK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  %!"**=9HHXDLCDLLMst  D  D  ES  THn o.::<FG45==iHWWXfgG3fSj)C-088FJdghppq  AL1*+33MBJ$j(8!';;DDEXY#J#
2BE1I$IJTQT\]gknq{k{  ~C  kC  ^C  UD  D  M  M  Nb  c$$%pq$|3<<=QR.1DDGZZccdrst||  ~L  ML/UV^^_lmKF *  * ST\\]klL"  g  h  p  p  qC  D ZFGOOPVWD4((*[-A-A-CCNJ J Iws|mwyj&@4
adCe&e*2E%L*B'C E GGQz|T[T[\gTh ((L4E4E4G-4Wac*dfnn  pF  Gd)C DEL7!(+E"FGN7r   rq   __main__selectfromr  r  )r  columnsrl  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
        )rv   )r0  Fr   )FTr  r  )r   __version____versionTime__r   weakrefr   r(  r  r   r*  r]  r  r  r'  r  r   _threadr   ImportError	threadingcollections.abcr   r   r   r  ordereddict__all__r>  version_infor&  r  maxsizer  r   r  chrrJ  r   r4  r/  r  reversedr  r  r  r  r   r!  r9  maxintxranger0  __builtin__r   fnamer~  r:  r   r   r  r   r  r   ascii_uppercaseascii_lowercaser7   rU   rG   r6   r  r   	printablerY   r;  r    r"   r$   r&   r)   r   r%   registerr<   rM   rJ   r  r  r  rT   r?  r'   r/   r   r   r   r|  rH  r   r   r
   ro   r2   r*   r(   r   r1   r  r   r   r   r-   r,   r4   r3   r#   r	   r   r   r   r!   r   r   rk  r   r5   r  r  r   r+   r   r  r0   r   r   r   r.   r   re   rC   r?   r  rR   rQ   r  rV   rD   rj   rk   rm   ri  rF   rL   rK   rd   rc   r   _escapedPunc_escapedHexChar_escapedOctChar_singleChar
_charRangerp  r[  rb   rP   r_   r]   rp   rg   rE   r  rN   rO   rh   r  rn   rW   r  r  rl   rX   rA   ra   r\   rf   rS   ri   r8   rZ   r:   r9   r  r   r  ra  r>   r^   r;   rH   rd  r`   rB   r@   rI   r[   r  r  r=   rq   r   selectToken	fromTokenident
columnNamecolumnNameList
columnSpec	tableNametableNameList	simpleSQLr  r  r  r  r  r  r   r   r|   <module>r1     s[  61 h )     
  	      +(.7* s''(!,aA{{HJFE c68T5#sCQTVYZ zzHE3* IOOQ	$$W[%?@ R +%(+,	 	 ##f&<&<<N"d]	WWWO 0 0OO
6; 6;p	' 	*	, 	
	. 	&H	 H#f #@
56 @
5D    %S
&yC-	4 D>@j#F j#Z'5M 5#E #?e ?%?e %?L $+ !?.e ?.B?g ?.?g ?$:? :?z\5 \~d'E d'LF5 FRE EN0(E 0(f#U # 4? ?<Cn C(. C C$ (n .nm n`I/ IXL0 L0^A0 A0Hy0? y0xJ- JZ$ 4  @$( $L! !F >  !l >" >@q  qfO! Ob  (  *n *XN *>> >B~ 4v  'XQ&K>88G^R!7F#J>g2 goog&k!!+.	i	*m##M2k!!+.	W/q:IIJ^_/0??@pq%445YZ_,>EYZA[[;#.<=
 < <X FFPY[ehs[sPuIw  JG  JG  HN  JO  O  RU  U0#*X 23 45 B:&&%>~ !( !4F ,x*23-hsm n` #  [% WXY\\]ee  gI  J% WXY\\]ee  gI  JuTUVYYTUVYYZ [[b[b  dP  \Q 3,"3"3"556>>?WX#t@Q@Q@S Xtp,d :;
,-%d6)D.&A&I&I)&TU 
;c4::<YGH#((>3F3F3H*II4OPXXYmn (
 56=>FFGXY "&'//? %5\))+33NC
,-55lC 0% 784?PQYYZmn E"  6]**+AB  /	$z"D"*DK-4S\M-:=DYJ-G #I#I K MMWZ\ZaZabmZn  #Hl.?.?.AM.Q[]$^`hhi}~ ZO8 O8d 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 Mo      +$**+  ;; L  		s^   f	 f f5 g	fff21f25g<gggggg$#g$