/ lib / setuptools / _vendor / pyparsing / core.pyc
core.pyc
   1  o

   2  ���c>A�
@s�UddlZddlZddlmZmZmZmZmZmZmZm	Z	m
   3  Z
   4  mZddlm
Z
mZddlmZddlZddlZddlZddlZddlZddlmZddlZddlZddlmZddlmZddlmZdd	l m!Z!d
   5  dl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z+m,Z-d
   6  dl.Td
   7  dl/Td
   8  d
l0m1Z1m2Z2d
   9  dl3m4Z4ej5Z6e7e8fZ9ee:dfe;d<ej<dkr�ddlm=Z=nGdd�d�Z=Gdd�de%�Z>Gdd�de%�Z?Gdd�de�Z@de@ddfdd�ZAde@ddfdd �ZBd�d!d"�ZC[%d#eje7d$ejDe7deEfd%d&�ZFeFejGejH�Id'���reC�eJeKeLeMeNeOePeQeReSeThZUejVZWeegefee1gefeeXe1gefee7eXe1geffZYeegeEfee1geEfeeXe1geEfee7eXe1geEffZZee7eXd(e[gdfZ\ee7eXd(eEgdfZ]ee7eXeXd(e1eEgdfZ^ee7eXd(e[eEgdfZ_ej`ejaZbe4jcjdZde4jcjeZed)Zfefd*ZgebefZhd+�id,d-�ejjD��Zkdalejme;d.<d�d0d1�Zn	2d�d3eZd4e7d5eEdeYfd6d7�Zo	2d�d8e7d9eXd:d(d;eEfd<d=�Zp	2d�d8e7d>eXd?eXd:d(d@e1d;eEfdAdB�Zq	2d�d8e7d9eXd:d(dCe[d;eEf
  10  dDdE�ZrdFdG�ZsGdHd(�d(e
�ZtGdIdJ�dJet�ZuGdKdL�dLet�ZvGdMdN�dNev�ZwGdOdP�dPev�ZxGdQdR�dRev�ZyGdSdT�dTey�Zzeyet_{GdUdV�dVev�Z|GdWdX�dXey�Z}GdYdZ�dZe|�Z~Gd[d\�d\ev�ZGd]d^�d^ev�Z�Gd_d`�d`e��Z�Gdadb�dbe��Z�Gdcdd�ddev�Z�Gdedf�dfev�Z�Gdgdh�dhev�Z�Gdidj�djev�Z�Gdkdl�dlev�Z�Gdmdn�dne��Z�Gdodp�dpe��Z�Gdqdr�dre��Z�Gdsdt�dte��Z�Gdudv�dve��Z�Gdwdx�dxe��Z�Gdydz�dze��Z�Gd{d|�d|et�Z�Gd}d~�d~e��Z�Gdd��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�et�Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d��Z�Gd�d��d�e��Z�e�ZDGd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�d�eYdeYfd�d��Z�ew���d��Z�e����d��Z�e����d��Z�e����d��Z�e����d��Z�e�e(d�d�d����d�d���Z�e�d����d�d���Z�e�d����d�d���Z�e�e�Be�Be�d�d
  11  d��BZ�e�e�e�d��e��Z�eyd��e�d����d¡e�e�e�e�B����dád�Z�d�e7de7fd�dDŽZ�deYfd�dɄZ�d�d�d˄Z�e�e�d̃d����dΡZ�e�e�dσd����dѡZ�e�e�d̃d�e�dσd�B���dҡZ�e�d�e������dԡZ�e�dՃZ�e�dփZ�d�d-�e�����D�Z�eete;d�<e�Z�eoZ�esZ�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�e�Z�dS)��N)
  12  13  NamedTuple�Union�Callable�Any�	Generator�Tuple�List�TextIO�Set�Sequence)�ABC�abstractmethod)�Enum)�Iterable)�
  14  itemgetter)�wraps)�RLock)�Path�)	�
  15  _FifoCache�_UnboundedCache�__config_flags�_collapse_string_to_ranges�_escape_regex_range_chars�_bslash�_flatten�LRUMemo�
UnboundedMemo)�*)�ParseResults�_ParseResultsWithOffset)�pyparsing_unicode.�str_type)��)�cached_propertyc@seZdZdd�Zddd�ZdS)r%cCs
  16  ||_dS�N)�_func)�self�func�r*��C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\site-packages\setuptools\_vendor\pyparsing\core.py�__init__Q�
  17  zcached_property.__init__NcCs|�|�}|j|jj<|Sr&)r'�__dict__�__name__)r(�instance�owner�retr*r*r+�__get__Tszcached_property.__get__r&)r/�
  18  __module__�__qualname__r,r3r*r*r*r+r%Psr%c@s0eZdZdZdZdZdd�e�D�Zd��Z	dS)�
  19  __compat__aJ
  20      A cross-version compatibility configuration for pyparsing features that will be
  21      released in a future version. By setting values in this configuration to True,
  22      those features can be enabled in prior versions for compatibility development
  23      and testing.
  24  
  25      - ``collect_all_And_tokens`` - flag to enable fix for Issue #63 that fixes erroneous grouping
  26        of results names when an :class:`And` expression is nested within an :class:`Or` or :class:`MatchFirst`;
  27        maintained for compatibility, but setting to ``False`` no longer restores pre-2.3.1
  28        behavior
  29      �
compatibilityTcC�g|]	}|�d�s|�qS��_��
  30  startswith��.0�__r*r*r+�
  31  <listcomp>j�z__compat__.<listcomp>z(
  32          collect_all_And_tokens
  33          N)
  34  r/r4r5�__doc__�
  35  _type_desc�collect_all_And_tokens�locals�
  36  _all_names�split�_fixed_namesr*r*r*r+r6Ys�r6c@sjeZdZdZdZdZdZdZdZdZ	dZ
  37  dZdd�e�D�Z
dd�e
D�Zdd�e
D�Zedd	d
  38  ��ZdS)�__diag__�
  39  diagnosticFcCr8r9r;r=r*r*r+r@|rAz__diag__.<listcomp>cC�g|]	}|�d�r|�qS)�warnr;�r>�namer*r*r+r@}rAcCrK)�enable_debugr;rMr*r*r+r@~rA�returnNcCs|jD]}|�|�qdSr&)�_warning_names�enable)�clsrNr*r*r+�enable_all_warnings�s
  40  �z__diag__.enable_all_warnings�rPN)r/r4r5rC�)warn_multiple_tokens_in_named_alternation�)warn_ungrouped_named_tokens_in_collection�warn_name_set_on_empty_Forward�!warn_on_parse_using_empty_Forward�warn_on_assignment_to_Forward�%warn_on_multiple_string_args_to_oneof�(warn_on_match_first_with_lshift_operator�!enable_debug_on_named_expressionsrErFrQ�_debug_names�classmethodrTr*r*r*r+rIpsrIc@s0eZdZdZdZdZdZdZdZdZ	dZ
  41  d	Zd
  42  S)�Diagnosticsa�
  43      Diagnostic configuration (all default to disabled)
  44      - ``warn_multiple_tokens_in_named_alternation`` - flag to enable warnings when a results
  45        name is defined on a :class:`MatchFirst` or :class:`Or` expression with one or more :class:`And` subexpressions
  46      - ``warn_ungrouped_named_tokens_in_collection`` - flag to enable warnings when a results
  47        name is defined on a containing expression with ungrouped subexpressions that also
  48        have results names
  49      - ``warn_name_set_on_empty_Forward`` - flag to enable warnings when a :class:`Forward` is defined
  50        with a results name, but has no contents defined
  51      - ``warn_on_parse_using_empty_Forward`` - flag to enable warnings when a :class:`Forward` is
  52        defined in a grammar but has never had an expression attached to it
  53      - ``warn_on_assignment_to_Forward`` - flag to enable warnings when a :class:`Forward` is defined
  54        but is overwritten by assigning using ``'='`` instead of ``'<<='`` or ``'<<'``
  55      - ``warn_on_multiple_string_args_to_oneof`` - flag to enable warnings when :class:`one_of` is
  56        incorrectly called with multiple str arguments
  57      - ``enable_debug_on_named_expressions`` - flag to auto-enable debug on all subsequent
  58        calls to :class:`ParserElement.set_name`
  59  
  60      Diagnostics are enabled/disabled by calling :class:`enable_diag` and :class:`disable_diag`.
  61      All warnings can be enabled by calling :class:`enable_all_warnings`.
  62      rr�r#����N)r/r4r5rBrVrWrXrYrZr[r\r]r*r*r*r+r`�sr`�	diag_enumrPcC�t�|j�dS)zO
  63      Enable a global pyparsing diagnostic flag (see :class:`Diagnostics`).
  64      N)rIrRrN�rfr*r*r+�enable_diag��ricCrg)zP
  65      Disable a global pyparsing diagnostic flag (see :class:`Diagnostics`).
  66      N)rI�disablerNrhr*r*r+�disable_diag�rjrlcCst��dS)zU
  67      Enable all global pyparsing diagnostic warnings (see :class:`Diagnostics`).
  68      N)rIrTr*r*r*r+rT�srT�cmd_line_warn_options�warn_env_varc	Csxt|�}|D]3}|d�d�dd�\}}}}}|���d�s,|s%|s%|r)|dkr,d}q|���d�r9|dvr9d}q|S)	Nz::::�:rc�i�	pyparsingT)rq�F)�boolrG�lowerr<)	rmrnrR�warn_opt�w_action�	w_message�
  69  w_category�w_module�w_liner*r*r+�_should_enable_warnings�s(������r{�PYPARSINGENABLEALLWARNINGS�
ParserElement�
  70  0123456789�ABCDEFabcdefrrcCsg|]	}|tjvr|�qSr*)�string�
  71  whitespace�r>�cr*r*r+r@rAr@�_trim_arity_call_liner#cs��tvr
  72  �fdd�Sd�d�ddd��d}tptjdd	�d
  73  atdtd|f�������fdd
�}t�dt�d�j�}||_�j|_|S)zAdecorator to trim function calls to match the arity of the targetcs�|�Sr&r*��s�l�t)r)r*r+�<lambda>�z_trim_arity.<locals>.<lambda>rFcSs$tj||d�}|d}|dd�gS)N��limit�����ra)�	traceback�
  74  extract_tb)�tbr��frames�
frame_summaryr*r*r+r�sz_trim_arity.<locals>.extract_tbrerar�r�rc
  75  s�	z
�|�d��}d�|WSty@}z&�r�|j}�|dd�ddd��k}~|r;��kr;�d7�WYd}~q�d}~ww)NrTrar�r�)�	TypeError�
__traceback__)�argsr2�ter��trim_arity_type_error�r��found_arityr)r��	max_limit�pa_call_line_synthr*r+�wrappers&���z_trim_arity.<locals>.wrapperr/�	__class__N�r)�_single_arg_builtinsr�r��
extract_stack�getattrr/rB)r)r��	LINE_DIFFr��	func_namer*r�r+�_trim_aritys
  76  	r�F�fn�message�fatalcs@|dur|nd�|rtnt�t���t�����fdd��}|S)aC
  77      Function to convert a simple predicate function that returns ``True`` or ``False``
  78      into a parse action. Can be used in places when a parse action is required
  79      and :class:`ParserElement.add_condition` cannot be used (such as when adding a condition
  80      to an operator level in :class:`infix_notation`).
  81  
  82      Optional keyword arguments:
  83  
  84      - ``message`` - define a custom message to be used in the raised exception
  85      - ``fatal`` - if True, will raise :class:`ParseFatalException` to stop parsing immediately;
  86        otherwise will raise :class:`ParseException`
  87  
  88      Nzfailed user-defined conditioncs t�|||��s�||���dSr&)rsr���exc_typer��msgr*r+�paVs�z%condition_as_parse_action.<locals>.pa)�ParseFatalException�ParseExceptionr�r)r�r�r�r�r*r�r+�condition_as_parse_actionBsr��instring�loc�expr�	cache_hitc
CsJ|rdnd}td�|||t||�t||�t||�dt||�d��dS)Nrrrz&{}Match {} at loc {}({},{})
  89    {}
  90    {}^� r)�print�format�lineno�col�line)r�r�r�r��
cache_hit_strr*r*r+�_default_start_debug_action^s��r��startloc�endloc�tokscCs&|rdnd}td�|||����dS)Nrrrz{}Matched {} -> {})r�r��as_list)r�r�r�r�r�r�r�r*r*r+�_default_success_debug_actionqsr��exccCs*|rdnd}td�||t|�j|��dS)Nrrrz {}Match {} failed, {} raised: {})r�r��typer/)r�r�r�r�r�r�r*r*r+�_default_exception_debug_action}s��r�cG�dS)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nr*)r�r*r*r+�null_debug_action��r�c'@s�eZdZUdZdZeed<dZeed<dZ	e
  91  jeed<e
ded	dfd
  92  d��Ze
ded	dfd
d��ZGdd�de�Zd�defdd�Zded	dfdd�Zd�dd�Z	d�dd�dededed	dfdd�Zd�dd �Zd�d"ed	dfd#d$�Zd%ed	dfd&d'�Zd%ed	dfd(d)�Zd%ed	dfd*d+�Zd,ed	dfd-d.�Zd/d0�Z d1d2�Z!d�d3d4�Z"d5d6�Z#	!d�d	e$e%e&ffd7d8�Z'd�d9ed:e%d;ed	e%fd<d=�Z(d9ed:e%d	efd>d?�Z)e*�Z+iZ,e
  93  j-e$e%d@efe$e%e.e&e/fffedA<iZ0e*�Z1dBdBgZ2	!d�d	e$e%e&ffdCdD�Z3e'Z4e
d�dEdF��Z5dZ6dZ7e
d�dGdH��Z8e
	d�ddI�dJe
  94  je%d	dfdKdL��Z9e
d�ddI�dJe%dNed	dfdOdP��Z:	d�ddQ�d9edRedSed	e&fdTdU�Z;e<dfde<dV�d9edWe%dXedYedZe%d	e=e$e&e%e%fddffd[d\�Z>dd]�d9edYed	efd^d_�Z?e<fde<dV�d9edWe%dYedZe%d	e&f
  95  d`da�Z@e<dfddb�d9edce%dded	e=eddffdedf�ZAd�dgdh�ZBd�didj�ZCd�dkdl�ZDd�dmdn�ZEd�dodp�ZFd�dqdr�ZGd�dsdt�ZHd�dudv�ZId�dwdx�ZJd�dydz�ZKd�d{d|�ZLd�d}d~�ZMd�dd��ZNdZOd�d��ZPd�ded	dfd�d��ZQd�d�d��ZRd�d�ed	dfd�d��ZSd�d�ed	dfd�d��ZT	d�de.eUeefd�ed	dfd�d��ZVd�d�d��ZWd�d�d��ZXd�eYd�eZd�e[d	dfd�d��Z\d�d�ed	dfd�d��Z]e^d	efd�d���Z_e`d�d���Zaded	dfd�d��Zbe^d	efd�d���Zcd	efd�d��Zdd	efd�d��Zed�d�d��Zfd	egdfd�d��Zhd�d��Zid�d�d�d��Zj	�	d�ddQ�d�e.eekelfd�edRedSed	e&f
  96  d�d��Zmd�d��Znd�d��Zo	!d�d!dQ�d�edRedSed	efd�d��Zp	!	�	!	!				d�d!d!d!ddd��d�e.eeqefdRed�e
  97  je.defd�ed�ed�ed�eree&gefd�e
  98  jeld�edSed�ed�ed�ed�eree&gefd	e$eeqe$ee.e&e/ffffd�d˄Zs	�		d�d�e.elekefd�e%d�ed�ed	df
  99  d�d҄ZteZueZveZweZxeZyeZzeZ{eZ|e(Z}e)Z~e5Ze9Z�e:Z�e;Z�e>Z�e@Z�e?Z�eVZ�eWZ�e\Z�e]Z�e_Z�ebZ�emZ�esZ�eSZ�eTZ�dS)�r}z)Abstract base level parser element class.z 
 100  	
�DEFAULT_WHITE_CHARSF�verbose_stacktraceN�_literalStringClass�charsrPcCs$|t_tD]
 101  }|jrt|�|_qdS)a�
 102          Overrides the default whitespace chars
 103  
 104          Example::
 105  
 106              # default whitespace chars are space, <TAB> and newline
 107              Word(alphas)[1, ...].parse_string("abc def\nghi jkl")  # -> ['abc', 'def', 'ghi', 'jkl']
 108  
 109              # change to just treat newline as significant
 110              ParserElement.set_default_whitespace_chars(" \t")
 111              Word(alphas)[1, ...].parse_string("abc def\nghi jkl")  # -> ['abc', 'def']
 112          N)r}r��_builtin_exprs�copyDefaultWhiteChars�set�
 113  whiteChars)r�r�r*r*r+�set_default_whitespace_chars�s
 114  ��z*ParserElement.set_default_whitespace_charsrScC�
 115  |t_dS)al
 116          Set class to be used for inclusion of string literals into a parser.
 117  
 118          Example::
 119  
 120              # default literal class used is Literal
 121              integer = Word(nums)
 122              date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
 123  
 124              date_str.parse_string("1999/12/31")  # -> ['1999', '/', '12', '/', '31']
 125  
 126  
 127              # change to Suppress
 128              ParserElement.inline_literals_using(Suppress)
 129              date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
 130  
 131              date_str.parse_string("1999/12/31")  # -> ['1999', '12', '31']
 132          N)r}r�)rSr*r*r+�inline_literals_using�s
 133  z#ParserElement.inline_literals_usingc@s8eZdZUejeed<ejeed<ejeed<dS)zParserElement.DebugActions�	debug_try�debug_match�
 134  debug_failN)	r/r4r5�typing�Optional�DebugStartAction�__annotations__�DebugSuccessAction�DebugExceptionActionr*r*r*r+�DebugActions�s
 135  r��savelistcCs�t�|_d|_d|_d|_d|_||_d|_tt	j
 136  �|_d|_d|_
d|_t�|_d|_d|_d|_d|_d|_|�ddd�|_d|_d|_g|_dS)NTFrr)�list�parseAction�
 137  failAction�
 138  customName�_defaultName�resultsName�
 139  saveAsList�skipWhitespacer�r}r�r�r��mayReturnEmpty�keepTabs�ignoreExprs�debug�streamlined�
mayIndexError�errmsg�modalResultsr��debugActions�callPreparse�
callDuringTry�suppress_warnings_)r(r�r*r*r+r,�s*
 140  zParserElement.__init__�warning_typecCs|j�|�|S)aY
 141          Suppress warnings emitted for a particular diagnostic on this expression.
 142  
 143          Example::
 144  
 145              base = pp.Forward()
 146              base.suppress_warning(Diagnostics.warn_on_parse_using_empty_Forward)
 147  
 148              # statement would normally raise a warning, but is now suppressed
 149              print(base.parseString("x"))
 150  
 151          )r��append)r(r�r*r*r+�suppress_warning�s
zParserElement.suppress_warningcCs@t�|�}|jdd�|_|jdd�|_|jrttj�|_|S)a7
 152          Make a copy of this :class:`ParserElement`.  Useful for defining
 153          different parse actions for the same parsing pattern, using copies of
 154          the original parse element.
 155  
 156          Example::
 157  
 158              integer = Word(nums).set_parse_action(lambda toks: int(toks[0]))
 159              integerK = integer.copy().add_parse_action(lambda toks: toks[0] * 1024) + Suppress("K")
 160              integerM = integer.copy().add_parse_action(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")
 161  
 162              print((integerK | integerM | integer)[1, ...].parse_string("5K 100 640K 256M"))
 163  
 164          prints::
 165  
 166              [5120, 100, 655360, 268435456]
 167  
 168          Equivalent form of ``expr.copy()`` is just ``expr()``::
 169  
 170              integerM = integer().add_parse_action(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")
 171          N)�copyr�r�r�r�r}r�r�)r(�cpyr*r*r+r��s
 172  zParserElement.copy)�listAllMatchesrN�list_all_matchesr�cCs|p|}|�||�S)a�
 173          Define name for referencing matching tokens as a nested attribute
 174          of the returned parse results.
 175  
 176          Normally, results names are assigned as you would assign keys in a dict:
 177          any existing value is overwritten by later values. If it is necessary to
 178          keep all values captured for a particular results name, call ``set_results_name``
 179          with ``list_all_matches`` = True.
 180  
 181          NOTE: ``set_results_name`` returns a *copy* of the original :class:`ParserElement` object;
 182          this is so that the client can define a basic element, such as an
 183          integer, and reference it in multiple places with different names.
 184  
 185          You can also set results names using the abbreviated syntax,
 186          ``expr("name")`` in place of ``expr.set_results_name("name")``
 187          - see :class:`__call__`. If ``list_all_matches`` is required, use
 188          ``expr("name*")``.
 189  
 190          Example::
 191  
 192              date_str = (integer.set_results_name("year") + '/'
 193                          + integer.set_results_name("month") + '/'
 194                          + integer.set_results_name("day"))
 195  
 196              # equivalent form:
 197              date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
 198          )�_setResultsName)r(rNr�r�r*r*r+�set_results_nameszParserElement.set_results_namecCs@|dur|S|��}|�d�r|dd�}d}||_||_|S)Nrr�T)r��endswithr�r�)r(rNr��newselfr*r*r+r�1s
 199  zParserElement._setResultsNameT�
 200  break_flagcsB|r|j�d�fdd�	}�|_||_|St|jd�r|jj|_|S)z�
 201          Method to invoke the Python pdb debugger when this element is
 202          about to be parsed. Set ``break_flag`` to ``True`` to enable, ``False`` to
 203          disable.
 204          Tcsddl}|���||||�S�Nr)�pdb�	set_trace)r�r��	doActions�callPreParser���_parseMethodr*r+�breakerEsz(ParserElement.set_break.<locals>.breaker�_originalParseMethodN�TT)�_parser�hasattr)r(r�rr*rr+�	set_break<s�
 205  zParserElement.set_break�fnscOs\t|�dgkrg|_|Stdd�|D��std��dd�|D�|_|�d|�dd	��|_|S)
 206  ao
 207          Define one or more actions to perform when successfully matching parse element definition.
 208  
 209          Parse actions can be called to perform data conversions, do extra validation,
 210          update external data structures, or enhance or replace the parsed tokens.
 211          Each parse action ``fn`` is a callable method with 0-3 arguments, called as
 212          ``fn(s, loc, toks)`` , ``fn(loc, toks)`` , ``fn(toks)`` , or just ``fn()`` , where:
 213  
 214          - s   = the original string being parsed (see note below)
 215          - loc = the location of the matching substring
 216          - toks = a list of the matched tokens, packaged as a :class:`ParseResults` object
 217  
 218          The parsed tokens are passed to the parse action as ParseResults. They can be
 219          modified in place using list-style append, extend, and pop operations to update
 220          the parsed list elements; and with dictionary-style item set and del operations
 221          to add, update, or remove any named results. If the tokens are modified in place,
 222          it is not necessary to return them with a return statement.
 223  
 224          Parse actions can also completely replace the given tokens, with another ``ParseResults``
 225          object, or with some entirely different object (common for parse actions that perform data
 226          conversions). A convenient way to build a new parse result is to define the values
 227          using a dict, and then create the return value using :class:`ParseResults.from_dict`.
 228  
 229          If None is passed as the ``fn`` parse action, all previously added parse actions for this
 230          expression are cleared.
 231  
 232          Optional keyword arguments:
 233  
 234          - call_during_try = (default= ``False``) indicate if parse action should be run during
 235            lookaheads and alternate testing. For parse actions that have side effects, it is
 236            important to only call the parse action once it is determined that it is being
 237            called as part of a successful parse. For parse actions that perform additional
 238            validation, then call_during_try should be passed as True, so that the validation
 239            code is included in the preliminary "try" parses.
 240  
 241          Note: the default parsing behavior is to expand tabs in the input string
 242          before starting the parsing process.  See :class:`parse_string` for more
 243          information on parsing strings containing ``<TAB>`` s, and suggested
 244          methods to maintain a consistent view of the parsed string, the parse
 245          location, and line and column positions within the parsed string.
 246  
 247          Example::
 248  
 249              # parse dates in the form YYYY/MM/DD
 250  
 251              # use parse action to convert toks from str to int at parse time
 252              def convert_to_int(toks):
 253                  return int(toks[0])
 254  
 255              # use a parse action to verify that the date is a valid date
 256              def is_valid_date(instring, loc, toks):
 257                  from datetime import date
 258                  year, month, day = toks[::2]
 259                  try:
 260                      date(year, month, day)
 261                  except ValueError:
 262                      raise ParseException(instring, loc, "invalid date given")
 263  
 264              integer = Word(nums)
 265              date_str = integer + '/' + integer + '/' + integer
 266  
 267              # add parse actions
 268              integer.set_parse_action(convert_to_int)
 269              date_str.set_parse_action(is_valid_date)
 270  
 271              # note that integer fields are now ints, not strings
 272              date_str.run_tests('''
 273                  # successful parse - note that integer fields were converted to ints
 274                  1999/12/31
 275  
 276                  # fail - invalid date
 277                  1999/13/31
 278                  ''')
 279          Ncs��|]}t|�VqdSr&)�callable�r>r�r*r*r+�	<genexpr>���z1ParserElement.set_parse_action.<locals>.<genexpr>zparse actions must be callablecS�g|]}t|��qSr*�r�rr*r*r+r@��z2ParserElement.set_parse_action.<locals>.<listcomp>�call_during_tryr�F)r�r��allr��getr��r(r	�kwargsr*r*r+�set_parse_actionSsK��zParserElement.set_parse_actioncOs8|jdd�|D�7_|jp|�d|�dd��|_|S)z�
 280          Add one or more parse actions to expression's list of parse actions. See :class:`set_parse_action`.
 281  
 282          See examples in :class:`copy`.
 283          cSrr*rrr*r*r+r@�rz2ParserElement.add_parse_action.<locals>.<listcomp>rr�F)r�r�rrr*r*r+�add_parse_action�s
 284  
 285  �zParserElement.add_parse_actionc
 286  OsN|D]}|j�t||�d�|�dd�d��q|jp#|�d|�dd��|_|S)a�Add a boolean predicate function to expression's list of parse actions. See
 287          :class:`set_parse_action` for function call signatures. Unlike ``set_parse_action``,
 288          functions passed to ``add_condition`` need to return boolean success/fail of the condition.
 289  
 290          Optional keyword arguments:
 291  
 292          - message = define a custom message to be used in the raised exception
 293          - fatal = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise
 294            ParseException
 295          - call_during_try = boolean to indicate if this method should be called during internal tryParse calls,
 296            default=False
 297  
 298          Example::
 299  
 300              integer = Word(nums).set_parse_action(lambda toks: int(toks[0]))
 301              year_int = integer.copy()
 302              year_int.add_condition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later")
 303              date_str = year_int + '/' + integer + '/' + integer
 304  
 305              result = date_str.parse_string("1999/12/31")  # -> Exception: Only support years 2000 and later (at char 0),
 306                                                                           (line:1, col:1)
 307          r�r�F)r�r�rr�)r�r�r�rr�)r(r	rr�r*r*r+�
add_condition�s��
 308  �zParserElement.add_conditionr�cCs
 309  ||_|S)a
 310          Define action to perform if parsing fails at this expression.
 311          Fail acton fn is a callable function that takes the arguments
 312          ``fn(s, loc, expr, err)`` where:
 313  
 314          - s = string being parsed
 315          - loc = location where expression match was attempted and failed
 316          - expr = the parse expression that failed
 317          - err = the exception thrown
 318  
 319          The function returns no value.  It may throw :class:`ParseFatalException`
 320          if it is desired to stop parsing immediately.)r�)r(r�r*r*r+�set_fail_action�s
zParserElement.set_fail_actionc	CsJd}|r#d}|jD]}z	|�||�\}}d}q
ty Yq	w|s|S�NTF)r�rr�)r(r�r��
 321  exprsFound�e�dummyr*r*r+�_skipIgnorables�s
 322  ���	zParserElement._skipIgnorablescCsZ|jr	|�||�}|jr+t|�}|j}||kr+|||vr+|d7}||kr+|||vs|S�Nr)r�rr��lenr�)r(r�r��instrlen�white_charsr*r*r+�preParse�s�zParserElement.preParsecCs|gfSr&r*�r(r�r�r�r*r*r+�	parseImpl�zParserElement.parseImplcCs|Sr&r*�r(r�r��	tokenlistr*r*r+�	postParse�zParserElement.postParsecCs&d\}}}|j}t|�}	|s|jr�zJ|r|jr|�||�}
 323  n|}
 324  |
 325  }|jjr/|j�|||d�|js6|
 326  |	krQz|�||
 327  |�\}}Wnt	yPt
 328  ||	|j|��w|�||
 329  |�\}}Wnaty�}
z|jj
rq|j�
||||
d�|jr||�||||
��d}
~
ww|r�|jr�|�||�}
 330  n|}
 331  |
 332  }|js�|
 333  |	kr�z|�||
 334  |�\}}Wnt	y�t
 335  ||	|j|��w|�||
 336  |�\}}|�|||�}t||j|j|jd�}|j�r||s�|j�r||�r;zA|jD];}z||||�}Wnt	y�}zt
 337  d�}||�d}~ww|du�r||u�rt||j|j�ot|ttf�|jd�}q�Wn^t�y:}
z|jj
�r5|j�
||||
d��d}
~
ww|jD]=}z||||�}Wnt	�y\}zt
 338  d�}||�d}~ww|du�rz||u�rzt||j|j�out|ttf�|jd�}�q>|�r�|jj�r�|j�|||||d�||fS)N�rrraF)�asList�modalz exception raised in parse action)r�r!r�r�r$r�r�r�r&�
 339  IndexErrorr�r��	Exceptionr�r*rr�r�r�r�r��
 340  isinstancer�r�)r(r�r�r�r�TRY�MATCH�FAIL�	debugging�len_instring�pre_loc�tokens_start�tokens�err�
 341  ret_tokensr��parse_action_excr�r*r*r+�
_parseNoCaches�
 342  
 343  
 344  ��
 345  ���
 346  
 347  ��
 348  �����
 349  
 350  ���
 351  ����
 352  �zParserElement._parseNoCacher�r��raise_fatalcCs<z|j||dd�dWSty|r�t|||j|��w)NF�r�r)rr�r�r�)r(r�r�r>r*r*r+�	try_parsens�zParserElement.try_parsec	Cs,z	|�||�WdSttfyYdSw)NFT)r@r�r/)r(r�r�r*r*r+�can_parse_nextvs��zParserElement.can_parse_next�Forward�recursion_memosrcCs�d\}}d\}}}	|||||f}
 353  tj��tj}|�|
 354  �}||jurdtj|d7<z
 355  |�||||�}WntyK}
z|�|
 356  |
j	|
j
 357  ���d}
~
ww|�|
 358  |d|d��|f�|Wd�Stj|d7<|jr�|j
jr�z|j
j|||dd�Wn	ty�Ynwt|t�r�|jr�|j
jr�z|j
j||||dd�W|�ty�Y|�w|�|d|d��|d}}}|jr�|j
jr�z|j
j|||||dd�Wn	ty�Ynw||fWd�S1s�wYdS)N)rrr,rrT)r�ra)r}�packrat_cache_lock�
packrat_cacher�not_in_cache�packrat_cache_statsr=�ParseBaseExceptionr�r�r�r�r�r�r�r�r1r0r�r�)r(r�r�r�r�HIT�MISSr2r3r4�lookup�cache�value�pe�loc_�resultr�r*r*r+�_parseCache�s`
 359  
 360  
 361  ����
 362  
 363  ��� 
 364  ��$�zParserElement._parseCachecCs2tj��dgttj�tjdd�<tj��dSr�)r}rE�clearr!rGrCr*r*r*r+�reset_cache�s
 365  
 366  �zParserElement.reset_cachecCs t��dt_dt_tjt_dS)a$
 367          Disables active Packrat or Left Recursion parsing and their memoization
 368  
 369          This method also works if neither Packrat nor Left Recursion are enabled.
 370          This makes it safe to call before activating Packrat nor Left Recursion
 371          to clear any previous settings.
 372          FN)r}rS�_left_recursion_enabled�_packratEnabledr=rr*r*r*r+�disable_memoization�s	z!ParserElement.disable_memoization)�force�cache_size_limitcCsZ|rt��ntjrtd��|durt�t_n|dkr"t|d�t_ntd|��dt_dS)a#
 373          Enables "bounded recursion" parsing, which allows for both direct and indirect
 374          left-recursion. During parsing, left-recursive :class:`Forward` elements are
 375          repeatedly matched with a fixed recursion depth that is gradually increased
 376          until finding the longest match.
 377  
 378          Example::
 379  
 380              import pyparsing as pp
 381              pp.ParserElement.enable_left_recursion()
 382  
 383              E = pp.Forward("E")
 384              num = pp.Word(pp.nums)
 385              # match `num`, or `num '+' num`, or `num '+' num '+' num`, ...
 386              E <<= E + '+' - num | num
 387  
 388              print(E.parse_string("1+2+3"))
 389  
 390          Recursion search naturally memoizes matches of ``Forward`` elements and may
 391          thus skip reevaluation of parse actions during backtracking. This may break
 392          programs with parse actions which rely on strict ordering of side-effects.
 393  
 394          Parameters:
 395  
 396          - cache_size_limit - (default=``None``) - memoize at most this many
 397            ``Forward`` elements during matching; if ``None`` (the default),
 398            memoize all ``Forward`` elements.
 399  
 400          Bounded Recursion parsing works similar but not identical to Packrat parsing,
 401          thus the two cannot be used together. Use ``force=True`` to disable any
 402          previous, conflicting settings.
 403          �0Packrat and Bounded Recursion are not compatibleNr)�capacityzMemo size of %sT)	r}rVrU�RuntimeError�_UnboundedMemorC�_LRUMemo�NotImplementedErrorrT�rXrWr*r*r+�enable_left_recursion�s$
 404  
 405  
 406  z#ParserElement.enable_left_recursion�rWcCsT|rt��ntjrtd��tjs(dt_|durt�t_nt|�t_tjt_	dSdS)af
 407          Enables "packrat" parsing, which adds memoizing to the parsing logic.
 408          Repeated parse attempts at the same string location (which happens
 409          often in many complex grammars) can immediately return a cached value,
 410          instead of re-executing parsing/validating code.  Memoizing is done of
 411          both valid results and parsing exceptions.
 412  
 413          Parameters:
 414  
 415          - cache_size_limit - (default= ``128``) - if an integer value is provided
 416            will limit the size of the packrat cache; if None is passed, then
 417            the cache size will be unbounded; if 0 is passed, the cache will
 418            be effectively disabled.
 419  
 420          This speedup may break existing programs that use parse actions that
 421          have side-effects.  For this reason, packrat parsing is disabled when
 422          you first import pyparsing.  To activate the packrat feature, your
 423          program must call the class method :class:`ParserElement.enable_packrat`.
 424          For best results, call ``enable_packrat()`` immediately after
 425          importing pyparsing.
 426  
 427          Example::
 428  
 429              import pyparsing
 430              pyparsing.ParserElement.enable_packrat()
 431  
 432          Packrat parsing works similar but not identical to Bounded Recursion parsing,
 433          thus the two cannot be used together. Use ``force=True`` to disable any
 434          previous, conflicting settings.
 435          rYTN)
 436  r}rVrTr[rUrrErrQrr_r*r*r+�enable_packrats 
 437  
 438  
 439  �zParserElement.enable_packrat)�parseAll�	parse_allrcc	
 440  Cs�|p|}t��|js|��|jD]}|��q|js |��}z"|�|d�\}}|r@|�||�}t	�t
 441  �}|�||�W|SW|StyW}z	tjrN�|�
d��d}~ww)a6	
 442          Parse a string with respect to the parser definition. This function is intended as the primary interface to the
 443          client code.
 444  
 445          :param instring: The input string to be parsed.
 446          :param parse_all: If set, the entire input string must match the grammar.
 447          :param parseAll: retained for pre-PEP8 compatibility, will be removed in a future release.
 448          :raises ParseException: Raised if ``parse_all`` is set and the input string does not match the whole grammar.
 449          :returns: the parsed data as a :class:`ParseResults` object, which may be accessed as a `list`, a `dict`, or
 450            an object with attributes if the given parser includes results names.
 451  
 452          If the input string is required to match the entire grammar, ``parse_all`` flag must be set to ``True``. This
 453          is also equivalent to ending the grammar with :class:`StringEnd`().
 454  
 455          To report proper column numbers, ``parse_string`` operates on a copy of the input string where all tabs are
 456          converted to spaces (8 spaces per tab, as per the default in ``string.expandtabs``). If the input string
 457          contains tabs and the grammar uses parse actions that use the ``loc`` argument to index into the string
 458          being parsed, one can ensure a consistent view of the input string by doing one of the following:
 459  
 460          - calling ``parse_with_tabs`` on your grammar before calling ``parse_string`` (see :class:`parse_with_tabs`),
 461          - define your parse action using the full ``(s,loc,toks)`` signature, and reference the input string using the
 462            parse action's ``s`` argument, or
 463          - explicitly expand the tabs in your input string before calling ``parse_string``.
 464  
 465          Examples:
 466  
 467          By default, partial matches are OK.
 468  
 469          >>> res = Word('a').parse_string('aaaaabaaa')
 470          >>> print(res)
 471          ['aaaaa']
 472  
 473          The parsing behavior varies by the inheriting class of this abstract class. Please refer to the children
 474          directly to see more examples.
 475  
 476          It raises an exception if parse_all flag is set and instring does not match the whole grammar.
 477  
 478          >>> res = Word('a').parse_string('aaaaabaaa', parse_all=True)
 479          Traceback (most recent call last):
 480          ...
 481          pyparsing.ParseException: Expected end of text, found 'b'  (at char 5), (line:1, col:6)
 482          rN)r}rSr��
 483  streamliner�r��
 484  expandtabsrr$�Empty�	StringEndrHr��with_traceback)	r(r�rdrcrr�r9�ser�r*r*r+�parse_string4s.-
 485  
 486  ��
 487  ��zParserElement.parse_string)r��
 488  maxMatches�max_matches�overlapr�rlc
 489  csl�t||�}|js
|��|jD]}|��q|js t|���}t|�}d}|j}	|j	}
 490  t
 491  ��d}zn||kr�||kr�z|	||�}|
 492  ||dd�\}
}Wn
tyX|d}Yn5w|
|kr�|d7}|rmt
|��||
d��|||
fV|r�|	||�}||kr�|
}n|d7}n|
}n|d}||kr�||ks;WdSWdSWdSWdSty�}z	t
 493  jr��|�d��d}~ww)at
 494          Scan the input string for expression matches.  Each match will return the
 495          matching tokens, start location, and end location.  May be called with optional
 496          ``max_matches`` argument, to clip scanning after 'n' matches are found.  If
 497          ``overlap`` is specified, then overlapping matches will be reported.
 498  
 499          Note that the start and end locations are reported relative to the string
 500          being parsed.  See :class:`parse_string` for more information on parsing
 501          strings with embedded tabs.
 502  
 503          Example::
 504  
 505              source = "sldjf123lsdjjkf345sldkjf879lkjsfd987"
 506              print(source)
 507              for tokens, start, end in Word(alphas).scan_string(source):
 508                  print(' '*start + '^'*(end-start))
 509                  print(' '*start + tokens[0])
 510  
 511          prints::
 512  
 513              sldjf123lsdjjkf345sldkjf879lkjsfd987
 514              ^^^^^
 515              sldjf
 516                      ^^^^^^^
 517                      lsdjjkf
 518                                ^^^^^^
 519                                sldkjf
 520                                         ^^^^^^
 521                                         lkjsfd
 522          rF�rr)r9�start�endN)�minr�rer�r��strrfr!r$rr}�
 523  resetCacher�r�r-rHr�ri)r(r�rmrnr�rlrr"r��
 524  preparseFn�parseFn�matches�preloc�nextLocr9�nextlocr�r*r*r+�scan_stringys\�
 525  '
 526  
 527  
 528  ���
 529  
 530  (�
 531  ��zParserElement.scan_string�r�c	
 532  Cs�g}d}d|_zX|j||d�D]3\}}}|�|||��|r@t|t�r+||��7}nt|t�r;t|t�s;|�|�n|�|�|}q|�||d��dd�|D�}d�	dd�t
 533  |�D��WStyt}z	tj
rk�|�d��d}~ww)	ab
 534          Extension to :class:`scan_string`, to modify matching text with modified tokens that may
 535          be returned from a parse action.  To use ``transform_string``, define a grammar and
 536          attach a parse action to it that modifies the returned token list.
 537          Invoking ``transform_string()`` on a target string will then scan for matches,
 538          and replace the matched text patterns according to the logic in the parse
 539          action.  ``transform_string()`` returns the resulting transformed string.
 540  
 541          Example::
 542  
 543              wd = Word(alphas)
 544              wd.set_parse_action(lambda toks: toks[0].title())
 545  
 546              print(wd.transform_string("now is the winter of our discontent made glorious summer by this sun of york."))
 547  
 548          prints::
 549  
 550              Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York.
 551          rTr|NcSsg|]}|r|�qSr*r*�r>�or*r*r+r@�rz2ParserElement.transform_string.<locals>.<listcomp>rrcSrr*�rs)r>r�r*r*r+r@�r)r�r{r�r1rr�rr"�extend�joinrrHr}r�ri)	r(r�r��out�lastEr�r�rr�r*r*r+�transform_string�s,
 552  
 553  
 554  ��zParserElement.transform_stringc
 555  CsVt||�}ztdd�|j|||d�D��WSty*}z	tjr!�|�d��d}~ww)a�
 556          Another extension to :class:`scan_string`, simplifying the access to the tokens found
 557          to match the given parse expression.  May be called with optional
 558          ``max_matches`` argument, to clip searching after 'n' matches are found.
 559  
 560          Example::
 561  
 562              # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters
 563              cap_word = Word(alphas.upper(), alphas.lower())
 564  
 565              print(cap_word.search_string("More than Iron, more than Lead, more than Gold I need Electricity"))
 566  
 567              # the sum() builtin can be used to merge results into a single ParseResults object
 568              print(sum(cap_word.search_string("More than Iron, more than Lead, more than Gold I need Electricity")))
 569  
 570          prints::
 571  
 572              [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']]
 573              ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity']
 574          cSsg|]\}}}|�qSr*r*)r>r�r�rr*r*r+r@sz/ParserElement.search_string.<locals>.<listcomp>r|N)rrrr{rHr}r�ri)r(r�rmr�rlr�r*r*r+�
search_strings
 575  �
 576  ��zParserElement.search_string)�includeSeparators�maxsplit�include_separatorsc	csZ�|p|}d}|j||d�D]\}}}|||�V|r!|dV|}q||d�VdS)aT
 577          Generator method to split a string using the given expression as a separator.
 578          May be called with optional ``maxsplit`` argument, to limit the number of splits;
 579          and the optional ``include_separators`` argument (default= ``False``), if the separating
 580          matching text should be included in the split results.
 581  
 582          Example::
 583  
 584              punc = one_of(list(".,;:/-!?"))
 585              print(list(punc.split("This, this?, this sentence, is badly punctuated!")))
 586  
 587          prints::
 588  
 589              ['This', ' this', '', ' this sentence', ' is badly punctuated', '']
 590          r)rmN)r{)	r(r�r�r�r��lastr�r�rr*r*r+rG(s�
 591  zParserElement.splitcCsN|turt|�St|t�r|�|�}t|t�s!td�t|�j	���t
 592  ||g�S)ah
 593          Implementation of ``+`` operator - returns :class:`And`. Adding strings to a :class:`ParserElement`
 594          converts them to :class:`Literal`s by default.
 595  
 596          Example::
 597  
 598              greet = Word(alphas) + "," + Word(alphas) + "!"
 599              hello = "Hello, World!"
 600              print(hello, "->", greet.parse_string(hello))
 601  
 602          prints::
 603  
 604              Hello, World! -> ['Hello', ',', 'World', '!']
 605  
 606          ``...`` may be used as a parse expression as a short form of :class:`SkipTo`.
 607  
 608              Literal('start') + ... + Literal('end')
 609  
 610          is equivalent to:
 611  
 612              Literal('start') + SkipTo('end')("_skipped*") + Literal('end')
 613  
 614          Note that the skipped text is returned with '_skipped' as a results name,
 615          and to support having multiple skips in the same parser, the value returned is
 616          a list of all skipped text.
 617          �4Cannot combine element of type {} with ParserElement)�Ellipsis�_PendingSkipr1r"r�r}r�r�r�r/�And�r(�otherr*r*r+�__add__Hs
 618  
 619  
 620  ��zParserElement.__add__cCsR|turt|�d�|St|t�r|�|�}t|t�s%td�t|�j	���||S)zd
 621          Implementation of ``+`` operator when left operand is not a :class:`ParserElement`
 622          �	_skipped*r�)
 623  r��SkipTor1r"r�r}r�r�r�r/r�r*r*r+�__radd__ps
 624  
 625  
 626  ��zParserElement.__radd__cCsBt|t�r
 627  |�|�}t|t�std�t|�j���|t�	�|S)zX
 628          Implementation of ``-`` operator, returns :class:`And` with error stop
 629          r�)
 630  r1r"r�r}r�r�r�r/r��
 631  _ErrorStopr�r*r*r+�__sub__�s
 632  
 633  
 634  ��zParserElement.__sub__cCs:t|t�r
 635  |�|�}t|t�std�t|�j���||S)zd
 636          Implementation of ``-`` operator when left operand is not a :class:`ParserElement`
 637          r��r1r"r�r}r�r�r�r/r�r*r*r+�__rsub__��
 638  
 639  
 640  ��zParserElement.__rsub__cs|turd}nt|t�r#|dd�tfkr#d|dd�ddd�}t|t�r.|d}}n}t|t�r�tdd	�|D��}|d
 641  dd�}|ddurPd|df}t|dt�r{|ddur{|ddkrgt��S|ddkrqt��S�|dt��St|dt�r�t|dt�r�|\}}||8}ntd�d�d
d	�|D�����td�t	|�j
 642  ���|dkr�td��|dkr�td��||kr�dkr�tg�S|r��fdd��|r�|dkr���|�}|St�g|��|�}|S�|�}|S|dkr��}|St�g|�}|S)a�
 643          Implementation of ``*`` operator, allows use of ``expr * 3`` in place of
 644          ``expr + expr + expr``.  Expressions may also be multiplied by a 2-integer
 645          tuple, similar to ``{min, max}`` multipliers in regular expressions.  Tuples
 646          may also include ``None`` as in:
 647          - ``expr*(n, None)`` or ``expr*(n, )`` is equivalent
 648               to ``expr*n + ZeroOrMore(expr)``
 649               (read as "at least n instances of ``expr``")
 650          - ``expr*(None, n)`` is equivalent to ``expr*(0, n)``
 651               (read as "0 to n instances of ``expr``")
 652          - ``expr*(None, None)`` is equivalent to ``ZeroOrMore(expr)``
 653          - ``expr*(1, None)`` is equivalent to ``OneOrMore(expr)``
 654  
 655          Note that ``expr*(None, n)`` does not raise an exception if
 656          more than n exprs exist in the input stream; that is,
 657          ``expr*(None, n)`` does not enforce a maximum number of expr
 658          occurrences.  If this behavior is desired, then write
 659          ``expr*(None, n) + ~expr``
 660          )rNNrr�r&rarcss �|]}|tur
 661  |ndVqdSr&)r�r}r*r*r+r
�s�z(ParserElement.__mul__.<locals>.<genexpr>)NNz.cannot multiply ParserElement and ({}) objects�,css�|]}t|�jVqdSr&�r�r/)r>�itemr*r*r+r
���z,cannot multiply ParserElement and {} objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuecs$|dkrt��|d��St��Sr )�Opt)�n��makeOptionalListr(r*r+r��sz/ParserElement.__mul__.<locals>.makeOptionalList)
r�r1�tuple�int�
 662  ZeroOrMore�	OneOrMorer�r�r�r�r/�
 663  ValueErrorr�)r(r��minElements�optElementsr2r*r�r+�__mul__�sl
 664  
 665  
 666  ������
 667  ����zParserElement.__mul__cCs
 668  |�|�Sr&)r�r�r*r*r+�__rmul__�r-zParserElement.__rmul__cCsR|tur
 669  t|dd�St|t�r|�|�}t|t�s#td�t|�j	���t
 670  ||g�S)zP
 671          Implementation of ``|`` operator - returns :class:`MatchFirst`
 672          T)�	must_skipr�)r�r�r1r"r�r}r�r�r�r/�
 673  MatchFirstr�r*r*r+�__or__�s
 674  
 675  
 676  ��zParserElement.__or__cCs:t|t�r
 677  |�|�}t|t�std�t|�j���||BS)zd
 678          Implementation of ``|`` operator when left operand is not a :class:`ParserElement`
 679          r�r�r�r*r*r+�__ror__r�zParserElement.__ror__cC�>t|t�r
 680  |�|�}t|t�std�t|�j���t||g�S)zH
 681          Implementation of ``^`` operator - returns :class:`Or`
 682          r�)	r1r"r�r}r�r�r�r/�Orr�r*r*r+�__xor__�
 683  
 684  
 685  ��zParserElement.__xor__cCs:t|t�r
 686  |�|�}t|t�std�t|�j���||AS)zd
 687          Implementation of ``^`` operator when left operand is not a :class:`ParserElement`
 688          r�r�r�r*r*r+�__rxor__#r�zParserElement.__rxor__cCr�)zJ
 689          Implementation of ``&`` operator - returns :class:`Each`
 690          r�)	r1r"r�r}r�r�r�r/�Eachr�r*r*r+�__and__1r�zParserElement.__and__cCs:t|t�r
 691  |�|�}t|t�std�t|�j���||@S)zd
 692          Implementation of ``&`` operator when left operand is not a :class:`ParserElement`
 693          r�r�r�r*r*r+�__rand__?r�zParserElement.__rand__cC�t|�S)zL
 694          Implementation of ``~`` operator - returns :class:`NotAny`
 695          )�NotAny�r(r*r*r+�
 696  __invert__MszParserElement.__invert__cCs�zt|t�r	|f}t|�Wn
ty||f}Ynwt|�dkr=td�|dd�t|�dkr9d�t|�����d���|t|dd��}|S)a{
 697          use ``[]`` indexing notation as a short form for expression repetition:
 698  
 699          - ``expr[n]`` is equivalent to ``expr*n``
 700          - ``expr[m, n]`` is equivalent to ``expr*(m, n)``
 701          - ``expr[n, ...]`` or ``expr[n,]`` is equivalent
 702               to ``expr*n + ZeroOrMore(expr)``
 703               (read as "at least n instances of ``expr``")
 704          - ``expr[..., n]`` is equivalent to ``expr*(0, n)``
 705               (read as "0 to n instances of ``expr``")
 706          - ``expr[...]`` and ``expr[0, ...]`` are equivalent to ``ZeroOrMore(expr)``
 707          - ``expr[1, ...]`` is equivalent to ``OneOrMore(expr)``
 708  
 709          ``None`` may be used in place of ``...``.
 710  
 711          Note that ``expr[..., n]`` and ``expr[m, n]``do not raise an exception
 712          if more than ``n`` ``expr``s exist in the input stream.  If this behavior is
 713          desired, then write ``expr[..., n] + ~expr``.
 714          raz,only 1 or 2 index arguments supported ({}{})Nrcz... [{}]rr)r1r"�iterr�r!r�r�)r(�keyr2r*r*r+�__getitem__Ws$
 715  �"����zParserElement.__getitem__cCs|dur	|�|�S|��S)a
 716          Shortcut for :class:`set_results_name`, with ``list_all_matches=False``.
 717  
 718          If ``name`` is given with a trailing ``'*'`` character, then ``list_all_matches`` will be
 719          passed as ``True``.
 720  
 721          If ``name` is omitted, same as calling :class:`copy`.
 722  
 723          Example::
 724  
 725              # these are equivalent
 726              userdata = Word(alphas).set_results_name("name") + Word(nums + "-").set_results_name("socsecno")
 727              userdata = Word(alphas)("name") + Word(nums + "-")("socsecno")
 728          N)r�r��r(rNr*r*r+�__call__s
 729  zParserElement.__call__cCr�)z�
 730          Suppresses the output of this :class:`ParserElement`; useful to keep punctuation from
 731          cluttering up returned output.
 732          )�Suppressr�r*r*r+�suppress�szParserElement.suppress�	recursivecC�
 733  d|_|S)z�
 734          Enables the skipping of whitespace before matching the characters in the
 735          :class:`ParserElement`'s defined pattern.
 736  
 737          :param recursive: If ``True`` (the default), also enable whitespace skipping in child elements (if any)
 738          T�r��r(r�r*r*r+�ignore_whitespace�szParserElement.ignore_whitespacecCr�)a|
 739          Disables the skipping of whitespace before matching the characters in the
 740          :class:`ParserElement`'s defined pattern.  This is normally only used internally by
 741          the pyparsing module, but may be needed in some whitespace-sensitive grammars.
 742  
 743          :param recursive: If true (the default), also disable whitespace skipping in child elements (if any)
 744          Fr�r�r*r*r+�leave_whitespace�szParserElement.leave_whitespace�
copy_defaultscCsd|_t|�|_||_|S)z8
 745          Overrides the default whitespace chars
 746          T)r�r�r�r�)r(r�r�r*r*r+�set_whitespace_chars�s
 747  z"ParserElement.set_whitespace_charscCr�)z�
 748          Overrides default behavior to expand ``<TAB>`` s to spaces before parsing the input string.
 749          Must be called before ``parse_string`` when the input grammar contains elements that
 750          match ``<TAB>`` characters.
 751          T)r�r�r*r*r+�parse_with_tabs�szParserElement.parse_with_tabsr�cCsVddl}t|t�r
t|�}t|t�r||jvr|j�|�|S|j�t|����|S)a�
 752          Define expression to be ignored (e.g., comments) while doing pattern
 753          matching; may be called repeatedly, to define multiple comment or other
 754          ignorable patterns.
 755  
 756          Example::
 757  
 758              patt = Word(alphas)[1, ...]
 759              patt.parse_string('ablaj /* comment */ lskjd')
 760              # -> ['ablaj']
 761  
 762              patt.ignore(c_style_comment)
 763              patt.parse_string('ablaj /* comment */ lskjd')
 764              # -> ['ablaj', 'lskjd']
 765          rN)r�r1r"r�r�r�r�)r(r�r�r*r*r+�ignore�s
 766  
 767  
 768  �zParserElement.ignore�start_action�success_action�exception_actioncCs&|�|pt|pt|pt�|_d|_|S)a 
 769          Customize display of debugging messages while doing pattern matching:
 770  
 771          - ``start_action`` - method to be called when an expression is about to be parsed;
 772            should have the signature ``fn(input_string: str, location: int, expression: ParserElement, cache_hit: bool)``
 773  
 774          - ``success_action`` - method to be called when an expression has successfully parsed;
 775            should have the signature ``fn(input_string: str, start_location: int, end_location: int, expression: ParserELement, parsed_tokens: ParseResults, cache_hit: bool)``
 776  
 777          - ``exception_action`` - method to be called when expression fails to parse;
 778            should have the signature ``fn(input_string: str, location: int, expression: ParserElement, exception: Exception, cache_hit: bool)``
 779          T)r�r�r�r�r�r�)r(r�r�r�r*r*r+�set_debug_actions�s�zParserElement.set_debug_actions�flagcCs |r|�ttt�|Sd|_|S)a�
 780          Enable display of debugging messages while doing pattern matching.
 781          Set ``flag`` to ``True`` to enable, ``False`` to disable.
 782  
 783          Example::
 784  
 785              wd = Word(alphas).set_name("alphaword")
 786              integer = Word(nums).set_name("numword")
 787              term = wd | integer
 788  
 789              # turn on debugging for wd
 790              wd.set_debug()
 791  
 792              term[1, ...].parse_string("abc 123 xyz 890")
 793  
 794          prints::
 795  
 796              Match alphaword at loc 0(1,1)
 797              Matched alphaword -> ['abc']
 798              Match alphaword at loc 3(1,4)
 799              Exception raised:Expected alphaword (at char 4), (line:1, col:5)
 800              Match alphaword at loc 7(1,8)
 801              Matched alphaword -> ['xyz']
 802              Match alphaword at loc 11(1,12)
 803              Exception raised:Expected alphaword (at char 12), (line:1, col:13)
 804              Match alphaword at loc 15(1,16)
 805              Exception raised:Expected alphaword (at char 15), (line:1, col:16)
 806  
 807          The output shown is that produced by the default debug actions - custom debug actions can be
 808          specified using :class:`set_debug_actions`. Prior to attempting
 809          to match the ``wd`` expression, the debugging message ``"Match <exprname> at loc <n>(<line>,<col>)"``
 810          is shown. Then if the parse succeeds, a ``"Matched"`` message is shown, or an ``"Exception raised"``
 811          message is shown. Also note the use of :class:`set_name` to assign a human-readable name to the expression,
 812          which makes debugging and exception messages easier to understand - for instance, the default
 813          name created for the :class:`Word` expression without calling ``set_name`` is ``"W:(A-Za-z)"``.
 814          F)r�r�r�r�r�)r(r�r*r*r+�	set_debug�s%��zParserElement.set_debugcCs|jdur
 815  |��|_|jSr&)r��_generateDefaultNamer�r*r*r+�default_name(s
 816  
 817  zParserElement.default_namecCr�)zg
 818          Child classes must define this method, which defines how the ``default_name`` is set.
 819          Nr*r�r*r*r+r�.r�z"ParserElement._generateDefaultNamecCs$||_d|j|_tjr|��|S)a\
 820          Define name for this expression, makes debugging and exception messages clearer.
 821          Example::
 822              Word(nums).parse_string("ABC")  # -> Exception: Expected W:(0-9) (at char 0), (line:1, col:1)
 823              Word(nums).set_name("integer").parse_string("ABC")  # -> Exception: Expected integer (at char 0), (line:1, col:1)
 824          �	Expected )r�rNr�rIr]r�r�r*r*r+�set_name4s
 825  zParserElement.set_namecCs|jdur|jS|jSr&)r�r�r�r*r*r+rNAszParserElement.namecC�|jSr&�rNr�r*r*r+�__str__F�zParserElement.__str__cCr�r&rr�r*r*r+�__repr__Ir'zParserElement.__repr__cCsd|_d|_|S�NT)r�r�r�r*r*r+reLszParserElement.streamlinecC�gSr&r*r�r*r*r+�recurseQr+zParserElement.recursecCs.|dd�|g}|��D]}|�|�q
dSr&)r��_checkRecursion�r(�parseElementList�subRecCheckListrr*r*r+r�Ts�zParserElement._checkRecursioncCs|�g�dS)zj
 826          Check defined expressions for valid structure, check for infinite recursive definitions.
 827          N)r�)r(�
validateTracer*r*r+�validateYszParserElement.validate�utf-8�file_or_filename�encodingcCs�|p|}z|��}Wn$ty.t|d|d��}|��}Wd�n1s'wYYnwz|�||�WStyK}z	tjrB�|�d��d}~ww)z�
 828          Execute the parse expression on the given file or filename.
 829          If a filename is specified (instead of a file object),
 830          the entire file is opened, read, and closed before parsing.
 831          �r�r�N)�read�AttributeError�openrkrHr}r�ri)r(r�r�rdrc�
file_contents�fr�r*r*r+�
 832  parse_file_s"

 833  ���
 834  ��zParserElement.parse_filecCsB||urdSt|t�r|j|dd�St|t�rt|�t|�kSdS)NT�rdF)r1r"rwr}�varsr�r*r*r+�__eq__{s
 835  
 836  zParserElement.__eq__cCr�r&)�idr�r*r*r+�__hash__�r'zParserElement.__hash__�test_stringcCs6|o|}z|jt|�|d�WdStyYdSw)a�
 837          Method for quick testing of a parser against a test string. Good for simple
 838          inline microtests of sub expressions while building up larger parser.
 839  
 840          Parameters:
 841          - ``test_string`` - to test against this expression for a match
 842          - ``parse_all`` - (default= ``True``) - flag to pass to :class:`parse_string` when running tests
 843  
 844          Example::
 845  
 846              expr = Word(nums)
 847              assert expr.matches("100")
 848          r�TF)rkrsrH)r(r�rdrcr*r*r+rw�s�zParserElement.matches�#)rc�fullDump�printResults�failureTestsr*�tests�comment�	full_dump�
print_results�
failure_tests�
 849  post_parse�file�with_line_numbersr�r�r�r*c
 850  s(ddlm}|
 851  o	|}
 852  |o
|}|o|}|
p|}
|p|}t|t�r1t|�j��fdd�|����D�}t|t�r:t|�}|durAt	j
 853  }|j}g}g}d}td��t
d���t�}d	}|D�]4}|durg|�|d
 854  �sk|rx|sx|�|	rt|�|�n|�qZ|s{qZ|r�dd�|�nd|	r�|�|�n|g}g}z|�|�|��}|j||
 855  d�}Wnnty�}z1t|t�r�d
nd}|�|���|�dt|��tjr�|�t�|j ��|o�|
}|}WYd}~n�d}~wt!�y}z%|�d�"t|�j#|��tjr�|�t�|j ��|�o|
}|}WYd}~nmd}~ww|�o|
}|du�rpz)|||�}|du�r=t|t$��r5|�|�%��n|�t|��n|�|�%��Wn3t!�yo}z|�|j%|d��|�d�"|j#t|�j#|��WYd}~nd}~ww|�|j%|d��|�d�|�r�|d�|��|�||f�qZ||fS)a�

 856          Execute the parse expression on a series of test strings, showing each
 857          test, the parsed results or where the parse failed. Quick and easy way to
 858          run a parse expression against a list of sample strings.
 859  
 860          Parameters:
 861          - ``tests`` - a list of separate test strings, or a multiline string of test strings
 862          - ``parse_all`` - (default= ``True``) - flag to pass to :class:`parse_string` when running tests
 863          - ``comment`` - (default= ``'#'``) - expression for indicating embedded comments in the test
 864            string; pass None to disable comment filtering
 865          - ``full_dump`` - (default= ``True``) - dump results as list followed by results names in nested outline;
 866            if False, only dump nested list
 867          - ``print_results`` - (default= ``True``) prints test output to stdout
 868          - ``failure_tests`` - (default= ``False``) indicates if these tests are expected to fail parsing
 869          - ``post_parse`` - (default= ``None``) optional callback for successful parse results; called as
 870            `fn(test_string, parse_results)` and returns a string to be added to the test output
 871          - ``file`` - (default= ``None``) optional file-like object to which test output will be written;
 872            if None, will default to ``sys.stdout``
 873          - ``with_line_numbers`` - default= ``False``) show test strings with line and column numbers
 874  
 875          Returns: a (success, results) tuple, where success indicates that all tests succeeded
 876          (or failed if ``failure_tests`` is True), and the results contain a list of lines of each
 877          test's output
 878  
 879          Example::
 880  
 881              number_expr = pyparsing_common.number.copy()
 882  
 883              result = number_expr.run_tests('''
 884                  # unsigned integer
 885                  100
 886                  # negative integer
 887                  -100
 888                  # float with scientific notation
 889                  6.02e23
 890                  # integer with scientific notation
 891                  1e-12
 892                  ''')
 893              print("Success" if result[0] else "Failed!")
 894  
 895              result = number_expr.run_tests('''
 896                  # stray character
 897                  100Z
 898                  # missing leading digit before '.'
 899                  -.100
 900                  # too many '.'
 901                  3.14.159
 902                  ''', failure_tests=True)
 903              print("Success" if result[0] else "Failed!")
 904  
 905          prints::
 906  
 907              # unsigned integer
 908              100
 909              [100]
 910  
 911              # negative integer
 912              -100
 913              [-100]
 914  
 915              # float with scientific notation
 916              6.02e23
 917              [6.02e+23]
 918  
 919              # integer with scientific notation
 920              1e-12
 921              [1e-12]
 922  
 923              Success
 924  
 925              # stray character
 926              100Z
 927                 ^
 928              FAIL: Expected end of text (at char 3), (line:1, col:4)
 929  
 930              # missing leading digit before '.'
 931              -.100
 932              ^
 933              FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1)
 934  
 935              # too many '.'
 936              3.14.159
 937                  ^
 938              FAIL: Expected end of text (at char 4), (line:1, col:5)
 939  
 940              Success
 941  
 942          Each test string must be on a single line. If you want to test a string that spans multiple
 943          lines, create a test like this::
 944  
 945              expr.run_tests(r"this is a test\n of strings that spans \n 3 lines")
 946  
 947          (Note that this is a raw string literal, you must include the leading ``'r'``.)
 948          r)�pyparsing_testcsg|]}�|��qSr*r*)r>�	test_line��
 949  line_stripr*r+r@rz+ParserElement.run_tests.<locals>.<listcomp>NT�\n�
 950  uFrrr�z(FATAL)zFAIL: zFAIL-EXCEPTION: {}: {})�fullz{} failed: {}: {})&�testingrr1r"r��strip�rstrip�
 951  splitlines�Literal�sys�stdout�writer�replace_withr��
quoted_stringrwr�r�r�r��lstriprkrHr��explainrsr}r�r�r��	format_tbr�r0r�r/r�dump)r(r�rdr�r�r�r�r�r�r�rcr�r�r�r*r�print_�
 952  allResults�comments�success�NL�BOMr�r�rPrNr�r��pp_valuerr*rr+�	run_tests�s�p
 953  
 954  
 955  
 956  ���
 957  ��
 958  
 959  
 960  �����
 961  zParserElement.run_testsr#�output_html�vertical�show_results_names�show_groupsc
 962  Ks�z
 963  ddlm}m}Wnty}ztd�|�d}~ww|��||||||d�}	t|ttf�rQt	|ddd��}
 964  |
 965 966  ||	��Wd�dS1sJwYdS|�
 967  ||	��dS)	a�
 968          Create a railroad diagram for the parser.
 969  
 970          Parameters:
 971          - output_html (str or file-like object) - output target for generated
 972            diagram HTML
 973          - vertical (int) - threshold for formatting multiple alternatives vertically
 974            instead of horizontally (default=3)
 975          - show_results_names - bool flag whether diagram should show annotations for
 976            defined results names
 977          - show_groups - bool flag whether groups should be highlighted with an unlabeled surrounding box
 978          Additional diagram-formatting keyword arguments can also be included;
 979          see railroad.Diagram class.
 980          r)�to_railroad�railroad_to_htmlzMmust ``pip install pyparsing[diagrams]`` to generate parser railroad diagramsN)rrr �diagram_kwargs�wr�r�)�diagramr!r"�ImportErrorr0rer1rsrr�r)r(rrrr rr!r"�ie�railroad�	diag_filer*r*r+�create_diagramas.�����"�zParserElement.create_diagram�F�rPr}�TrrUr&)ra)r�r}rPr})r�F)Tr�TTFNNF)r#FF)�r/r4r5rBr�rsr�r�rsr�r�r�r��staticmethodr�r�rr�r,r`r�r�r�r�r�ParseActionrr�ParseConditionr�ParseFailActionrrr$r&r*rr�rr=r@rAr�recursion_lockrC�Dictrr0rErDrGrQrrSrUrTrVr`rbrk�_MAX_INTrr{r�r�rGr�r�r�r�r�r�r�r�r�r�r�r�r��__iter__r�r�r�r�r�r
 981  r�r�r�r�r�r�r�r��propertyr�r
r�r�rNr�r�rerr�r�r�rr	r�r�r�rwrrrr*�setDefaultWhitespaceChars�inlineLiteralsUsing�setResultsName�setBreak�setParseAction�addParseAction�addCondition�
setFailAction�tryParse�canParseNextrt�enableLeftRecursion�
enablePackrat�parseString�
 982  scanString�searchString�transformString�setWhitespaceChars�
parseWithTabs�setDebugActions�setDebug�defaultName�setName�	parseFile�runTests�ignoreWhitespace�leaveWhitespacer*r*r*r+r}�sV
 983  
 984  �����
 985 986  !V#
 987  �
 988  
 989  �f	� ���
 990  
 991  �0
����/ ,�����
 992  �H�������
 993  �Y1������
 994  �+�����
 995 996   
 997  (
 998  
 999  
1000  
1001  V
1002  
1003  
1004  
1005  
1006  
1007  
1008  (
1009  
1010  ���
10111012  
1013  	���
1014  �/
1015  

1016  	������
1017  �	�����
1018  ����������	�
1019  ��
����
1020  �G�����
1021  �.csJeZdZddedef�fdd�
Zdd�Zdd
1022  d�Zdd
�Zdd�Z	�Z
1023  S)r�Fr�r�cst���||_||_dSr&)�superr,�anchorr�)r(r�r��r�r*r+r,��
1024  
1025  z_PendingSkip.__init__cCst|jt���dd�S)Nrg�...)rsrRrg�replacer�r*r*r+r���z!_PendingSkip._generateDefaultNamerPr}cs\t|��d�d�}�jr'dd�}�fdd�}�j|��|�|��|�B|S�j||S)NrUr�cSs0|jr|j��dgkr|d=|�dd�dSdS)Nrrr�_skipped)rXr��pop�r�r*r*r+r��s�z'_PendingSkip.__add__.<locals>.must_skipcs@|j��dd�dgkr|�d�dt�j�d|d<dSdS)Nr�rrrXz	missing <�>)rXr�rY�reprrRrZr�r*r+�	show_skip�s
1026  �z'_PendingSkip.__add__.<locals>.show_skip)r�r�r�rRr)r(r��skipperr�r]r*r�r+r��s
1027  ��z_PendingSkip.__add__cCr�r&)rKr�r*r*r+r��r�z_PendingSkip.__repr__cGstd��)NzBuse of `...` expression without following SkipTo target expression)r0)r(r�r*r*r+r&�s�z_PendingSkip.parseImplr+r,)r/r4r5r}rsr,r�r�r�r&�
__classcell__r*r*rSr+r��s
1028  r�cs(eZdZdZ�fdd�Zdd�Z�ZS)�TokenzYAbstract :class:`ParserElement` subclass, for defining atomic
1029      matching patterns.
1030      cst�jdd�dS)NF�r��rQr,r�rSr*r+r,��zToken.__init__cCs
1031  t|�jSr&r�r�r*r*r+r��r-zToken._generateDefaultName)r/r4r5rBr,r�r_r*r*rSr+r`�sr`cs eZdZdZ�fdd�Z�ZS)rgz,
1032      An empty token, will always match.
1033      c�t���d|_d|_dSr�rQr,r�r�r�rSr*r+r,�rTzEmpty.__init__)r/r4r5rBr,r_r*r*rSr+rg�srgc�*eZdZdZ�fdd�Zddd�Z�ZS)�NoMatchz(
1034      A token that will never match.
1035      cs t���d|_d|_d|_dS)NTFzUnmatchable token)rQr,r�r�r�r�rSr*r+r,�s
1036  
1037  zNoMatch.__init__TcCst|||j|��r&)r�r�r%r*r*r+r&�szNoMatch.parseImplr-�r/r4r5rBr,r&r_r*r*rSr+rg��rgcsDeZdZdZd
dd�dedef�fdd�Zdd	�Zddd�Z�ZS)ra�
1038      Token to exactly match a specified string.
1039  
1040      Example::
1041  
1042          Literal('blah').parse_string('blah')  # -> ['blah']
1043          Literal('blah').parse_string('blahfooblah')  # -> ['blah']
1044          Literal('blah').parse_string('bla')  # -> Exception: Expected "blah"
1045  
1046      For case-insensitive matching, use :class:`CaselessLiteral`.
1047  
1048      For keyword matching (force word break before and after the matched string),
1049      use :class:`Keyword` or :class:`CaselessKeyword`.
1050      rr��matchString�match_stringrkcs�t���|p|}||_t|�|_z|d|_Wnty#td��wd|j|_	d|_
1051  d|_|jdkr@t|�t
urBt|_dSdSdS)Nrz2null string passed to Literal; use Empty() insteadr�Fr)rQr,�matchr!�matchLen�firstMatchCharr/r�rNr�r�r�r�r�_SingleCharLiteralr��r(rlrkrSr*r+r,	s
1052  
1053  �
1054  �zLiteral.__init__cC�
1055  t|j�Sr&�r\rmr�r*r*r+r�	r-zLiteral._generateDefaultNameTcCs<|||jkr|�|j|�r||j|jfSt|||j|��r&)ror<rmrnr�r�r%r*r*r+r& 	s
1056  �zLiteral.parseImpl�rrr-)	r/r4r5rBrsr,r�r&r_r*r*rSr+r�s
1057  rc@�eZdZddd�ZdS)rpTcCs,|||jkr|d|jfSt|||j|��r )rormr�r�r%r*r*r+r&)	sz_SingleCharLiteral.parseImplNr-�r/r4r5r&r*r*r*r+rp(	�rpc
s~eZdZdZedZ			dddd�dedejed	e	d
1058  edejef
1059  �fdd
�Z
1060  dd�Zddd�Ze
ddd��ZeZ�ZS)�Keyworda�
1061      Token to exactly match a specified string as a keyword, that is,
1062      it must be immediately followed by a non-keyword character.  Compare
1063      with :class:`Literal`:
1064  
1065      - ``Literal("if")`` will match the leading ``'if'`` in
1066        ``'ifAndOnlyIf'``.
1067      - ``Keyword("if")`` will not; it will only match the leading
1068        ``'if'`` in ``'if x=1'``, or ``'if(y==2)'``
1069  
1070      Accepts two optional constructor arguments in addition to the
1071      keyword string:
1072  
1073      - ``identChars`` is a string of characters that would be valid
1074        identifier characters, defaulting to all alphanumerics + "_" and
1075        "$"
1076      - ``caseless`` allows case-insensitive matching, default is ``False``.
1077  
1078      Example::
1079  
1080          Keyword("start").parse_string("start")  # -> ['start']
1081          Keyword("start").parse_string("starting")  # -> Exception
1082  
1083      For case-insensitive matching, use :class:`CaselessKeyword`.
1084      z_$rrNF�rk�
1085  identCharsrl�ident_chars�caselessrkrzcs�t���|p|}|durtj}|p|}||_t|�|_z|d|_Wnty.t	d��wd�
1086  t|�j|j
�|_d|_d|_||_|rN|��|_|��}t|�|_dS)Nrz2null string passed to Keyword; use Empty() insteadzExpected {} {}F)rQr,rx�DEFAULT_KEYWORD_CHARSrmr!rnror/r�r�r�r/rNr�r�r�r|�upper�
caselessmatchr�rz)r(rlr{r|rkrzrSr*r+r,O	s(
1087  	
1088  �
1089  zKeyword.__init__cCrrr&rsr�r*r*r+r�l	r-zKeyword._generateDefaultNameTcCsR|j}|}|jrU||||j���|jkrT|dks%||d��|jvrL|t|�|jks:|||j��|jvrB||j|jfS|d7}||j}nV|d7}|d}nM|||jkra|jdksh|�	|j|�r�|dksu||d|jvr�|t|�|jks�|||j|jvr�||j|jfS|d7}||j}n|d7}|d}t
1090  ||||��)Nrrz/, was immediately followed by keyword characterz7, keyword was immediately preceded by keyword characterz7, keyword was immediately followed by keyword character)r�r|rnr~rrzr!rmror<r�)r(r�r�r�r��errlocr*r*r+r&o	s8�
1091  ��zKeyword.parseImplrPcCr�)zX
1092          Overrides the default characters used by :class:`Keyword` expressions.
1093          N)rxr})r�r*r*r+�set_default_keyword_chars�	s
1094  z!Keyword.set_default_keyword_chars)rrNFr-rU)r/r4r5rB�	alphanumsr}rsr�r�rsr,r�r&r.r��setDefaultKeywordCharsr_r*r*rSr+rx2	s2�������
1095  /rxcs<eZdZdZddd�dedef�fdd�Zdd	d
1096  �Z�ZS)
�CaselessLiteralaq
1097      Token to match a specified string, ignoring case of letters.
1098      Note: the matched results will always be in the case of the given
1099      match string, NOT the case of the input text.
1100  
1101      Example::
1102  
1103          CaselessLiteral("CMD")[1, ...].parse_string("cmd CMD Cmd10")
1104          # -> ['CMD', 'CMD', 'CMD']
1105  
1106      (Contrast with example for :class:`CaselessKeyword`.)
1107      rrrjrlrkcs.|p|}t��|���||_d|j|_dS)Nr�)rQr,r~�returnStringrNr�rqrSr*r+r,�	szCaselessLiteral.__init__TcCs<||||j���|jkr||j|jfSt|||j|��r&)rnr~rmr�r�r�r%r*r*r+r&�	szCaselessLiteral.parseImplrtr-)r/r4r5rBrsr,r&r_r*r*rSr+r��	s
r�csLeZdZdZ		dddd�dedejededejef�fd	d
1108  �Z�ZS)�CaselessKeywordz�
1109      Caseless version of :class:`Keyword`.
1110  
1111      Example::
1112  
1113          CaselessKeyword("CMD")[1, ...].parse_string("cmd CMD Cmd10")
1114          # -> ['CMD', 'CMD']
1115  
1116      (Contrast with example for :class:`CaselessLiteral`.)
1117      rrNryrlr{rkrzcs&|p|}|p|}t�j||dd�dS)NT)r|rb)r(rlr{rkrzrSr*r+r,�	szCaselessKeyword.__init__)rrN)	r/r4r5rBrsr�r�r,r_r*r*rSr+r��	s 
������r�csLeZdZdZ	dddd�dededef�fd	d
1118  �Zdd�Zddd�Z�Z	S)�
1119  CloseMatcha�A variation on :class:`Literal` which matches "close" matches,
1120      that is, strings with at most 'n' mismatching characters.
1121      :class:`CloseMatch` takes parameters:
1122  
1123      - ``match_string`` - string to be matched
1124      - ``caseless`` - a boolean indicating whether to ignore casing when comparing characters
1125      - ``max_mismatches`` - (``default=1``) maximum number of
1126        mismatches allowed to count as a match
1127  
1128      The results from a successful parse will contain the matched text
1129      from the input string and the following named results:
1130  
1131      - ``mismatches`` - a list of the positions within the
1132        match_string where mismatches were found
1133      - ``original`` - the original match_string used to compare
1134        against the input string
1135  
1136      If ``mismatches`` is an empty list, then the match was an exact
1137      match.
1138  
1139      Example::
1140  
1141          patt = CloseMatch("ATCATCGAATGGA")
1142          patt.parse_string("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']})
1143          patt.parse_string("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1)
1144  
1145          # exact match
1146          patt.parse_string("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']})
1147  
1148          # close match allowing up to 2 mismatches
1149          patt = CloseMatch("ATCATCGAATGGA", max_mismatches=2)
1150          patt.parse_string("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']})
1151      NrF)�
maxMismatchesr|rl�max_mismatchesr�csN|dur|n|}t���||_||_d�|j|j�|_||_d|_d|_dS)Nz(Expected {!r} (with up to {} mismatches)F)	rQr,rlr�r�r�r|r�r�)r(rlr�r�r|rSr*r+r,�	s
1152  �
1153  zCloseMatch.__init__cCsd�t|�j|j�S)Nz{}:{!r})r�r�r/rlr�r*r*r+r�
1154  �zCloseMatch._generateDefaultNameTcCs�|}t|�}|t|j�}||krg|j}d}g}	|j}
1155  tt|||�|��D]%\}}|\}}
|jr:|��|
��}}
||
krK|	�|�t|	�|
1156  krKnq&||d}t|||�g�}||d<|	|d<||fSt	|||j
1157  |��)Nrr�original�
1158  mismatches)r!rlr��	enumerate�zipr|rtr�rr�r�)r(r�r�r�rpr"�maxlocrl�match_stringlocr�r��s_m�src�mat�resultsr*r*r+r&
1159  s2�
1160  �zCloseMatch.parseImplr&r-�
1161  r/r4r5rBrsr�r,r�r&r_r*r*rSr+r��	s%�����r�cs�eZdZdZ							dddddd�ded	ejed
1162  ededed
edejedejedejededejef�fdd�Z	dd�Z
1163  ddd�Z�ZS)�Worda8Token for matching words composed of allowed character sets.
1164      Parameters:
1165      - ``init_chars`` - string of all characters that should be used to
1166        match as a word; "ABC" will match "AAA", "ABAB", "CBAC", etc.;
1167        if ``body_chars`` is also specified, then this is the string of
1168        initial characters
1169      - ``body_chars`` - string of characters that
1170        can be used for matching after a matched initial character as
1171        given in ``init_chars``; if omitted, same as the initial characters
1172        (default=``None``)
1173      - ``min`` - minimum number of characters to match (default=1)
1174      - ``max`` - maximum number of characters to match (default=0)
1175      - ``exact`` - exact number of characters to match (default=0)
1176      - ``as_keyword`` - match as a keyword (default=``False``)
1177      - ``exclude_chars`` - characters that might be
1178        found in the input ``body_chars`` string but which should not be
1179        accepted for matching ;useful to define a word of all
1180        printables except for one or two characters, for instance
1181        (default=``None``)
1182  
1183      :class:`srange` is useful for defining custom character set strings
1184      for defining :class:`Word` expressions, using range notation from
1185      regular expression character sets.
1186  
1187      A common mistake is to use :class:`Word` to match a specific literal
1188      string, as in ``Word("Address")``. Remember that :class:`Word`
1189      uses the string argument to define *sets* of matchable characters.
1190      This expression would match "Add", "AAA", "dAred", or any other word
1191      made up of the characters 'A', 'd', 'r', 'e', and 's'. To match an
1192      exact literal string, use :class:`Literal` or :class:`Keyword`.
1193  
1194      pyparsing includes helper strings for building Words:
1195  
1196      - :class:`alphas`
1197      - :class:`nums`
1198      - :class:`alphanums`
1199      - :class:`hexnums`
1200      - :class:`alphas8bit` (alphabetic characters in ASCII range 128-255
1201        - accented, tilded, umlauted, etc.)
1202      - :class:`punc8bit` (non-alphabetic characters in ASCII range
1203        128-255 - currency, symbols, superscripts, diacriticals, etc.)
1204      - :class:`printables` (any non-whitespace character)
1205  
1206      ``alphas``, ``nums``, and ``printables`` are also defined in several
1207      Unicode sets - see :class:`pyparsing_unicode``.
1208  
1209      Example::
1210  
1211          # a word composed of digits
1212          integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9"))
1213  
1214          # a word with a leading capital, and zero or more lowercase
1215          capital_word = Word(alphas.upper(), alphas.lower())
1216  
1217          # hostnames are alphanumeric, with leading alpha, and '-'
1218          hostname = Word(alphas, alphanums + '-')
1219  
1220          # roman numeral (not a strict parser, accepts invalid mix of characters)
1221          roman = Word("IVXLCDM")
1222  
1223          # any string of non-whitespace characters, except for ','
1224          csv_value = Word(printables, exclude_chars=",")
1225      rrNrrF)�	initChars�	bodyChars�	asKeyword�excludeChars�
1226  init_chars�
1227  body_charsrr�max�exact�
1228  as_keyword�
exclude_charsr�r�r�r�c
s�|p|}|	p|}	|
1229  p|}
1230  |p|}t���|s!td�t|�j���t|�}||_|r:t|�}||8}|	r:t|	�|}	d�t	|��|_
1231  |	rRd�t	|	��|_t|	�|_n
d�t	|��|_t|�|_|dk|_
|dkrltd��||_|dkrw||_nt|_|dkr�||_||_d|j|_d|_|
1232  |_d|j|jBv�rI|dk�rK|dk�rM|j|jkr�|dkr�d	}n|dkr�d}nd
1233  �|j|jtkr�dn|j�}d�t|j�|�|_nIt|j�dkr�|dkr�d}nd
�|d�}d�t�|j
1234  �t|j�|�|_n$|dkr�d}n|dk�rd}nd
�|d�}d�t|j�t|j�|�|_|j�r&d|jd|_z	t�|j�|_Wntj�y>d|_YdSw|jj|_t|_dSdSdSdS)Nz,invalid {}, initChars cannot be empty stringrrrrzUcannot specify a minimum length < 1; use Opt(Word()) if zero-length word is permittedr�Fr��+�	{{{},{}}}z[{}]{}rz{{0,{}}}z{}[{}]{}raz
1235  [{}][{}]{}z\b) rQr,r�r�r�r/r�r�r��sorted�
initCharsOrig�
bodyCharsOrigr��maxSpecified�minLen�maxLenr4rNr�r�r�r�reStringr!�re�escape�compile�errorrm�re_match�
1236  _WordRegexr�)
r(r�r�rrr�r�r�r�r�r�r�r��repeatrSr*r+r,v
1237  s�
1238  ��
1239  
1240  �&��
1241  �
1242  ��
1243  
1244  �z
Word.__init__cCs�dd�}|j|jkrd�||j�||j��}nd�||j��}|jdks)|jtkrY|j|jkrB|jdkr:|dd�S|d�|j�S|jtkrO|d�|j�S|d	�|j|j�S|S)
1245  NcSs4d}t|dd�}t|�|kr|d|d�dS|S)N�F)�	re_escaper#rU)rr!)r��max_repr_lenr*r*r+�
1246  charsAsStr�
1247  s
1248  z-Word._generateDefaultName.<locals>.charsAsStrz
1249  W:({}, {})zW:({})rraz{{{}}}z
1250  {{{},...}}r�)r�r�r�r�r�r4)r(r��baser*r*r+r��
1251  s�
1252  
1253  zWord._generateDefaultNameTc	Cs|||jvrt|||j|��|}|d7}t|�}|j}||j}t||�}||kr>|||vr>|d7}||kr>|||vs0d}|||jkrJd}n+|jrZ||krZ|||vrZd}n|j	ru|dkri||d|vss||kru|||vrud}|rt|||j|��||||�fS)NrFTr)
1254  r�r�r�r!r�r�rrr�r�r�)	r(r�r�r�rpr"�	bodycharsr��throwExceptionr*r*r+r&s2
1255  
1256  �zWord.parseImpl)rrNrrrFNr-)
r/r4r5rBrsr�r�r�rsr,r�r&r_r*r*rSr+r�5
1257  sNB�
1258  ��������
1259  ���
�qr�c@ru)r�TcCs4|�||�}|st|||j|��|��}||��fSr&)r�r�r�rq�group)r(r�r�r�rPr*r*r+r&&s
1260  z_WordRegex.parseImplNr-rvr*r*r*r+r�%rwr�c
sPeZdZdZ		dddd�dededejeded	ejef
1261  �fd
1262  d�Z�Z	S)
�Charz�A short-cut class for defining :class:`Word` ``(characters, exact=1)``,
1263      when defining a match of any single character in a string of
1264      characters.
1265      FN)r�r��charsetr�r�r�r�csd|p|}|p|}t�j|d||d�d�t|j��|_|r$d�|j�|_t�|j�|_|jj|_	dS)Nr)r�r�r�z[{}]z\b{}\b)
1266  rQr,r�rr�r�r�r�rmr�)r(r�r�r�r�r�rSr*r+r,5s	�z
Char.__init__)FN)
1267  r/r4r5rBrsrsr�r�r,r_r*r*rSr+r�/s$�������r�cs�eZdZdZ			d ddd�dedeejefde	de	d	e	d
1268  e	f�fdd�Z
1269  ed
d��Zedd��Zedd��Z
dd�Zd!dd�Zd!dd�Zd!dd�Zdedefdd�Z�ZS)"�Regexa�Token for matching strings that match a given regular
1270      expression. Defined with string specifying the regular expression in
1271      a form recognized by the stdlib Python  `re module <https://docs.python.org/3/library/re.html>`_.
1272      If the given regex contains named groups (defined using ``(?P<name>...)``),
1273      these will be preserved as named :class:`ParseResults`.
1274  
1275      If instead of the Python stdlib ``re`` module you wish to use a different RE module
1276      (such as the ``regex`` module), you can do so by building your ``Regex`` object with
1277      a compiled RE that was compiled using ``regex``.
1278  
1279      Example::
1280  
1281          realnum = Regex(r"[+-]?\d+\.\d*")
1282          # ref: https://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
1283          roman = Regex(r"M{0,4}(CM|CD|D?{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")
1284  
1285          # named fields in a regex will be returned as named results
1286          date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
1287  
1288          # the Regex class will accept re's compiled using the regex module
1289          import regex
1290          parser = pp.Regex(regex.compile(r'[0-9]'))
1291      rF)�asGroupList�asMatch�pattern�flags�
as_group_list�as_matchr�r�cs�t���|p|}|p|}t|t�r%|std��d|_||_|_||_nt	|d�r=t	|d�r=||_|j|_|_||_nt
1292  d��d|j|_d|_
||_||_|jrW|j|_|jr`|j|_dSdS)aThe parameters ``pattern`` and ``flags`` are passed
1293          to the ``re.compile()`` function as-is. See the Python
1294          `re module <https://docs.python.org/3/library/re.html>`_ module for an
1295          explanation of the acceptable patterns and flags.
1296          z0null string passed to Regex; use Empty() insteadNr�rmzCRegex may only be constructed with a string or a compiled RE objectr�F)rQr,r1r"r��_rer�r�r�rr�rNr�r�r�r��parseImplAsGroupListr&�parseImplAsMatch)r(r�r�r�r�r�r�rSr*r+r,cs2
1297  
1298  ��zRegex.__init__cCs@|jr|jSz	t�|j|j�WStjytd�|j���w)Nz&invalid pattern ({!r}) passed to Regex)r�r�r�r�r�r�r�r�r�r*r*r+r��s
1299  ��zRegex.recCs|jjSr&)r�rmr�r*r*r+r��szRegex.re_matchcCs|�d�duS�Nrr)r�r�r*r*r+r��szRegex.mayReturnEmptycCsd�t|j��dd��S)NzRe:({})z\\�\)r�r\r�rVr�r*r*r+r��rWzRegex._generateDefaultNameTc	Csb|�||�}|st|||j|��|��}t|���}|��}|r-|��D]\}}|||<q$||fSr&)r�r�r�rqrr��	groupdict�items)	r(r�r�r�rPr2�d�k�vr*r*r+r&�s
1300  zRegex.parseImplcCs8|�||�}|st|||j|��|��}|��}||fSr&)r�r�r�rq�groups�r(r�r�r�rPr2r*r*r+r��szRegex.parseImplAsGroupListcCs4|�||�}|st|||j|��|��}|}||fSr&)r�r�r�rqr�r*r*r+r��szRegex.parseImplAsMatch�replrPcsP�jrtd���jrt��rtd���jr�fdd�}n��fdd�}��|�S)a�
1301          Return :class:`Regex` with an attached parse action to transform the parsed
1302          result as if called using `re.sub(expr, repl, string) <https://docs.python.org/3/library/re.html#re.sub>`_.
1303  
1304          Example::
1305  
1306              make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2</\1>")
1307              print(make_html.transform_string("h1:main title:"))
1308              # prints "<h1>main title</h1>"
1309          z-cannot use sub() with Regex(asGroupList=True)z9cannot use sub() with a callable with Regex(asMatch=True)cs|d���Sr�)�expand�r9)r�r*r+r���zRegex.sub.<locals>.pacs�j��|d�Sr�)r��subr��r�r(r*r+r��rc)r�r�r�rr)r(r�r�r*r�r+r��s
1310  z	Regex.sub)rFFr-)r/r4r5rBrrr��	RegexFlagr�rsr,r%r�r�r�r&r�r�rsr}r�r_r*r*rSr+r�Js@��������.
1311  
1312  
1313  
1314  
1315  
1316  		r�cs�eZdZdZdZ							dddddddd�ded	ejed
1317  ejededed
ejedededejedejededejedef�fdd�Z	dd�Z
1318  ddd�Z�ZS)�QuotedStringa
1319      Token for matching strings that are delimited by quoting characters.
1320  
1321      Defined with the following parameters:
1322  
1323      - ``quote_char`` - string of one or more characters defining the
1324        quote delimiting string
1325      - ``esc_char`` - character to re_escape quotes, typically backslash
1326        (default= ``None``)
1327      - ``esc_quote`` - special quote sequence to re_escape an embedded quote
1328        string (such as SQL's ``""`` to re_escape an embedded ``"``)
1329        (default= ``None``)
1330      - ``multiline`` - boolean indicating whether quotes can span
1331        multiple lines (default= ``False``)
1332      - ``unquote_results`` - boolean indicating whether the matched text
1333        should be unquoted (default= ``True``)
1334      - ``end_quote_char`` - string of one or more characters defining the
1335        end of the quote delimited string (default= ``None``  => same as
1336        quote_char)
1337      - ``convert_whitespace_escapes`` - convert escaped whitespace
1338        (``'\t'``, ``'\n'``, etc.) to actual whitespace
1339        (default= ``True``)
1340  
1341      Example::
1342  
1343          qs = QuotedString('"')
1344          print(qs.search_string('lsjdf "This is the quote" sldjf'))
1345          complex_qs = QuotedString('{{', end_quote_char='}}')
1346          print(complex_qs.search_string('lsjdf {{This is the "quote"}} sldjf'))
1347          sql_qs = QuotedString('"', esc_quote='""')
1348          print(sql_qs.search_string('lsjdf "This is the quote with ""embedded"" quotes" sldjf'))
1349  
1350      prints::
1351  
1352          [['This is the quote']]
1353          [['This is the "quote"']]
1354          [['This is the quote with "embedded" quotes']]
1355      ))z\t�	)rr)z\f�)z\r�
rrNFT)�	quoteChar�escChar�escQuote�unquoteResults�endQuoteChar�convertWhitespaceEscapes�
1356  quote_char�esc_char�	esc_quote�	multiline�unquote_results�end_quote_char�convert_whitespace_escapesr�r�r�r�r�r�c	sVt���|	p|}	|
1357  p|}
1358  |o|}|p|}|
o|}
|p|}|��}|s'td��|dur.|}n
1359  |��}|s8td��|�_t|��_|d�_|�_t|��_	|	�_
1360  |
1361  �_|�_|
�_
d}d}|
1362  rl|d�|t�|
1363  ��7}d}|	r�|d�|t�|	��7}d}t��j
1364  �d�_t�j�d	kr�|d
1365  �|�d��fdd�tt�j�d	dd
�D��d7}d}|r�tjtjB�_|d�|t�jd�|	dur�t|	�nd�7}nd�_|d�|t�jd�|	dur�t|	�nd�7}d�t��j�d|dt��j�g��_zt��j�j��_�j�_�jj�_Wntj�ytd��j���wd�j�_d�_ d�_!dS)Nz%quote_char cannot be the empty stringz'endQuoteChar cannot be the empty stringrrrz{}(?:{})�|z	{}(?:{}.)z(.)rz{}(?:c	3s<�|]}d�t��jd|��t��j|d���VqdS)z(?:{}(?!{}))N)r�r�r�r�)r>rpr�r*r+r
Ns���
1366  �z(QuotedString.__init__.<locals>.<genexpr>r��)z
{}(?:[^{}{}])z{}(?:[^{}\n\r{}])z(?:z)*z$invalid pattern {!r} passed to Regexr�FT)"rQr,rr�r�r!�quoteCharLen�firstQuoteCharr��endQuoteCharLenr�r�r�r�r�r�r��escCharReplacePatternr��range�	MULTILINE�DOTALLr�rr�r�r�rmr�r�rNr�r�r�)r(r�r�r�r�r�r�r�r�r�r�r�r�r��sep�
inner_patternrSr�r+r,s�
1367  �
1368  
1369  
1370  ������
1371  
1372  ��
1373  
1374  ��
1375  zQuotedString.__init__cCs4|j|jkrt|jt�rd�|j�Sd�|j|j�S)Nzstring enclosed in {!r}z.quoted string, starting with {} ending with {})r�r�r1r"r�r�r*r*r+r�s
1376  �z!QuotedString._generateDefaultNamecCs�|||jkr
|�||�pd}|st|||j|��|��}|��}|jr]||j|j�}t	|t
1377  �r]d|vrG|jrG|jD]
1378  \}}|�
||�}q<|jrRt�|jd|�}|jr]|�
|j|j�}||fS)Nr�z\g<1>)r�r�r�r�rqr�r�r�r�r1r"r��ws_maprVr�r�r�r�r�r�)r(r�r�r�rPr2�wslit�wscharr*r*r+r&�s(
1379  ��
1380  zQuotedString.parseImpl)rrNNFTNTr-)
r/r4r5rBr�rsr�r�rsr,r�r&r_r*r*rSr+r��s\&�
1381  ��������
1382  ���
���qr�csXeZdZdZ				ddd�dededed	ed
1383  ef
1384  �fdd�Zd
d�Zddd�Z�Z	S)�
1385  CharsNotIna�Token for matching words composed of characters *not* in a given
1386      set (will include whitespace in matched characters if not listed in
1387      the provided exclusion set - see example). Defined with string
1388      containing all disallowed characters, and an optional minimum,
1389      maximum, and/or exact length.  The default value for ``min`` is
1390      1 (a minimum value < 1 is not valid); the default values for
1391      ``max`` and ``exact`` are 0, meaning no maximum or exact
1392      length restriction.
1393  
1394      Example::
1395  
1396          # define a comma-separated-value as anything that is not a ','
1397          csv_value = CharsNotIn(',')
1398          print(delimited_list(csv_value).parse_string("dkls,lsdkjf,s12 34,@!#,213"))
1399  
1400      prints::
1401  
1402          ['dkls', 'lsdkjf', 's12 34', '@!#', '213']
1403      rrrr)�notChars�	not_charsrrr�r�r�cs�t���d|_|p||_t|j�|_|dkrtd��||_|dkr&||_nt	|_|dkr3||_||_d|j
1404  |_|jdk|_d|_
dS)NFrzacannot specify a minimum length < 1; use Opt(CharsNotIn()) if zero-length char group is permittedrr�)rQr,r�r�r��notCharsSetr�r�r�r4rNr�r�r�)r(r�rrr�r�r�rSr*r+r,�s$
1405  	
1406  �
1407  zCharsNotIn.__init__cCs6t|j�}t|�dkrd�|jdd��Sd�|j�S)Nr�z
1408  !W:({}...)�
z!W:({}))rr�r!r�)r(�
not_chars_strr*r*r+r��s
1409  zCharsNotIn._generateDefaultNameTcCs�|j}|||vrt|||j|��|}|d7}t||jt|��}||kr9|||vr9|d7}||kr9|||vs+|||jkrHt|||j|��||||�fSr )r�r�r�rrr�r!r�)r(r�r�r��notcharsrp�maxlenr*r*r+r&�s�zCharsNotIn.parseImpl)rrrrrr-r�r*r*rSr+r��s*�������#r�c	s�eZdZdZidd�dd�dd�dd	�d
1410  d�dd
�dd�dd�dd�dd�dd�dd�dd�dd�dd�d d!�d"d#�d$d%d&d'd(d)d*��Zd9d.ed/ed0ed1ef�fd2d3�
Zd4d5�Zd:d7d8�Z	�Z
1411  S);�Whitea�Special matching class for matching whitespace.  Normally,
1412      whitespace is ignored by pyparsing grammars.  This class is included
1413      when some whitespace structures are significant.  Define with
1414      a string containing the whitespace characters to be matched; default
1415      is ``" \t\r\n"``.  Also takes optional ``min``,
1416      ``max``, and ``exact`` arguments, as defined for the
1417      :class:`Word` class.
1418      r�z<SP>r�z<TAB>rz<LF>r�z<CR>r�z<FF>� z<NBSP>u z<OGHAM_SPACE_MARK>u᠎z<MONGOLIAN_VOWEL_SEPARATOR>u z	<EN_QUAD>u z	<EM_QUAD>u z
1419  <EN_SPACE>u z
1420  <EM_SPACE>u z<THREE-PER-EM_SPACE>u z<FOUR-PER-EM_SPACE>u z<SIX-PER-EM_SPACE>u z<FIGURE_SPACE>u z<PUNCTUATION_SPACE>z<THIN_SPACE>z<HAIR_SPACE>z<ZERO_WIDTH_SPACE>z<NNBSP>z<MMSP>z<IDEOGRAPHIC_SPACE>)u u u​u u u � 	
1421  rr�wsrrr�r�cs~t���|�_�jd��fdd��jD��dd�d�_d�j�_|�_	|dkr.|�_
1422  nt�_
1423  |dkr=|�_
1424  |�_	dSdS)Nrrc3s�|]
1425  }|�jvr|VqdSr&)�
1426  matchWhiter�r�r*r+r
!
s�z!White.__init__.<locals>.<genexpr>T�r�r�r)rQr,rr�r��	whiteStrsr�rNr�r�r�r4)r(r�rrr�r�rSr�r+r,
s 
1427  �
1428  �zWhite.__init__cCsd�dd�|jD��S)Nrrcss�|]}tj|VqdSr&)r�rr�r*r*r+r
4
r�z-White._generateDefaultName.<locals>.<genexpr>)r�rr�r*r*r+r�3
�zWhite._generateDefaultNameTcCs�|||jvrt|||j|��|}|d7}||j}t|t|��}||kr;|||jvr;|d7}||kr;|||jvs,|||jkrJt|||j|��||||�fSr )rr�r�r�rrr!r�)r(r�r�r�rpr�r*r*r+r&6
s
1429  �zWhite.parseImpl)r�rrrr-)r/r4r5rBrrsr�r,r�r&r_r*r*rSr+r��s^	��������	�
1430  ���
������ r�cseZdZ�fdd�Z�ZS)�
PositionTokencrdrrer�rSr*r+r,G
rTzPositionToken.__init__)r/r4r5r,r_r*r*rSr+rF
srcs8eZdZdZdef�fdd�Zdd�Zd
1431  dd	�Z�ZS)�
1432  GoToColumnzaToken to advance to a specific column of input text; useful for
1433      tabular report scraping.
1434      �colnocst���||_dSr&)rQr,r�)r(rrSr*r+r,R
�
1435  
1436  zGoToColumn.__init__cCs~t||�|jkr=t|�}|jr|�||�}||kr=||��r=t||�|jkr=|d7}||kr=||��r=t||�|jks'|Sr )r�r!r�r�isspace)r(r�r�r"r*r*r+r$V
s
1437  ��
1438  �zGoToColumn.preParseTcCsDt||�}||jkrt||d|��||j|}|||�}||fS)NzText not in expected column)r�r�)r(r�r�r��thiscol�newlocr2r*r*r+r&c
s
1439  
1440  zGoToColumn.parseImplr-)	r/r4r5rBr�r,r$r&r_r*r*rSr+rM
s
1441  
rcs2eZdZdZ�fdd�Zdd�Zd	dd�Z�ZS)
1442  �	LineStarta�Matches if current position is at the beginning of a line within
1443      the parse string
1444  
1445      Example::
1446  
1447          test = '''\
1448          AAA this line
1449          AAA and this line
1450            AAA but not this one
1451          B AAA and definitely not this one
1452          '''
1453  
1454          for t in (LineStart() + 'AAA' + restOfLine).search_string(test):
1455              print(t)
1456  
1457      prints::
1458  
1459          ['AAA', ' this line']
1460          ['AAA', ' and this line']
1461  
1462      csFt���|��t�|jB|_|j�d�t��|j�|_	d|_
1463  dS)NrzExpected start of line)rQr,r�r�r��orig_whiteChars�discardrgr�r^r�r�rSr*r+r,�
s
1464  
1465  zLineStart.__init__cCsb|dkr|S|j�||�}d|jvr/|||d�dkr/|j�||d�}|||d�dks|S)Nrrr)r^r$r)r(r�r�r2r*r*r+r$�
s
1466  �zLineStart.preParseTcCs&t||�dkr|gfSt|||j|��r )r�r�r�r%r*r*r+r&�
szLineStart.parseImplr-)r/r4r5rBr,r$r&r_r*r*rSr+rl
s
1467  
1468  rcrf)�LineEndzTMatches if current position is at the end of a line within the
1469      parse string
1470      cs0t���|j�d�|j|jdd�d|_dS)NrFrzExpected end of line)rQr,r�r
r�r�r�rSr*r+r,�
s
1471  
1472  zLineEnd.__init__TcCs\|t|�kr||dkr|ddfSt|||j|��|t|�kr&|dgfSt|||j|��)Nrr�r!r�r�r%r*r*r+r&�
szLineEnd.parseImplr-rhr*r*rSr+r�
rircrf)�StringStartzLMatches if current position is at the beginning of the parse
1473      string
1474      c�t���d|_dS)NzExpected start of text�rQr,r�r�rSr*r+r,�
rzStringStart.__init__TcCs0|dkr||�|d�krt|||j|��|gfSr�)r$r�r�r%r*r*r+r&�
szStringStart.parseImplr-rhr*r*rSr+r�
�rcrf)rhzG
1475      Matches if current position is at the end of the parse string
1476      cr)NzExpected end of textrr�rSr*r+r,�
rzStringEnd.__init__TcCsX|t|�krt|||j|��|t|�kr|dgfS|t|�kr$|gfSt|||j|��r rr%r*r*r+r&�
szStringEnd.parseImplr-rhr*r*rSr+rh�
rrhc�>eZdZdZefed�dedef�fdd�Zd
1477  dd	�Z�ZS)�	WordStarta�Matches if the current position is at the beginning of a
1478      :class:`Word`, and is not preceded by any character in a given
1479      set of ``word_chars`` (default= ``printables``). To emulate the
1480      ```` behavior of regular expressions, use
1481      ``WordStart(alphanums)``. ``WordStart`` will also match at
1482      the beginning of the string being parsed, or at the beginning of
1483      a line.
1484      ��	wordChars�
1485  word_charsrcs.|tkr|n|}t���t|�|_d|_dS)NzNot at the start of a word)�
1486  printablesrQr,r�rr��r(rrrSr*r+r,�
s
1487  
1488  
1489  zWordStart.__init__TcCs@|dkr||d|jvs|||jvrt|||j|��|gfS�Nrr)rr�r�r%r*r*r+r&�
s
1490  zWordStart.parseImplr-�	r/r4r5rBrrsr,r&r_r*r*rSr+r�
s 	rcr)�WordEndaiMatches if the current position is at the end of a :class:`Word`,
1491      and is not followed by any character in a given set of ``word_chars``
1492      (default= ``printables``). To emulate the ```` behavior of
1493      regular expressions, use ``WordEnd(alphanums)``. ``WordEnd``
1494      will also match at the end of the string being parsed, or at the end
1495      of a line.
1496      rrrcs4|tkr|n|}t���t|�|_d|_d|_dS)NFzNot at the end of a word)rrQr,r�rr�r�rrSr*r+r,�
s
1497  
1498  
1499  
1500  zWordEnd.__init__TcCsPt|�}|dkr$||kr$|||jvs||d|jvr$t|||j|��|gfSr)r!rr�r�)r(r�r�r�r"r*r*r+r&szWordEnd.parseImplr-rr*r*rSr+r�
s rcs�eZdZdZddejedef�fdd�
Zde	efdd	�Z
1501  defd
1502  d�Zd d
edef�fdd�
Zd d
edef�fdd�
Z
def�fdd�Zdd�Zdef�fdd�Zd!d"dd�Zdef�fdd�Zd�fdd�	Ze
ZeZ�ZS)#�ParseExpressionz]Abstract subclass of ParserElement, for combining and
1503      post-processing parsed tokens.
1504      F�exprsr�cs�t��|��t|t�rt|�}t|t�r��|�g�_n@t|t�r(|g�_n6t|t	�rIt|�}t
1505  dd�|D��rC�fdd�|D�}t|��_nzt|��_Wn
ty]|g�_Ynwd�_dS)Ncss�|]}t|t�VqdSr&)r1r")r>r�r*r*r+r
r�z+ParseExpression.__init__.<locals>.<genexpr>c3s(�|]}t|t�r��|�n|VqdSr&)r1r"r��r>rr�r*r+r
s
1506  ��
1507  �F)
rQr,r1�_generatorTyper�r"r�rr}r�anyr�r��r(rr�rSr�r+r,s*
1508  
1509  
1510  
1511  
1512  
1513  ��
1514  zParseExpression.__init__rPcCs|jdd�Sr&)rr�r*r*r+r�+r�zParseExpression.recursecCs|j�|�d|_|Sr&)rr�r�r�r*r*r+r�.szParseExpression.appendTr�c�<t��|�|rdd�|jD�|_|jD]}|�|�q|S)z�
1515          Extends ``leave_whitespace`` defined in base class, and also invokes ``leave_whitespace`` on
1516             all contained expressions.
1517          cS�g|]}|���qSr*�r�r r*r*r+r@;rz4ParseExpression.leave_whitespace.<locals>.<listcomp>)rQr�r�r(r�rrSr*r+r�3s
1518  z ParseExpression.leave_whitespacecr$)z�
1519          Extends ``ignore_whitespace`` defined in base class, and also invokes ``leave_whitespace`` on
1520             all contained expressions.
1521          cSr%r*r&r r*r*r+r@Grz5ParseExpression.ignore_whitespace.<locals>.<listcomp>)rQr�rr'rSr*r+r�@s
1522  z!ParseExpression.ignore_whitespacecslt|t�r ||jvrt��|�|jD]
1523  }|�|jd�q|St��|�|jD]
1524  }|�|jd�q)|S�Nr�)r1r�r�rQr�r)r(r�rrSr*r+r�L�
1525  
1526  
1527  �
1528  zParseExpression.ignorecC�d�|jjt|j��S�Nz{}:({}))r�r�r/rsrr�r*r*r+r�Xrz$ParseExpression._generateDefaultNamecs&|jr|St���|jD]}|��q
t|j�dkr�|jd}t||j�rR|jsR|jdurR|j	sR|jdd�|jdg|_d|_
1529  |j|jO_|j|jO_|jd}t||j�r�|js�|jdur�|j	s�|jdd�|jdd�|_d|_
1530  |j|jO_|j|jO_dt
|�|_|S)Nrarrr�r�)r�rQrerr!r1r�r�r�r�r�r�r�rsr�)r(rr�rSr*r+re[s@
1531  
1532  
1533  
1534  
1535  ��
1536  �
1537  
1538  ��
1539  �zParseExpression.streamlineNcCsB|dur|ngdd�|g}|jD]}|�|�q|�g�dSr&)rr�r�)r(r��tmprr*r*r+r��s
1540  zParseExpression.validatecs t���}dd�|jD�|_|S)NcSr%r*r&r r*r*r+r@�rz(ParseExpression.copy.<locals>.<listcomp>)rQr�r�r(r2rSr*r+r��s
1541  zParseExpression.copycsjtjr.tj|jvr.|jD]!}t|t�r-|jr-tj|jvr-tj	d�
1542  d|t|�j|j�dd�qt
��||�S�NzY{}: setting results name {!r} on {} expression collides with {!r} on contained expressionrWr#��
1543  stacklevel)rIrWr`r�rr1r}r��warningsrLr�r�r/rQr��r(rNr�rrSr*r+r��s2��
1544  ������zParseExpression._setResultsNamer+r-r&rU)r/r4r5rBr�rr}rsr,rr�r�r�r�r�r�rer�r�r�rOrPr_r*r*rSr+rs
)rcsxeZdZdZGdd�de�Z	ddejede	f�fdd�
Z
1545  d	ef�fd
1546  d�Zddd
�Zdd�Z
dd�Zdd�Z�ZS)r�a
1547      Requires all given :class:`ParseExpression` s to be found in the given order.
1548      Expressions may be separated by whitespace.
1549      May be constructed using the ``'+'`` operator.
1550      May also be constructed using the ``'-'`` operator, which will
1551      suppress backtracking.
1552  
1553      Example::
1554  
1555          integer = Word(nums)
1556          name_expr = Word(alphas)[1, ...]
1557  
1558          expr = And([integer("id"), name_expr("name"), integer("age")])
1559          # more easily written as:
1560          expr = integer("id") + name_expr("name") + integer("age")
1561      cs$eZdZ�fdd�Zdd�Z�ZS)zAnd._ErrorStopcst�j|i|��|��dSr&)rQr,r�)r(r�rrSr*r+r,�szAnd._ErrorStop.__init__cCr�)N�-r*r�r*r*r+r��r+z#And._ErrorStop._generateDefaultName)r/r4r5r,r�r_r*r*rSr+r��sr�T�	exprs_argr�cst|�}|rFt|vrFg}t|�D]/\}}|tur:|t|�dkr6t�||djd}|�t|�d��qtd��|�|�q||dd�<t	��
1562  ||�|jr~tdd�|jD��|_t
|jdt�sz|j|jdj|jdjd�|jdj|_nd	|_nd
1563  |_d
1564  |_dS)Nrr�r�z0cannot construct And with sequence ending in ...cs��|]}|jVqdSr&�r�r r*r*r+r
���zAnd.__init__.<locals>.<genexpr>rrFT)r�r�r�r!rgrr�r�r0rQr,rr�r1r�r�r�r�r�r�)r(r4r�rr,rpr��
1565  skipto_argrSr*r+r,�s2�
1566  
1567  �
1568  zAnd.__init__rPcsH|jrStdd�|jdd�D��rSt|jdd��D]/\}}|dur#qt|t�rI|jrIt|jdt�rI|jd|j|d|jd<d|j|d<qdd�|jD�|_t���t|j|jdd��D]3\}}t	�}|r�t
1569  |�|vrsn#|�t
1570  |��t|t�r�|�
|fdd��n
|��}tt|�d�}|slqctd	d�|jD��|_|S)
1571  Ncss0�|]}t|t�o|jot|jdt�VqdS�r�N)r1rrr�r r*r*r+r
�s�
1572  ��
1573  �z!And.streamline.<locals>.<genexpr>r�rcSsg|]}|dur|�qSr&r*r r*r*r+r@��z"And.streamline.<locals>.<listcomp>cSst|dt||��S)N�
parent_anchor)�setattrr�)r�r�r��cur_r*r*r+r�
1574  s�z And.streamline.<locals>.<lambda>csr5r&r6r r*r*r+r
r7)rr"r�r1rr�rQrer�r�r��add�
IndentedBlockrr��nextr�rr�)r(rpr�prev�cur�seen�subsrSr*r+re�sF�����
1575  
1576  
1577  ���zAnd.streamlinec	Cs�|jdj|||dd�\}}d}|jdd�D]X}t|�tjur#d}q|r\z|�|||�\}}Wn4ty8�tyK}zd|_t�|��d}~wt	y[t|t
1578  |�|j|��w|�|||�\}}|sk|��ro||7}q||fS)NrFrorT)
rrr�r�r��ParseSyntaxExceptionrHr��_from_exceptionr/r!r��haskeys)	r(r�r�r��
1579  resultlist�	errorStopr�
1580  exprtokensrNr*r*r+r&s6
1581  
1582  �
1583  ����z
And.parseImplcC�t|t�r
1584  |�|�}|�|�Sr&�r1r"r�r�r�r*r*r+�__iadd__3�
1585  
1586  
1587  zAnd.__iadd__cCs8|dd�|g}|jD]
}|�|�|jsdSqdSr&)rr�r�r�r*r*r+r�8s
1588  
1589  ��zAnd._checkRecursioncCszd�dd�|jD��}t|�dkr7|ddt|�d�dkr7|dd�}t|�dkr7|ddt|�d�dksd|d	S)
1590  Nr�csr
1591  r&rr r*r*r+r
@rz+And._generateDefaultName.<locals>.<genexpr>rr�{}r��{�})r�rr!�r(�innerr*r*r+r�?s
1592  &&�zAnd._generateDefaultNamer-)r/r4r5rBrgr�r�rr}rsr,rer&rMr�r�r_r*r*rSr+r��s	���!
1593  -r�c�leZdZdZddejedef�fdd�
Zdef�fdd	�Z	ddd�Z
1594  d
d�Zdd�Zd�fdd�	Z
�ZS)r�a�Requires that at least one :class:`ParseExpression` is found. If
1595      two expressions match, the expression that matches the longest
1596      string will be used. May be constructed using the ``'^'``
1597      operator.
1598  
1599      Example::
1600  
1601          # construct Or using '^' operator
1602  
1603          number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums))
1604          print(number.search_string("123 3.1416 789"))
1605  
1606      prints::
1607  
1608          [['123'], ['3.1416'], ['789']]
1609      Frr�c�Nt��||�|jr"tdd�|jD��|_tdd�|jD��|_dSd|_dS)Ncsr5r&r6r r*r*r+r
\r7zOr.__init__.<locals>.<genexpr>csr5r&r�r r*r*r+r
]r7T�rQr,rr"r�rr�r#rSr*r+r,Y�
1610  
1611  zOr.__init__rPcs`t���|jr+tdd�|jD��|_tdd�|jD��|_tdd�|jD��|_|Sd|_|S)Ncsr5r&r6r r*r*r+r
dr7z Or.streamline.<locals>.<genexpr>csr5r&�r�r r*r*r+r
er7cs�"�|]}|jot|t�VqdSr&�r�r1r�r r*r*r+r
f��
1612  �F)rQrerr"r�r�rr�r�rSr*r+reas
1613  
1614  ��z
Or.streamlineTcCsxd}d}g}g}tdd�|jD��r|�||�}|jD]q}z
1615  |j||dd�}	Wn]tyH}
1616  zd|
1617  _||
1618  _|�|
1619  �d}d}WYd}
1620  ~
1621  qd}
1622  ~
1623  wtyh}z|s^d|_|j	|kr^|}|j	}WYd}~qd}~wt
1624  y�t|�|kr�t|t|�|j|�}t|�}Yqw|�|	|f�q|r�|j
td�dd�|s�|dd}|�|||�Sd	}
|D]M\}}||
dkr�|
Sz|�|||�\}	}Wnty�}zd|_|j	|kr�|}|j	}WYd}~q�d}~ww|	|kr�|	|fS|	|
dkr�|	|f}
q�|
d	kr�|
S|�r*t|�dk�r$|j
d
1625  d�d�|dj	|dj	k�r$|j
d
d�d�|d}|�|du�r5|j|_|�t||d|��)Nr�csr5r&)r�r r*r*r+r
rr7zOr.parseImpl.<locals>.<genexpr>T�r>r)r��reverserr9cS�|jSr&�r��rr*r*r+r��r�zOr.parseImpl.<locals>.<lambda>�r�cS�|jtt|j��fSr&�r�r!rs�
parserElementr`r*r*r+r��r:� no defined alternatives to match)rrr$r@r�r�rdr�r�r�r/r!r��sortrrr�)r(r�r�r��	maxExcLoc�maxExceptionrw�fatalsr�loc2�pfer:�	best_expr�longest�loc1�expr1r��	max_fatalr*r*r+r&ms�
1626  
1627  �
1628  ����
1629  ���
1630  �zOr.parseImplcCrKr&rLr�r*r*r+�__ixor__�rNzOr.__ixor__cC�dd�dd�|jD��dS)NrPz ^ csr
1631  r&rr r*r*r+r
�rz*Or._generateDefaultName.<locals>.<genexpr>rQ�r�rr�r*r*r+r���zOr._generateDefaultNamec�Rtjr"tj|jvr"tdd�|jD��r"tjd�d|t	|�j
1632  �dd�t��||�S)Ncs�&�|]}t|t�otj|jvVqdSr&�r1r�r`rVr�r r*r*r+r
���
1633  ��
1634  �z%Or._setResultsName.<locals>.<genexpr>��{}: setting results name {!r} on {} expression will return a list of all parsed tokens in an And alternative, in prior versions only the first token was returned; enclose contained argument in GrouprVr#r/�
rIrVr`r�r"rr1rLr�r�r/rQr��r(rNr�rSr*r+r���$�����zOr._setResultsNamer+r-)r/r4r5rBr�rr}rsr,rer&rqr�r�r_r*r*rSr+r�Gs
1635  Rr�crT)r�a�Requires that at least one :class:`ParseExpression` is found. If
1636      more than one expression matches, the first one listed is the one that will
1637      match. May be constructed using the ``'|'`` operator.
1638  
1639      Example::
1640  
1641          # construct MatchFirst using '|' operator
1642  
1643          # watch the order of expressions to match
1644          number = Word(nums) | Combine(Word(nums) + '.' + Word(nums))
1645          print(number.search_string("123 3.1416 789")) #  Fail! -> [['123'], ['3'], ['1416'], ['789']]
1646  
1647          # put more selective expression first
1648          number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums)
1649          print(number.search_string("123 3.1416 789")) #  Better -> [['123'], ['3.1416'], ['789']]
1650      Frr�crU)Ncsr5r&r6r r*r*r+r
�r7z&MatchFirst.__init__.<locals>.<genexpr>csr5r&r�r r*r*r+r
�r7TrVr#rSr*r+r,�rWzMatchFirst.__init__rPcsp|jr|St���|jr0tdd�|jD��|_tdd�|jD��|_tdd�|jD��|_|Sd|_d|_|S)Ncsr5r&rXr r*r*r+r
r7z(MatchFirst.streamline.<locals>.<genexpr>csr5r&r6r r*r*r+r
r7csrYr&rZr r*r*r+r
r[FT)	r�rQrerr"r�r�rr�r�rSr*r+re�s
1651  
1652  ��zMatchFirst.streamlineTc	Cs�d}d}|jD]V}z
1653  |�|||�WSty&}zd|_||_�d}~wtyA}z|j|kr7|}|j}WYd}~qd}~wty]t|�|kr[t|t|�|j	|�}t|�}Yqw|durh|j	|_
1654  |�t||d|��)Nr�re)rrr�r�rdr�r�r/r!r�r�)	r(r�r�r�rgrhrrkr:r*r*r+r&sB
1655  
1656  ��
1657  �����zMatchFirst.parseImplcCrKr&rLr�r*r*r+�__ior__.rNzMatchFirst.__ior__cCrr)NrPz | csr
1658  r&rr r*r*r+r
4rz2MatchFirst._generateDefaultName.<locals>.<genexpr>rQrsr�r*r*r+r�3rtzMatchFirst._generateDefaultNamecru)Ncsrvr&rwr r*r*r+r
<rxz-MatchFirst._setResultsName.<locals>.<genexpr>ryrVr#r/rzr{rSr*r+r�6r|zMatchFirst._setResultsNamer+r-)r/r4r5rBr�rr}rsr,rer&r}r�r�r_r*r*rSr+r��s
1659  "r�csVeZdZdZddejedef�fdd�
Zdef�fdd	�Z	dd
1660  d�Z
1661  dd
�Z�ZS)r�alRequires all given :class:`ParseExpression` s to be found, but in
1662      any order. Expressions may be separated by whitespace.
1663  
1664      May be constructed using the ``'&'`` operator.
1665  
1666      Example::
1667  
1668          color = one_of("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN")
1669          shape_type = one_of("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON")
1670          integer = Word(nums)
1671          shape_attr = "shape:" + shape_type("shape")
1672          posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn")
1673          color_attr = "color:" + color("color")
1674          size_attr = "size:" + integer("size")
1675  
1676          # use Each (using operator '&') to accept attributes in any order
1677          # (shape and posn are required, color and size are optional)
1678          shape_spec = shape_attr & posn_attr & Opt(color_attr) & Opt(size_attr)
1679  
1680          shape_spec.run_tests('''
1681              shape: SQUARE color: BLACK posn: 100, 120
1682              shape: CIRCLE size: 50 color: BLUE posn: 50,80
1683              color:GREEN size:20 shape:TRIANGLE posn:20,40
1684              '''
1685              )
1686  
1687      prints::
1688  
1689          shape: SQUARE color: BLACK posn: 100, 120
1690          ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']]
1691          - color: BLACK
1692          - posn: ['100', ',', '120']
1693            - x: 100
1694            - y: 120
1695          - shape: SQUARE
1696  
1697  
1698          shape: CIRCLE size: 50 color: BLUE posn: 50,80
1699          ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']]
1700          - color: BLUE
1701          - posn: ['50', ',', '80']
1702            - x: 50
1703            - y: 80
1704          - shape: CIRCLE
1705          - size: 50
1706  
1707  
1708          color: GREEN size: 20 shape: TRIANGLE posn: 20,40
1709          ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']]
1710          - color: GREEN
1711          - posn: ['20', ',', '40']
1712            - x: 20
1713            - y: 40
1714          - shape: TRIANGLE
1715          - size: 20
1716      Trr�csHt��||�|jrtdd�|jD��|_nd|_d|_d|_d|_dS)Ncsr5r&r6r r*r*r+r
�r7z Each.__init__.<locals>.<genexpr>T)rQr,rrr�r��initExprGroupsr�r#rSr*r+r,�s
1717  z
Each.__init__rPcs4t���|jrtdd�|jD��|_|Sd|_|S)Ncsr5r&r6r r*r*r+r
�r7z"Each.streamline.<locals>.<genexpr>T)rQrerrr�r�rSr*r+re�s
1718  �zEach.streamlinecs�|jrItdd�|jD��|_dd�|jD�}dd�|jD�}|||_dd�|jD�|_dd�|jD�|_dd�|jD�|_|j|j7_d	|_|}|jdd�}|jdd��|jdd�}g}	d
1719  }
1720  g}g}|
1721  r�|�|}
|��|��|
D][}z
1722  |j	||d
1723  d�}Wn/t
1724  y�}zd|_||_|�
|�|�
|�WYd}~qzd}~wty�|�
|�Yqzw|	�
|j�t|�|��||vr�|�|�qz|�vrՈ�|�qzt|�t|
�kr�d	}
1725  |
1726  sj|�r
t|�dk�r|jd
d�d�|dj|djk�r|jdd�d�|d}|�|�r#d�dd�|D��}t||d�|���|	�fdd�|jD�7}	tg�}|	D]}|�|||�\}}||7}�q5||fS)Ncss(�|]}t|t�rt|j�|fVqdSr&)r1r�r�r�r r*r*r+r
�s�
1727  �
1728  �z!Each.parseImpl.<locals>.<genexpr>cSsg|]
1729  }t|t�r|j�qSr*�r1r�r�r r*r*r+r@��z"Each.parseImpl.<locals>.<listcomp>cSs&g|]}|jrt|tttf�s|�qSr*)r�r1r�r�r�r r*r*r+r@�s���cS�(g|]}t|t�r|jj|jdd��qS�T)r�)r1�_MultipleMatchr�r�r�r r*r*r+r@����cSr�r�)r1r�r�r�r�r r*r*r+r@�r�cSs g|]}t|tttf�s|�qSr*)r1r�r�r�r r*r*r+r@�s
1730  ��FTr\rcSr^r&r_r`r*r*r+r��r�z Each.parseImpl.<locals>.<lambda>rarcSrbr&rcr`r*r*r+r��r:z, cSrr*rr r*r*r+r@�rz*Missing one or more required elements ({})cs$g|]}t|t�r|j�vr|�qSr*rr ��tmpOptr*r+r@�s$)r~�dictr�opt1map�	optionals�multioptionals�
multirequired�requiredrRr@r�r�rdr�r�rr��remover!rfr�r�r�rr)r(r�r�r��opt1�opt2�tmpLoc�tmpReqd�multis�
1731  matchOrder�keepMatching�failedri�tmpExprsrrkrp�missing�
total_resultsr�r*r�r+r&�s�
1732  ��
1733  ���
1734  ��
1735  ���zEach.parseImplcCrr)NrPz & csr
1736  r&rr r*r*r+r
�rz,Each._generateDefaultName.<locals>.<genexpr>rQrsr�r*r*r+r��rtzEach._generateDefaultNamer-)
r/r4r5rBr�rr}rsr,rer&r�r_r*r*rSr+r�Qs9
1737  
1738  Wr�cs�eZdZdZddeeefdef�fdd�
Zde	efdd	�Z
1739  ddd�Zdd
edef�fdd�
Zdd
edef�fdd�
Z
def�fdd�Zdef�fdd�Zdd�Zdd dd�Zdd�Ze
ZeZ�ZS)!�ParseElementEnhancezfAbstract subclass of :class:`ParserElement`, for combining and
1740      post-processing parsed tokens.
1741      Fr�r�cs�t��|�t|t�r+t|jt�r|�|�}ntt|�|j�r$t|�}n|�t|��}||_	|durX|j
1742  |_
1743  |j|_|j|j
|jd�|j|_|j|_|j|_|j�|j�dSdS)Nr)rQr,r1r"�
1744  issubclassr�r`r�rr�r�r�r�r�r�r�r�r�r�r��r(r�r�rSr*r+r,�s&
1745  
1746  ��zParseElementEnhance.__init__rPcCs|jdur	|jgSgSr&�r�r�r*r*r+r�rzParseElementEnhance.recurseTcCs,|jdur|jj|||dd�St||d|��)NFrozNo expression defined)r�rr�r%r*r*r+r&s
1747  zParseElementEnhance.parseImplr�c�6t��|�|r|j��|_|jdur|j�|�|Sr&)rQr�r�r�r�rSr*r+r��
1748  z$ParseElementEnhance.leave_whitespacecr�r&)rQr�r�r�r�rSr*r+r�$r�z%ParseElementEnhance.ignore_whitespacecslt|t�r ||jvrt��|�|jdur|j�|jd�|St��|�|jdur4|j�|jd�|Sr()r1r�r�rQr�r�r�rSr*r+r�-r)zParseElementEnhance.ignorecs"t���|jdur|j��|Sr&)rQrer�r�rSr*r+re9s
1749  
1750  
1751  zParseElementEnhance.streamlinecCsF||vrt||g��|dd�|g}|jdur!|j�|�dSdSr&)�RecursiveGrammarExceptionr�r�)r(r�r�r*r*r+r�?s
1752  �z#ParseElementEnhance._checkRecursionNcCsB|durg}|dd�|g}|jdur|j�|�|�g�dSr&�r�r�r��r(r�r,r*r*r+r�Fs
1753  zParseElementEnhance.validatecCr*r+)r�r�r/rsr�r�r*r*r+r�Nrz(ParseElementEnhance._generateDefaultNamer+r-r&rU)r/r4r5rBrr}rsrsr,rr�r&r�r�r�rer�r�r�rOrPr_r*r*rSr+r��s 
1754  		r�cs`eZdZdZGdd�de�ZGdd�de�Zddd�d	ed
1755  edef�fdd
�Z	ddd�Z
1756  �ZS)r?z�
1757      Expression to match one or more expressions at a given indentation level.
1758      Useful for parsing text where structure is implied by indentation (like Python source code).
1759      c�"eZdZdef�fdd�Z�ZS)zIndentedBlock._Indent�ref_colc�,t���d���|_|��fdd��dS)Nzexpected indent at column {}cst||��kSr&�r�r��r�r*r+r�_�z0IndentedBlock._Indent.__init__.<locals>.<lambda>�rQr,r�r�r�r(r�rSr�r+r,\�
1760  zIndentedBlock._Indent.__init__�r/r4r5r�r,r_r*r*rSr+�_Indent[�r�cr�)zIndentedBlock._IndentGreaterr�cr�)Nz)expected indent at column greater than {}cst||��kSr&r�r�r�r*r+r�er�z7IndentedBlock._IndentGreater.__init__.<locals>.<lambda>r�r�rSr�r+r,br�z%IndentedBlock._IndentGreater.__init__r�r*r*rSr+�_IndentGreaterar�r�FT�r��groupedr�r�r�cs&t�j|dd�||_||_d|_dS)NTrar)rQr,�
1761  _recursive�_groupedr;)r(r�r�r�rSr*r+r,gs
1762  zIndentedBlock.__init__c
Cs�t��||�}|j�|||�t||�}|�|�}t�||j}|jrD|�|�}t|j|j|j	d�}	|	�
1763  |j�||	_|t
||	�7}|�dtt|��dd����d|���t|�}
1764  |�|j�t�B}|j	rlt}ndd�}||
1765  �t|��|||�S)Nr�zinner ������@cS�|Sr&r*r�r*r*r+r��r�z)IndentedBlock.parseImpl.<locals>.<lambda>)rgr$r�r@r�r�r�r�r?r�r�r�r;r�r��hexr�r~r�rh�Groupr�r&)
r(r�r�r��
1766  anchor_loc�
1767  indent_col�peer_detect_expr�
1768  inner_expr�
1769  sub_indent�nested_block�block�trailing_undentr�r*r*r+r&qs,
1770  
1771  
1772  �*�zIndentedBlock.parseImplr-)r/r4r5rBrgr�r�r}rsr,r&r_r*r*rSr+r?Us����
1773  r?c�<eZdZdZdeeeff�fdd�Zd�fdd�	Z�Z	S)	�
AtStringStartz�Matches if expression matches at the beginning of the parse
1774      string::
1775  
1776          AtStringStart(Word(nums)).parse_string("123")
1777          # prints ["123"]
1778  
1779          AtStringStart(Word(nums)).parse_string("    123")
1780          # raises ParseException
1781      r�c�t��|�d|_dS�NF�rQr,r��r(r�rSr*r+r,��
1782  zAtStringStart.__init__Tcs$|dkr
1783  t||d��t��|||�S)Nrznot found at string start)r�rQr&r%rSr*r+r&�szAtStringStart.parseImplr-�
1784  r/r4r5rBrr}rsr,r&r_r*r*rSr+r��s
1785  r�cr�)	�AtLineStarta�Matches if an expression matches at the beginning of a line within
1786      the parse string
1787  
1788      Example::
1789  
1790          test = '''\
1791          AAA this line
1792          AAA and this line
1793            AAA but not this one
1794          B AAA and definitely not this one
1795          '''
1796  
1797          for t in (AtLineStart('AAA') + restOfLine).search_string(test):
1798              print(t)
1799  
1800      prints::
1801  
1802          ['AAA', ' this line']
1803          ['AAA', ' and this line']
1804  
1805      r�cr�r�r�r�rSr*r+r,�r�zAtLineStart.__init__Tcs*t||�dkr
t||d��t��|||�S)Nrznot found at line start)r�r�rQr&r%rSr*r+r&�szAtLineStart.parseImplr-r�r*r*rSr+r��sr�cs8eZdZdZdeeeff�fdd�Zddd�Z�Z	S)	�
1806  FollowedByacLookahead matching of the given parse expression.
1807      ``FollowedBy`` does *not* advance the parsing position within
1808      the input string, it only verifies that the specified parse
1809      expression matches at the current position.  ``FollowedBy``
1810      always returns a null token list. If any results names are defined
1811      in the lookahead expression, those *will* be returned for access by
1812      name.
1813  
1814      Example::
1815  
1816          # use FollowedBy to match a label only if it is followed by a ':'
1817          data_word = Word(alphas)
1818          label = data_word + FollowedBy(':')
1819          attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
1820  
1821          attr_expr[1, ...].parse_string("shape: SQUARE color: BLACK posn: upper left").pprint()
1822  
1823      prints::
1824  
1825          [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']]
1826      r�cr�r��rQr,r�r�rSr*r+r,�r�zFollowedBy.__init__TcCs(|jj|||d�\}}|dd�=||fS)Nr?)r�r)r(r�r�r�r:r2r*r*r+r&�s
1827  zFollowedBy.parseImplr-r�r*r*rSr+r��sr�csFeZdZdZ	ddeeefdeje	f�fdd�
Z
1828  dd	d
1829  �Z�ZS)
�
1830  PrecededBya�Lookbehind matching of the given parse expression.
1831      ``PrecededBy`` does not advance the parsing position within the
1832      input string, it only verifies that the specified parse expression
1833      matches prior to the current position.  ``PrecededBy`` always
1834      returns a null token list, but if a results name is defined on the
1835      given expression, it is returned.
1836  
1837      Parameters:
1838  
1839      - expr - expression that must match prior to the current parse
1840        location
1841      - retreat - (default= ``None``) - (int) maximum number of characters
1842        to lookbehind prior to the current parse location
1843  
1844      If the lookbehind expression is a string, :class:`Literal`,
1845      :class:`Keyword`, or a :class:`Word` or :class:`CharsNotIn`
1846      with a specified exact or maximum length, then the retreat
1847      parameter is not required. Otherwise, retreat must be specified to
1848      give a maximum number of characters to look back from
1849      the current parse position for a lookbehind match.
1850  
1851      Example::
1852  
1853          # VB-style variable names with type prefixes
1854          int_var = PrecededBy("#") + pyparsing_common.identifier
1855          str_var = PrecededBy("$") + pyparsing_common.identifier
1856  
1857      Nr��retreatcs�t��|�|����|_d|_d|_d|_t|t�r#t	|�}d|_n+t|t
1858  tf�r1|j}d|_nt|t
tf�rD|jtkrD|j}d|_n
1859  t|t�rNd}d|_||_dt|�|_d|_|j�dd��dS)NTFrznot preceded by cSs|�tdd��Sr&)�__delitem__�slicer�r*r*r+r�$sz%PrecededBy.__init__.<locals>.<lambda>)rQr,r�r�r�r�r�r1r"r!rrxrnr�r�r�r4rr�rsr�r�r�r�)r(r�r�rSr*r+r,
s*
1860  
1861  zPrecededBy.__init__rTcCs�|jr!||jkrt|||j��||j}|j�||�\}}||fS|jt�}|td||j�|�}t|||j�}	tdt	||jd�d�D])}
1862  z|�|t
1863  |�|
1864  �\}}Wntyk}z|}	WYd}~qGd}~ww||fS|	�r)r�r�r�r�r�rrhr�r�rrr!rH)r(r�r�r�rpr:r2�	test_expr�instring_slice�	last_expr�offset�pber*r*r+r&&s*
1865  
1866  �����zPrecededBy.parseImplr&)rT)
r/r4r5rBrr}rsr�r�r�r,r&r_r*r*rSr+r��s�
1867  ��r�c@seZdZdZddd�ZdS)�Locateda�
1868      Decorates a returned token with its starting and ending
1869      locations in the input string.
1870  
1871      This helper adds the following results names:
1872  
1873      - ``locn_start`` - location where matched expression begins
1874      - ``locn_end`` - location where matched expression ends
1875      - ``value`` - the actual parsed results
1876  
1877      Be careful if the input text contains ``<TAB>`` characters, you
1878      may want to call :class:`ParserElement.parse_with_tabs`
1879  
1880      Example::
1881  
1882          wd = Word(alphas)
1883          for match in Located(wd).search_string("ljsdf123lksdjjf123lkkjj1222"):
1884              print(match)
1885  
1886      prints::
1887  
1888          [0, ['ljsdf'], 5]
1889          [8, ['lksdjjf'], 15]
1890          [18, ['lkkjj'], 23]
1891  
1892      TcCsZ|}|jj|||dd�\}}t|||g�}||d<||d<||d<|jr)||gfS||fS)NFro�
1893  locn_startrM�locn_end)r�rrr�)r(r�r�r�rpr9r;r*r*r+r&\s
1894  zLocated.parseImplNr-)r/r4r5rBr&r*r*r*r+r�@sr�cs@eZdZdZdeeeff�fdd�Zd
1895  dd�Zdd	�Z	�Z
1896  S)r�a�
1897      Lookahead to disallow matching with the given parse expression.
1898      ``NotAny`` does *not* advance the parsing position within the
1899      input string, it only verifies that the specified parse expression
1900      does *not* match at the current position.  Also, ``NotAny`` does
1901      *not* skip over leading whitespace. ``NotAny`` always returns
1902      a null token list.  May be constructed using the ``'~'`` operator.
1903  
1904      Example::
1905  
1906          AND, OR, NOT = map(CaselessKeyword, "AND OR NOT".split())
1907  
1908          # take care not to mistake keywords for identifiers
1909          ident = ~(AND | OR | NOT) + Word(alphas)
1910          boolean_term = Opt(NOT) + ident
1911  
1912          # very crude boolean expression - to support parenthesis groups and
1913          # operation hierarchy, use infix_notation
1914          boolean_expr = boolean_term + ((AND | OR) + boolean_term)[...]
1915  
1916          # integers that are followed by "." are actually floats
1917          integer = Word(nums) + ~Char(".")
1918      r�cs,t��|�d|_d|_dt|j�|_dS)NFTzFound unwanted token, )rQr,r�r�rsr�r�r�rSr*r+r,�szNotAny.__init__TcCs&|j�||�rt|||j|��|gfSr&)r�rAr�r�r%r*r*r+r&�szNotAny.parseImplcC�dt|j�dS)Nz~{rQ�rsr�r�r*r*r+r��rczNotAny._generateDefaultNamer-)r/r4r5rBrr}rsr,r&r�r_r*r*rSr+r�js
1919  
1920  	r�csveZdZ	ddd�dedejeeefdejeeeff�fdd�Zdefd	d
1921  �Z	ddd
�Z
1922  d�fdd�	Z�ZS)r�N��stopOnr��stop_onr�cs@t��|�|p	|}d|_|}t|t�r|�|�}|�|�dSr�)rQr,r�r1r"r�r�)r(r�r�r��enderrSr*r+r,�s
1923  
1924  z_MultipleMatch.__init__rPcCs2t|t�r
1925  |�|�}|dur||_|Sd|_|Sr&)r1r"r��	not_ender)r(r�r*r*r+r��s
1926  
1927  �z_MultipleMatch.stopOnTc	Cs�|jj}|j}|jdu}|r|jj}|r|||�||||�\}}z*|j}		|r/|||�|	r7|||�}
1928  n|}
1929  |||
1930  |�\}}|sG|��rK||7}q(ttfyYY||fSwr&)	r�rrr�r?r�rGr�r/)r(r�r�r��self_expr_parse�self_skip_ignorables�check_ender�
try_not_enderr9�hasIgnoreExprsrx�	tmptokensr*r*r+r&�s0
1931  
1932  
1933  
1934  �
1935  �z_MultipleMatch.parseImplFcsvtjr4tj|jvr4|jg|j��D]!}t|t�r3|jr3tj|jvr3t	j
1936  d�d|t|�j
|j�dd�qt��||�Sr.)rIrWr`r�r�r�r1r}r�r1rLr�r�r/rQr�r2rSr*r+r��s2��������z_MultipleMatch._setResultsNamer&r-r+)
r/r4r5r}r�r�rrsr,r�r&r�r_r*r*rSr+r��s�����
1937  r�c@seZdZdZdd�ZdS)r�ar
1938      Repetition of one or more of the given expression.
1939  
1940      Parameters:
1941      - expr - expression that must match one or more times
1942      - stop_on - (default= ``None``) - expression for a terminating sentinel
1943           (only required if the sentinel would ordinarily match the repetition
1944           expression)
1945  
1946      Example::
1947  
1948          data_word = Word(alphas)
1949          label = data_word + FollowedBy(':')
1950          attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).set_parse_action(' '.join))
1951  
1952          text = "shape: SQUARE posn: upper left color: BLACK"
1953          attr_expr[1, ...].parse_string(text).pprint()  # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]
1954  
1955          # use stop_on attribute for OneOrMore to avoid reading label string as part of the data
1956          attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
1957          OneOrMore(attr_expr).parse_string(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']]
1958  
1959          # could also be written as
1960          (attr_expr * (1,)).parse_string(text).pprint()
1961      cCr�)NrPz}...r�r�r*r*r+r��rczOneOrMore._generateDefaultNameN)r/r4r5rBr�r*r*r*r+r��sr�csjeZdZdZ	ddd�dedejeeefdejeeeff�fdd�Z	d�fd
1962  d�	Z
1963  dd
�Z�ZS)r�ao
1964      Optional repetition of zero or more of the given expression.
1965  
1966      Parameters:
1967      - ``expr`` - expression that must match zero or more times
1968      - ``stop_on`` - expression for a terminating sentinel
1969        (only required if the sentinel would ordinarily match the repetition
1970        expression) - (default= ``None``)
1971  
1972      Example: similar to :class:`OneOrMore`
1973      Nr�r�r�r�cst�j||p|d�d|_dS)Nr�Tr�)r(r�r�r�rSr*r+r,s
1974  zZeroOrMore.__init__Tc	s<z	t��|||�WSttfy|tg|jd�fYSw)Nr�)rQr&r�r/rr�r%rSr*r+r&s
1975  �zZeroOrMore.parseImplcCr�)N�[z]...r�r�r*r*r+r�rczZeroOrMore._generateDefaultNamer&r-)
r/r4r5rBr}r�r�rrsr,r&r�r_r*r*rSr+r�s�����
1976  r�c@seZdZdd�Zdd�ZdS)�
1977  _NullTokencCr�r�r*r�r*r*r+�__bool__$r+z_NullToken.__bool__cCr�r�r*r�r*r*r+r�'r+z_NullToken.__str__N)r/r4r5r�r�r*r*r*r+r�#sr�csNeZdZdZe�Zefdeeefde	f�fdd�
Z
1978  ddd�Zd	d
1979  �Z�Z
S)r�aN
1980      Optional matching of the given expression.
1981  
1982      Parameters:
1983      - ``expr`` - expression that must match zero or more times
1984      - ``default`` (optional) - value to be returned if the optional expression is not found.
1985  
1986      Example::
1987  
1988          # US postal code can be a 5-digit zip, plus optional 4-digit qualifier
1989          zip = Combine(Word(nums, exact=5) + Opt('-' + Word(nums, exact=4)))
1990          zip.run_tests('''
1991              # traditional ZIP code
1992              12345
1993  
1994              # ZIP+4 form
1995              12101-0001
1996  
1997              # invalid ZIP
1998              98765-
1999              ''')
2000  
2001      prints::
2002  
2003          # traditional ZIP code
2004          12345
2005          ['12345']
2006  
2007          # ZIP+4 form
2008          12101-0001
2009          ['12101-0001']
2010  
2011          # invalid ZIP
2012          98765-
2013               ^
2014          FAIL: Expected end of text (at char 5), (line:1, col:6)
2015      r��defaultcs*t�j|dd�|jj|_||_d|_dS)NFraT)rQr,r�r��defaultValuer�)r(r�r�rSr*r+r,Ts
2016  
2017  zOpt.__init__Tc	Cs�|j}z|j|||dd�\}}W||fSttfyG|j}||jur6|jr2t|g�}|||j<n|g}ng}Y||fSY||fSY||fSw)NFro)r�rr�r/r��_Opt__optionalNotMatchedr�r)r(r�r�r��	self_exprr9�
default_valuer*r*r+r&\s$�
2018  
2019  ���z
Opt.parseImplcCsnt|j�}t|�dkr1|ddt|�d�dkr1|dd�}t|�dkr1|ddt|�d�dksd|dS)NrrrOr�r��])rsr�r!rRr*r*r+r�ls
2020  
2021  &&�zOpt._generateDefaultNamer-)r/r4r5rBr�r�rr}rsrr,r&r�r_r*r*rSr+r�+s&�
2022  ��
2023  r�csleZdZdZ			ddd�deeefdededej	eeefd	eeeff
2024  �fd
2025  d�Z
2026  dd
d�Z�ZS)r�a*
2027  
2028      Token for skipping over all undefined text until the matched
2029      expression is found.
2030  
2031      Parameters:
2032      - ``expr`` - target expression marking the end of the data to be skipped
2033      - ``include`` - if ``True``, the target expression is also parsed
2034        (the skipped text and target expression are returned as a 2-element
2035        list) (default= ``False``).
2036      - ``ignore`` - (default= ``None``) used to define grammars (typically quoted strings and
2037        comments) that might contain false matches to the target expression
2038      - ``fail_on`` - (default= ``None``) define expressions that are not allowed to be
2039        included in the skipped test; if found before the target expression is found,
2040        the :class:`SkipTo` is not a match
2041  
2042      Example::
2043  
2044          report = '''
2045              Outstanding Issues Report - 1 Jan 2000
2046  
2047                 # | Severity | Description                               |  Days Open
2048              -----+----------+-------------------------------------------+-----------
2049               101 | Critical | Intermittent system crash                 |          6
2050                94 | Cosmetic | Spelling error on Login ('log|n')         |         14
2051                79 | Minor    | System slow when running too many reports |         47
2052              '''
2053          integer = Word(nums)
2054          SEP = Suppress('|')
2055          # use SkipTo to simply match everything up until the next SEP
2056          # - ignore quoted strings, so that a '|' character inside a quoted string does not match
2057          # - parse action will call token.strip() for each matched token, i.e., the description body
2058          string_data = SkipTo(SEP, ignore=quoted_string)
2059          string_data.set_parse_action(token_map(str.strip))
2060          ticket_expr = (integer("issue_num") + SEP
2061                        + string_data("sev") + SEP
2062                        + string_data("desc") + SEP
2063                        + integer("days_open"))
2064  
2065          for tkt in ticket_expr.search_string(report):
2066              print tkt.dump()
2067  
2068      prints::
2069  
2070          ['101', 'Critical', 'Intermittent system crash', '6']
2071          - days_open: '6'
2072          - desc: 'Intermittent system crash'
2073          - issue_num: '101'
2074          - sev: 'Critical'
2075          ['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14']
2076          - days_open: '14'
2077          - desc: "Spelling error on Login ('log|n')"
2078          - issue_num: '94'
2079          - sev: 'Cosmetic'
2080          ['79', 'Minor', 'System slow when running too many reports', '47']
2081          - days_open: '47'
2082          - desc: 'System slow when running too many reports'
2083          - issue_num: '79'
2084          - sev: 'Minor'
2085      FN)�failOnr��includer��fail_onr�csdt��|�|p	|}||_d|_d|_||_d|_t|t�r%|�	|�|_
2086  n||_
2087  dt|j�|_
dS)NTFzNo match found for )rQr,�
2088  ignoreExprr�r��includeMatchr�r1r"r�r�rsr�r�)r(r�r�r�r�r�rSr*r+r,�s	
2089  zSkipTo.__init__Tc
	Cs|}t|�}|jj}|jdur|jjnd}|jdur|jjnd}|}	|	|krf|dur0|||	�r0n>|durG	z|||	�}	Wn	tyEYnwq5z
2090  |||	ddd�Wntt	fy`|	d7}	Ynwn|	|ks&t|||j
2091  |��|	}|||�}
2092  t|
2093  �}|jr�||||dd�\}}||7}||fS)NrF)r�rro)
r!r�rr�r@r�r?rHr�r/r�rr�)
r(r�r�r�r�r"r��self_failOn_canParseNext�self_ignoreExpr_tryParse�tmploc�skiptext�
2094  skipresultr�r*r*r+r&�sF��
2095  ����zSkipTo.parseImpl)FNNr-)
r/r4r5rBrr}rsrsr�r�r,r&r_r*r*rSr+r�ws&?��
2096  ����
2097  �r�cs�eZdZdZd"dejeeeff�fdd�
Z	dd�Z
2098  dd	�Z�fd
2099  d�Zdd
�Z
d#�fdd�	Zd#dedefdd�Zd#dedefdd�Zdefdd�Zd"d$dd�Zdd�Zdef�fdd�Zd%�fd d!�	ZeZeZ�ZS)&rBaw
2100      Forward declaration of an expression to be defined later -
2101      used for recursive grammars, such as algebraic infix notation.
2102      When the expression is known, it is assigned to the ``Forward``
2103      variable using the ``'<<'`` operator.
2104  
2105      Note: take care when assigning to ``Forward`` not to overlook
2106      precedence of operators.
2107  
2108      Specifically, ``'|'`` has a lower precedence than ``'<<'``, so that::
2109  
2110          fwd_expr << a | b | c
2111  
2112      will actually be evaluated as::
2113  
2114          (fwd_expr << a) | b | c
2115  
2116      thereby leaving b and c out as parseable alternatives.  It is recommended that you
2117      explicitly group the values inserted into the ``Forward``::
2118  
2119          fwd_expr << (a | b | c)
2120  
2121      Converting to use the ``'<<='`` operator instead will avoid this problem.
2122  
2123      See :class:`ParseResults.pprint` for an example of a recursive
2124      parser created using ``Forward``.
2125      Nr�cs,tjdd�d|_t�j|dd�d|_dS)Nrar�rFra)r�r��caller_framerQr,�lshift_liner�rSr*r+r,s
2126  zForward.__init__cCs�t|d�r|`t|t�r|�|�}||_|jj|_|jj|_|j|jj	|jj
2127  d�|jj|_|jj|_|j
�|jj
�tjdd�d|_|S)Nr�rrar������)rr�r1r"r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r*r*r+�
2128  __lshift__s
2129  
2130  
2131  
2132  
2133  �
2134  
2135  zForward.__lshift__cCs||>Sr&r*r�r*r*r+�__ilshift__0r'zForward.__ilshift__csJtjdd�d}tjr||jkrtj|jvrtjddd�t	��
2136  |�}|S)Nrar�r�z<using '<<' operator with '|' is probably an error, use '<<='r/)r�r�rIr\r�r`r�r1rLrQr�)r(r��caller_liner2rSr*r+r�3s�
2137  ��zForward.__or__cCsF|jdurtjrtj|jvr!tjdt|jj	|jj
2138  d�dSdSdSdS)NzIForward defined here but no expression attached later using '<<=' or '<<')�filenamer�)r�rIrZr`r�r1�
warn_explicit�UserWarningr�r�r�r�r*r*r+�__del__Bs
2139  �
2140  ��zForward.__del__TcsX|jdur9tjr9tj|jvr9gd�}tjdd�}tt|�dd�D]\}}|j	|vr/|d}nq d}t
2141  jd|d�tj
sDt��|||�Stj��tj}	z|	|||f\}
2142  }t|t�r\|�|
2143  |��fWWd�St�y ||d	f}||d
2144  f}
|dt||d|�f\}
2145  }|	|
<|r�|	|
|	|<	zt��||d
2146  �\}}Wnty�t|t�r��|
2147  |}}Ynw||
2148  kr�|r�|	|\}
2149  }|	|
<|	|
=|	|=|
2150  |��fYWd�S|	|
=|
2151  |��fYWd�S|�rzt��||d	�|	|<Wnt�y}z||f|	|
<|	|<�d}~ww||f\}
2152  }|	|
<q�w1�s%wYdS)N)rkr{r�r���r�r)rprazGForward expression was never assigned a value, will not parse any inputr/TFz#Forward recursion without base case)r�rIrYr`r�r�r�r��reversedrNr1rLr}rTrQr&r2rCr1r0r��KeyErrorr�)r(r�r�r��	parse_fnsr�rp�frmr0�memo�prev_loc�prev_result�act_key�peek_key�	prev_peek�new_loc�new_peekrrSr*r+r&Ps�
2153  ��
2154  ��
2155  �
2156  
2157  ��
2158  ��%�)�����zForward.parseImplr�rPcCr�r�r�r�r*r*r+r���zForward.leave_whitespacecCr�r�r�r�r*r*r+r��rzForward.ignore_whitespacecCs$|jsd|_|jdur|j��|Sr�)r�r�rer�r*r*r+re�s
2159  
2160  
2161  zForward.streamlinecCsJ|durg}||vr|dd�|g}|jdur|j�|�|�g�dSr&r�r�r*r*r+r��s
2162  zForward.validatecCsnd|_d}z#|jdurt|j�dd�}nd}W|jjd|SW|jjd|S|jjd|YS)Nz: ...rUi��Nonez: )r�r�rsr�r/)r(�	retStringr*r*r+r��s
2163  �,zForward._generateDefaultNamecs&|jdur
2164  t���St�}||K}|Sr&)r�rQr�rBr-rSr*r+r��s
2165  
2166  
2167  zForward.copyFcsHtjrtj|jvr|jdurtjd�d|t|�j	�dd�t
2168  ��||�S)NzO{}: setting results name {!r} on {} expression that has no contained expressionrXr#r/)rIrXr`r�r�r1rLr�r�r/rQr�)r(rNr�rSr*r+r��s��
2169  ��zForward._setResultsNamer&r-rUr+)r/r4r5rBr�r�rr}rsr,r�r�r�rr&rsr�r�rer�r�r�r�rOrPr_r*r*rSr+rB�s""_
2170  rBcs0eZdZdZddeeeff�fdd�
Z�ZS)�TokenConverterzW
2171      Abstract subclass of :class:`ParseExpression`, for converting parsed results.
2172      Fr�cr�r�)rQr,r�r�rSr*r+r,�r�zTokenConverter.__init__r+)	r/r4r5rBrr}rsr,r_r*r*rSr+r�s$rcs^eZdZdZ		ddd�dededed	ejef�fd
2173  d�Z	def�fd
d�Z
2174  dd�Z�ZS)�Combinea�Converter to concatenate all matching tokens to a single string.
2175      By default, the matching patterns must also be contiguous in the
2176      input string; this can be disabled by specifying
2177      ``'adjacent=False'`` in the constructor.
2178  
2179      Example::
2180  
2181          real = Word(nums) + '.' + Word(nums)
2182          print(real.parse_string('3.1416')) # -> ['3', '.', '1416']
2183          # will also erroneously match the following
2184          print(real.parse_string('3. 1416')) # -> ['3', '.', '1416']
2185  
2186          real = Combine(Word(nums) + '.' + Word(nums))
2187          print(real.parse_string('3.1416')) # -> ['3.1416']
2188          # no match when there are internal spaces
2189          print(real.parse_string('3. 1416')) # -> Exception: Expected W:(0123...)
2190      rrTN)�
2191  joinStringr��join_string�adjacentrcsDt��|�|dur|n|}|r|��||_d|_||_d|_dSr�)rQr,r�rr�rr�)r(r�rrrrSr*r+r,s
2192  zCombine.__init__rPcs&|jrt�||�|St��|�|Sr&)rr}r�rQr�rSr*r+r�"s
2193  �zCombine.ignorecCsL|��}|dd�=|td�|�|j��g|jd�7}|jr$|��r$|gS|S)Nrr)r.)r�rr��
_asStringListrr�r�rG)r(r�r�r)�retToksr*r*r+r*)s
2194  �zCombine.postParse)rrT)
r/r4r5rBr}rsrsr�r�r,r�r*r_r*r*rSr+r�s"������rc�4eZdZdZd	dedef�fdd�
Zdd�Z�ZS)
2195  r�a�Converter to return the matched tokens as a list - useful for
2196      returning tokens of :class:`ZeroOrMore` and :class:`OneOrMore` expressions.
2197  
2198      The optional ``aslist`` argument when set to True will return the
2199      parsed tokens as a Python list instead of a pyparsing ParseResults.
2200  
2201      Example::
2202  
2203          ident = Word(alphas)
2204          num = Word(nums)
2205          term = ident | num
2206          func = ident + Opt(delimited_list(term))
2207          print(func.parse_string("fn a, b, 100"))
2208          # -> ['fn', 'a', 'b', '100']
2209  
2210          func = ident + Group(Opt(delimited_list(term)))
2211          print(func.parse_string("fn a, b, 100"))
2212          # -> ['fn', ['a', 'b', '100']]
2213      Fr��aslistc�t��|�d|_||_dSr�)rQr,r��
_asPythonList)r(r�rrSr*r+r,K�
2214  zGroup.__init__cCs.|jrt�t|t�r|���St|��S|gSr&)rrrr1r-r�r(r*r*r+r*Ps���zGroup.postParser+�	r/r4r5rBr}rsr,r*r_r*r*rSr+r�6sr�cr)
2215  r3arConverter to return a repetitive expression as a list, but also
2216      as a dictionary. Each element can also be referenced using the first
2217      token in the expression as its key. Useful for tabular report
2218      scraping when the first column can be used as a item key.
2219  
2220      The optional ``asdict`` argument when set to True will return the
2221      parsed tokens as a Python dict instead of a pyparsing ParseResults.
2222  
2223      Example::
2224  
2225          data_word = Word(alphas)
2226          label = data_word + FollowedBy(':')
2227  
2228          text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
2229          attr_expr = (label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
2230  
2231          # print attributes as plain groups
2232          print(attr_expr[1, ...].parse_string(text).dump())
2233  
2234          # instead of OneOrMore(expr), parse using Dict(Group(expr)[1, ...]) - Dict will auto-assign names
2235          result = Dict(Group(attr_expr)[1, ...]).parse_string(text)
2236          print(result.dump())
2237  
2238          # access named fields as dict entries, or output as dict
2239          print(result['shape'])
2240          print(result.as_dict())
2241  
2242      prints::
2243  
2244          ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']
2245          [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
2246          - color: 'light blue'
2247          - posn: 'upper left'
2248          - shape: 'SQUARE'
2249          - texture: 'burlap'
2250          SQUARE
2251          {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}
2252  
2253      See more examples at :class:`ParseResults` of accessing fields by results name.
2254      Fr��asdictcrr�)rQr,r��
_asPythonDict)r(r�rrSr*r+r,�rz
Dict.__init__c		Cs&t|�D]w\}}t|�dkrq|d}t|t�rt|���}t|�dkr,td|�||<qt|�dkrCt|dt�sCt|d|�||<qz|��}Wnt	yWt
2255  d�}|d�w|d=t|�dksjt|t�rr|��rrt||�||<qt|d|�||<q|jr�|j
r�|��gS|��S|j
r�|gS|S)Nrrrrrazdcould not extract dict values from parsed results - Dict expression must contain Grouped expressions)r�r!r1r�rsrr rr�r0r�rGrr��as_dict)	r(r�r�r)rp�tok�ikey�	dictvaluer�r*r*r+r*�s:
2256  ����zDict.postParser+rr*r*rSr+r3[s)r3csfeZdZdZddeeefdef�fdd�
Zd�fd	d
2257  �Z	d�fdd�Z
2258  d
d�Zdefdd�Z�Z
S)r�a�Converter for ignoring the results of a parsed expression.
2259  
2260      Example::
2261  
2262          source = "a, b, c,d"
2263          wd = Word(alphas)
2264          wd_list1 = wd + (',' + wd)[...]
2265          print(wd_list1.parse_string(source))
2266  
2267          # often, delimiters that are useful during parsing are just in the
2268          # way afterward - use Suppress to keep them out of the parsed output
2269          wd_list2 = wd + (Suppress(',') + wd)[...]
2270          print(wd_list2.parse_string(source))
2271  
2272          # Skipped text (using '...') can be suppressed as well
2273          source = "lead in START relevant text END trailing text"
2274          start_marker = Keyword("START")
2275          end_marker = Keyword("END")
2276          find_body = Suppress(...) + start_marker + ... + end_marker
2277          print(find_body.parse_string(source)
2278  
2279      prints::
2280  
2281          ['a', ',', 'b', ',', 'c', ',', 'd']
2282          ['a', 'b', 'c', 'd']
2283          ['START', 'relevant text ', 'END']
2284  
2285      (See also :class:`delimited_list`.)
2286      Fr�r�cs"|dur	tt��}t��|�dS)N.)r�rgrQr,r�rSr*r+r,�s
2287  zSuppress.__init__rPr}cs(t|jt�rtt|��|St��|�Sr&)r1r�r�r�r�rQr�r�rSr*r+r���zSuppress.__add__cs(t|jt�rtt|��|St��|�Sr&)r1r�r�r�r�rQr�r�rSr*r+r��r$zSuppress.__sub__cCr�r&r*r(r*r*r+r*�r+zSuppress.postParsecCr�r&r*r�r*r*r+r��r+zSuppress.suppressr+r,)r/r4r5rBrr}rsrsr,r�r�r*r�r_r*r*rSr+r��s r�r�cs t����fdd�}�j|_|S)asDecorator for debugging parse actions.
2288  
2289      When the parse action is called, this decorator will print
2290      ``">> entering method-name(line:<current_source_line>, <parse_location>, <matched_tokens>)"``.
2291      When the parse action completes, the decorator will print
2292      ``"<<"`` followed by the returned value, or any exception that the parse action raised.
2293  
2294      Example::
2295  
2296          wd = Word(alphas)
2297  
2298          @trace_parse_action
2299          def remove_duplicate_chars(tokens):
2300              return ''.join(sorted(set(''.join(tokens))))
2301  
2302          wds = wd[1, ...].set_parse_action(remove_duplicate_chars)
2303          print(wds.parse_string("slkdjs sld sldd sdlf sdljf"))
2304  
2305      prints::
2306  
2307          >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {}))
2308          <<leaving remove_duplicate_chars (ret: 'dfjkls')
2309          ['dfjkls']
2310      c
2311  s��j}|dd�\}}}t|�dkr|djjd|}tj�d�|t||�||��z�|�}WntyH}ztj�d�||���d}~wwtj�d�||��|S)N�����r#r�.z$>>entering {}(line: {!r}, {}, {!r})
2312  z<<leaving {} (exception: {})
2313  z<<leaving {} (ret: {!r})
2314  )	r/r!r�r�stderrrr�r�r0)�paArgs�thisFuncr�r�r�r2r��r�r*r+�zs ���ztrace_parse_action.<locals>.z)r�r/)r�r+r*r*r+�trace_parse_action�sr,�empty�
2315  line_start�line_end�string_start�
2316  string_endz\[]-*.$+^?()~ ra)r�cCs|ddSrr*r�r*r*r+r� sr�z\\0?[xX][0-9a-fA-F]+cCstt|d�d�d��S)Nrz\0xr�)�chrr�rr�r*r*r+r�#r:z	\\0[0-7]+cCstt|ddd�d��S)Nrrr$)r2r�r�r*r*r+r�&rAz\]r3r��^�negate�bodyr�r�cs@dd��zd��fdd�t�|�jD��WStyYdSw)a	Helper to easily define string ranges for use in :class:`Word`
2317      construction. Borrows syntax from regexp ``'[]'`` string range
2318      definitions::
2319  
2320          srange("[0-9]")   -> "0123456789"
2321          srange("[a-z]")   -> "abcdefghijklmnopqrstuvwxyz"
2322          srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"
2323  
2324      The input string must be enclosed in []'s, and the returned string
2325      is the expanded character set joined into a single string. The
2326      values enclosed in the []'s may be:
2327  
2328      - a single character
2329      - an escaped character with a leading backslash (such as ``\-``
2330        or ``\]``)
2331      - an escaped hex character with a leading ``'\x'``
2332        (``\x21``, which is a ``'!'`` character) (``\0x##``
2333        is also supported for backwards compatibility)
2334      - an escaped octal character with a leading ``'\0'``
2335        (``\041``, which is a ``'!'`` character)
2336      - a range of any of the above, separated by a dash (``'a-z'``,
2337        etc.)
2338      - any combination of the above (``'aeiouy'``,
2339        ``'a-zA-Z0-9_$'``, etc.)
2340      cSs<t|t�s|Sd�dd�tt|d�t|d�d�D��S)Nrrcsr
2341  r&)r2r�r*r*r+r
Qrz+srange.<locals>.<lambda>.<locals>.<genexpr>rr)r1rr�r��ord)�pr*r*r+r�Os�.zsrange.<locals>.<lambda>rrc3s�|]}�|�VqdSr&r*)r>�part��	_expandedr*r+r
Trzsrange.<locals>.<genexpr>)r��_reBracketExprrkr5r0)r�r*r9r+�srange4s�"�r<cs,��fdd�}t�dt�d�j�}||_|S)a^Helper to define a parse action by mapping a function to all
2342      elements of a :class:`ParseResults` list. If any additional args are passed,
2343      they are forwarded to the given function as additional arguments
2344      after the token, as in
2345      ``hex_integer = Word(hexnums).set_parse_action(token_map(int, 16))``,
2346      which will convert the parsed data to an integer using base 16.
2347  
2348      Example (compare the last to example in :class:`ParserElement.transform_string`::
2349  
2350          hex_ints = Word(hexnums)[1, ...].set_parse_action(token_map(int, 16))
2351          hex_ints.run_tests('''
2352              00 11 22 aa FF 0a 0d 1a
2353              ''')
2354  
2355          upperword = Word(alphas).set_parse_action(token_map(str.upper))
2356          upperword[1, ...].run_tests('''
2357              my kingdom for a horse
2358              ''')
2359  
2360          wd = Word(alphas).set_parse_action(token_map(str.title))
2361          wd[1, ...].set_parse_action(' '.join).run_tests('''
2362              now is the winter of our discontent made glorious summer by this sun of york
2363              ''')
2364  
2365      prints::
2366  
2367          00 11 22 aa FF 0a 0d 1a
2368          [0, 17, 34, 170, 255, 10, 13, 26]
2369  
2370          my kingdom for a horse
2371          ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE']
2372  
2373          now is the winter of our discontent made glorious summer by this sun of york
2374          ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York']
2375      cs��fdd�|D�S)Ncsg|]
2376  }�|g��R��qSr*r*)r>�tokn�r�r)r*r+r@r�z)token_map.<locals>.pa.<locals>.<listcomp>r*r�r>r*r+r�~r�ztoken_map.<locals>.par/r�)r�r/)r)r�r�r�r*r>r+�	token_mapYs%r?cCs8t��jj��D]\}}t|t�r|js|�|�qdS)zy
2377      Utility to simplify mass-naming of parser elements, for
2378      generating railroad diagram with named subdiagrams.
2379      N)	r�	_getframe�f_back�f_localsr�r1r}r�r�)rN�varr*r*r+�autoname_elements�s
2380  
2381  ��rDz4"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*�"z string enclosed in double quotesz4'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*�'z string enclosed in single quotesz*quotedString using single or double quotes�uzunicode string literalz#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]cCsg|]	}t|t�r|�qSr*)r1r})r>r�r*r*r+r@�s
2382  
2383  ��r�rU)r#r�r+)��osr�rrrrrrrr	r
2384  r�abcrr
�enumrr�r�r1r�r�collections.abcrr��types�operatorr�	functoolsr�	threadingr�pathlibr�utilrrrrrrrrr]rr\�
2385  exceptions�actionsr�rr �unicoder!�maxsizer4rs�bytesr"r�r��version_infor%r6rIr`rirlrTr�rsr{�warnoptions�environr�sumr!r�rr�r�r�r"rrrr�r��
GeneratorTyper!r�r/r0r0r1r�r�r��ascii_uppercase�ascii_lowercase�alphas�Latin1�
2386  identchars�identbodychars�nums�hexnumsr�r��	printablerr��StackSummaryr�r�r�r�r�r�r}r�r`rgrgrrpr�rxr�r�r�r�r�r�r�r�r�r�rrrrrrhrrrr�r�r�r�r�r?r�r�r�r�r�r�r�r�r�r�r�r�rBrrr�r3r�r,r�r-r.r/r0r1r�_escapedPunc�_escapedHexChar�_escapedOctChar�_singleChar�
2387  _charRanger�r;r<r?rD�dbl_quoted_string�sgl_quoted_stringr�unicode_string�
2388  alphas8bit�punc8bitr��valuesr��tokenMap�conditionAsParseAction�nullDebugAction�sglQuotedString�dblQuotedString�quotedString�
unicodeString�	lineStart�lineEnd�stringStart�	stringEnd�traceParseActionr*r*r*r+�<module>s$
2389  0,
2390  	!
2391  ��
2392  ���
2393  ��
2394  ���
2395  =����
2396  �����
2397  �������
2398  ������
2399  �*)-vYq
2400  EPM/"o(]@!$Q*+N!Iw
2401  9%W70��������%
2402  .
2403  
2404  ��
2405  ��
2406  
2407  ����