1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
3

Y'íc٘ã
@sÐUddlZddlZddlZddlmZddlTddlmZm	Z	m
Z
dSddœeee
feee
feejeejeee
d	œd
d„ZdTddœe
eje
eje
e
d
œdd„Ze
e
dœdd„Ze
e
dœdd„ZdUdddœeejeefeeeeee
dœdd„Ze
e
e
dœdd„ZdVddœe
eee
dœdd „Ze
e
dœd!d"„Ze
e
dœd#d$„Zd%d&deƒfeƒd'œeee
feee
feje
e
e
e
d(œd)d*„Zed+ƒed,ƒfd-d.„Zeee
fee
e
fd/œd0d1„Z eee
fee
e
fd/œd2d3„Z!e
"e
#e e$e%e&d4ƒj'd5ƒƒ\Z"Z#d6d7„ej(j)j*ƒDƒZ+e,d8d9j-e+ƒd:ƒj'd;ƒZ.d<d=„Z/Gd>d?„d?e0ƒZ1ee
eeee
efee
efffZ2eee2ee1eje3fee2ee1ffZ4ed%ƒed&ƒfe
e5e4eee
feee
fe
d@œdAdB„Z6dgfdCdD„Z7e8e,dEƒdFƒj'dGƒZ9e,dHƒj'dIƒZ:e,dJƒj;ƒj'dKƒZ<e,dLƒj'dMƒZ=e8e,dEƒdFe=Bƒj'dNƒZ>e>Z?e,dOƒj'dPƒZ@dQdR„eAƒjBƒDƒZCe5e
CeZDeZEeZFeZGeZHeZIeZJeZKe ZLe!ZMe"e#ZNZOe.ZPe/ZQe1ZRe6ZSe9ZTe:ZUe<ZVe=ZWe>ZXe?ZYe@ZZdS)WéNé)Ú__diag__)Ú*)Ú_bslashÚ_flattenÚ_escape_regex_range_charsú,F)Úallow_trailing_delim)ÚexprÚdelimÚcombineÚminÚmaxr	ÚreturncCsÞt|tƒrtj|ƒ}djt|jƒjƒƒt|ƒ|r>djt|ƒƒndd}|sRt|ƒ}|dk	rr|dkrjt	dƒ‚|d8}|dk	rš|dk	r’||kr’t	dƒ‚|d8}|||||f}|r¾|t
|ƒ7}|rÐt|ƒj|ƒS|j|ƒSdS)	a/Helper to define a delimited list of expressions - the delimiter
    defaults to ','. By default, the list elements and delimiters can
    have intervening whitespace, and comments, but this can be
    overridden by passing ``combine=True`` in the constructor. If
    ``combine`` is set to ``True``, the matching tokens are
    returned as a single token string, with the delimiters included;
    otherwise, the matching tokens are returned as a list of tokens,
    with the delimiters suppressed.

    If ``allow_trailing_delim`` is set to True, then the list may end with
    a delimiter.

    Example::

        delimited_list(Word(alphas)).parse_string("aa,bb,cc") # -> ['aa', 'bb', 'cc']
        delimited_list(Word(hexnums), delim=':', combine=True).parse_string("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
    z{expr} [{delim} {expr}]...{end}z [{}]Ú)r
rÚendNrzmin must be greater than 0z)max must be greater than, or equal to min)
Ú
isinstanceÚstr_typeÚ
ParserElementÚ_literalStringClassÚformatÚstrÚcopyÚ
streamlineÚSuppressÚ
ValueErrorÚOptÚCombineÚset_name)r
rrr
rr	ÚdlNameZdelimited_list_expr©r ú6/tmp/pip-build-gk9425m9/pyparsing/pyparsing/helpers.pyÚdelimited_lists,

r")ÚintExpr)r
Úint_exprr#rcsr|p|}tƒ‰‡‡fdd„}|dkr8ttƒjdd„ƒ}n|jƒ}|jdƒ|j|dd|ˆjd	tˆƒd
ƒS)a~Helper to define a counted list of expressions.

    This helper defines a pattern of the form::

        integer expr expr expr...

    where the leading integer tells how many expr expressions follow.
    The matched tokens returns the array of expr tokens as a list - the
    leading count token is suppressed.

    If ``int_expr`` is specified, it should be a pyparsing expression
    that produces an integer value.

    Example::

        counted_array(Word(alphas)).parse_string('2 ab cd ef')  # -> ['ab', 'cd']

        # in this parser, the leading integer value is given in binary,
        # '10' indicating that 2 values are in the array
        binary_constant = Word('01').set_parse_action(lambda t: int(t[0], 2))
        counted_array(Word(alphas), int_expr=binary_constant).parse_string('10 ab cd ef')  # -> ['ab', 'cd']

        # if other fields must be parsed after the count but before the
        # list items, give the fields results names and they will
        # be preserved in the returned ParseResults:
        count_with_metadata = integer + Word(alphas)("type")
        typed_array = counted_array(Word(alphanums), int_expr=count_with_metadata)("items")
        result = typed_array.parse_string("3 bool True True False")
        print(result.dump())

        # prints
        # ['True', 'True', 'False']
        # - items: ['True', 'True', 'False']
        # - type: 'bool'
    cs,|d}ˆ|rˆ|ntƒK‰|dd…=dS)Nr)ÚEmpty)ÚsÚlÚtÚn)Ú
array_exprr
r r!Úcount_field_parse_actionssz/counted_array.<locals>.count_field_parse_actionNcSst|dƒS)Nr)Úint)r(r r r!Ú<lambda>{szcounted_array.<locals>.<lambda>ÚarrayLenT)Zcall_during_tryz(len) z...)ÚForwardÚWordÚnumsÚset_parse_actionrrÚadd_parse_actionr)r
r$r#r+r )r*r
r!Ú
counted_arrayGs)
r4)r
rcs6tƒ‰‡fdd„}|j|ddˆjdt|ƒƒˆS)a9Helper to define an expression that is indirectly defined from
    the tokens matched in a previous expression, that is, it looks for
    a 'repeat' of a previous expression.  For example::

        first = Word(nums)
        second = match_previous_literal(first)
        match_expr = first + ":" + second

    will match ``"1:1"``, but not ``"1:2"``.  Because this
    matches a previous literal, will also match the leading
    ``"1:1"`` in ``"1:10"``. If this is not desired, use
    :class:`match_previous_expr`. Do *not* use with packrat parsing
    enabled.
    csP|rBt|ƒdkrˆ|d>qLt|jƒƒ}ˆtdd„|Dƒƒ>n
ˆtƒ>dS)Nrrcss|]}t|ƒVqdS)N)ÚLiteral)Ú.0Úttr r r!ú	<genexpr>›szImatch_previous_literal.<locals>.copy_token_to_repeater.<locals>.<genexpr>)ÚlenrÚas_listÚAndr%)r&r'r(Útflat)Úrepr r!Úcopy_token_to_repeater”sz6match_previous_literal.<locals>.copy_token_to_repeaterT)Ú
callDuringTryz(prev) )r/r3rr)r
r>r )r=r!Úmatch_previous_literalƒs
r@csFtƒ‰|jƒ}ˆ|K‰‡fdd„}|j|ddˆjdt|ƒƒˆS)aWHelper to define an expression that is indirectly defined from
    the tokens matched in a previous expression, that is, it looks for
    a 'repeat' of a previous expression.  For example::

        first = Word(nums)
        second = match_previous_expr(first)
        match_expr = first + ":" + second

    will match ``"1:1"``, but not ``"1:2"``.  Because this
    matches by expressions, will *not* match the leading ``"1:1"``
    in ``"1:10"``; the expressions are evaluated first, and then
    compared, so ``"1"`` is compared with ``"10"``. Do *not* use
    with packrat parsing enabled.
    cs*t|jƒƒ‰‡fdd„}ˆj|dddS)Ncs,t|jƒƒ}|ˆkr(t||djˆ|ƒƒ‚dS)NzExpected {}, found{})rr:ÚParseExceptionr)r&r'r(ÚtheseTokens)ÚmatchTokensr r!Úmust_match_these_tokensºszTmatch_previous_expr.<locals>.copy_token_to_repeater.<locals>.must_match_these_tokensT)r?)rr:r2)r&r'r(rD)r=)rCr!r>·sz3match_previous_expr.<locals>.copy_token_to_repeaterT)r?z(prev) )r/rr3rr)r
Úe2r>r )r=r!Úmatch_previous_expr¤srFT)ÚuseRegexÚ	asKeyword)ÚstrsÚcaselessÚ	use_regexÚ
as_keywordrGrHrcsF|p|}|o|}t|tƒr.tjr.tjddd|rPdd„}dd„}|rJtnt‰ndd„}dd„}|rhtnt	‰g}t|tƒr„|j
ƒ}nt|tƒr˜t|ƒ}nt
d	ƒ‚|sªtƒStd
d„|DƒƒrPd}	xŒ|	t|ƒd
krN||	}
xlt||	d
d…ƒD]L\}}|||
ƒr||	|d
=Pqô||
|ƒrô||	|d
=|j|	|ƒPqôW|	d
7}	qÄW|r$|rbtjnd}
y–tdd„|Dƒƒr˜djdjdd„|Dƒƒƒ}ndjdd„|Dƒƒ}|r¼dj|ƒ}t||
djdj|ƒƒ}|rúdd„|Dƒ‰|j‡fdd„ƒ|Stjk
r"tjdddYnXt‡fdd„|Dƒƒjdj|ƒƒS)a Helper to quickly define a set of alternative :class:`Literal` s,
    and makes sure to do longest-first testing when there is a conflict,
    regardless of the input order, but returns
    a :class:`MatchFirst` for best performance.

    Parameters:

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

    Example::

        comp_oper = one_of("< = > <= >= !=")
        var = Word(alphas)
        number = Word(nums)
        term = var | number
        comparison_expr = term + comp_oper + term
        print(comparison_expr.search_string("B = 12  AA=23 B<=AA AA>12"))

    prints::

        [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']]
    z`More than one string argument passed to one_of, pass choices as a list or space-delimited stringé)Ú
stacklevelcSs|jƒ|jƒkS)N)Úupper)ÚaÚbr r r!r-ÿszone_of.<locals>.<lambda>cSs|jƒj|jƒƒS)N)rOÚ
startswith)rPrQr r r!r-scSs||kS)Nr )rPrQr r r!r-scSs
|j|ƒS)N)rR)rPrQr r r!r-sz7Invalid argument to one_of, expected string or iterablecss|]}t|ƒdkVqdS)rN)r9)r6Úsymr r r!r8szone_of.<locals>.<genexpr>rrNcss|]}t|ƒdkVqdS)rN)r9)r6rSr r r!r8&sz[{}]rcss|]}t|ƒVqdS)N)r)r6rSr r r!r8)sú|css|]}tj|ƒVqdS)N)ÚreÚescape)r6rSr r r!r8,sz
\b(?:{})\b)Úflagsz | cSsi|]}||jƒ“qSr )Úlower)r6rSr r r!ú
<dictcomp>7szone_of.<locals>.<dictcomp>csˆ|djƒS)Nr)rX)r&r'r()Ú
symbol_mapr r!r-8sz8Exception creating Regex for one_of, building MatchFirstc3s|]}ˆ|ƒVqdS)Nr )r6rS)ÚparseElementClassr r!r8Bs)rrrZ%warn_on_multiple_string_args_to_oneofÚwarningsÚwarnÚCaselessKeywordÚCaselessLiteralÚKeywordr5ÚsplitÚIterableÚlistÚ	TypeErrorÚNoMatchÚanyr9Ú	enumerateÚinsertrUÚ
IGNORECASEÚallrÚjoinÚRegexrr3ÚerrorÚ
MatchFirst)rIrJrKrLrGrHÚisequalÚmasksÚsymbolsÚiÚcurÚjÚotherZre_flagsÚpattÚretr )r[rZr!Úone_ofÈsl)






rx)ÚkeyÚvaluercCsttt||ƒƒƒS)aøHelper to easily and clearly define a dictionary by specifying
    the respective patterns for the key and value.  Takes care of
    defining the :class:`Dict`, :class:`ZeroOrMore`, and
    :class:`Group` tokens in the proper order.  The key pattern
    can include delimiting markers or punctuation, as long as they are
    suppressed, thereby leaving the significant key text.  The value
    pattern can include named results, so that the :class:`Dict` results
    can include named token fields.

    Example::

        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(attr_expr[1, ...].parse_string(text).dump())

        attr_label = label
        attr_value = Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join)

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

    prints::

        [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
        - color: 'light blue'
        - posn: 'upper left'
        - shape: 'SQUARE'
        - texture: 'burlap'
        SQUARE
        SQUARE
        {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'}
    )ÚDictÚ	OneOrMoreÚGroup)ryrzr r r!Údict_ofGs%r~)ÚasString)r
Ú	as_stringrrcCsr|o|}tƒjdd„ƒ}|jƒ}d|_|dƒ||dƒ}|rHdd„}ndd„}|j|ƒ|j|_|jtjƒ|S)	aHelper to return the original, untokenized text for a given
    expression.  Useful to restore the parsed fields of an HTML start
    tag into the raw tag text itself, or to revert separate tokens with
    intervening whitespace back to the original matching input text. By
    default, returns astring containing the original parsed text.

    If the optional ``as_string`` argument is passed as
    ``False``, then the return value is
    a :class:`ParseResults` containing any results names that
    were originally matched, and a single token containing the original
    matched text from the input string.  So if the expression passed to
    :class:`original_text_for` contains expressions with defined
    results names, you must set ``as_string`` to ``False`` if you
    want to preserve those results name values.

    The ``asString`` pre-PEP8 argument is retained for compatibility,
    but will be removed in a future release.

    Example::

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

    prints::

        ['<b> bold <i>text</i> </b>']
        ['<i>text</i>']
    cSs|S)Nr )r&Úlocr(r r r!r-“sz#original_text_for.<locals>.<lambda>FÚ_original_startÚ
_original_endcSs||j|j…S)N)r‚rƒ)r&r'r(r r r!r-˜scSs&||jdƒ|jdƒ…g|dd…<dS)Nr‚rƒ)Úpop)r&r'r(r r r!ÚextractText›sz&original_text_for.<locals>.extractText)r%r2rÚcallPreparseÚignoreExprsZsuppress_warningZDiagnosticsZ)warn_ungrouped_named_tokens_in_collection)r
r€rÚ	locMarkerÚendlocMarkerÚ	matchExprr…r r r!Úoriginal_text_foros"

r‹cCst|ƒjdd„ƒS)zkHelper to undo pyparsing's default grouping of And expressions,
    even if all but one are non-empty.
    cSs|dS)Nrr )r(r r r!r-¨szungroup.<locals>.<lambda>)ÚTokenConverterr3)r
r r r!Úungroup¤srcCs4tƒjdd„ƒ}t|dƒ|dƒ|jƒjƒdƒƒS)aû
    (DEPRECATED - future code should use the Located class)
    Helper to decorate a returned token with its starting and ending
    locations in the input string.

    This helper adds the following results names:

    - ``locn_start`` - location where matched expression begins
    - ``locn_end`` - location where matched expression ends
    - ``value`` - the actual parsed results

    Be careful if the input text contains ``<TAB>`` characters, you
    may want to call :class:`ParserElement.parseWithTabs`

    Example::

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

    prints::

        [[0, 'ljsdf', 5]]
        [[8, 'lksdjjf', 15]]
        [[18, 'lkkjj', 23]]
    cSs|S)Nr )ÚssZllr7r r r!r-ÆszlocatedExpr.<locals>.<lambda>Ú
locn_startrzÚlocn_end)r%r2r}rÚleaveWhitespace)r
Úlocatorr r r!ÚlocatedExpr«sr“ú(ú))Ú
ignoreExpr)ÚopenerÚcloserÚcontentÚignore_exprr–rcCs¸||kr|tƒkr|n|}||kr*tdƒ‚|dkrDt|tƒoFt|tƒr<t|ƒdkrÀt|ƒdkrÀ|dk	rštt|t||tj	ddƒƒj
dd„ƒ}n$tjƒt||tj	ƒj
dd„ƒ}nz|dk	rtt|t
|ƒt
|ƒttj	ddƒƒj
dd„ƒ}n4ttt
|ƒt
|ƒttj	ddƒƒj
d	d„ƒ}ntd
ƒ‚tƒ}|dk	r~|tt|ƒt||B|Bƒt|ƒƒK}n$|tt|ƒt||Bƒt|ƒƒK}|jd||fƒ|S)a&
Helper method for defining nested lists enclosed in opening and
    closing delimiters (``"("`` and ``")"`` are the default).

    Parameters:
    - ``opener`` - opening character for a nested list
      (default= ``"("``); can also be a pyparsing expression
    - ``closer`` - closing character for a nested list
      (default= ``")"``); can also be a pyparsing expression
    - ``content`` - expression for items within the nested lists
      (default= ``None``)
    - ``ignore_expr`` - expression for ignoring opening and closing delimiters
      (default= :class:`quoted_string`)
    - ``ignoreExpr`` - this pre-PEP8 argument is retained for compatibility
      but will be removed in a future release

    If an expression is not provided for the content argument, the
    nested expression will capture all whitespace-delimited content
    between delimiters as a list of separate values.

    Use the ``ignore_expr`` argument to define expressions that may
    contain opening or closing characters that should not be treated as
    opening or closing characters for nesting, such as quoted_string or
    a comment expression.  Specify multiple expressions using an
    :class:`Or` or :class:`MatchFirst`. The default is
    :class:`quoted_string`, but if no expressions are to be ignored, then
    pass ``None`` for this argument.

    Example::

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

        code_body = nested_expr('{', '}', ignore_expr=(quoted_string | c_style_comment))

        c_function = (decl_data_type("type")
                      + ident("name")
                      + LPAR + Opt(delimited_list(arg), [])("args") + RPAR
                      + code_body("body"))
        c_function.ignore(c_style_comment)

        source_code = '''
            int is_odd(int x) {
                return (x%2);
            }

            int dec_to_hex(char hchar) {
                if (hchar >= '0' && hchar <= '9') {
                    return (ord(hchar)-ord('0'));
                } else {
                    return (10+ord(hchar)-ord('A'));
                }
            }
        '''
        for func in c_function.search_string(source_code):
            print("%(name)s (%(type)s) args: %(args)s" % func)


    prints::

        is_odd (int) args: [['int', 'x']]
        dec_to_hex (int) args: [['char', 'hchar']]
    z.opening and closing strings cannot be the sameNr)ÚexactcSs|djƒS)Nr)Ústrip)r(r r r!r-(sznested_expr.<locals>.<lambda>cSs|djƒS)Nr)rœ)r(r r r!r-,scSs|djƒS)Nr)rœ)r(r r r!r-6scSs|djƒS)Nr)rœ)r(r r r!r->szOopening and closing arguments must be strings if no content expression is givenznested %s%s expression)Ú
quoted_stringrrrr9rr|Ú
CharsNotInrÚDEFAULT_WHITE_CHARSr2Úemptyrr5r/r}rÚ
ZeroOrMorer)r—r˜r™ršr–rwr r r!Únested_exprÎsHJ

,&
&$r¢ú<ú>cs‚t|tƒr|‰t||d}n|j‰tttdƒ}|rŽtjƒj	t
ƒ}||dƒttt
|tdƒ|ƒƒƒtddgddƒj	d	d
„ƒ|}nptjƒj	t
ƒttddB}||dƒttt
|j	d
d
„ƒttdƒ|ƒƒƒƒtddgddƒj	dd
„ƒ|}ttdƒ|ddd}|jdˆƒ|j‡fdd
„ƒ|ddjˆjddƒjƒjƒƒƒjdˆƒ}ˆ|_ˆ|_t|ƒƒ|_||fS)zRInternal helper to construct opening and closing tag expressions, given a tag name)rJz_-:Útagú=ú/F)Údefaultr cSs|ddkS)Nrr§r )r&r'r(r r r!r-^sz_makeTags.<locals>.<lambda>r¤)Z
exclude_charscSs|djƒS)Nr)rX)r(r r r!r-lscSs|ddkS)Nrr§r )r&r'r(r r r!r-rsz</)Úadjacentz<%s>cs*|jddjˆjddƒjƒjƒƒ|jƒƒS)NÚstartrú:ú )Ú__setitem__rkÚreplaceÚtitlerar)r()Úresnamer r!r-{srrr«r¬z</%s>)rrr`Únamer0ÚalphasÚ	alphanumsZdbl_quoted_stringrr2Z
remove_quotesr{r¡r}rrrÚ
printablesrr5rr3rkr®r¯rar¥ÚSkipToZtag_body)ÚtagStrÚxmlZsuppress_LTZsuppress_GTÚtagAttrNameÚtagAttrValueÚopenTagÚcloseTagr )r°r!Ú	_makeTagsNs,
JV 
r¼)Útag_strrcCs
t|dƒS)aPHelper to construct opening and closing tag expressions for HTML,
    given a tag name. Matches tags in either upper or lower case,
    attributes with namespaces and with quoted or unquoted values.

    Example::

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

        for link in link_expr.search_string(text):
            # attributes in the <A> tag (like "href" shown here) are
            # also accessible as named results
            print(link.link_text, '->', link.href)

    prints::

        pyparsing -> https://github.com/pyparsing/pyparsing/wiki
    F)r¼)r½r r r!Úmake_html_tagsˆsr¾cCs
t|dƒS)z½Helper to construct opening and closing tag expressions for XML,
    given a tag name. Matches tags only in the given upper/lower case.

    Example: similar to :class:`make_html_tags`
    T)r¼)r½r r r!Ú
make_xml_tags£sr¿z_:zany tagcCsi|]\}}||jdƒ“qS)ú;)Úrstrip)r6ÚkÚvr r r!rY´srYz&(?P<entity>rTz);zcommon HTML entitycCstj|jƒS)zRHelper parser action to replace common HTML entities with their special characters)Ú_htmlEntityMapÚgetÚentity)r(r r r!Úreplace_html_entityºsrÇc@seZdZdZdZdS)ÚOpAssocrrMN)Ú__name__Ú
__module__Ú__qualname__ÚLEFTÚRIGHTr r r r!rÈ¿srÈ)Ú	base_exprÚop_listÚlparÚrparrcCsFGdd„dtƒ}d|_tƒ}t|tƒr.t|ƒ}t|tƒr@t|ƒ}t|tƒoRt|tƒsj|t|||ƒB}n||||B}x¼t|ƒD]®\}}|ddd…\}	}
}}t|	tƒr¼t	j
|	ƒ}	|
dkrt|	ttfƒsât
|	ƒdkrêtdƒ‚|	\}
}d	j|
|ƒ}n
d
j|	ƒ}d|
kodkns.tdƒ‚|tjtjfkrHtd
ƒ‚tƒj|ƒ}|tjkr|
dkrˆ|||	ƒt||	dƒ}n’|
dkrÜ|	dk	rÂ|||	|ƒt||	|dƒ}n|||ƒt|dƒ}n>|
dkrô|||
|||ƒt|t|
|||ƒƒ}nØ|tjkrô|
dkrbt|	tƒsFt|	ƒ}	||	j|ƒt|	|ƒ}n’|
dkrº|	dk	rœ|||	|ƒt||	|dƒ}n|||ƒt||dƒ}n:|
dkrô|||
|||ƒt||
|||ƒ}|r t|ttfƒr|j|Žn
|j|ƒ|||Bj|ƒK}|}q†W||K}|S)aJHelper method for constructing grammars of expressions made up of
    operators working in a precedence hierarchy.  Operators may be unary
    or binary, left- or right-associative.  Parse actions can also be
    attached to operator expressions. The generated parser will also
    recognize the use of parentheses to override operator precedences
    (see example below).

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

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

      - ``op_expr`` is the pyparsing expression for the operator; may also
        be a string, which will be converted to a Literal; if ``num_operands``
        is 3, ``op_expr`` is a tuple of two expressions, for the two
        operators separating the 3 terms
      - ``num_operands`` is the number of terms for this operator (must be 1,
        2, or 3)
      - ``right_left_assoc`` is the indicator whether the operator is right
        or left associative, using the pyparsing-defined constants
        ``OpAssoc.RIGHT`` and ``OpAssoc.LEFT``.
      - ``parse_action`` is the parse action to be associated with
        expressions matching this operator expression (the parse action
        tuple member may be omitted); if the parse action is passed
        a tuple or list of functions, this is equivalent to calling
        ``set_parse_action(*fn)``
        (:class:`ParserElement.set_parse_action`)
    - ``lpar`` - expression for matching left-parentheses; if passed as a
      str, then will be parsed as Suppress(lpar). If lpar is passed as
      an expression (such as ``Literal('(')``), then it will be kept in
      the parsed results, and grouped with them. (default= ``Suppress('(')``)
    - ``rpar`` - expression for matching right-parentheses; if passed as a
      str, then will be parsed as Suppress(rpar). If rpar is passed as
      an expression (such as ``Literal(')')``), then it will be kept in
      the parsed results, and grouped with them. (default= ``Suppress(')')``)

    Example::

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

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

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

    prints::

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

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

        -2--11
        [[['-', 2], '-', ['-', 11]]]
    c@seZdZddd„ZdS)zinfix_notation.<locals>._FBTcSs|jj||ƒ|gfS)N)r
Z	try_parse)ÚselfÚinstringrÚ	doActionsr r r!Ú	parseImpl(sz%infix_notation.<locals>._FB.parseImplN)T)rÉrÊrËrÕr r r r!Ú_FB'srÖzFollowedBy>NéérMz@if numterms=3, opExpr must be a tuple or list of two expressionsz	{}{} termz{} termrz6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity.)N)r.)r.)rM.)r.)r.)Ú
FollowedByrÉr/rrrr}rgrrrÚtuplercr9rrrÈrÌrÍrr|rr
r2ÚsetName)rÎrÏrÐrÑrÖrwÚlastExprrrÚoperDefÚopExprÚarityÚrightLeftAssocÚpaÚopExpr1ÚopExpr2Z	term_nameÚthisExprrŠr r r!Úinfix_notationÖszQ









 




råcs0ˆjˆdd…ƒ‡‡fdd„‰‡fdd„}‡fdd„}‡fdd	„}ttƒjd
ƒjƒƒ}tƒtƒj|ƒjdƒ}tƒj|ƒjdƒ}	tƒj|ƒjd
ƒ}
|rÆtt	|ƒ|t|	t|ƒt	|ƒƒ|
ƒ}n,tt	|ƒt|	t|ƒt	|ƒƒt	|
ƒƒ}|j
‡fdd„ƒ|j‡fdd„ƒ|jt
tƒƒ|jdƒS)a‘	
    (DEPRECATED - use IndentedBlock class instead)
    Helper method for defining space-delimited indentation blocks,
    such as those used to define block statements in Python source code.

    Parameters:

    - ``blockStatementExpr`` - expression defining syntax of statement that
      is repeated within the indented block
    - ``indentStack`` - list created by caller to manage indentation stack
      (multiple ``statementWithIndentedBlock`` expressions within a single
      grammar should share a common ``indentStack``)
    - ``indent`` - boolean indicating whether block must be indented beyond
      the current level; set to ``False`` for block of left-most statements
      (default= ``True``)

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

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

    Example::

        data = '''
        def A(z):
          A1
          B = 100
          G = A2
          A2
          A3
        B
        def BB(a,b,c):
          BB1
          def BBA():
            bba1
            bba2
            bba3
        C
        D
        def spam(x,y):
             def eggs(z):
                 pass
        '''


        indentStack = [1]
        stmt = Forward()

        identifier = Word(alphas, alphanums)
        funcDecl = ("def" + identifier + Group("(" + Opt(delimitedList(identifier)) + ")") + ":")
        func_body = indentedBlock(stmt, indentStack)
        funcDef = Group(funcDecl + func_body)

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

        module_body = stmt[1, ...]

        parseTree = module_body.parseString(data)
        parseTree.pprint()

    prints::

        [['def',
          'A',
          ['(', 'z', ')'],
          ':',
          [['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]],
         'B',
         ['def',
          'BB',
          ['(', 'a', 'b', 'c', ')'],
          ':',
          [['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]],
         'C',
         'D',
         ['def',
          'spam',
          ['(', 'x', 'y', ')'],
          ':',
          [[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]]
    Ncsˆdˆdd…<dS)Nréÿÿÿÿr r )Ú
backup_stacksÚindentStackr r!Úreset_stackÓsz"indentedBlock.<locals>.reset_stackcsN|t|ƒkrdSt||ƒ}|ˆdkrJ|ˆdkr>t||dƒ‚t||dƒ‚dS)Nrzillegal nestingznot a peer entryræræ)r9ÚcolrA)r&r'r(ÚcurCol)rèr r!ÚcheckPeerIndentÖs
z&indentedBlock.<locals>.checkPeerIndentcs2t||ƒ}|ˆdkr"ˆj|ƒnt||dƒ‚dS)Nrznot a subentryræ)rêÚappendrA)r&r'r(rë)rèr r!ÚcheckSubIndentßs
z%indentedBlock.<locals>.checkSubIndentcsJ|t|ƒkrdSt||ƒ}ˆo$|ˆks2t||dƒ‚|ˆdkrFˆjƒdS)Nznot an unindentrræ)r9rêrAr„)r&r'r(rë)rèr r!Ú
checkUnindentæs
z$indentedBlock.<locals>.checkUnindentz	 ÚINDENTrÚUNINDENTcsˆrˆjdƒodSdS)Nrræ)r„r )rçr r!r-szindentedBlock.<locals>.<lambda>csˆƒS)Nr )rPrQÚcÚd)rér r!r-szindented block)rír|ÚLineEndZset_whitespace_charsÚsuppressr%r2rr}rr3Zset_fail_actionÚignorer)ÚblockStatementExprrèÚindentrçrìrîrïÚNLrðÚPEERÚUNDENTÚsmExprr )rçrèrér!Ú
indentedBlock{s&V		,*rýz/\*(?:[^*]|\*(?!/))*z*/zC style commentz<!--[\s\S]*?-->zHTML commentz.*zrest of linez//(?:\\\n|[^\n])*z
// commentzC++ style commentz#.*zPython style commentcCsg|]}t|tƒr|‘qSr )rr)r6rÃr r r!ú
<listcomp>&srþ)rFNN)N)FTF)T)[Ú
html.entitiesÚhtmlrUÚtypingrrÚcoreÚutilrrrÚUnionrrÚboolÚOptionalr,r"r4r@rFrbrxr~r‹rr“rr¢rr¼ÚTupler¾r¿Zany_open_tagZ
any_close_tagr0r²r³rÚentitiesÚhtml5ÚitemsrÄrlrkZcommon_html_entityrÇÚEnumrÈZInfixNotationOperatorArgTypeZParseActionZInfixNotationOperatorSpecÚListrårýrZc_style_commentZhtml_commentZleave_whitespaceZrest_of_lineZdbl_slash_commentZcpp_style_commentZjava_style_commentZpython_style_commentÚvarsÚvaluesZ_builtin_exprsÚ
delimitedListÚcountedArrayÚmatchPreviousLiteralÚmatchPreviousExprÚoneOfÚdictOfÚoriginalTextForÚ
nestedExprÚmakeHTMLTagsÚmakeXMLTagsÚ
anyOpenTagÚanyCloseTagÚcommonHTMLEntityÚreplaceHTMLEntityÚopAssocÚ
infixNotationÚ
cStyleCommentÚhtmlCommentÚ
restOfLineÚdblSlashCommentÚcppStyleCommentÚjavaStyleCommentÚpythonStyleCommentr r r r!Ú<module>sÆ.37!& w)3$(y;

	$$!