bg>A UddlZddlZddlmZmZmZmZmZmZmZm Z m Z m Z ddl m Z mZddlmZddlZddlZddlZddlZddlZddlmZddlZddlZddlmZddlmZddlmZdd l m!Z!d d l"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z+m,Z-d d l.Td d l/Td d l0m1Z1m2Z2d dl3m4Z4ej5Z6e7e8fZ9ee:dfe;d<ej<dkrddlm=Z=n GddZ=Gdde%Z>Gdde%Z?GddeZ@de@ddfdZAde@ddfdZBddZC[%d eje7d!ejDe7deEfd"ZFeFejGejHId#r eCeJeKeLeMeNeOePeQeReSeTh ZUejVZWeegefee1gefeeXe1gefee7eXe1geffZYeegeEfee1geEfeeXe1geEfee7eXe1geEffZZee7eXd$e[gdfZ\ee7eXd$eEgdfZ]ee7eXeXd$e1eEgdfZ^ee7eXd$e[eEgdfZ_ej`ejazZbe4jcjdZde4jcjeZed%Zfefd&zZgebefzZhd'id(ejjDZkdalejme;d)<dd+Zn dd-eZd.e7d/eEdeYfd0Zo dd1e7d2eXd3d$d4eEfd5Zp dd1e7d6eXd7eXd3d$d8e1d4eEf d9Zq dd1e7d2eXd3d$d:e[d4eEf d;Zrd<ZsGd=d$e ZtGd>d?etZuGd@dAetZvGdBdCevZwGdDdEevZxGdFdGevZyGdHdIeyZzeyet_{GdJdKevZ|GdLdMeyZ}GdNdOe|Z~GdPdQevZGdRdSevZGdTdUeZGdVdWeZGdXdYevZGdZd[evZGd\d]evZGd^d_evZGd`daevZGdbdceZGdddeeZGdfdgeZGdhdieZGdjdkeZGdldmeZGdndoeZGdpdqetZGdrdseZGdtdueZGdvdweZGdxdyeZGdzd{etZGd|d}eZGd~deZGddeZGddeZGddeZGddeZGddeZGddeZGddeZGddeZGddZGddeZeZDGddeZGddeZGddeZGddeZGddeZGddeZGddeZdeYdeYfdZewdZedZedZedZedZee(dddZeddZeddZeezezedd zZeeedzezZeydeddzeeeezdzdzZde7de7fdZdeYfdZddZeeddzdZeeddzdZeeddzeddzzd¦ZedezdĦZedŦZedƦZdDŽeDZeete;d<eZeoZesZeZeZeZeZeZeZeZeZeZdS)N) NamedTupleUnionCallableAny GeneratorTupleListTextIOSetSequence)ABCabstractmethod)Enum)Iterable) itemgetter)wraps)RLock)Path) _FifoCache_UnboundedCache__config_flags_collapse_string_to_ranges_escape_regex_range_chars_bslash_flattenLRUMemo UnboundedMemo)*) ParseResults_ParseResultsWithOffset)pyparsing_unicode.str_type))cached_propertyceZdZdZddZdS)r&c||_dSN)_func)selffuncs _/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pyparsing/core.py__init__zcached_property.__init__Qs DJJJNcX||x}|j|jj<|Sr))r*__dict____name__)r+instanceownerrets r-__get__zcached_property.__get__Ts*;?::h;O;O OC(#DJ$78Jr/r))r2 __module__ __qualname__r.r6r/r-r&r&Ps7         r/r&cjeZdZdZdZdZdeDZdZ dS) __compat__aJ A cross-version compatibility configuration for pyparsing features that will be released in a future version. By setting values in this configuration to True, those features can be enabled in prior versions for compatibility development and testing. - ``collect_all_And_tokens`` - flag to enable fix for Issue #63 that fixes erroneous grouping of results names when an :class:`And` expression is nested within an :class:`Or` or :class:`MatchFirst`; maintained for compatibility, but setting to ``False`` no longer restores pre-2.3.1 behavior compatibilityTc<g|]}|d|S_ startswith.0__s r- z__compat__.j)BBBr}}S/A/AB"BBBr/z( collect_all_And_tokens N) r2r7r8__doc__ _type_desccollect_all_And_tokenslocals _all_namessplit _fixed_namesr9r/r-r;r;YsQ  !J!BBvvxxBBBJ EGGLLr/r;ceZdZdZdZdZdZdZdZdZ dZ dZ de DZ de DZde DZed dZdS) __diag__ diagnosticFc<g|]}|d|Sr>r@rBs r-rEz__diag__.|rFr/c<g|]}|d|S)warnr@rCnames r-rEz__diag__.}s)MMMtT__V5L5LMdMMMr/c<g|]}|d|S) enable_debugr@rTs r-rEz__diag__.~s)SSST4??>3R3RSDSSSr/returnNcD|jD]}||dSr))_warning_namesenable)clsrUs r-enable_all_warningsz__diag__.enable_all_warningss3&  D JJt      r/rXN)r2r7r8rH)warn_multiple_tokens_in_named_alternation)warn_ungrouped_named_tokens_in_collectionwarn_name_set_on_empty_Forward!warn_on_parse_using_empty_Forwardwarn_on_assignment_to_Forward%warn_on_multiple_string_args_to_oneof(warn_on_match_first_with_lshift_operator!enable_debug_on_named_expressionsrJrKrZ _debug_names classmethodr]r9r/r-rOrOpsJ05-05-%*"(-%$)!,1)/4,(-%BBvvxxBBBJMMzMMMNSSZSSSL[r/rOc2eZdZdZdZdZdZdZdZdZ dZ d Z d S) Diagnosticsa Diagnostic configuration (all default to disabled) - ``warn_multiple_tokens_in_named_alternation`` - flag to enable warnings when a results name is defined on a :class:`MatchFirst` or :class:`Or` expression with one or more :class:`And` subexpressions - ``warn_ungrouped_named_tokens_in_collection`` - flag to enable warnings when a results name is defined on a containing expression with ungrouped subexpressions that also have results names - ``warn_name_set_on_empty_Forward`` - flag to enable warnings when a :class:`Forward` is defined with a results name, but has no contents defined - ``warn_on_parse_using_empty_Forward`` - flag to enable warnings when a :class:`Forward` is defined in a grammar but has never had an expression attached to it - ``warn_on_assignment_to_Forward`` - flag to enable warnings when a :class:`Forward` is defined but is overwritten by assigning using ``'='`` instead of ``'<<='`` or ``'<<'`` - ``warn_on_multiple_string_args_to_oneof`` - flag to enable warnings when :class:`one_of` is incorrectly called with multiple str arguments - ``enable_debug_on_named_expressions`` - flag to auto-enable debug on all subsequent calls to :class:`ParserElement.set_name` Diagnostics are enabled/disabled by calling :class:`enable_diag` and :class:`disable_diag`. All warnings can be enabled by calling :class:`enable_all_warnings`. rrr$N) r2r7r8rGr_r`rarbrcrdrerfr9r/r-rjrjsL,12-01-%&"()%$%!,-)/0,()%%%r/rj diag_enumrXcDt|jdS)zO Enable a global pyparsing diagnostic flag (see :class:`Diagnostics`). N)rOr[rUrps r- enable_diagrss OOIN#####r/cDt|jdS)zP Disable a global pyparsing diagnostic flag (see :class:`Diagnostics`). N)rOdisablerUrrs r- disable_diagrvs  Y^$$$$$r/c8tdS)zU Enable all global pyparsing diagnostic warnings (see :class:`Diagnostics`). N)rOr]r9r/r-r]r]s   """""r/cmd_line_warn_options warn_env_varc@t|}|D]}|dzddd\}}}}}|ds|s|s|r|dkrd}^|dr|dvrd}|S) Nz:::::rmi pyparsingT)r}F)boolrLlowerrA) rxryr[warn_optw_action w_message w_categoryw_modulew_lines r-_should_enable_warningsrs,  F)  =E=NO2O2OF Mr/PYPARSINGENABLEALLWARNINGS ParserElement 0123456789 ABCDEFabcdefr~c.g|]}|tjv|Sr9)string whitespacerCcs r-rErEs%PPPAQf>O5O5Oa5O5O5Or/_trim_arity_call_liner$cBtvrfdSddd dd}tptjddatdtd |zffd }t d t d j}||_j|_|S)zAdecorator to trim function calls to match the arity of the targetc|Sr)r9)sltr,s r-z_trim_arity.. sttAwwr/rFcTtj||}|d}|ddgS)Nlimitrk) traceback extract_tb)tbrframes frame_summarys r-rz_trim_arity..extract_tbs2%b666r bqb!""r/rorkrrrc |d}d|S#t$rB}r|j}|dddd k}~|r kr dz Yd}~Yd}~wwxYw)NrTrkrr) TypeError __traceback__) argsr5tertrim_arity_type_errorr found_arityr,r max_limitpa_call_line_synths r-wrapperz_trim_arity..wrappers  dDL)"     )B" 2Q///3BQB7;MM*,% 9,,!QJE$HHHH! s A!7AAA!r2 __class__r)_single_arg_builtinsrr extract_stackgetattrr2rG) r,r LINE_DIFFr func_namerrrrs `` @@@@r- _trim_arityrs ###&&&&& EK####I3Zi6MTU6V6V6VWY6Z/24I!4Ly4XY8j'$ *D*D*MNNI GlGO Nr/Ffnmessagefatalc||nd|rtntttfd}|S)aC Function to convert a simple predicate function that returns ``True`` or ``False`` into a parse action. Can be used in places when a parse action is required and :class:`ParserElement.add_condition` cannot be used (such as when adding a condition to an operator level in :class:`infix_notation`). Optional keyword arguments: - ``message`` - define a custom message to be used in the raised exception - ``fatal`` - if True, will raise :class:`ParseFatalException` to stop parsing immediately; otherwise will raise :class:`ParseException` Nzfailed user-defined conditioncVt|||s ||dSr))r)rrrexc_typermsgs r-paz%condition_as_parse_action..paVs=BBq!QKK   &(1a%% % & &r/)ParseFatalExceptionParseExceptionrr)rrrrrrs` @@r-condition_as_parse_actionrBsk (''.MC&+?""H RB 2YY&&&&&&Y& Ir/instringlocexpr cache_hitc|rdnd}td|||t||t||t ||dt||dz zdS)Nrr~z&{}Match {} at loc {}({},{}) {} {}^ r)printformatlinenocolline)rrrr cache_hit_strs r-_default_start_debug_actionr^s%,CC"M 6 = =sH%%C""S(##s3))A-.       r/startlocendloctoksc~|rdnd}td|||dS)Nrr~z{}Matched {} -> {})rras_list)rrrrrrrs r-_default_success_debug_actionrqsA%,CC"M  % %mT4<<>> J JKKKKKr/excc |rdnd}td||t|j|dS)Nrr~z {}Match {} failed, {} raised: {})rrtyper2)rrrrrrs r-_default_exception_debug_actionr}sS%,CC"M *11 4c!3S  r/cdS)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nr9)rs r-null_debug_actionrr/c'eZdZUdZdZeed<dZeed<dZ e j e ed<e ded dfd Ze d e d dfd ZGd deZddefdZded dfdZddZ ddddededed dfdZddZdded dfdZded dfdZded dfdZded dfd Zd!ed dfd"Zd#Z d$Z!dd%Z"d&Z# dd e$e%e&ffd'Z'dd(ed)e%d*ed e%fd+Z(d(ed)e%d efd,Z)e*Z+iZ,e j-e$e%d-efe$e%e.e&e/fffed.<iZ0e*Z1d/d/gZ2 dd e$e%e&ffd0Z3e'Z4e dd1Z5dZ6dZ7e dd2Z8e ddd3d4e j e%d dfd5Z9e ddd3d4e%d7ed dfd8Z: ddd9d(ed:ed;ed e&fd<Z;ee%d?ed@edAe%d e=e$e&e%e%fddff dBZ>ddCd(ed@ed efdDZ?ee%d@edAe%d e&f dEZ@eZe@Ze?ZeVZeWZe\Ze]Ze_ZebZemZesZeSZeTZdS)rz)Abstract base level parser element class.z DEFAULT_WHITE_CHARSFverbose_stacktraceN_literalStringClasscharsrXch|t_tD]}|jrt ||_dS)a Overrides the default whitespace chars Example:: # default whitespace chars are space, and newline Word(alphas)[1, ...].parse_string("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl'] # change to just treat newline as significant ParserElement.set_default_whitespace_chars(" \t") Word(alphas)[1, ...].parse_string("abc def\nghi jkl") # -> ['abc', 'def'] N)rr_builtin_exprscopyDefaultWhiteCharsset whiteChars)rrs r-set_default_whitespace_charsz*ParserElement.set_default_whitespace_charss@-2 )# - -D) -"%e** - -r/r\c|t_dS)al Set class to be used for inclusion of string literals into a parser. Example:: # default literal class used is Literal integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parse_string("1999/12/31") # -> ['1999', '/', '12', '/', '31'] # change to Suppress ParserElement.inline_literals_using(Suppress) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parse_string("1999/12/31") # -> ['1999', '12', '31'] N)rr)r\s r-inline_literals_usingz#ParserElement.inline_literals_usings(-0 )))r/cpeZdZUejeed<ejeed<ejeed<dS)ParserElement.DebugActions debug_try debug_match debug_failN) r2r7r8typingOptionalDebugStartAction__annotations__DebugSuccessActionDebugExceptionActionr9r/r- DebugActionsrsN?#34444_%78888O$8999999r/rsavelistct|_d|_d|_d|_d|_||_d|_ttj |_ d|_ d|_ d|_t|_d|_d|_d|_d|_d|_|ddd|_d|_d|_g|_dS)NTFr~)list parseAction failAction customName _defaultName resultsName saveAsListskipWhitespacerrrrrmayReturnEmptykeepTabs ignoreExprsdebug streamlined mayIndexErrorerrmsg modalResultsr debugActions callPreparse callDuringTrysuppress_warnings_)r+rs r-r.zParserElement.__init__s.2ff<@ ""m?@@%)"# 26&&  !   --dD$?? "57r/ warning_typec:|j||S)aY Suppress warnings emitted for a particular diagnostic on this expression. Example:: base = pp.Forward() base.suppress_warning(Diagnostics.warn_on_parse_using_empty_Forward) # statement would normally raise a warning, but is now suppressed print(base.parseString("x")) )rappend)r+rs r-suppress_warningzParserElement.suppress_warnings  &&|444 r/ctj|}|jdd|_|jdd|_|jrt t j|_|S)a7 Make a copy of this :class:`ParserElement`. Useful for defining different parse actions for the same parsing pattern, using copies of the original parse element. Example:: integer = Word(nums).set_parse_action(lambda toks: int(toks[0])) integerK = integer.copy().add_parse_action(lambda toks: toks[0] * 1024) + Suppress("K") integerM = integer.copy().add_parse_action(lambda toks: toks[0] * 1024 * 1024) + Suppress("M") print((integerK | integerM | integer)[1, ...].parse_string("5K 100 640K 256M")) prints:: [5120, 100, 655360, 268435456] Equivalent form of ``expr.copy()`` is just ``expr()``:: integerM = integer().add_parse_action(lambda toks: toks[0] * 1024 * 1024) + Suppress("M") N)copyrrrrrrr)r+cpys r-r zParserElement.copysZ,ioo*111-*111-  % D !BCCCN r/)listAllMatchesrUlist_all_matchesrc6|p|}|||S)a Define name for referencing matching tokens as a nested attribute of the returned parse results. Normally, results names are assigned as you would assign keys in a dict: any existing value is overwritten by later values. If it is necessary to keep all values captured for a particular results name, call ``set_results_name`` with ``list_all_matches`` = True. NOTE: ``set_results_name`` returns a *copy* of the original :class:`ParserElement` object; this is so that the client can define a basic element, such as an integer, and reference it in multiple places with different names. You can also set results names using the abbreviated syntax, ``expr("name")`` in place of ``expr.set_results_name("name")`` - see :class:`__call__`. If ``list_all_matches`` is required, use ``expr("name*")``. Example:: date_str = (integer.set_results_name("year") + '/' + integer.set_results_name("month") + '/' + integer.set_results_name("day")) # equivalent form: date_str = integer("year") + '/' + integer("month") + '/' + integer("day") )_setResultsName)r+rUrrs r-set_results_namezParserElement.set_results_names%<(;+;##D.999r/c||S|}|dr |dd}d}||_| |_|S)NrrT)r endswithrr)r+rUrnewselfs r-rzParserElement._setResultsName1sW <K))++ ==   "9D!N"#11r/T break_flagc|r|jdfd }|_||_n&t|jdr|jj|_|S)z Method to invoke the Python pdb debugger when this element is about to be parsed. Set ``break_flag`` to ``True`` to enable, ``False`` to disable. TcPddl}|||||SNr)pdb set_trace)rr doActions callPreParser _parseMethods r-breakerz(ParserElement.set_break..breakerEs1  #|Hc9lKKKr/_originalParseMethodTT)_parser hasattr)r+rrrs @r- set_breakzParserElement.set_break<sq  ?;L L L L L L L,8G (!DKKt{$:;; ?"k>  r/fnsct|dgkrg|_nhtd|Dstdd|D|_|d|dd|_|S)ao Define one or more actions to perform when successfully matching parse element definition. Parse actions can be called to perform data conversions, do extra validation, update external data structures, or enhance or replace the parsed tokens. Each parse action ``fn`` is a callable method with 0-3 arguments, called as ``fn(s, loc, toks)`` , ``fn(loc, toks)`` , ``fn(toks)`` , or just ``fn()`` , where: - s = the original string being parsed (see note below) - loc = the location of the matching substring - toks = a list of the matched tokens, packaged as a :class:`ParseResults` object The parsed tokens are passed to the parse action as ParseResults. They can be modified in place using list-style append, extend, and pop operations to update the parsed list elements; and with dictionary-style item set and del operations to add, update, or remove any named results. If the tokens are modified in place, it is not necessary to return them with a return statement. Parse actions can also completely replace the given tokens, with another ``ParseResults`` object, or with some entirely different object (common for parse actions that perform data conversions). A convenient way to build a new parse result is to define the values using a dict, and then create the return value using :class:`ParseResults.from_dict`. If None is passed as the ``fn`` parse action, all previously added parse actions for this expression are cleared. Optional keyword arguments: - call_during_try = (default= ``False``) indicate if parse action should be run during lookaheads and alternate testing. For parse actions that have side effects, it is important to only call the parse action once it is determined that it is being called as part of a successful parse. For parse actions that perform additional validation, then call_during_try should be passed as True, so that the validation code is included in the preliminary "try" parses. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See :class:`parse_string` for more information on parsing strings containing ```` s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. Example:: # parse dates in the form YYYY/MM/DD # use parse action to convert toks from str to int at parse time def convert_to_int(toks): return int(toks[0]) # use a parse action to verify that the date is a valid date def is_valid_date(instring, loc, toks): from datetime import date year, month, day = toks[::2] try: date(year, month, day) except ValueError: raise ParseException(instring, loc, "invalid date given") integer = Word(nums) date_str = integer + '/' + integer + '/' + integer # add parse actions integer.set_parse_action(convert_to_int) date_str.set_parse_action(is_valid_date) # note that integer fields are now ints, not strings date_str.run_tests(''' # successful parse - note that integer fields were converted to ints 1999/12/31 # fail - invalid date 1999/13/31 ''') Nc34K|]}t|VdSr))callablerCrs r- z1ParserElement.set_parse_action..s(22x||222222r/zparse actions must be callablec,g|]}t|Sr9rr)s r-rEz2ParserElement.set_parse_action..s>>>B B>>>r/call_during_tryrF)rrallrgetrr+r%kwargss r-set_parse_actionzParserElement.set_parse_actionSsV 99  !D  22c22222 B @AAA>>#>>>D !'!6::ou#E#E""D  r/c|xjd|Dz c_|jp)|d|dd|_|S)z Add one or more parse actions to expression's list of parse actions. See :class:`set_parse_action`. See examples in :class:`copy`. c,g|]}t|Sr9r,r)s r-rEz2ParserElement.add_parse_action..s;;;[__;;;r/r-rF)rrr/r0s r-add_parse_actionzParserElement.add_parse_actionsa ;;s;;;;!/ 6:: vzz/5AA4 4  r/c |D]S}|jt||d|ddT|jp)|d|dd|_|S)aAdd a boolean predicate function to expression's list of parse actions. See :class:`set_parse_action` for function call signatures. Unlike ``set_parse_action``, functions passed to ``add_condition`` need to return boolean success/fail of the condition. Optional keyword arguments: - message = define a custom message to be used in the raised exception - fatal = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException - call_during_try = boolean to indicate if this method should be called during internal tryParse calls, default=False Example:: integer = Word(nums).set_parse_action(lambda toks: int(toks[0])) year_int = integer.copy() year_int.add_condition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later") date_str = year_int + '/' + integer + '/' + integer result = date_str.parse_string("1999/12/31") # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1) rrF)rrr-r)rr rr/r)r+r%r1rs r- add_conditionzParserElement.add_conditions.  B   # #) 9 5 5VZZQV=W=W     "/ 6:: vzz/5AA4 4  r/rc||_|S)a Define action to perform if parsing fails at this expression. Fail acton fn is a callable function that takes the arguments ``fn(s, loc, expr, err)`` where: - s = string being parsed - loc = location where expression match was attempted and failed - expr = the parse expression that failed - err = the exception thrown The function returns no value. It may throw :class:`ParseFatalException` if it is desired to stop parsing immediately.)r)r+rs r-set_fail_actionzParserElement.set_fail_actions r/cd}|r;d}|jD]/} |||\}}d}#t$rY,wxYw|;|SNTF)rr"r)r+rr exprsFoundedummys r-_skipIgnorableszParserElement._skipIgnorabless  J%  *%&XXh%<%< U%) *&D  s . ;;c|jr|||}|jr;t|}|j}||kr|||vr|dz }||kr |||v|SNr)rr?rlenr)r+rrinstrlen white_charss r-preParsezParserElement.preParses   6&&x55C   8}}H/K..Xc]k%A%Aq..Xc]k%A%A r/c |gfSr)r9r+rrrs r- parseImplzParserElement.parseImpls Bwr/c|Sr)r9r+rr tokenlists r- postParsezParserElement.postParsesr/c  d\}}}|j}t|} |s|jr |r|jr|||} n|} | } |jjr|j|| |d|js| | krA ||| |\}} n?#t$rt|| |j |wxYw||| |\}} n#t$rO} |jj r|j || || d|jr||| || d} ~ wwxYw|r|jr|||} n|} | } |js| | krA ||| |\}} n?#t$rt|| |j |wxYw||| |\}} |||| } t| |j|j|j}|jrM|s|jrC|r |jD]y} ||| |} n$#t$r}td}||d}~wwxYw| B| |ur>t| |j|jot+| tt,f|j}zn#t$r0} |jj r|j || || dd} ~ wwxYw|jD]y} ||| |} n$#t$r}td}||d}~wwxYw| B| |ur>t| |j|jot+| tt,f|j}z|r+|jjr|j|| |||d||fS)NrrrkF)asListmodalz exception raised in parse action)rrBrrrErrrrH IndexErrorrr ExceptionrrLr rrrrr isinstancerr)r+rrrrTRYMATCHFAIL debugging len_instringpre_loc tokens_starttokenserr ret_tokensrparse_action_excrs r- _parseNoCachezParserElement._parseNoCaches#UDJ 8}} & K& K "D$5""mmHc::GG!G& $.U%//,eTTT%OL)@)@X&*nnXw &R&R VV%XXX,X|T[RVWWWX#'..7I"N"NKC   $/%00 ,c5?GOOHlD#FFF   1 --#66"L! KW %<%<T"&..7I"N"NKC!TTT(<dSSST#nnXw JJ V#v66! D$T_DDU     ( ( d.@( ' ".<%'R, %K%KFF)<<<"01S"T"TC"%+;;<"-& 2J2J)5 & $ 0'+(M$.v d7K$L$L&*&7 ***J!(3)44$lD#u *B8!#HlJ!G!G%888,-OPP!'778)fJ.F.F%1" ,#'?$I *6L$3G H H"&"3 &&&    , !--lCz5JsACBC"CC D7(A D22D7,F"F) J H,+J, I 6II  AJ K +K  K K++ L 5LL rr raise_fatalc |||ddS#t$r|rt|||j|wxYw)NFrr)r"rrr)r+rrr`s r- try_parsezParserElement.try_parsense C;;x;>>qA A" C C C  3 TBB B Cs  %Acd |||dS#ttf$rYdSwxYwr;)rcrrQ)r+rrs r-can_parse_nextzParserElement.can_parse_nextvsK  NN8S ) ) )4 +   55 s //Forwardrecursion_memosrc xd\}}d\}}} |||||f} tj5tj} | | } | | jurtj|xxdz cc< |||||} | | | d| d|f| cdddS#t$r)} | | | j | j d} ~ wwxYwtj|xxdz cc<|j r<|j jr0 |j |||dn#t$rYnwxYwt!| t"rF|j r=|j jr1 |j |||| dn#t$rYnwxYw| | d| d| d}}}|j r>|j jr2 |j |||||dn#t$rYnwxYw||fcdddS#1swxYwYdS)N)rrrNrrT)rrk)rpackrat_cache_lock packrat_cacher/ not_in_cachepackrat_cache_statsr_rr ParseBaseExceptionrrrrrrrSrRrr)r+rrrrHITMISSrTrUrVlookupcachevaluepeloc_resultrs r- _parseCachezParserElement._parseCaches6 T"UD#|Y?  -( $( $!/EIIf%%E***1$7771<777! ..xiVVE IIfuQxq#&FGGG ( $( $( $( $( $( $( $( $*IIflblBG&<===1#666!;666:$"3"=)33Hc4SW3XXXX$eY// z!d&7&B!! -88 (#tUd9 )!!! D!K',Qxq%(ff:$"3"?)55$dFD&D6%V|Q( $( $( $( $( $( $( $( $( $( $( $( $( $( $( $( $( $( $sAH/%C=8H/ C5 $C00C550H/&EH/ EH/E+H/>FH/ F+(H/*F++AH/. HH/ HH/HH//H36H3ctjdgttjztjdd<tjdSr)rrjclearrBrlrgr9r/r- reset_cachezParserElement.reset_caches^#))+++01sS  -6 6 0 )!!!, %++-----r/ctdt_dt_tjt_dS)a$ Disables active Packrat or Left Recursion parsing and their memoization This method also works if neither Packrat nor Left Recursion are enabled. This makes it safe to call before activating Packrat nor Left Recursion to clear any previous settings. FN)rry_left_recursion_enabled_packratEnabledr_r"r9r/r-disable_memoizationz!ParserElement.disable_memoizations7 !!###05 -(- %,: r/)forcecache_size_limitc(|rtntjrtd|t t_n3|dkrt |t_ntd|zdt_dS)a# Enables "bounded recursion" parsing, which allows for both direct and indirect left-recursion. During parsing, left-recursive :class:`Forward` elements are repeatedly matched with a fixed recursion depth that is gradually increased until finding the longest match. Example:: import pyparsing as pp pp.ParserElement.enable_left_recursion() E = pp.Forward("E") num = pp.Word(pp.nums) # match `num`, or `num '+' num`, or `num '+' num '+' num`, ... E <<= E + '+' - num | num print(E.parse_string("1+2+3")) Recursion search naturally memoizes matches of ``Forward`` elements and may thus skip reevaluation of parse actions during backtracking. This may break programs with parse actions which rely on strict ordering of side-effects. Parameters: - cache_size_limit - (default=``None``) - memoize at most this many ``Forward`` elements during matching; if ``None`` (the default), memoize all ``Forward`` elements. Bounded Recursion parsing works similar but not identical to Packrat parsing, thus the two cannot be used together. Use ``force=True`` to disable any previous, conflicting settings. 0Packrat and Bounded Recursion are not compatibleNr)capacityzMemo size of %sT) rr}r| RuntimeError_UnboundedMemorg_LRUMemoNotImplementedErrorr{rr~s r-enable_left_recursionz#ParserElement.enable_left_recursionsH  S  - - / / / /  * SQRR R  #,:,<,N,O,O,OM ) )%&7:J&JKK K04 ---r/r~c<|rtntjrtdtjsXdt_|t t_nt|t_tjt_ dSdS)af Enables "packrat" parsing, which adds memoizing to the parsing logic. Repeated parse attempts at the same string location (which happens often in many complex grammars) can immediately return a cached value, instead of re-executing parsing/validating code. Memoizing is done of both valid results and parsing exceptions. Parameters: - cache_size_limit - (default= ``128``) - if an integer value is provided will limit the size of the packrat cache; if None is passed, then the cache size will be unbounded; if 0 is passed, the cache will be effectively disabled. This speedup may break existing programs that use parse actions that have side-effects. For this reason, packrat parsing is disabled when you first import pyparsing. To activate the packrat feature, your program must call the class method :class:`ParserElement.enable_packrat`. For best results, call ``enable_packrat()`` immediately after importing pyparsing. Example:: import pyparsing pyparsing.ParserElement.enable_packrat() Packrat parsing works similar but not identical to Bounded Recursion parsing, thus the two cannot be used together. Use ``force=True`` to disable any previous, conflicting settings. rTN) rr}r{rr|rrjrrvr"rs r-enable_packratzParserElement.enable_packrats@  S  - - / / / /  2 SQRR R, =,0M )'.=.?.? ++.89I.J.J +#0#>> res = Word('a').parse_string('aaaaabaaa') >>> print(res) ['aaaaa'] The parsing behavior varies by the inheriting class of this abstract class. Please refer to the children directly to see more examples. It raises an exception if parse_all flag is set and instring does not match the whole grammar. >>> res = Word('a').parse_string('aaaaabaaa', parse_all=True) Traceback (most recent call last): ... pyparsing.ParseException: Expected end of text, found 'b' (at char 5), (line:1, col:6) rN)rryr streamlinerr expandtabsr"rEEmpty StringEndrmrwith_traceback) r+rrrr=rr[sers r- parse_stringzParserElement.parse_string4s!Z(!!###  OO   !  A LLNNNN} -**,,H ++h22KC )mmHc22WWy{{* (C(((M" / / // /((...  /s3A$C D #"DD )r maxMatches max_matchesoverlaprrc#*Kt||}|js||jD]}||js!t |}t|}d}|j} |j } t d} ||kr| |kr | ||} | || d\} }| |krS| dz } |r%t| | | d|| | fV|r| ||}||kr| }n$|dz }n| }n| dz}n#t$r| dz}YnwxYw||kr | |kdSdSdSdS#t$r'}tjr|dd}~wwxYw)at Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location. May be called with optional ``max_matches`` argument, to clip scanning after 'n' matches are found. If ``overlap`` is specified, then overlapping matches will be reported. Note that the start and end locations are reported relative to the string being parsed. See :class:`parse_string` for more information on parsing strings with embedded tabs. Example:: source = "sldjf123lsdjjkf345sldkjf879lkjsfd987" print(source) for tokens, start, end in Word(alphas).scan_string(source): print(' '*start + '^'*(end-start)) print(' '*start + tokens[0]) prints:: sldjf123lsdjjkf345sldkjf879lkjsfd987 ^^^^^ sldjf ^^^^^^^ lsdjjkf ^^^^^^ sldkjf ^^^^^^ lkjsfd rFrr)r[startendN)minrrrrstrrrBrEr"r resetCacherrOrrmrr)r+rrrrrr=rCr preparseFnparseFnmatchesprelocnextLocr[nextlocrs r- scan_stringzParserElement.scan_stringys.N[11   OO   !  A LLNNNN} 28}}//11Hx==] +  """" ///g &:&:)'Z#66F&-ghU&S&S&SOGV}}1  !.4mmoo-3+2!"!"%fg5555"*&0j3&?&?G&}}&- #q")CC$qj/&%%% 1*CCC% //g &:&:&:&://&:&://8" / / // /((...  /s=/ E!<D8AE!8E E! E  E!! F+"F  Frcg}d}d|_ |||D]\}}}|||||rt|tr||z }nUt|t r+t|ts||n|||}|||dd|D}d dt|DS#t$r'}tj r|dd}~wwxYw)ab Extension to :class:`scan_string`, to modify matching text with modified tokens that may be returned from a parse action. To use ``transform_string``, define a grammar and attach a parse action to it that modifies the returned token list. Invoking ``transform_string()`` on a target string will then scan for matches, and replace the matched text patterns according to the logic in the parse action. ``transform_string()`` returns the resulting transformed string. Example:: wd = Word(alphas) wd.set_parse_action(lambda toks: toks[0].title()) print(wd.transform_string("now is the winter of our discontent made glorious summer by this sun of york.")) prints:: Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York. rTrNcg|]}||Sr9r9rCos r-rEz2ParserElement.transform_string..s'''Q'1'''r/r~c,g|]}t|Sr9r)rCrs r-rEz2ParserElement.transform_string..s:::qCFF:::r/)rrr rSr rrr#extendjoinrrmrrr) r+rroutlastErrr=rs r-transform_stringzParserElement.transform_stringso(  /++HE+BB  1a 8E!G,---&!!\22&qyy{{*#Ax00&Ax9P9P& 1  1  JJx' ( ( (''c'''C77::HSMM:::;; ;! / / // /((...  /sDD## E-"EEct||} td||||DS#t$r'}tjr|dd}~wwxYw)a Another extension to :class:`scan_string`, simplifying the access to the tokens found to match the given parse expression. May be called with optional ``max_matches`` argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.search_string("More than Iron, more than Lead, more than Gold I need Electricity")) # the sum() builtin can be used to merge results into a single ParseResults object print(sum(cap_word.search_string("More than Iron, more than Lead, more than Gold I need Electricity"))) prints:: [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']] ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity'] cg|]\}}}| Sr9r9)rCrrr=s r-rEz/ParserElement.search_string..sVVVwq!QVVVr/rN)rr rrmrrr)r+rrrrrs r- search_stringzParserElement.search_strings8[11  /VV$"2"28Zu"2"U"UVVV " / / // /((...  /s.A A2 "A--A2)includeSeparatorsmaxsplitinclude_separatorsc#K|p|}d}|||D] \}}}|||V|r |dV|}!||dVdS)aT Generator method to split a string using the given expression as a separator. May be called with optional ``maxsplit`` argument, to limit the number of splits; and the optional ``include_separators`` argument (default= ``False``), if the separating matching text should be included in the split results. Example:: punc = one_of(list(".,;:/-!?")) print(list(punc.split("This, this?, this sentence, is badly punctuated!"))) prints:: ['This', ' this', '', ' this sentence', ' is badly punctuated', ''] r)rN)r) r+rrrrlastrrr=s r-rLzParserElement.split(s..C1C''h'GG  GAq!46" " " "  d DDtuuor/c:|turt|St|tr||}t|t s4t dt|j t||gS)ah Implementation of ``+`` operator - returns :class:`And`. Adding strings to a :class:`ParserElement` converts them to :class:`Literal`s by default. Example:: greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print(hello, "->", greet.parse_string(hello)) prints:: Hello, World! -> ['Hello', ',', 'World', '!'] ``...`` may be used as a parse expression as a short form of :class:`SkipTo`. Literal('start') + ... + Literal('end') is equivalent to: Literal('start') + SkipTo('end')("_skipped*") + Literal('end') Note that the skipped text is returned with '_skipped' as a results name, and to support having multiple skips in the same parser, the value returned is a list of all skipped text. 4Cannot combine element of type {} with ParserElement) Ellipsis _PendingSkiprSr#rrrrrr2Andr+others r-__add__zParserElement.__add__Hs6 H  %% % eX & & 4,,U33E%// FMMKK(  D%=!!!r/c:|turt|d|zSt|tr||}t|t s4t dt|j ||zS)zd Implementation of ``+`` operator when left operand is not a :class:`ParserElement` _skipped*r) rSkipTorSr#rrrrrr2rs r-__radd__zParserElement.__radd__ps H  6$<< ,,t3 3 eX & & 4,,U33E%// FMMKK(  t|r/c&t|tr||}t|ts4t dt |j|t z|zS)zX Implementation of ``-`` operator, returns :class:`And` with error stop r) rSr#rrrrrr2r _ErrorStoprs r-__sub__zParserElement.__sub__s eX & & 4,,U33E%// FMMKK(  cnn&&&..r/ct|tr||}t|ts4t dt |j||z S)zd Implementation of ``-`` operator when left operand is not a :class:`ParserElement` rrSr#rrrrrr2rs r-__rsub__zParserElement.__rsub__x eX & & 4,,U33E%// FMMKK(  t|r/c&|turd}nAt|tr,|ddtfkrd|ddzdzdd}t|tr|d}}nvt|tr,td|D}|d zdd}|d d|df}t|dtrY|dQ|ddkrt S|ddkrt S|dzt zSt|dtr&t|dtr |\}}||z}nst d d d |Dt d t|j |dkrtd|dkrtd||cxkrdkrnntgS|rIfd|r5|dkr|z}nHtg|z|z}n(|}n|dkr}ntg|z}|S)a Implementation of ``*`` operator, allows use of ``expr * 3`` in place of ``expr + expr + expr``. Expressions may also be multiplied by a 2-integer tuple, similar to ``{min, max}`` multipliers in regular expressions. Tuples may also include ``None`` as in: - ``expr*(n, None)`` or ``expr*(n, )`` is equivalent to ``expr*n + ZeroOrMore(expr)`` (read as "at least n instances of ``expr``") - ``expr*(None, n)`` is equivalent to ``expr*(0, n)`` (read as "0 to n instances of ``expr``") - ``expr*(None, None)`` is equivalent to ``ZeroOrMore(expr)`` - ``expr*(1, None)`` is equivalent to ``OneOrMore(expr)`` Note that ``expr*(None, n)`` does not raise an exception if more than n exprs exist in the input stream; that is, ``expr*(None, n)`` does not enforce a maximum number of expr occurrences. If this behavior is desired, then write ``expr*(None, n) + ~expr`` )rNNrrr)rkrc30K|]}|tur|ndVdSr))rrs r-r*z(ParserElement.__mul__..s0JJqq00!!dJJJJJJr/)NNz.cannot multiply ParserElement and ({}) objects,c3>K|]}t|jVdSr)rr2)rCitems r-r*z(ParserElement.__mul__..s+ G Gd!4 G G G G G Gr/z,cannot multiply ParserElement and {} objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuecj|dkrt|dz zStSrA)Opt)nmakeOptionalListr+s r-rz/ParserElement.__mul__..makeOptionalLists;q55t&6&6q1u&=&==>>>t99$r/) rrStupleint ZeroOrMore OneOrMorerrrrr2 ValueErrorr)r+r minElements optElementsr5rs` @r-__mul__zParserElement.__mul__s( H  EE u % % 5%){*B*BE!""I%/!4E eS ! ! ',aKK u % % JJEJJJJJE\)2A2.EQxE!H %(C(( U1X-=8q==%d+++8q==$T??*%(?Z-=-===E!Hc** z%(C/H/H +0( [{* DKK G G G G GGG >EEKK(  ??NOO O ??R  + * * * * * * * * *r77N  0 % % % % % %  4!##!1!1+!>!>>CCtf{2336F6F{6S6SSCC&&{33a4&;.// r/c,||Sr))rrs r-__rmul__zParserElement.__rmul__s||E"""r/c>|turt|dSt|tr||}t|t s4t dt|j t||gS)zP Implementation of ``|`` operator - returns :class:`MatchFirst` T) must_skipr) rrrSr#rrrrrr2 MatchFirstrs r-__or__zParserElement.__or__s H  555 5 eX & & 4,,U33E%// FMMKK(  4-(((r/ct|tr||}t|ts4t dt |j||zS)zd Implementation of ``|`` operator when left operand is not a :class:`ParserElement` rrrs r-__ror__zParserElement.__ror__rr/c t|tr||}t|ts4t dt |jt||gS)zH Implementation of ``^`` operator - returns :class:`Or` r) rSr#rrrrrr2Orrs r-__xor__zParserElement.__xor__s eX & & 4,,U33E%// FMMKK(  4-   r/ct|tr||}t|ts4t dt |j||z S)zd Implementation of ``^`` operator when left operand is not a :class:`ParserElement` rrrs r-__rxor__zParserElement.__rxor__#rr/c t|tr||}t|ts4t dt |jt||gS)zJ Implementation of ``&`` operator - returns :class:`Each` r) rSr#rrrrrr2Eachrs r-__and__zParserElement.__and__1s eX & & 4,,U33E%// FMMKK(  T5M"""r/ct|tr||}t|ts4t dt |j||zS)zd Implementation of ``&`` operator when left operand is not a :class:`ParserElement` rrrs r-__rand__zParserElement.__rand__?rr/c t|S)zL Implementation of ``~`` operator - returns :class:`NotAny` )NotAnyr+s r- __invert__zParserElement.__invert__Msd||r/c  t|tr|f}t|n#t$r||f}YnwxYwt |dkr`td|ddt |dkr"dt |nd|t |ddz}|S)a{ use ``[]`` indexing notation as a short form for expression repetition: - ``expr[n]`` is equivalent to ``expr*n`` - ``expr[m, n]`` is equivalent to ``expr*(m, n)`` - ``expr[n, ...]`` or ``expr[n,]`` is equivalent to ``expr*n + ZeroOrMore(expr)`` (read as "at least n instances of ``expr``") - ``expr[..., n]`` is equivalent to ``expr*(0, n)`` (read as "0 to n instances of ``expr``") - ``expr[...]`` and ``expr[0, ...]`` are equivalent to ``ZeroOrMore(expr)`` - ``expr[1, ...]`` is equivalent to ``OneOrMore(expr)`` ``None`` may be used in place of ``...``. Note that ``expr[..., n]`` and ``expr[m, n]``do not raise an exception if more than ``n`` ``expr``s exist in the input stream. If this behavior is desired, then write ``expr[..., n] + ~expr``. rkz,only 1 or 2 index arguments supported ({}{})Nrmz... [{}]r~)rSr#iterrrBrr)r+keyr5s r- __getitem__zParserElement.__getitem__Ws, #x(( f IIII   *CCC  s88a<<>EEGCHHqLLZ..s3xx888b U3rr7^^# s '*;;cX|||S|S)a Shortcut for :class:`set_results_name`, with ``list_all_matches=False``. If ``name`` is given with a trailing ``'*'`` character, then ``list_all_matches`` will be passed as ``True``. If ``name` is omitted, same as calling :class:`copy`. Example:: # these are equivalent userdata = Word(alphas).set_results_name("name") + Word(nums + "-").set_results_name("socsecno") userdata = Word(alphas)("name") + Word(nums + "-")("socsecno") )rr r+rUs r-__call__zParserElement.__call__s,  ''-- -99;; r/c t|S)z Suppresses the output of this :class:`ParserElement`; useful to keep punctuation from cluttering up returned output. )Suppressrs r-suppresszParserElement.suppresss ~~r/ recursivecd|_|S)z Enables the skipping of whitespace before matching the characters in the :class:`ParserElement`'s defined pattern. :param recursive: If ``True`` (the default), also enable whitespace skipping in child elements (if any) Trr+rs r-ignore_whitespacezParserElement.ignore_whitespaces# r/cd|_|S)a| Disables the skipping of whitespace before matching the characters in the :class:`ParserElement`'s defined pattern. This is normally only used internally by the pyparsing module, but may be needed in some whitespace-sensitive grammars. :param recursive: If true (the default), also disable whitespace skipping in child elements (if any) Frrs r-leave_whitespacezParserElement.leave_whitespaces$ r/ copy_defaultscJd|_t||_||_|S)z8 Overrides the default whitespace chars T)rrrr)r+rrs r-set_whitespace_charsz"ParserElement.set_whitespace_charss& #e**%2" r/cd|_|S)z Overrides default behavior to expand ```` s to spaces before parsing the input string. Must be called before ``parse_string`` when the input grammar contains elements that match ```` characters. T)rrs r-parse_with_tabszParserElement.parse_with_tabss   r/rc:ddl}t|trt|}t|tr$||jvr|j|n9|jt||S)a Define expression to be ignored (e.g., comments) while doing pattern matching; may be called repeatedly, to define multiple comment or other ignorable patterns. Example:: patt = Word(alphas)[1, ...] patt.parse_string('ablaj /* comment */ lskjd') # -> ['ablaj'] patt.ignore(c_style_comment) patt.parse_string('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd'] rN)rrSr#rrr r )r+rrs r-ignorezParserElement.ignores  eX & & $UOOE eX & & <D,,, ''...   # #HUZZ\\$:$: ; ; ; r/ start_actionsuccess_actionexception_actioncv||pt|pt|pt|_d|_|S)a  Customize display of debugging messages while doing pattern matching: - ``start_action`` - method to be called when an expression is about to be parsed; should have the signature ``fn(input_string: str, location: int, expression: ParserElement, cache_hit: bool)`` - ``success_action`` - method to be called when an expression has successfully parsed; should have the signature ``fn(input_string: str, start_location: int, end_location: int, expression: ParserELement, parsed_tokens: ParseResults, cache_hit: bool)`` - ``exception_action`` - method to be called when expression fails to parse; should have the signature ``fn(input_string: str, location: int, expression: ParserElement, exception: Exception, cache_hit: bool)`` T)rrrrrr)r+rrrs r-set_debug_actionszParserElement.set_debug_actionssE$!--  77  ;;  ? ?     r/flagcf|r'|tttnd|_|S)a Enable display of debugging messages while doing pattern matching. Set ``flag`` to ``True`` to enable, ``False`` to disable. Example:: wd = Word(alphas).set_name("alphaword") integer = Word(nums).set_name("numword") term = wd | integer # turn on debugging for wd wd.set_debug() term[1, ...].parse_string("abc 123 xyz 890") prints:: Match alphaword at loc 0(1,1) Matched alphaword -> ['abc'] Match alphaword at loc 3(1,4) Exception raised:Expected alphaword (at char 4), (line:1, col:5) Match alphaword at loc 7(1,8) Matched alphaword -> ['xyz'] Match alphaword at loc 11(1,12) Exception raised:Expected alphaword (at char 12), (line:1, col:13) Match alphaword at loc 15(1,16) Exception raised:Expected alphaword (at char 15), (line:1, col:16) The output shown is that produced by the default debug actions - custom debug actions can be specified using :class:`set_debug_actions`. Prior to attempting to match the ``wd`` expression, the debugging message ``"Match at loc (,)"`` is shown. Then if the parse succeeds, a ``"Matched"`` message is shown, or an ``"Exception raised"`` message is shown. Also note the use of :class:`set_name` to assign a human-readable name to the expression, which makes debugging and exception messages easier to understand - for instance, the default name created for the :class:`Word` expression without calling ``set_name`` is ``"W:(A-Za-z)"``. F)rrrrr)r+rs r- set_debugzParserElement.set_debugsAJ    " "+-/     DJ r/cP|j||_|jSr))r_generateDefaultNamers r- default_namezParserElement.default_name(s(   $ $ 9 9 ; ;D   r/cdS)zg Child classes must define this method, which defines how the ``default_name`` is set. Nr9rs r-rz"ParserElement._generateDefaultName.rr/cr||_d|jz|_tjr||S)a\ Define name for this expression, makes debugging and exception messages clearer. Example:: Word(nums).parse_string("ABC") # -> Exception: Expected W:(0-9) (at char 0), (line:1, col:1) Word(nums).set_name("integer").parse_string("ABC") # -> Exception: Expected integer (at char 0), (line:1, col:1) Expected )rrUrrOrfrrs r-set_namezParserElement.set_name4s9!DI-  5  NN    r/c,|j|jn|jSr))rrrs r-rUzParserElement.nameAs#'/"=t4CTTr/c|jSr)rUrs r-__str__zParserElement.__str__Fs yr/c t|Sr)rrs r-__repr__zParserElement.__repr__Is4yyr/c"d|_d|_|SNT)rrrs r-rzParserElement.streamlineLs  r/cgSr)r9rs r-recursezParserElement.recurseQ r/cz|dd|gz}|D]}||dSr))r&_checkRecursionr+parseElementListsubRecCheckListr=s r-r)zParserElement._checkRecursionTsO*111-6 / /A  o . . . . / /r/c0|gdS)zj Check defined expressions for valid structure, check for infinite recursive definitions. N)r))r+ validateTraces r-validatezParserElement.validateYs R     r/utf-8file_or_filenameencodingch|p|} |}nN#t$rAt|d|5}|}dddn #1swxYwYYnwxYw |||S#t$r'}t jr|dd}~wwxYw)z Execute the parse expression on the given file or filename. If a filename is specified (instead of a file object), the entire file is opened, read, and closed before parsing. rr2N)readAttributeErroropenrrmrrr)r+r1r2rr file_contentsfrs r- parse_filezParserElement.parse_file_s(y ),1133MM ) ) )&h??? )1 !  ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) /$$]H== =! / / // /((...  /sJA&A A&A A&A A&%A&*B B1 "B,,B1c||urdSt|tr||dSt|tr t |t |kSdS)NTrF)rSr#rrvarsrs r-__eq__zParserElement.__eq__{sf 5==4 x ( ( -<<<66 6 } - - -::e, ,ur/c t|Sr))idrs r-__hash__zParserElement.__hash__s $xxr/ test_stringcz|o|} |t||dS#t$rYdSwxYw)a Method for quick testing of a parser against a test string. Good for simple inline microtests of sub expressions while building up larger parser. Parameters: - ``test_string`` - to test against this expression for a match - ``parse_all`` - (default= ``True``) - flag to pass to :class:`parse_string` when running tests Example:: expr = Word(nums) assert expr.matches("100") r=TF)rrrm)r+rCrrs r-rzParserElement.matchess[ )     c+..(  C C C4!   55 s $, ::#)rfullDump printResults failureTestsrLtestscomment full_dump print_results failure_tests post_parsefilewith_line_numbersrFrGrHrLc  V ddlm}| o|} | o|} | o|} | p|} |p|}t|trFt |jfd|D}t|trt|}| tj }|j }g}g}d}td tdt}d}|D]}|||d s|r/|s-|| r||n|L|sO|rdd|znd | r||n|g}g} |||}||| }|o| }| |||}|`t|t.r(||nJ|t3|n'||n#t4$ru}||| |d |jt |j|Yd}~nxd}~wwxYw||| nE#t:$r}t|t<rdnd }|||dt3|zt@j!r,|"tGj$|j%|o| }|}Yd}~nd}~wt4$r}|dt |j|t@j!r,|"tGj$|j%|o| }|}Yd}~nd}~wwxYw|d | r|d||||f||fS)a Execute the parse expression on a series of test strings, showing each test, the parsed results or where the parse failed. Quick and easy way to run a parse expression against a list of sample strings. Parameters: - ``tests`` - a list of separate test strings, or a multiline string of test strings - ``parse_all`` - (default= ``True``) - flag to pass to :class:`parse_string` when running tests - ``comment`` - (default= ``'#'``) - expression for indicating embedded comments in the test string; pass None to disable comment filtering - ``full_dump`` - (default= ``True``) - dump results as list followed by results names in nested outline; if False, only dump nested list - ``print_results`` - (default= ``True``) prints test output to stdout - ``failure_tests`` - (default= ``False``) indicates if these tests are expected to fail parsing - ``post_parse`` - (default= ``None``) optional callback for successful parse results; called as `fn(test_string, parse_results)` and returns a string to be added to the test output - ``file`` - (default= ``None``) optional file-like object to which test output will be written; if None, will default to ``sys.stdout`` - ``with_line_numbers`` - default= ``False``) show test strings with line and column numbers Returns: a (success, results) tuple, where success indicates that all tests succeeded (or failed if ``failure_tests`` is True), and the results contain a list of lines of each test's output Example:: number_expr = pyparsing_common.number.copy() result = number_expr.run_tests(''' # unsigned integer 100 # negative integer -100 # float with scientific notation 6.02e23 # integer with scientific notation 1e-12 ''') print("Success" if result[0] else "Failed!") result = number_expr.run_tests(''' # stray character 100Z # missing leading digit before '.' -.100 # too many '.' 3.14.159 ''', failure_tests=True) print("Success" if result[0] else "Failed!") prints:: # unsigned integer 100 [100] # negative integer -100 [-100] # float with scientific notation 6.02e23 [6.02e+23] # integer with scientific notation 1e-12 [1e-12] Success # stray character 100Z ^ FAIL: Expected end of text (at char 3), (line:1, col:4) # missing leading digit before '.' -.100 ^ FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1) # too many '.' 3.14.159 ^ FAIL: Expected end of text (at char 4), (line:1, col:5) Success Each test string must be on a single line. If you want to test a string that spans multiple lines, create a test like this:: expr.run_tests(r"this is a test\n of strings that spans \n 3 lines") (Note that this is a raw string literal, you must include the leading ``'r'``.) r)pyparsing_testc&g|] }|Sr9r9)rC test_line line_strips r-rEz+ParserElement.run_tests..s#XXXyZZ **XXXr/NT\n uFr~r=)fullz{} failed: {}: {}z(FATAL)zFAIL: zFAIL-EXCEPTION: {}: {})&testingrRrSr#rstriprstrip splitlinesLiteralsysstdoutwriter5 replace_withr  quoted_stringrr rPrrlstriprr dumprrRrr2rmrexplainrrrr format_tbr)r+rIrrJrKrLrMrNrOrPrrFrGrHrLrRprint_ allResultscommentssuccessNLBOMrrrupp_valuer=rsrrrUs @r- run_testszParserElement.run_testss` ,+++++) ) #5 #4} + eX & & Ye*JXXXXELLNNtyy****B7HO00333aCH& ;'' 66**1*AA "6,&6(#,9Q#7#7#/)(LAA: # 8==?? ; ; ; ; # 3x== 9 9 9 9JJv{{}}555$ 6;;H;#=#=>>> /66 ) 2DGG4DaJJv{{{99::::E&   %/4G%H%HP b 2::<<((( 8c"gg-... 3FJJy223CDDEEE!2l    3::499;MsSSTTT 3GJJy233DEEFFF!2l  6 JJrNNN 'tyy~~&&&   q&k * * * * ""s@?LBI'' K&1A*K!!K& QB#O QA9QQr$ output_htmlverticalshow_results_names show_groupsc  ddlm}m}n"#t$r}t d|d}~wwxYw|||||||} t |ttfrKt|dd5} | || ddddS#1swxYwYdS| || dS) a Create a railroad diagram for the parser. Parameters: - output_html (str or file-like object) - output target for generated diagram HTML - vertical (int) - threshold for formatting multiple alternatives vertically instead of horizontally (default=3) - show_results_names - bool flag whether diagram should show annotations for defined results names - show_groups - bool flag whether groups should be highlighted with an unlabeled surrounding box Additional diagram-formatting keyword arguments can also be included; see railroad.Diagram class. r) to_railroadrailroad_to_htmlzMmust ``pip install pyparsing[diagrams]`` to generate parser railroad diagramsN)rprqrrdiagram_kwargswr0r5) diagramrtru ImportErrorrRrrSrrr8r`) r+rorprqrrr1rtruierailroad diag_files r-create_diagramzParserElement.create_diagramasd.  > > > > > > > > >   _   ; 1#!     kC; / / :k3999       8&+/   4--d-o----^!c!!!X!   ^ S _    UcUUUXU# /2/// !!!!!  /  ///T6 12// /  / ////837LP+/EI 4@C"#9=(,"'A#!"8.must_skipsPz,QZ%7%7%9%9bT%A%A!EE*d+++++&B%Ar/c|jdddgkr4|ddtjzdz|d<dSdS)Nrr~rz missing <>)rrrreprr)rr+s r- show_skipz'_PendingSkip.__add__..show_skipsb:%%'',44EE*%%%$/$t{2C2C$Cc$IAjMMM54r/)rrrrr5)r+rskipperrrs` r-rz_PendingSkip.__add__s/&--((// << >  , , ,  J J J J J  ggii88CCC')),,Y778  {W$u,,r/c|jSr))rrs r-r"z_PendingSkip.__repr__s r/c td)NzBuse of `...` expression without following SkipTo target expression)rR)r+rs r-rHz_PendingSkip.parseImpls P   r/r~r) r2r7r8rrr.rrr"rH __classcell__rs@r-rrs##]#t###### BBB----*          r/rc(eZdZdZfdZdZxZS)TokenzYAbstract :class:`ParserElement` subclass, for defining atomic matching patterns. cLtddS)NFrrr.r+rs r-r.zToken.__init__s$ %(((((r/c*t|jSr)rrs r-rzToken._generateDefaultNamesDzz""r/)r2r7r8rGr.rrrs@r-rrsQ)))))#######r/rc"eZdZdZfdZxZS)rz, An empty token, will always match. cdtd|_d|_dSr;rr.rrrs r-r.zEmpty.__init__/ ""r/)r2r7r8rGr.rrs@r-rrsB#########r/rc*eZdZdZfdZddZxZS)NoMatchz( A token that will never match. crtd|_d|_d|_dS)NTFzUnmatchable token)rr.rrrrs r-r.zNoMatch.__init__s4 "") r/Tc0t|||j|r))rrrGs r-rHzNoMatch.parseImplsXsDK>>>r/rr2r7r8rGr.rHrrs@r-rrsV***** ????????r/rcBeZdZdZd dddedeffdZdZd d ZxZS) r]a Token to exactly match a specified string. Example:: Literal('blah').parse_string('blah') # -> ['blah'] Literal('blah').parse_string('blahfooblah') # -> ['blah'] Literal('blah').parse_string('bla') # -> Exception: Expected "blah" For case-insensitive matching, use :class:`CaselessLiteral`. For keyword matching (force word break before and after the matched string), use :class:`Keyword` or :class:`CaselessKeyword`. r~ matchString match_stringrczt|p|}||_t||_ |d|_n#t $rtdwxYwd|jz|_ d|_ d|_ |jdkr$t|turt|_dSdSdS)Nrz2null string passed to Literal; use Empty() insteadrFr)rr.matchrBmatchLenfirstMatchCharrQrrUrrrrr]_SingleCharLiteralrr+rrrs r-r.zLiteral.__init__ s "2l ! L))  S".q/D   S S SQRR R S!DI- #" =A  $t**"7"7/DNNN  "7"7s  AA*c*t|jSr)rrrs r-rzLiteral._generateDefaultName DJr/Tc|||jkr,||j|r||jz|jfSt |||j|r))rrArrrrrGs r-rHzLiteral.parseImpl s\ C=D/ / /H4G4G J5 5 /& 2 2XsDK>>>r/r~r) r2r7r8rGrr.rrHrrs@r-r]r]s  0R000S0s000000$   ????????r/r]ceZdZddZdS)rTcj|||jkr |dz|jfSt|||j|rA)rrrrrGs r-rHz_SingleCharLiteral.parseImpl) s; C=D/ / /7DJ& &XsDK>>>r/Nrr2r7r8rHr9r/r-rr( s(??????r/rc eZdZdZedzZ dddddedejed e d ed ejef fd Z d Z ddZ e ddZeZxZS)Keyworda Token to exactly match a specified string as a keyword, that is, it must be immediately followed by a non-keyword character. Compare with :class:`Literal`: - ``Literal("if")`` will match the leading ``'if'`` in ``'ifAndOnlyIf'``. - ``Keyword("if")`` will not; it will only match the leading ``'if'`` in ``'if x=1'``, or ``'if(y==2)'`` Accepts two optional constructor arguments in addition to the keyword string: - ``identChars`` is a string of characters that would be valid identifier characters, defaulting to all alphanumerics + "_" and "$" - ``caseless`` allows case-insensitive matching, default is ``False``. Example:: Keyword("start").parse_string("start") # -> ['start'] Keyword("start").parse_string("starting") # -> Exception For case-insensitive matching, use :class:`CaselessKeyword`. z_$r~NFr identCharsr ident_charscaselessrrct|p|}| tj}|p|}||_t ||_ |d|_n#t$rtdwxYwd t|j |j |_d|_d|_||_|r-||_|}t)||_dS)Nrz2null string passed to Keyword; use Empty() insteadzExpected {} {}F)rr.rDEFAULT_KEYWORD_CHARSrrBrrrQrrrr2rUrrrrupper caselessmatchrr)r+rrrrrrs r-r.zKeyword.__init__O s  .;   6J"2l ! L))  S".q/D   S S SQRR R S&--d4jj.A49MM #"   ,!-!3!3!5!5D #))++Jj//s  A""A<c*t|jSr)rrs r-rzKeyword._generateDefaultNamel rr/Tc,|j}|}|jr||||jz|jkr|dks$||dz |jvre|t ||jz ks)|||jz|jvr||jz|jfS|dz }||jz}n|dz }|dz }n|||jkr |jdks| |j|ru|dks||dz |jvrS|t ||jz ks|||jz|jvr||jz|jfS|dz }||jz}n |dz }|dz }t||||)Nrrz/, was immediately followed by keyword characterz7, keyword was immediately preceded by keyword characterz7, keyword was immediately followed by keyword character) rrrrrrrBrrrAr)r+rrrrerrlocs r-rHzKeyword.parseImplo s =' %cDM11288::d>PPP!88xa06688OOs8}}t}<<<#C$-$78>>@@WW"T]2DJ>>"SS!$t}!4WWF 1WF  !444MQ&&&&tz377'!88xa0GGs8}}t}<<<#C$-$78OO"T]2DJ>>U"%t}!4WWF 1WFXvvt<< ['CMD', 'CMD', 'CMD'] (Contrast with example for :class:`CaselessKeyword`.) r~rrrc|p|}t|||_d|jz|_dS)Nr)rr.r returnStringrUrrs r-r.zCaselessLiteral.__init__ sK"2l  ++--...(!DI- r/Tc||||jz|jkr||jz|jfSt |||j|r))rrrrrrrGs r-rHzCaselessLiteral.parseImpl sW C# -- . 4 4 6 6$* D D&(99 9XsDK>>>r/rr)r2r7r8rGrr.rHrrs@r-rr sz  .R...S.s......????????r/rc neZdZdZ d ddddedejededejeffd ZxZS) CaselessKeywordz Caseless version of :class:`Keyword`. Example:: CaselessKeyword("CMD")[1, ...].parse_string("cmd CMD Cmd10") # -> ['CMD', 'CMD'] (Contrast with example for :class:`CaselessLiteral`.) r~Nrrrrrc`|p|}|p|}t||ddS)NT)rr)r+rrrrrs r-r.zCaselessKeyword.__init__ s> .; "2l  zDAAAAAr/)r~N) r2r7r8rGrrrr.rrs@r-rr s  ,0 B +/ B B B B_S) B  B OC( B B B B B B B B B Br/rcJeZdZdZ d ddddededeffd Zd Zdd ZxZ S) CloseMatchaA variation on :class:`Literal` which matches "close" matches, that is, strings with at most 'n' mismatching characters. :class:`CloseMatch` takes parameters: - ``match_string`` - string to be matched - ``caseless`` - a boolean indicating whether to ignore casing when comparing characters - ``max_mismatches`` - (``default=1``) maximum number of mismatches allowed to count as a match The results from a successful parse will contain the matched text from the input string and the following named results: - ``mismatches`` - a list of the positions within the match_string where mismatches were found - ``original`` - the original match_string used to compare against the input string If ``mismatches`` is an empty list, then the match was an exact match. Example:: patt = CloseMatch("ATCATCGAATGGA") patt.parse_string("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']}) patt.parse_string("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1) # exact match patt.parse_string("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']}) # close match allowing up to 2 mismatches patt = CloseMatch("ATCATCGAATGGA", max_mismatches=2) patt.parse_string("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']}) NrF) maxMismatchesrrmax_mismatchesrc||n|}t||_||_d|j|j|_||_d|_d|_dS)Nz(Expected {!r} (with up to {} mismatches)F) rr.rrrrrrr)r+rrrrrs r-r.zCloseMatch.__init__ sz+9*D-  (*@GG  t1   ! "#r/c\dt|j|jS)Nz{}:{!r})rrr2rrs r-rzCloseMatch._generateDefaultName s$T 3T5FGGGr/Tc*|}t|}|t|jz}||kr|j}d}g} |j} tt ||||D]i\}} | \} } |jr(| | } } | | kr*| |t| | krn/j||zdz}t|||g}||d<| |d<||fSt|||j |)Nrroriginal mismatches) rBrr enumerateziprrr r rr)r+rrrrrCmaxlocrmatch_stringlocrrs_msrcmatresultss r-rHzCloseMatch.parseImpl s>x==T./// X  ,LOJ .M(1HSZ(,77)) $ $$S=8"yy{{CIIKKC#::%%o666:66o-1&s(;'<==&2 #(2 %G|#XsDK>>>r/r)r r2r7r8rGrrr.rrHrrs@r-rr s  J#$  $$$$$  $$$$$$&HHH????????r/rceZdZdZ ddddddded ejed ed ed ed edejedejedejededejeffdZ dZ ddZ xZ S)Worda8 Token for matching words composed of allowed character sets. Parameters: - ``init_chars`` - string of all characters that should be used to match as a word; "ABC" will match "AAA", "ABAB", "CBAC", etc.; if ``body_chars`` is also specified, then this is the string of initial characters - ``body_chars`` - string of characters that can be used for matching after a matched initial character as given in ``init_chars``; if omitted, same as the initial characters (default=``None``) - ``min`` - minimum number of characters to match (default=1) - ``max`` - maximum number of characters to match (default=0) - ``exact`` - exact number of characters to match (default=0) - ``as_keyword`` - match as a keyword (default=``False``) - ``exclude_chars`` - characters that might be found in the input ``body_chars`` string but which should not be accepted for matching ;useful to define a word of all printables except for one or two characters, for instance (default=``None``) :class:`srange` is useful for defining custom character set strings for defining :class:`Word` expressions, using range notation from regular expression character sets. A common mistake is to use :class:`Word` to match a specific literal string, as in ``Word("Address")``. Remember that :class:`Word` uses the string argument to define *sets* of matchable characters. This expression would match "Add", "AAA", "dAred", or any other word made up of the characters 'A', 'd', 'r', 'e', and 's'. To match an exact literal string, use :class:`Literal` or :class:`Keyword`. pyparsing includes helper strings for building Words: - :class:`alphas` - :class:`nums` - :class:`alphanums` - :class:`hexnums` - :class:`alphas8bit` (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.) - :class:`punc8bit` (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.) - :class:`printables` (any non-whitespace character) ``alphas``, ``nums``, and ``printables`` are also defined in several Unicode sets - see :class:`pyparsing_unicode``. Example:: # a word composed of digits integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9")) # a word with a leading capital, and zero or more lowercase capital_word = Word(alphas.upper(), alphas.lower()) # hostnames are alphanumeric, with leading alpha, and '-' hostname = Word(alphas, alphanums + '-') # roman numeral (not a strict parser, accepts invalid mix of characters) roman = Word("IVXLCDM") # any string of non-whitespace characters, except for ',' csv_value = Word(printables, exclude_chars=",") r~NrrF) initChars bodyChars asKeyword excludeChars init_chars body_charsrmaxexact as_keyword exclude_charsrrr r c~|p|}| p|} | p|} | p|} t|s4tdt |jt |}||_| r(t | } || z}| rt | | z } dt||_ | rEEJJ'   NN "  :|,,L  %I : NN\9 WWVI%6%677  ,!# ):):!;!;D  ^^DNN!# ):):!;!;D  ^^DN!G 77g  77DKK"DK 199DKDK!DI- "" dnt~5 5 53!88QR ~//!88 FFAXXFF(// 4;(+B+BRR F!).t~>>!! T^$$))!88 FF'..sQw77F * 1 1Id011.t~>>!! !88 FFAXXFF'..sQw77F , 3 3.t~>>.t~>>!! ~ > % 5 =  ,*T]33!%  !+ 8    S 6 588 sNN65N6c2d}|j|jkr3d||j||j}n#d||j}|jdks|jt kr|j|jkr2|jdkr |ddS|d|jzS|jt kr|d|jzS|d|j|jzS|S) Ncrd}t|d}t||kr|d|dz dzS|S)NF) re_escaper$r)rrB)r max_repr_lens r- charsAsStrz-Word._generateDefaultName..charsAsStr sJL*1>>>A1vv $$+T^ + +&& 4>**JJt~,F,FDD??::dn#=#=>>D ;??dkX55{dk));!##8O(//$+">">>>((l11$+>>>>k00dkJJJJ r/Tc|||jvrt|||j||}|dz }t|}|j}||jz}t ||}||kr|||vr|dz }||kr |||vd}||z |jkrd}nF|jr||kr |||vrd}n,|j r%|dkr ||dz |vs||kr |||vrd}|rt|||j|||||fS)NrFTr) rrrrBrrrrrr ) r+rrrrrC bodycharsrthrowExceptions r-rHzWord.parseImpl s[ C= . . 3 TBB B qx==N $VX&&Fllx} 99 1HCFllx} 99 ; $ $!NN   &3>>hsmy6P6P!NN ^ & UQY'944>>SMY..!%  C 3 TBB BHU3Y'''r/)r~NrrrFNr) r2r7r8rGrrrrrr.rrHrrs@r-rr5 sC>>D+/ .2o,+/*.-1o,o,o,o,OC(o, o,  o,  o,o,s+o,?3'o,?3'o,o,oc*o,o,o,o,o,o,b:((((((((r/rceZdZddZdS)rTc|||}|st|||j||}||fSr))rrrrgroup)r+rrrrus r-rHz_WordRegex.parseImpl& sTx-- C 3 TBB BjjllFLLNN""r/Nrrr9r/r-rr% s(######r/rc reZdZdZ d ddddededejeded ejef fd ZxZ S) CharzA short-cut class for defining :class:`Word` ``(characters, exact=1)``, when defining a match of any single character in a string of characters. FN)r r charsetrrr r cZ|p|}|p|}t|d||dt|j|_|rd|j|_t j|j|_|jj|_ dS)Nr)rr r z[{}]z\b{}\b) rr.rrrrrrrr)r+r1rrr r rs r-r.z Char.__init__5 s+ #4}   1      &@&P&PQQ  <%,,T];;DM*T]++  r/)FN) r2r7r8rGrrrrr.rrs@r-r0r0/ s!.2 &  -1&&&&&s+ &  &oc*&&&&&&&&&&r/r0ceZdZdZ dddddedeejefde de d e d e f fd Z e d Ze d Z e dZ dZddZddZddZdedefdZxZS)RegexaToken for matching strings that match a given regular expression. Defined with string specifying the regular expression in a form recognized by the stdlib Python `re module `_. If the given regex contains named groups (defined using ``(?P...)``), these will be preserved as named :class:`ParseResults`. If instead of the Python stdlib ``re`` module you wish to use a different RE module (such as the ``regex`` module), you can do so by building your ``Regex`` object with a compiled RE that was compiled using ``regex``. Example:: realnum = Regex(r"[+-]?\d+\.\d*") # ref: https://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression roman = Regex(r"M{0,4}(CM|CD|D?{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})") # named fields in a regex will be returned as named results date = Regex(r'(?P\d{4})-(?P\d\d?)-(?P\d\d?)') # the Regex class will accept re's compiled using the regex module import regex parser = pp.Regex(regex.compile(r'[0-9]')) rF) asGroupListasMatchpatternflags as_group_listas_matchr5r6ct|p|}|p|}t|tr.|st dd|_|x|_|_||_nQt|dr2t|dr"||_|jx|_|_||_ntdd|j z|_ d|_ ||_||_|jr |j|_|jr|j|_dSdS)aThe parameters ``pattern`` and ``flags`` are passed to the ``re.compile()`` function as-is. See the Python `re module `_ module for an explanation of the acceptable patterns and flags. z0null string passed to Regex; use Empty() insteadNr7rzCRegex may only be constructed with a string or a compiled RE objectrF)rr.rSr#r_rerr7r8r#rrUrrr5r6parseImplAsGroupListrHparseImplAsMatch)r+r7r8r9r:r5r6rs r-r.zRegex.__init__c s/ !2] %X gx ( (  U !STTTDH+2 2DMDLDJJ Wi ( ( WWg-F-F DH+2? :DL4=DJJU "DI- "&   7!6DN < 3!2DNNN 3 3r/c|jr|jS tj|j|jS#tj$r(t d|jwxYw)Nz&invalid pattern ({!r}) passed to Regex)r<rrr7r8r rrrs r-rzRegex.re sp 8 8O z$, ;;;8    <CCDLQQ s /7A&c|jjSr))rrrs r-rzRegex.re_match s w}r/c0|dduSNr~)rrs r-rzRegex.mayReturnEmpty s}}R  ,,r/cxdt|jddS)NzRe:({})z\\\)rrr7rrs r-rzRegex._generateDefaultName s0T\ 2 2 : :64 H HIIIr/Tc<|||}|st|||j||}t |}|}|r|D] \}}|||< ||fSr))rrrrr r. groupdictitems) r+rrrrur5dkvs r-rHzRegex.parseImpl sx-- C 3 TBB Bjjll6<<>>**          1ACxr/c|||}|st|||j||}|}||fSr))rrrrgroupsr+rrrrur5s r-r=zRegex.parseImplAsGroupList sWx-- C 3 TBB BjjllmmooCxr/c|||}|st|||j||}|}||fSr))rrrrrMs r-r>zRegex.parseImplAsMatch sOx-- C 3 TBB BjjllCxr/replrXcjrtdjrtrtdjrfd}nfd}|S)a Return :class:`Regex` with an attached parse action to transform the parsed result as if called using `re.sub(expr, repl, string) `_. Example:: make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2") print(make_html.transform_string("h1:main title:")) # prints "

main title

" z-cannot use sub() with Regex(asGroupList=True)z9cannot use sub() with a callable with Regex(asMatch=True)c:|dSr)expand)r[rOs r-rzRegex.sub..pa say''---r/cFj|dSr)rsub)r[rOr+s r-rzRegex.sub..pa sw{{4333r/)r5rr6r(r5)r+rOrs`` r-rTz Regex.sub s   MKLL L < YHTNN YWXX X < 4 . . . . . .  4 4 4 4 4 4$$R(((r/)rFFr)r2r7r8rGrrr RegexFlagrrr.r&rrrrHr=r>rrrTrrs@r-r4r4J sq6+,# ,3",3,3,3,3R\3&',3 ,3  ,3,3,3,3,3,3,3,3\  _ _--_-JJJ    )) ))))))))r/r4ceZdZdZdZ ddddddddded ejed ejed ed ed ejedededejedejededejedeffdZ dZ ddZ xZ S) QuotedStringa Token for matching strings that are delimited by quoting characters. Defined with the following parameters: - ``quote_char`` - string of one or more characters defining the quote delimiting string - ``esc_char`` - character to re_escape quotes, typically backslash (default= ``None``) - ``esc_quote`` - special quote sequence to re_escape an embedded quote string (such as SQL's ``""`` to re_escape an embedded ``"``) (default= ``None``) - ``multiline`` - boolean indicating whether quotes can span multiple lines (default= ``False``) - ``unquote_results`` - boolean indicating whether the matched text should be unquoted (default= ``True``) - ``end_quote_char`` - string of one or more characters defining the end of the quote delimited string (default= ``None`` => same as quote_char) - ``convert_whitespace_escapes`` - convert escaped whitespace (``'\t'``, ``'\n'``, etc.) to actual whitespace (default= ``True``) Example:: qs = QuotedString('"') print(qs.search_string('lsjdf "This is the quote" sldjf')) complex_qs = QuotedString('{{', end_quote_char='}}') print(complex_qs.search_string('lsjdf {{This is the "quote"}} sldjf')) sql_qs = QuotedString('"', esc_quote='""') print(sql_qs.search_string('lsjdf "This is the quote with ""embedded"" quotes" sldjf')) prints:: [['This is the quote']] [['This is the "quote"']] [['This is the quote with "embedded" quotes']] ))z\t )rVrW)z\f )z\r r~NFT) quoteCharescCharescQuoteunquoteResults endQuoteCharconvertWhitespaceEscapes quote_charesc_char esc_quote multilineunquote_resultsend_quote_charconvert_whitespace_escapesr[r\r]r^r_r`c t| p|} | p|} | o|} | p|} | o|} |p|}|}|std| |} n%| } | std|_t |_|d_| _t | _ | _ | _ | _ | _ d}d}| r-|d|tj| z }d}| rN|d|tj| z }d}tjj dz_t jd krc|d |dfd t't jd z dd Dzd zz }d}|rbtjtjz_|d|t/jd| t/| ndz }nJd_|d|t/jd| t/| ndz }dtjjd|dtjjg_ tjjj_j_jj_n:#tj$r(tdjwxYwdjz_d_ d_!dS)Nz%quote_char cannot be the empty stringz'endQuoteChar cannot be the empty stringrr~z{}(?:{})|z {}(?:{}.)z(.)rz{}(?:c 3K|]X}dtjjd|tjj|dVYdS)z (?:{}(?!{}))N)rrrr_)rCr|r+s r-r*z(QuotedString.__init__..N s{  #)) $"3BQB"788 $"3ABB"788r/r)z {}(?:[^{}{}])z{}(?:[^{}\n\r{}])z(?:z)*z$invalid pattern {!r} passed to RegexrFT)"rr.rZrr[rB quoteCharLenfirstQuoteCharr_endQuoteCharLenr\r]r^r`rrrescCharReplacePatternrrange MULTILINEDOTALLr8rr7rrrrr rUrrr)r+rarbrcrdrerfrgr[r\r]r^r_r`sep inner_patternrs` r-r.zQuotedString.__init__ s" %X(y';O#5~ $ C)C !,*  %%''  FDEE E  %LL'--//L L !JKKK# OO(m("<00   ,(@%   [//RYx5H5HII IMC  I \00bi6H6HII IMC)+4<)@)@5)HD & t ! !A % % s##(( #3t'8#9#9A#=q"EE  MC   1DJ -44)$*;A*>??7>7J*7333PR MM DJ 188)$*;A*>??7>7J*7333PR M ww $.)) $+,,      jtz::DG LDM GMDMMx   6==dlKK   "DI- ""s #AL%%7Mc|j|jkr4t|jtrd|jSd|j|jS)Nzstring enclosed in {!r}z.quoted string, starting with {} ending with {})r[r_rSr#rrs r-rz!QuotedString._generateDefaultName s[ >T. . .:dnh3W3W .,33DNCC C?FF ND-   r/c.|||jkr|||pd}|st|||j||}|}|jr||j|j }t|trwd|vr*|j r#|j D]\}}| ||}|jrtj|jd|}|jr | |j|j}||fS)NrDz\g<1>)rmrrrrr.r^rlrnrSr#r`ws_maprr\rrTror]r_)r+rrrrur5wslitwschars r-rHzQuotedString.parseImpl s3 SMT0 0 - h,,    C 3 TBB Bjjllllnn   Hd'4+?*??@C#x(( H3;;4#@;)-99 v!kk%88<L&!;XsKKC=H++dmT5FGGCCxr/)r~NNFTNTr) r2r7r8rGrwrrrrr.rrHrrs@r-rWrW sn%%LJF)-*. $/3+/o#(,)-#-1)-o#o#o#o#/#&o#?3' o#  o#  o#,o#%)o#o#%o#/#&o#o#oc*o##'o#o#o#o#o#o#b   r/rWc VeZdZdZ ddddededed ed ef fd Zd ZddZxZ S) CharsNotInaToken for matching words composed of characters *not* in a given set (will include whitespace in matched characters if not listed in the provided exclusion set - see example). Defined with string containing all disallowed characters, and an optional minimum, maximum, and/or exact length. The default value for ``min`` is 1 (a minimum value < 1 is not valid); the default values for ``max`` and ``exact`` are 0, meaning no maximum or exact length restriction. Example:: # define a comma-separated-value as anything that is not a ',' csv_value = CharsNotIn(',') print(delimited_list(csv_value).parse_string("dkls,lsdkjf,s12 34,@!#,213")) prints:: ['dkls', 'lsdkjf', 's12 34', '@!#', '213'] r~rr)notChars not_charsrr rr|cztd|_|p||_t |j|_|dkrt d||_|dkr||_n t|_|dkr||_||_d|j z|_ |jdk|_ d|_ dS)NFrzacannot specify a minimum length < 1; use Opt(CharsNotIn()) if zero-length char group is permittedrr)rr.rr|r notCharsSetrrrrrUrrr)r+r}rr rr|rs r-r.zCharsNotIn.__init__ s #!-X t}-- 77K   77DKK"DK 199DKDK!DI- "kQ."r/ct|j}t|dkr"d|jddSd|jS)Nr$z !W:({}...) z!W:({}))rr|rBr)r+ not_chars_strs r-rzCharsNotIn._generateDefaultName sY24=AA }   " "&&t}XvX'>?? ?##DM22 2r/TcV|j}|||vrt|||j||}|dz }t||jzt |}||kr|||vr|dz }||kr |||v||z |jkrt|||j|||||fSrA)rrrrrrBr)r+rrrnotcharsrmaxlens r-rHzCharsNotIn.parseImpl s# C=H $ $ 3 TBB B qUT[(#h--88Fllx}H<< 1HCFllx}H<< ; $ $ 3 TBB BHU3Y'''r/)r~rrrrrrs@r-r{r{ s, !#!#!#!#!#!# !#  !#!#!#!#!#!#!#F333((((((((r/r{c eZdZdZidddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*Zd6d.ed/ed0ed1effd2 Zd3Zd7d5Z xZ S)8WhiteaSpecial matching class for matching whitespace. Normally, whitespace is ignored by pyparsing grammars. This class is included when some whitespace structures are significant. Define with a string containing the whitespace characters to be matched; default is ``" \t\r\n"``. Also takes optional ``min``, ``max``, and ``exact`` arguments, as defined for the :class:`Word` class. rzrXzrWzrZzrYz zu zu᠎zu z u z u z u z u zu zu zu zu zz z zzzz)u u u​u u u  rrwsrr rcht|_dfdjDdd_djz_|_ |dkr|_ n t_ |dkr|_ |_ dSdS)Nr~c3.K|]}|jv |VdSr)) matchWhite)rCrr+s r-r*z!White.__init__..! s/JJ!$/1I1IA1I1I1I1IJJr/Trrr) rr.rr r whiteStrsrrUrrrr)r+rrr rrs` r-r.zWhite.__init__ s  !! GGJJJJt~JJJ J J "   #!DI-  77DKK"DK 199DKDKKK 9r/cJdd|jDS)Nr~c3:K|]}tj|VdSr))rrrs r-r*z-White._generateDefaultName..4 s)CCauq)CCCCCCr/)rrrs r-rzWhite._generateDefaultName3 s%wwCC4?CCCCCCr/Tcj|||jvrt|||j||}|dz }||jz}t |t |}||kr)|||jvr|dz }||kr|||jv||z |jkrt|||j|||||fSrA)rrrrrrBr)r+rrrrrs r-rHzWhite.parseImpl6 s C= / / 3 TBB B q$VS]]++Fllx}?? 1HCFllx}?? ; $ $ 3 TBB BHU3Y'''r/)rrrrr) r2r7r8rGrrrr.rrHrrs@r-rr s V g f f  f  (  & / + + , , ( ' & "!" '#$! &'/I4  3  s s      ,DDD ( ( ( ( ( ( ( (r/rceZdZfdZxZS) PositionTokencdtd|_d|_dSr;rrs r-r.zPositionToken.__init__G rr/)r2r7r8r.rrs@r-rrF s8#########r/rc6eZdZdZdeffd ZdZddZxZS) GoToColumnzaToken to advance to a specific column of input text; useful for tabular report scraping. colnocVt||_dSr))rr.r)r+rrs r-r.zGoToColumn.__init__R s$ r/c~t|||jkrt|}|jr|||}||krq||rWt|||jkr>|dz }||kr3||rt|||jk>|SrA)rrBrr?isspace)r+rrrCs r-rEzGoToColumn.preParseV s sH   ) )8}}H :**8S99hSM))++X&&$(22q hSM))++X&&$(22 r/Tct||}||jkrt||d|||jz|z }|||}||fS)NzText not in expected column)rr)r+rrrthiscolnewlocr5s r-rHzGoToColumn.parseImplc s[c8$$ TX   30MtTT Ttx')s6z"s{r/r) r2r7r8rGrr.rErHrrs@r-rrM sqc   r/rc0eZdZdZfdZdZddZxZS) LineStartaMatches if current position is at the beginning of a line within the parse string Example:: test = '''\ AAA this line AAA and this line AAA but not this one B AAA and definitely not this one ''' for t in (LineStart() + 'AAA' + restOfLine).search_string(test): print(t) prints:: ['AAA', ' this line'] ['AAA', ' and this line'] c>t|t|jz|_|jdt|j|_ d|_ dS)NrWzExpected start of line) rr.rrrorig_whiteCharsdiscardrr rrrs r-r.zLineStart.__init__ sz  "uut6 %%%ww33DODD . r/c|dkr|S|j||}d|jvr@|||dzdkr/|j||dz}|||dzdk/|S)NrrWr)rrEr)r+rrr5s r-rEzLineStart.preParse s !88J,''#66Ct+++sS1W}-55,//#'BBCsS1W}-55Jr/Tc`t||dkr|gfSt|||j|rA)rrrrGs r-rHzLineStart.parseImpl s6 sH   " "7NXsDK>>>r/r)r2r7r8rGr.rErHrrs@r-rrl se,/////????????r/rc*eZdZdZfdZddZxZS)LineEndzTMatches if current position is at the end of a line within the parse string ct|jd||jdd|_dS)NrWFrzExpected end of line)rr.rrr rrs r-r.zLineEnd.__init__ sU  %%% !!$/!GGG, r/Tc|t|kr*||dkr|dzdfSt|||j||t|kr|dzgfSt|||j|)NrWrrBrrrGs r-rHzLineEnd.parseImpl s{ X  }$$Qw}$$XsDKFFF CMM ! !7B;  3 TBB Br/rrrs@r-rr s^----- C C C C C C C Cr/rc*eZdZdZfdZddZxZS) StringStartzLMatches if current position is at the beginning of the parse string cVtd|_dS)NzExpected start of textrr.rrs r-r.zStringStart.__init__ s$ . r/Tcx|dkr1|||dkrt|||j||gfSr)rErrrGs r-rHzStringStart.parseImpl sC !88dmmHa0000$XsDKFFFBwr/rrrs@r-rr sV/////r/rc*eZdZdZfdZddZxZS)rzG Matches if current position is at the end of the parse string cVtd|_dS)NzExpected end of textrrs r-r.zStringEnd.__init__ s$ , r/Tc|t|krt|||j||t|kr|dzgfS|t|kr|gfSt|||j|rArrGs r-rHzStringEnd.parseImpl sx X   3 TBB B CMM ! !7B;  3x== 7N 3 TBB Br/rrrs@r-rr s^-----CCCCCCCCr/rc>eZdZdZefeddedeffdZddZxZS) WordStartaMatches if the current position is at the beginning of a :class:`Word`, and is not preceded by any character in a given set of ``word_chars`` (default= ``printables``). To emulate the ```` behavior of regular expressions, use ``WordStart(alphanums)``. ``WordStart`` will also match at the beginning of the string being parsed, or at the beginning of a line.  wordChars word_charsrc|tkr|n|}tt||_d|_dS)NzNot at the start of a word) printablesrr.rrrr+rrrs r-r.zWordStart.__init__ sD"+z"9"9JJy  Y2 r/Tc|dkr8||dz |jvs|||jvrt|||j||gfSNrr)rrrrGs r-rHzWordStart.parseImpl sQ !88q!T^33C=66$XsDKFFFBwr/r r2r7r8rGrrr.rHrrs@r-rr s*43333333333333 r/rc>eZdZdZefeddedeffdZddZxZS) WordEndaiMatches if the current position is at the end of a :class:`Word`, and is not followed by any character in a given set of ``word_chars`` (default= ``printables``). To emulate the ```` behavior of regular expressions, use ``WordEnd(alphanums)``. ``WordEnd`` will also match at the end of the string being parsed, or at the end of a line. rrrc|tkr|n|}tt||_d|_d|_dS)NFzNot at the end of a word)rrr.rrrrrs r-r.zWordEnd.__init__ sL"+z"9"9JJy  Y#0 r/Tct|}|dkr>||kr8|||jvs||dz |jvrt|||j||gfSr)rBrrr)r+rrrrCs r-rHzWordEnd.parseImplsdx== a<.s,@@$:dH--@@@@@@r/c3pK|]0}t|tr|n|V1dSr))rSr#r)rCr=r+s r-r*z+ParseExpression.__init__..sZ4>a3J3JQD,,Q///PQr/F) rr.rS_generatorTyperr#rrrranyrrr+rrrs` r-r.zParseExpression.__init__sG """ ' e^ , , KKE eX & & %22599:DJJ } - - %DJJ x ( ( %KKE@@%@@@@@ "eDJJ %!%[[  % % %#W  %!s:DD$#D$rXc |jddSr))rrs r-r&zParseExpression.recurse+sz!!!}r/cH|j|d|_|Sr))rr rrs r-r zParseExpression.append.s% %     r/Trct||r5d|jD|_|jD]}|||S)z Extends ``leave_whitespace`` defined in base class, and also invokes ``leave_whitespace`` on all contained expressions. c6g|]}|Sr9r rCr=s r-rEz4ParseExpression.leave_whitespace..; 777q!&&((777r/)rrrr+rr=rs r-rz ParseExpression.leave_whitespace3si   +++  .77DJ777DJZ . .""9---- r/ct||r5d|jD|_|jD]}|||S)z Extends ``ignore_whitespace`` defined in base class, and also invokes ``leave_whitespace`` on all contained expressions. c6g|]}|Sr9rrs r-rEz5ParseExpression.ignore_whitespace..Grr/)rrrrs r-rz!ParseExpression.ignore_whitespace@si !!),,,  /77DJ777DJZ / /##I.... r/crt|trU||jvrKt||jD]"}||jd#nKt||jD]"}||jd#|SNr)rSrrrr r)r+rr=rs r-r zParseExpression.ignoreLs eX & & /D,,,u%%%33AHHT-b12222 GGNN5 ! ! !Z / /)"-.... r/cfd|jjt|jSNz{}:({}))rrr2rrrs r-rz$ParseExpression._generateDefaultNameXs% 7TZIIIr/c$|jr|St|jD]}|t |jdkr|jd}t ||jri|jsb|j[|j sT|jdd|jdgz|_d|_ |xj |j zc_ |xj |j zc_ |jd}t ||jrj|jsc|j\|j sU|jdd|jddz|_d|_ |xj |j zc_ |xj |j zc_ dt|z|_|S)Nrkrrrr)rrrrrBrSrrrrrrrrr)r+r=rrs r-rzParseExpression.streamline[s   K   A LLNNNN tz??a  JqME5$.11 :) :%- .#[^tz!}o= $(!##u';;##""e&99""JrNE5$.11 :) :%- ."Z_u{111~= $(!##u';;##""e&99""!CII-  r/Nc||ngdd|gz}|jD]}|||gdSr))rr/r))r+r.tmpr=s r-r/zParseExpression.validates\ - 9}}r111EN  A JJsOOOO R     r/ctt}d|jD|_|S)Nc6g|]}|Sr9rrs r-rEz(ParseExpression.copy..s 222!QVVXX222r/)rr rr+r5rs r-r zParseExpression.copys0ggllnn22tz222  r/c ~tjrtj|jvr||jD]t}t |t r]|jrVtj|jvrCtj d d|t|j |jdut||SNzY{}: setting results name {!r} on {} expression collides with {!r} on contained expressionr`r$ stacklevel)rOr`rjrrrSrrwarningsrSrrr2rrr+rUrr=rs r-rzParseExpression._setResultsNames  > E*++Z  q-00 $M/00MEEKVG  JJ/M FF $%    ww&&t^<<.%%K%K1a&6%K%K%K%K%K%Kr/rrFT)rrrrBrrr rrRrr.r.rrSrr rrrr) r+rrrrr|r skipto_argrs r-r.z And.__init__s&*)__  X&&C$U++ % %48##3u::>))5:WWuQU|5K4RSU4V  #56*#5#5k#B#BCCCC'NJJt$$$$E!!!H ))) : '"%%K%K %K%K%K"K"KD djmU33 ,))JqM,"&*Q-"E*'+jm&B##&+##"&D  r/rXc|jrtd|jddDrt|jddD]w\}}|t|trZ|jrSt|jdt r3|jd|j|dzz|jd<d|j|dz<xd|jD|_t t|j|jddD]\}}t}|rt||vrn| t|t|tr| |fdn3|}tt!|d}|t#d|jD|_|S)Nc3K|]@}t|to&|jot|jdtVAdSrN)rSrrrrs r-r*z!And.streamline..sd1o..:G:qwr{L99r/rrcg|]}||Sr)r9rs r-rEz"And.streamline..sEEEAq}a}}}r/c@t|dt||S)N parent_anchor)setattrr)rrrcur_s r-rz And.streamline.. s' /3q!9933r/c3$K|] }|jV dSr)rrs r-r*z!And.streamline..s%!G!Gq!"2!G!G!G!G!G!Gr/)rrrrSrrrrrrrAadd IndentedBlockr5r&nextrr.r)r+r|r=prevcurseensubsrs r-rzAnd.streamlines  : FCRC  F &dj"o66 1 1DAqy "1o661G1'qwr{LAA1 '(gbkDJq1u4E&E ,0 1q5)EEEEE  TZABB88 - -ID#55D -c77d??C!!!c=11))-0 {{}}4::t,, -"!G!GDJ!G!G!GGG r/c6|jd|||d\}}d}|jddD]}t|tjurd} |r ||||\}}n#t $rt $r&}d|_t |d}~wt$r%t |t||j |wxYw||||\}}|s| r||z }||fS)NrFrrT) rr"rrrParseSyntaxExceptionrmr_from_exceptionrQrBrhaskeys) r+rrr resultlist errorStopr= exprtokensrss r-rHz And.parseImplsh*Q-.. c95/  Z ABB ) )AAww#.((  E &'hhxi&H&HOC+)CCC'+B$.>>rBBB!. #h--d #$((8S)"D"DZ )Z//11 )j( JsA77C !B,,2Cct|tr||}||Sr)rSr#rr rs r-__iadd__z And.__iadd__39 eX & & 4,,U33E{{5!!!r/ct|dd|gz}|jD]!}|||jsdS"dSr))rr)rr*s r-r)zAnd._checkRecursion8s]*111-6  A  o . . .#    r/c6dd|jD}t|dkr[|ddt|dz dkr<|dd}t|dkr|ddt|dz dk.@s(44AQ444444r/rr{}r{})rrrBr+inners r-rzAnd._generateDefaultName?s4444444%jj1nnq':CJJN':!;t!C!C!B$KE%jj1nnq':CJJN':!;t!C!CU{S  r/r)r2r7r8rGrrrrrrr.rrHr r)rrrs@r-rrs"UKO!!7!CG!!!!!!B+M++++++Z<""" !!!!!!!r/rcteZdZdZd dejedeffd Zdeffd Z dd Z d Z d Z d fd Z xZS)raRequires that at least one :class:`ParseExpression` is found. If two expressions match, the expression that matches the longest string will be used. May be constructed using the ``'^'`` operator. Example:: # construct Or using '^' operator number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums)) print(number.search_string("123 3.1416 789")) prints:: [['123'], ['3.1416'], ['789']] Frrct|||jrHtd|jD|_t d|jD|_dSd|_dS)Nc3$K|] }|jV dSr)rrs r-r*zOr.__init__..\rr/c3$K|] }|jV dSr)rrs r-r*zOr.__init__..]rr/Trr.rrrr.rrs r-r.z Or.__init__Y} ))) : '"%%K%K %K%K%K"K"KD "%%K%K %K%K%K"K"KD   "&D   r/rXc8t|jrjtd|jD|_td|jD|_t d|jD|_nd|_|S)Nc3$K|] }|jV dSr)rrs r-r*z Or.streamline..drr/c3$K|] }|jV dSr)rrs r-r*z Or.streamline..e$!C!C1!,!C!C!C!C!C!Cr/c3PK|]!}|jot|t V"dSr)rrSrrs r-r*z Or.streamline..fH&&BC =Au)=)=%=&&&&&&r/F)rrrrrrr.rrs r-rz Or.streamlineas  : $"%%K%K %K%K%K"K"KD !!C!C !C!C!CCCDO"%&&GKz&&&##D  $DO r/Tc0d}d}g}g}td|jDr|||}|jD]} |||d} || |f3#t $r1} d| _|| _|| d}d}Yd} ~ id} ~ wt$r'} |sd| _| j |kr | }| j }Yd} ~ d} ~ wt$rIt||kr3t|t||j |}t|}YwxYw|r| tdd|s%|dd} | |||Sd} |D]~\}}|| dkr| cS ||||\} }| |kr| |fcS| | dkr| |f} M#t$r%} d| _| j |kr | }| j }Yd} ~ wd} ~ wwxYw| dkr| S|rgt|dkrJ| d |dj |dj kr| d |d}|||j |_|t||d |) Nrc3$K|] }|jV dSr))rrs r-r*zOr.parseImpl..rs$22!q~222222r/Tr`r)rreverserrc|j Sr)rr=s r-rzOr.parseImpl.. 15&r/rcV|j tt|j fSr)rrBr parserElementr(s r-rzOr.parseImpl..$vC.(;;1A;;;;;;r/rrrrs r-rzOr._generateDefaultName/UZZ;; ;;;;;;cAAr/c <tjrntj|jvr[t d|jDr=t jdd|t|j dt ||S)Nc3fK|],}t|totj|jvV-dSr)rSrrjr_rrs r-r*z%Or._setResultsName..X1c"",I+,r/{}: 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 Groupr_r$r rOr_rjrrrrrSrrr2rrr+rUrrs r-rzOr._setResultsName  > E*++    239&CT +33 !    ww&&t^<< [['123'], ['3'], ['1416'], ['789']] # put more selective expression first number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums) print(number.search_string("123 3.1416 789")) # Better -> [['123'], ['3.1416'], ['789']] Frrct|||jrHtd|jD|_t d|jD|_dSd|_dS)Nc3$K|] }|jV dSr)rrs r-r*z&MatchFirst.__init__..rr/c3$K|] }|jV dSr)rrs r-r*z&MatchFirst.__init__..rr/Trrs r-r.zMatchFirst.__init__rr/rXcX|jr|St|jrjt d|jD|_t d|jD|_td|jD|_nd|_d|_|S)Nc3$K|] }|jV dSr)rrs r-r*z(MatchFirst.streamline..rr/c3$K|] }|jV dSr)rrs r-r*z(MatchFirst.streamline..rr/c3PK|]!}|jot|t V"dSr)r rs r-r*z(MatchFirst.streamline..r!r/FT) rrrrrrrr.rrs r-rzMatchFirst.streamlines   K  : '!!C!C !C!C!CCCDO"%%K%K %K%K%K"K"KD "%&&GKz&&&##D  $DO"&D  r/Tcd}d}|jD]} ||||cS#t$r}d|_||_d}~wt $r}|j|kr |}|j}Yd}~[d}~wt$rIt||kr3t |t||j |}t|}YwxYw||j |_ |t ||d|)Nrr/) rr"rrr-rrrQrBrr) r+rrrr1r2r=r5r\s r-rHzMatchFirst.parseImpl s9   . .A .xx '   $(!$%!! ( ( (7Y&&#&L #I . . .x==9,,#1 #h--4$$L!$H I  .  ##{L   #A4 s'( B=A B=A''AB=<B=ct|tr||}||Sr)r rs r-__ior__zMatchFirst.__ior__.r r/cVddd|jDzdzS)Nrz | c34K|]}t|VdSr)rrs r-r*z2MatchFirst._generateDefaultName..4r?r/rr@rs r-rzMatchFirst._generateDefaultName3rAr/c <tjrntj|jvr[t d|jDr=t jdd|t|j dt ||S)Nc3fK|],}t|totj|jvV-dSr)rDrs r-r*z-MatchFirst._setResultsName..<rEr/rFr_r$rrGrHs r-rzMatchFirst._setResultsName6rIr/r~r)r2r7r8rGrrrrr.rrHrTrrrrs@r-rrs"''fom<'''''''M    D""" BBB==========r/rcbeZdZdZd dejedeffd Zdeffd Z d dZ d Z xZ S) ralRequires all given :class:`ParseExpression` s to be found, but in any order. Expressions may be separated by whitespace. May be constructed using the ``'&'`` operator. Example:: color = one_of("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN") shape_type = one_of("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON") integer = Word(nums) shape_attr = "shape:" + shape_type("shape") posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn") color_attr = "color:" + color("color") size_attr = "size:" + integer("size") # use Each (using operator '&') to accept attributes in any order # (shape and posn are required, color and size are optional) shape_spec = shape_attr & posn_attr & Opt(color_attr) & Opt(size_attr) shape_spec.run_tests(''' shape: SQUARE color: BLACK posn: 100, 120 shape: CIRCLE size: 50 color: BLUE posn: 50,80 color:GREEN size:20 shape:TRIANGLE posn:20,40 ''' ) prints:: shape: SQUARE color: BLACK posn: 100, 120 ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']] - color: BLACK - posn: ['100', ',', '120'] - x: 100 - y: 120 - shape: SQUARE shape: CIRCLE size: 50 color: BLUE posn: 50,80 ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']] - color: BLUE - posn: ['50', ',', '80'] - x: 50 - y: 80 - shape: CIRCLE - size: 50 color: GREEN size: 20 shape: TRIANGLE posn: 20,40 ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']] - color: GREEN - posn: ['20', ',', '40'] - x: 20 - y: 40 - shape: TRIANGLE - size: 20 Trrct|||jr$td|jD|_nd|_d|_d|_d|_dS)Nc3$K|] }|jV dSr)rrs r-r*z Each.__init__..rr/T)rr.rr.rrinitExprGroupsrrs r-r.z Each.__init__sn ))) : '"%%K%K %K%K%K"K"KD  "&D ""r/rXct|jr$td|jD|_nd|_|S)Nc3$K|] }|jV dSr)rrs r-r*z"Each.streamline..rr/T)rrrr.rrs r-rzEach.streamlinesT  : '"%%K%K %K%K%K"K"KD  "&D  r/cv|jrtd|jD|_d|jD}d|jD}||z|_d|jD|_d|jD|_d|jD|_|xj|jz c_d|_|}|jdd}|jdd|jdd}g} d} g} g} | rP|z|z} | | | D]} | ||d }| |j t||||vr| |p|vr |#t$rB}d|_||_| || |Yd}~d}~wt"$r| |YwxYwt%| t%| krd} | P| rgt%| d krJ| d | d j| d jkr| d | d }||rCdd|D}t#||d|| fd|jDz } t/g}| D]!}||||\}}||z }"||fS)Nc3lK|]/}t|tt|j|fV0dSr))rSrrArrs r-r*z!Each.parseImpl..sQ  $%z!S7I7I AFQ      r/cFg|]}t|t|jSr9rSrrrs r-rEz"Each.parseImpl..s)EEEq*Q2D2DEAFEEEr/cdg|]-}|j t|tttf+|.Sr9)rrSrr4rrs r-rEz"Each.parseImpl..sL#-7q3z:R,S,Sr/czg|]8}t|t|j|jd9ST)r)rS_MultipleMatchrrrrs r-rEz"Each.parseImpl..sO###a00#'' 'MM###r/czg|]8}t|t|j|jd9Sre)rSrrrrrs r-rEz"Each.parseImpl..sO"""a++"'' 'MM"""r/cVg|]&}t|tttf$|'Sr9)rSrrrrs r-rEz"Each.parseImpl..s>ZCY;W-X-Xr/FTr$rc|j Sr)r'r(s r-rz Each.parseImpl..r)r/r*rcV|j tt|j fSr)r,r(s r-rz Each.parseImpl..r.r/z, c,g|]}t|Sr9rrs r-rEz"Each.parseImpl..s 9 9 9AQ 9 9 9r/z*Missing one or more required elements ({})cPg|]"}t|t|jv |#Sr9rb)rCr=tmpOpts r-rEz"Each.parseImpl..s5XXXQ 1c0B0BXqvQWGWGWqGWGWGWr/)r\dictropt1map optionalsmultioptionals multirequiredrequiredrxrcr r/rAremoverrr-rrBr0rrrr r")r+rrropt1opt2tmpLoctmpReqdmultis matchOrder keepMatchingfailedr3tmpExprsr=r5r:missing total_resultsrrms @r-rHzEach.parseImpls   (  )-   DLFEDJEEEDD "D[DN#####D  """""D  :DM MMT/ /MM"'D -""$QQQ'   %'&0H LLNNN LLNNN ) ))[[6t[LLF%%dl&6&6r!uua&@&@AAAG||q))))f a(((+%%%(,C%()C%MM#&&&MM!$$$$$$$$%%%%MM!$$$$$%6{{c(mm++$ + %0  6{{Q 0 0 111!9=F1IM11KK$R$RKSSSq IO  ii 9 9 9 9 9::G <CCGLL  XXXX$*XXXX $R((  % %A88Hc9==LC W $MMM!!s%F,, H68G33"HHcVddd|jDzdzS)Nrz & c34K|]}t|VdSr)rrs r-r*z,Each._generateDefaultName..r?r/rr@rs r-rzEach._generateDefaultNamerAr/r) r2r7r8rGrrrrr.rrHrrrs@r-rrQs77rfom<MU"U"U"U"nBBBBBBBr/rceZdZdZddeeefdeffd Zde efdZ dd Z dd edeffd Z dd edeffd Z deffd Zdeffd ZdZdddZdZe Ze ZxZS)ParseElementEnhancezfAbstract subclass of :class:`ParserElement`, for combining and post-processing parsed tokens. Frrct|t|trt |jt r||}nTt t||jrt|}n"|t|}||_ |~|j |_ |j |_ | |j |j|j|_|j|_|j|_|j|jdSdS)Nr)rr.rSr# issubclassrrrr]rrrr rrrrrrrr+rrrs r-r.zParseElementEnhance.__init__s+ """ dH % % ?$2E:: ?//55DJJ(@AA ?t}}// >>  !%!3D "&"5D   % %t/I &   #'"5D "oDO $ 1D    # #D$4 5 5 5 5 5  r/rXc$|j|jgngSr)rrs r-r&zParseElementEnhance.recurses"i3 {{;r/Tcp|j|j|||dSt||d|)NFrzNo expression defined)rr"rrGs r-rHzParseElementEnhance.parseImpls> 9 9##Hc95#QQ Q 30GNN Nr/rct||r?|j|_|j|j||Sr))rrrr r+rrs r-rz$ParseElementEnhance.leave_whitespacesY   +++  6 ((DIy$ **9555 r/ct||r?|j|_|j|j||Sr))rrrr rs r-rz%ParseElementEnhance.ignore_whitespace$sY !!),,,  7 ((DIy$ ++I666 r/czt|trW||jvrMt||j%|j|jdnMt||j%|j|jd|Sr)rSrrrr rr+rrs r-r zParseElementEnhance.ignore-s eX & & 7D,,,u%%%9(I$$T%5b%9::: GGNN5 ! ! !y$   !1"!5666 r/ct|j|j|Sr))rrrrs r-rzParseElementEnhance.streamline9s:  9 I " " " r/c||vrt||gz|dd|gz}|j|j|dSdSr))RecursiveGrammarExceptionrr))r+r+r,s r-r)z#ParseElementEnhance._checkRecursion?se # # #+,<v,EFF F*111-6 9 I % %o 6 6 6 6 6 ! r/Nc|g}|dd|gz}|j|j||gdSr)rr/r)r+r.rs r-r/zParseElementEnhance.validateFsZ  MAAA$' 9 I  s # # # R     r/cfd|jjt|jSr)rrr2rrrs r-rz(ParseElementEnhance._generateDefaultNameNs% 7TYHHHr/r~rr)r^)r2r7r8rGrrrrr.r r&rHrrr rr)r/rrrrrs@r-rrs66U=##566$666666*<-0<<<<OOOO $-4= }      M 777!!!!!III)&OOOOOr/rcxeZdZdZGddeZGddeZdddd ed ed effd Z dd Z xZ S)rz Expression to match one or more expressions at a given indentation level. Useful for parsing text where structure is implied by indentation (like Python source code). c$eZdZdeffd ZxZS)IndentedBlock._Indentref_colctd|_|fddS)Nzexpected indent at column {}c,t||kSr)rrrrrs r-rz0IndentedBlock._Indent.__init__.._ss1ayyG/Cr/rr.rrr7r+rrs `r-r.zIndentedBlock._Indent.__init__\sS GG     8??HHDK   CCCC D D D D Dr/r2r7r8rr.rrs@r-_Indentr[sO EC E E E E E E E E E Er/rc$eZdZdeffd ZxZS)IndentedBlock._IndentGreaterrctd|_|fddS)Nz)expected indent at column greater than {}c,t||kSr)rrs r-rz7IndentedBlock._IndentGreater.__init__..ess1ayy7/Br/rrs `r-r.z%IndentedBlock._IndentGreater.__init__bsS GG     ELLWUUDK   BBBB C C C C Cr/rrs@r-_IndentGreaterrasO DC D D D D D D D D D Dr/rFTrgroupedrrrcxt|d||_||_d|_dS)NTrr)rr. _recursive_groupedr)r+rrrrs r-r.zIndentedBlock.__init__gs@ ---$ r/crt||}|j|||t ||}||}t|z|jz}|jrl||}t|j|j|j } | |j || _ |t|| zz }|dtt!|ddd|t%|} ||j t'z} |j rt(} nd} | | t+| z|||S)Nrzinner @c|Sr)r9rs r-rz)IndentedBlock.parseImpl..s4r/)rrErrcrrrrrrrrrrrhexrArrrGrouprrH) r+rrr anchor_loc indent_colpeer_detect_expr inner_expr sub_indent nested_blockblocktrailing_undentrs r-rHzIndentedBlock.parseImplqsWW%%h44  Hj)<<<X.. << 33WW//$); ? 9,,Z88J( T_dmL  " "4: . . .)3L & #j<788 8JTSJ%8%8%=%C%C%E%ETT TTUUU*%%,,t'9::Y[[H = (GG''G/!:!::EE j)   r/r) r2r7r8rGrrrrrr.rHrrs@r-rrUs EEEEE%EEE DDDDDDDD9>t!15HL! ! ! ! ! ! ! ! r/rcDeZdZdZdeeefffd Zdfd ZxZ S) AtStringStartzMatches if expression matches at the beginning of the parse string:: AtStringStart(Word(nums)).parse_string("123") # prints ["123"] AtStringStart(Word(nums)).parse_string(" 123") # raises ParseException rcXt|d|_dSNFrr.rr+rrs r-r.zAtStringStart.__init__) !r/Tcx|dkrt||dt|||S)Nrznot found at string start)rrrHr+rrrrs r-rHzAtStringStart.parseImpls; !88 30KLL Lww  3 :::r/r r2r7r8rGrrrr.rHrrs@r-rrsv"U=##56"""""";;;;;;;;;;r/rcDeZdZdZdeeefffd Zdfd ZxZ S) AtLineStartaMatches if an expression matches at the beginning of a line within the parse string Example:: test = '''\ AAA this line AAA and this line AAA but not this one B AAA and definitely not this one ''' for t in (AtLineStart('AAA') + restOfLine).search_string(test): print(t) prints:: ['AAA', ' this line'] ['AAA', ' and this line'] rcXt|d|_dSrrrs r-r.zAtLineStart.__init__rr/Tct||dkrt||dt|||S)Nrznot found at line start)rrrrHrs r-rHzAtLineStart.parseImplsG sH   " " 30IJJ Jww  3 :::r/rrrs@r-rrsv,"U=##56"""""";;;;;;;;;;r/rc@eZdZdZdeeefffd ZddZxZ S) FollowedByacLookahead matching of the given parse expression. ``FollowedBy`` does *not* advance the parsing position within the input string, it only verifies that the specified parse expression matches at the current position. ``FollowedBy`` always returns a null token list. If any results names are defined in the lookahead expression, those *will* be returned for access by name. Example:: # use FollowedBy to match a label only if it is followed by a ':' data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join)) attr_expr[1, ...].parse_string("shape: SQUARE color: BLACK posn: upper left").pprint() prints:: [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']] rcXt|d|_dSr$rr.rrs r-r.zFollowedBy.__init__s) "r/TcT|j|||\}}|dd=||fS)Nrb)rr")r+rrrr?r5s r-rHzFollowedBy.parseImpls8!!(C9!EE3 FCxr/rrrs@r-rrsl,#U=##56######r/rc^eZdZdZ d deeefdeje ffd Z d dZ xZ S) PrecededByaLookbehind matching of the given parse expression. ``PrecededBy`` does not advance the parsing position within the input string, it only verifies that the specified parse expression matches prior to the current position. ``PrecededBy`` always returns a null token list, but if a results name is defined on the given expression, it is returned. Parameters: - expr - expression that must match prior to the current parse location - retreat - (default= ``None``) - (int) maximum number of characters to lookbehind prior to the current parse location If the lookbehind expression is a string, :class:`Literal`, :class:`Keyword`, or a :class:`Word` or :class:`CharsNotIn` with a specified exact or maximum length, then the retreat parameter is not required. Otherwise, retreat must be specified to give a maximum number of characters to look back from the current parse position for a lookbehind match. Example:: # VB-style variable names with type prefixes int_var = PrecededBy("#") + pyparsing_common.identifier str_var = PrecededBy("$") + pyparsing_common.identifier Nrretreatct|||_d|_d|_d|_t|trt|}d|_nt|ttfr|j }d|_nYt|ttfr|jt kr|j}d|_nt|t"r d}d|_||_dt'|z|_d|_|jddS)NTFrznot preceded by cH|tddSr)) __delitem__slicerrrs r-rz%PrecededBy.__init__..$s eD$>O>O0P0Pr/)rr.rrrrrrSr#rBr]rrrr{rrrrrrrrr )r+rrrs r-r.zPrecededBy.__init__ s/ IIKK0022 "" dH % % $iiGDJJ w0 1 1 mGDJJ tZ0 1 1 dkX6M6MkGDJJ m , , GDJ (3t994 #  P PQQQQQr/rTc(|jrJ||jkrt|||j||jz }|j||\}}n|jt z}|td||jz |}t|||j} tdt||jdzdzD]F} ||t|| z \}}n#t$r } | } Yd} ~ ?d} ~ wwxYw| ||fSr) rrrrrr"rr rprrBrm) r+rrrrr?r5 test_exprinstring_slice last_exproffsetpbes r-rHzPrecededBy.parseImpl&sA : T\!!$XsDK@@@$,&EY%%h66FAss IKK/I%c!S4<-?&@&@3&FGN&xdkBBI3sDL1,<#=#=#ABB &--&N(;(;f(DFAs E*$$$ #IIIIII$  Cxs )C55 D ?DD r))rT) r2r7r8rGrrrrrrr.rHrrs@r-rrs<PTRR-,-R8>8LRRRRRR2r/rceZdZdZddZdS)Locateda Decorates a returned token with its starting and ending locations in the input string. This helper adds the following results names: - ``locn_start`` - location where matched expression begins - ``locn_end`` - location where matched expression ends - ``value`` - the actual parsed results Be careful if the input text contains ```` characters, you may want to call :class:`ParserElement.parse_with_tabs` Example:: wd = Word(alphas) for match in Located(wd).search_string("ljsdf123lksdjjf123lkkjj1222"): print(match) prints:: [0, ['ljsdf'], 5] [8, ['lksdjjf'], 15] [18, ['lkkjj'], 23] Tc|}|j|||d\}}t|||g}||d<||d<||d<|jr||gfS||fS)NFr locn_startrrlocn_end)rr"r r)r+rrrrr[r]s r-rHzLocated.parseImpl\s~i&&x PU&VV V!5&#"677 #( < $ 7!$ :   # $ $ ? "r/Nr)r2r7r8rGrHr9r/r-rr@s26 # # # # # #r/rcFeZdZdZdeeefffd ZddZdZ xZ S)ra Lookahead to disallow matching with the given parse expression. ``NotAny`` does *not* advance the parsing position within the input string, it only verifies that the specified parse expression does *not* match at the current position. Also, ``NotAny`` does *not* skip over leading whitespace. ``NotAny`` always returns a null token list. May be constructed using the ``'~'`` operator. Example:: AND, OR, NOT = map(CaselessKeyword, "AND OR NOT".split()) # take care not to mistake keywords for identifiers ident = ~(AND | OR | NOT) + Word(alphas) boolean_term = Opt(NOT) + ident # very crude boolean expression - to support parenthesis groups and # operation hierarchy, use infix_notation boolean_expr = boolean_term + ((AND | OR) + boolean_term)[...] # integers that are followed by "." are actually floats integer = Word(nums) + ~Char(".") rct|d|_d|_dt |jz|_dS)NFTzFound unwanted token, )rr.rrrrrrs r-r.zNotAny.__init__sE $".TY? r/Tcn|j||rt|||j||gfSr))rrerrrGs r-rHzNotAny.parseImpls< 9 # #Hc 2 2 C 3 TBB BBwr/c6dt|jzdzS)Nz~{rrrrs r-rzNotAny._generateDefaultNamesc$)nn$s**r/r) r2r7r8rGrrrr.rHrrrs@r-rrjs0@U=##56@@@@@@ +++++++r/rc eZdZ d dddedejeeefdejeeefffdZdefdZ dd Z dfd Z xZ S)rfNstopOnrstop_onrct||p|}d|_|}t|tr||}||dSr$)rr.rrSr#rr)r+rrrenderrs r-r.z_MultipleMatch.__init__sp "7 eX & & 4,,U33E Er/rXcrt|tr||}||nd|_|Sr))rSr#r not_ender)r+rs r-rz_MultipleMatch.stopOns> eX & & 4,,U33E#(#4%$ r/Tct|jj}|j}|jdu}|r |jj}|r |||||||\}} |j } |r |||| r |||} n|} ||| |\}} | s| r|| z }K#ttf$rYnwxYw||fSr)) rr"r?rrrrrrQ) r+rrrself_expr_parseself_skip_ignorables check_ender try_not_enderr[hasIgnoreExprsr tmptokenss r-rHz_MultipleMatch.parseImpls-)*#3nD0  4 N3M  ) M(C ( ( (%ohY?? V %)%5!55N (1!M(C000!!11(C@@FF F!069!M!MY( 1 1 3 3(i'F ( +    D F{s ABB32B3Fc tjrtj|jvr|jg|jzD]t}t |tr]|jrVtj|jvrCtj d d|t|j |jdut||Sr)rOr`rjrrr&rSrrrrSrrr2rrrs r-rz_MultipleMatch._setResultsNames  > E*++i[49#4#4#6#66  q-00 $M/00MEEKVG  JJ/M FF $%    ww&&t^<<B    }c'9!:;  mS&8 9:      } :==========r/rfceZdZdZdZdS)rar Repetition of one or more of the given expression. Parameters: - expr - expression that must match one or more times - stop_on - (default= ``None``) - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).set_parse_action(' '.join)) text = "shape: SQUARE posn: upper left color: BLACK" attr_expr[1, ...].parse_string(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']] # use stop_on attribute for OneOrMore to avoid reading label string as part of the data attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join)) OneOrMore(attr_expr).parse_string(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']] # could also be written as (attr_expr * (1,)).parse_string(text).pprint() c6dt|jzdzS)Nrz}...rrs r-rzOneOrMore._generateDefaultNameS^^#f,,r/N)r2r7r8rGrr9r/r-rrs-4-----r/rc eZdZdZ d dddedejeeefdejeeefffdZ d fd Z d Z xZ S) rao Optional repetition of zero or more of the given expression. Parameters: - ``expr`` - expression that must match zero or more times - ``stop_on`` - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) - (default= ``None``) Example: similar to :class:`OneOrMore` Nrrrrc`t||p|d|_dS)NrTr)r+rrrrs r-r.zZeroOrMore.__init__s5 f&7888"r/Tc t|||S#ttf$r|t g|jfcYSwxYw)Nr)rrHrrQr rrs r-rHzZeroOrMore.parseImplsj @77$$XsI>> > + @ @ @ Rd.>???? ? ? ? @s"&)AAc6dt|jzdzS)N[z]...rrs r-rzZeroOrMore._generateDefaultNamerr/r)r) r2r7r8rGrrrrrr.rHrrrs@r-rrs  ?C# >B ####}c'9!:;# mS&8 9: ######@@@@@@ -------r/rceZdZdZdZdS) _NullTokencdSrr9rs r-__bool__z_NullToken.__bool__$sur/cdSrBr9rs r-r z_NullToken.__str__'srr/N)r2r7r8rr r9r/r-rr#s2r/rcbeZdZdZeZefdeeefde ffd Z ddZ dZ xZ S) raN Optional matching of the given expression. Parameters: - ``expr`` - expression that must match zero or more times - ``default`` (optional) - value to be returned if the optional expression is not found. Example:: # US postal code can be a 5-digit zip, plus optional 4-digit qualifier zip = Combine(Word(nums, exact=5) + Opt('-' + Word(nums, exact=4))) zip.run_tests(''' # traditional ZIP code 12345 # ZIP+4 form 12101-0001 # invalid ZIP 98765- ''') prints:: # traditional ZIP code 12345 ['12345'] # ZIP+4 form 12101-0001 ['12101-0001'] # invalid ZIP 98765- ^ FAIL: Expected end of text (at char 5), (line:1, col:6) rdefaultct|d|jj|_||_d|_dS)NFrT)rr.rr defaultValuer)r+rrrs r-r.z Opt.__init__TsD ...).#"r/Tc|j} ||||d\}}nO#ttf$r;|j}||jur&|jrt|g}|||j<n|g}ng}YnwxYw||fS)NFr)rr"rrQr_Opt__optionalNotMatchedrr )r+rrr self_exprr[ default_values r-rHz Opt.parseImpl\sI  #**8S)RW*XXKC +    -MD$===(-)=/::F4AF9011+_FF F{s&A A21A2ct|j}t|dkr[|ddt|dz dkr<|dd}t|dkr|ddt|dz dkt||p|}||_d|_d|_||_d|_t|tr| ||_ n||_ dt|j z|_ dS)NTFzNo match found for )rr. ignoreExprrr includeMatchrrSr#rr rrr)r+rrr rr rs r-r.zSkipTo.__init__s "7 ""# fh ' ' !226::DKK DK+c$)nn< r/Tc|}t|}|jj}|j |jjnd}|j |jjnd}|} | |krd| ||| rnl| ||| } n#t$rYnwxYw ||| ddn9#ttf$r| dz } YnwxYw| |kdt|||j || }|||} t| } |j r||||d\}} | | z } || fS)NrF)rrr) rBrr"r rrrrmrrQrr r) r+rrrrrCrself_failOn_canParseNextself_ignoreExpr_tryParsetmplocskiptext skipresultrs r-rHzSkipTo.parseImplsx==)*(, (?DK $ $T !)-(CDO $ $ !  '3++Hf=='3!9!9(F!K!K-  &EPUVVVV  #J/   !  !  2!3 TBB BHSL)!(++   &xieTTTHC # JJs$# A00 A=<A=BB+*B+)FNNr) r2r7r8rGrrrrrrr.rHrrs@r-rrws::~>B =-1===]C'(== = }c'9!:; =mS()======,00000000r/rceZdZdZddejeeefffd Z dZ dZ fdZ dZ dfd Zdd ed efd Zdd ed efdZd efdZdddZdZd effd Zdfd ZeZeZxZS)rfaw Forward declaration of an expression to be defined later - used for recursive grammars, such as algebraic infix notation. When the expression is known, it is assigned to the ``Forward`` variable using the ``'<<'`` operator. Note: take care when assigning to ``Forward`` not to overlook precedence of operators. Specifically, ``'|'`` has a lower precedence than ``'<<'``, so that:: fwd_expr << a | b | c will actually be evaluated as:: (fwd_expr << a) | b | c thereby leaving b and c out as parseable alternatives. It is recommended that you explicitly group the values inserted into the ``Forward``:: fwd_expr << (a | b | c) Converting to use the ``'<<='`` operator instead will avoid this problem. See :class:`ParseResults.pprint` for an example of a recursive parser created using ``Forward``. Nrctjdd|_t|dd|_dS)NrkrrFr)rr caller_framerr. lshift_liners r-r.zForward.__init__sI%3!<<> >( )/ Q/ Q 0D- Q(,S$ -A(B%+k955&%%!1!1!3!33/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ Q' Q' Q' Qd+u-!G" #'Ld8#)d8n 3$(NDMQ@,1GG,=,=hU,S,S))@@@%i;;"!,4i @ (**$@FJ']R1HkDN $XW #+[-=-=-?-?#???I/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ QJ!N')9)9999M/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ QR%&&050A0A(CQU0V0VW #1&&&BI1 MXg %&@G?PP+)d8n5Q' Q/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ Q/ Qs I5:DAI2 &FI2$F.+I2-F..7I2%I53I2 I5I2&II2 I  II  I22I55I9<I9rrXcd|_|Srrrs r-rzForward.leave_whitespaces# r/cd|_|Sr$rrs r-rzForward.ignore_whitespaces" r/cb|js'd|_|j|j|Sr$)rrrrs r-rzForward.streamlines6 '#D y$ $$&&& r/c|g}||vr/|dd|gz}|j|j||gdSr)rrs r-r/zForward.validatese  M } $ $"dV+Cy$ ""3''' R     r/cd|_d} |jt|jdd}nd}|jjdz|zS#|jjdz|zccYSxYw)Nz: ...riNonez: )rrrrr2)r+ retStrings r-rzForward._generateDefaultNamesz#  >y$ NN5D51 " >*T1I= =4>*T1I= = = = = = = = =s &AAc||j tSt}||z}|Sr))rrr rfrs r-r z Forward.copys4 9 77<<>> !))C DLCJr/Fc tjrWtj|jvrD|j=t jdd|t|j dt ||S)NzO{}: setting results name {!r} on {} expression that has no contained expressionrar$r) rOrarjrrrrSrrr2rr)r+rUrrs r-rzForward._setResultsNames  3 :*++y  77=v8$T @S88 ! ww&&t-=>>>r/r)rr^r~)r2r7r8rGrrrrrr.rr!rr(rHrrrrr/rr rrrrrs@r-rfrfs8  foeM34F.GH      "        ]Q]Q]Q]Q]Q]Q~$-4=M!!!!! > > >m??????")&OOOOOr/rfc:eZdZdZddeeefffd ZxZS)TokenConverterzW Abstract subclass of :class:`ParseExpression`, for converting parsed results. FrcXt|d|_dSr)rr.rrs r-r.zTokenConverter.__init__s& r/r~) r2r7r8rGrrrr.rrs@r-rArAs]  U=##56          r/rAc leZdZdZ ddddededed ejeffd Z d effd Z d Z xZ S)CombineaConverter to concatenate all matching tokens to a single string. By default, the matching patterns must also be contiguous in the input string; this can be disabled by specifying ``'adjacent=False'`` in the constructor. Example:: real = Word(nums) + '.' + Word(nums) print(real.parse_string('3.1416')) # -> ['3', '.', '1416'] # will also erroneously match the following print(real.parse_string('3. 1416')) # -> ['3', '.', '1416'] real = Combine(Word(nums) + '.' + Word(nums)) print(real.parse_string('3.1416')) # -> ['3.1416'] # no match when there are internal spaces print(real.parse_string('3. 1416')) # -> Exception: Expected W:(0123...) r~TN) joinStringr join_stringadjacentrEct|||n|}|r|||_d|_||_d|_dSr$)rr.rrGrrEr)r+rrFrGrErs r-r.zCombine.__init__si #-#9ZZ{  $  ! ! # # #  "$ r/rXc|jrt||n!t||Sr))rGrr rrs r-r zCombine.ignore"sA = "  u - - - - GGNN5 ! ! ! r/c|}|dd=|td||jg|jz }|jr|r|gS|S)Nr~)rP)r r r _asStringListrErrr)r+rrrKretTokss r-rLzCombine.postParse)s.."" AAAJ< WWY,,T_== > > ?tGX        1 1 9 Nr/)r~T) r2r7r8rGrrrrrr.r rLrrs@r-rDrDs* ! ,0 !!!!! ! OC( !!!!!!$}       r/rDc4eZdZdZddedeffd ZdZxZS)raConverter to return the matched tokens as a list - useful for returning tokens of :class:`ZeroOrMore` and :class:`OneOrMore` expressions. The optional ``aslist`` argument when set to True will return the parsed tokens as a Python list instead of a pyparsing ParseResults. Example:: ident = Word(alphas) num = Word(nums) term = ident | num func = ident + Opt(delimited_list(term)) print(func.parse_string("fn a, b, 100")) # -> ['fn', 'a', 'b', '100'] func = ident + Group(Opt(delimited_list(term))) print(func.parse_string("fn a, b, 100")) # -> ['fn', ['a', 'b', '100']] Fraslistcft|d|_||_dSr$)rr.r _asPythonList)r+rrNrs r-r.zGroup.__init__K0 #r/c|jrJtjt|tr|nt |S|gSr))rPr r rSrOrrJs r-rLzGroup.postParsePsX   $i66%   """)__  ; r/r~ r2r7r8rGrrr.rLrrs@r-rr6si($$]$D$$$$$$ r/rc4eZdZdZddedeffd ZdZxZS)rarConverter to return a repetitive expression as a list, but also as a dictionary. Each element can also be referenced using the first token in the expression as its key. Useful for tabular report scraping when the first column can be used as a item key. The optional ``asdict`` argument when set to True will return the parsed tokens as a Python dict instead of a pyparsing ParseResults. Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join)) # print attributes as plain groups print(attr_expr[1, ...].parse_string(text).dump()) # instead of OneOrMore(expr), parse using Dict(Group(expr)[1, ...]) - Dict will auto-assign names result = Dict(Group(attr_expr)[1, ...]).parse_string(text) print(result.dump()) # access named fields as dict entries, or output as dict print(result['shape']) print(result.as_dict()) prints:: ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap'] [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: 'light blue' - posn: 'upper left' - shape: 'SQUARE' - texture: 'burlap' SQUARE {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'} See more examples at :class:`ParseResults` of accessing fields by results name. Frasdictcft|d|_||_dSr$)rr.r _asPythonDict)r+rrUrs r-r.z Dict.__init__rQr/c~t|D]j\}}t|dkr|d}t|tr!t |}t|dkrt d|||<t|dkr5t|dtst |d|||< |}n #t$rtd}|dwxYw|d=t|dks)t|tr)| rt ||||<Qt |d|||<l|j r0|j r|gn|S|j r|gn|S)Nrrr~rkzdcould not extract dict values from parsed results - Dict expression must contain Grouped expressions)rrBrSrrrZr!r r rRrrrWras_dict) r+rrrKr|tokikey dictvaluers r-rLzDict.postParses ** O OFAs3xx1}}q6D$$$ )4yy((3xx1}}"9"a"@"@ $SQz#a&,'G'G"9#a&!"D"D $( # II (((#NC4' (aLy>>Q&&y,77'i&K&KIdOO&=ilA&N&NIdOO   B,0,<UI%%''(()BSBSBUBU U"&"2AI;; As C--D r~rSrs@r-rr[sq''R$$]$D$$$$$$ %B%B%B%B%B%B%Br/rcheZdZdZd deeefdeffd Zd fd Z d fd Z d Z defd Z xZ S)raConverter for ignoring the results of a parsed expression. Example:: source = "a, b, c,d" wd = Word(alphas) wd_list1 = wd + (',' + wd)[...] print(wd_list1.parse_string(source)) # often, delimiters that are useful during parsing are just in the # way afterward - use Suppress to keep them out of the parsed output wd_list2 = wd + (Suppress(',') + wd)[...] print(wd_list2.parse_string(source)) # Skipped text (using '...') can be suppressed as well source = "lead in START relevant text END trailing text" start_marker = Keyword("START") end_marker = Keyword("END") find_body = Suppress(...) + start_marker + ... + end_marker print(find_body.parse_string(source) prints:: ['a', ',', 'b', ',', 'c', ',', 'd'] ['a', 'b', 'c', 'd'] ['START', 'relevant text ', 'END'] (See also :class:`delimited_list`.) Frrc|durtt}t|dS)N.)rrrr.rs r-r.zSuppress.__init__s; 3;; **D r/rXrct|jtrtt ||zSt |Sr))rSrrrrrrrs r-rzSuppress.__add__F di . . *F5MM**U2 277??5)) )r/ct|jtrtt ||z St |Sr))rSrrrrrrrs r-rzSuppress.__sub__r`r/cgSr)r9rJs r-rLzSuppress.postParser'r/c|Sr)r9rs r-rzSuppress.suppresss r/r~r)r2r7r8rGrrrrr.rrrLrrrs@r-rrs<U=##56$ ****** ****** -r/rr:cHtfd}j|_|S)asDecorator for debugging parse actions. When the parse action is called, this decorator will print ``">> entering method-name(line:, , )"``. When the parse action completes, the decorator will print ``"<<"`` followed by the returned value, or any exception that the parse action raised. Example:: wd = Word(alphas) @trace_parse_action def remove_duplicate_chars(tokens): return ''.join(sorted(set(''.join(tokens)))) wds = wd[1, ...].set_parse_action(remove_duplicate_chars) print(wds.parse_string("slkdjs sld sldd sdlf sdljf")) prints:: >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {})) <>entering {}(line: {!r}, {}, {!r}) z<.zs :+1a v;;??ay*3c9HDH  3 : :8T!QZZQRTU V V    !V*CC    J  =DDXsSS T T T   5< "0123456789" srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz" srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_" The input string must be enclosed in []'s, and the returned string is the expanded character set joined into a single string. The values enclosed in the []'s may be: - a single character - an escaped character with a leading backslash (such as ``\-`` or ``\]``) - an escaped hex character with a leading ``'\x'`` (``\x21``, which is a ``'!'`` character) (``\0x##`` is also supported for backwards compatibility) - an escaped octal character with a leading ``'\0'`` (``\041``, which is a ``'!'`` character) - a range of any of the above, separated by a dash (``'a-z'``, etc.) - any combination of the above (``'aeiouy'``, ``'a-zA-Z0-9_$'``, etc.) c t|ts|nUddtt |dt |ddzDS)Nr~c34K|]}t|VdSr))rtrs r-r*z+srange....Qs(EESVVEEEEEEr/rr)rSr rrpord)ps r-rzsrange..Os^!\**F!! WWEEU3qt99c!A$ii!m%D%DEEE E Er/r~c3.K|]}|VdSr)r9)rCpart _expandeds r-r*zsrange..Ts+WW4yyWWWWWWr/)r_reBracketExprrrxrR)rrs @r-sranger4ss6 F F wwWWWW>3N3Nq3Q3Q3VWWWWWW rrs=A AAclfd}tdtdj}||_|S)a^Helper to define a parse action by mapping a function to all elements of a :class:`ParseResults` list. If any additional args are passed, they are forwarded to the given function as additional arguments after the token, as in ``hex_integer = Word(hexnums).set_parse_action(token_map(int, 16))``, which will convert the parsed data to an integer using base 16. Example (compare the last to example in :class:`ParserElement.transform_string`:: hex_ints = Word(hexnums)[1, ...].set_parse_action(token_map(int, 16)) hex_ints.run_tests(''' 00 11 22 aa FF 0a 0d 1a ''') upperword = Word(alphas).set_parse_action(token_map(str.upper)) upperword[1, ...].run_tests(''' my kingdom for a horse ''') wd = Word(alphas).set_parse_action(token_map(str.title)) wd[1, ...].set_parse_action(' '.join).run_tests(''' now is the winter of our discontent made glorious summer by this sun of york ''') prints:: 00 11 22 aa FF 0a 0d 1a [0, 17, 34, 170, 255, 10, 13, 26] my kingdom for a horse ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE'] now is the winter of our discontent made glorious summer by this sun of york ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York'] c"fd|DS)Nc"g|] }|gR Sr9r9)rCtoknrr,s r-rEz)token_map..pa..s+000dT!D!!!000r/r9)rrrrr,s r-rztoken_map..pa~s 00000a0000r/r2r)rr2)r,rrrs`` r- token_maprYsOJ111111j'$ *D*D*MNNIBK Ir/ctjjjD]6\}}t |t r|js||7dS)zy Utility to simplify mass-naming of parser elements, for generating railroad diagram with named subdiagrams. N) r^ _getframef_backf_localsrGrSrrr)rUvars r-autoname_elementsrsg ]__+4::<< c c= ) ) #.  LL   r/z4"(?:[^"\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 quotesuzunicode string literalz#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]c<g|]}t|t|Sr9)rSr)rCrJs r-rErEs7''' *Q ">">''''r/rr^)r$rr~)osrrrrrrrr r r r abcr renumrrr rrr^collections.abcrrtypesoperatorr functoolsr threadingrpathlibrutilrrrrrrrrrrr exceptionsactionsrr r!unicoder"maxsizerrbytesr#rr version_infor&r;rOrjrsrvr]rrr warnoptionsenvironr/sumrBrr+rrrrr.rr r GeneratorTyperrrrrRrrrrascii_uppercaseascii_lowercasealphasLatin1 identcharsidentbodycharsnumshexnumsrr printablerr StackSummaryrrrrrrrrrrrr]rrrrrrrrr0r4rWr{rrrrrrrrrrrrrrrrrrrrrrrfrrrrrrfrArDrrrrlrrmrnrorprqr2 _escapedPunc_escapedHexChar_escapedOctChar _singleChar _charRangerrrrrdbl_quoted_stringsgl_quoted_stringrbunicode_string alphas8bitpunc8bitr>valuesrtokenMapconditionAsParseActionnullDebugActionsglQuotedStringdblQuotedString quotedString unicodeString lineStartlineEnd stringStart stringEndtraceParseActionr9r/r-rs                         $#######  $$$$$$                       ::::::::&&&&&& ;!5\%c )))4v))))))).~,*****$***B$;$4$$$$%K%D%%%%####!?3/?Es?S "ORZ^^$@AA     $ RW l^S ! c< # %& c3 %s *+-  RX l^T !" c< $ &' c3 %t +,. CoyA4GHS#=tCD#sO\48$> c?It Ld RS  &"8 8  % 0 ")8   TM WWPP!1PPP Q Q 04y-4449999z,?,?,?,?,? ,?,?,?^CCCCCmCCC.-"CCCCC CCC( 4m6^'^'^'^'^'m^'^'^'BW!W!W!W!W!/W!W!W!tX=X=X=X=X=X=X=X=vl=l=l=l=l=l=l=l=^dBdBdBdBdB?dBdBdBNZ'Z'Z'Z'Z'-Z'Z'Z'z= = = = = '= = = @;;;;;';;;*;;;;;%;;;B!!!!!$!!!HNNNNN$NNNb'#'#'#'#'#!'#'#'#T(+(+(+(+(+ (+(+(+VK=K=K=K=K=(K=K=K=\-------->--------BF!F!F!F!F! F!F!F!R CCCCC CCCLs's's's's'!s's's'l     (   66666n666r"""""N"""JTBTBTBTBTB>TBTBTBn44444~444n, +, +, , , , ` !! Y[[ ! !, / / 799  j ) ){}}%%n55 Y[[ ! !, / / tG.a888II %/00AA55% %%66))?"_4zz%q7Q7Q7QQ U;#.< = =  GCLL c#hh))* eIIj;. / /00AA&IIJ  "c"c""""J+k++++\G E ABBSH ( -..G E ABBSH ( -.. E ABBSH e CDDsJK ( 788 }1133344==>VWWV: ; ; 6, - -''tvv}}''']# 2###     %r/