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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
U
G=®dwŠãi@sÖ dZdZdZdZddlZddlmZddlZddl    Z    ddl
Z
ddl Z ddl Z ddl Z ddlZddlZddlZddlmZzddlmZWn ek
r¨ddlmZYnXzdd    lmZdd
lmZWn,ek
ròdd    l mZdd
l mZYnXzdd l mZWnBek
rFzdd lmZWnek
r@dZYnXYnXd d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtgiZee    jƒddu…ZeddukZ e rpe    j!Z"e#Z$e%Z&e#Z'e(e)e*e+e,ee-e.e/e0e1g Z2n`e    j3Z"e4Z5dvdw„Z'gZ2ddl6Z6dx 7¡D]8Z8ze2 9e:e6e8ƒ¡Wne;k
rÊYq–YnXq–e<dydz„e5d{ƒDƒƒZ=d|d}„Z>Gd~d„de?ƒZ@ejAejBZCd€ZDeDdZEeCeDZFe%d‚ƒZGdƒ Hd„dz„ejIDƒ¡ZJGd…d#„d#eKƒZLGd†d%„d%eLƒZMGd‡d'„d'eLƒZNGdˆd)„d)eNƒZOGd‰d,„d,eKƒZPGdŠd‹„d‹e?ƒZQGdŒd(„d(e?ƒZRe SeR¡dd?„ZTdŽdP„ZUddM„ZVdd‘„ZWd’d“„ZXd”d•„ZYd–dW„ZZd/d˜d™„Z[Gdšd*„d*e?ƒZ\Gd›d2„d2e\ƒZ]Gdœd„de]ƒZ^Gdd„de]ƒZ_Gdžd„de]ƒZ`e`Zae`e\_bGdŸd„de]ƒZcGd d„de`ƒZdGd¡d „d ecƒZeGd¢dr„dre]ƒZfGd£d5„d5e]ƒZgGd¤d-„d-e]ƒZhGd¥d+„d+e]ƒZiGd¦d„de]ƒZjGd§d4„d4e]ƒZkGd¨d©„d©e]ƒZlGdªd„delƒZmGd«d„delƒZnGd¬d„delƒZoGd­d0„d0elƒZpGd®d/„d/elƒZqGd¯d7„d7elƒZrGd°d6„d6elƒZsGd±d&„d&e\ƒZtGd²d „d etƒZuGd³d"„d"etƒZvGd´d„detƒZwGdµd„detƒZxGd¶d$„d$e\ƒZyGd·d„deyƒZzGd¸d„deyƒZ{Gd¹dº„dºeyƒZ|Gd»d„de|ƒZ}Gd¼d8„d8e|ƒZ~Gd½d¾„d¾e?ƒZeƒZ€Gd¿d!„d!eyƒZGdÀd.„d.eyƒZ‚GdÁd„deyƒZƒGdÂdÄdÃeƒƒZ„GdÄd3„d3eyƒZ…GdÅd„de…ƒZ†GdÆd„de…ƒZ‡GdÇd„de…ƒZˆGdÈd1„d1e…ƒZ‰GdÉd „d e?ƒZŠdÊdh„Z‹d0dÍdF„ZŒd1dÎdB„ZdÏdЄZŽdÑdU„ZdÒdT„ZdÓdԄZ‘d2dÖdY„Z’d×dG„Z“d3dØdm„Z”dÙdn„Z•dÚdp„Z–e^ƒ —dI¡Z˜enƒ —dO¡Z™eoƒ —dN¡Zšepƒ —dg¡Z›eqƒ —df¡ZœegeGdÛd—d܍ dÝdބ¡Zžehd߃ dàdބ¡ZŸehdრdâdބ¡Z ežeŸBe Bejdãd{d܍BZ¡e‡e¡e‰däƒe¡ƒZ¢e`dåƒed惠£dç¡e‡e}e¢e¡Bƒƒ £dè¡déZ¤dêde„Z¥dëdS„Z¦dìdb„Z§díd`„Z¨dîds„Z©e©dïdބƒZªe©dðdބƒZ«dñdò„Z¬dódQ„Z­dôdR„Z®dõdk„Z¯e?ƒe¯_°d4dödq„Z±e@ƒZ²e?ƒe²_³e?ƒe²_´e‰d÷ƒe‰døƒfdùdo„ZµeµZ¶e†ehdúƒdûƒ —dü¡Z·e†ehdýƒdþƒ —dÿ¡Z¸e†ehdúƒdûehdýƒdþBƒ —d¡Z¹e†eadƒe¹ ¡ƒ —d¡Zºd÷døde¹ ¡fddV„Z»d5ddl„Z¼e¥dƒZ½e¥dƒZ¾e­egeCeFdƒ —d¡ƒ\Z¿ZÀeÁed     7¡d
ƒƒZÃehd d  Heàġ¡d ƒ —d¡ZŐdda„ZÆe†ehdƒdƒ —d¡ZÇehdƒ —d¡ZÈehdƒ É¡ —d¡ZÊehdƒ —d¡ZËe†ehdƒdeËBƒ —d¡ZÌeÌZÍehdƒ —d¡ZÎe†e}egeJdːdeegdƒe`d˃eoƒƒƒƒ Ï¡ —d¡ZÐeŒee¹ ¡eÐBdƒdƒ —d@¡ZÑGd dt„dtƒZÒeӐd!k rÒedd"ƒZÔedd#ƒZÕegeCeFd$ƒZÖeŒe֐d%dՐd& eª¡Z×e‡eŒe׃ƒ —d'¡Zؐd(eØBZÙeŒe֐d%dՐd& eª¡ZÚe‡eŒeڃƒ —d)¡ZÛeԐd*ƒeِd'ƒeÕeېd)ƒZÜeܠݐd+¡eÒjޠݐd,¡eÒjߠݐd,¡eÒjà Ýd-¡ddláZáeÒj᠝e©eáj⃡eÒjá Ýd.¡dS(6aÜ    
pyparsing module - Classes and methods to define and execute parsing grammars
=============================================================================
 
The pyparsing module is an alternative approach to creating and executing simple grammars,
vs. the traditional lex/yacc approach, or the use of regular expressions.  With pyparsing, you
don't need to learn a new syntax for defining grammars or matching expressions - the parsing module
provides a library of classes that you use to construct the grammar directly in Python.
 
Here is a program to parse "Hello, World!" (or any greeting of the form 
C{"<salutation>, <addressee>!"}), built up using L{Word}, L{Literal}, and L{And} elements 
(L{'+'<ParserElement.__add__>} operator gives L{And} expressions, strings are auto-converted to
L{Literal} expressions)::
 
    from pyparsing import Word, alphas
 
    # define grammar of a greeting
    greet = Word(alphas) + "," + Word(alphas) + "!"
 
    hello = "Hello, World!"
    print (hello, "->", greet.parseString(hello))
 
The program outputs the following::
 
    Hello, World! -> ['Hello', ',', 'World', '!']
 
The Python representation of the grammar is quite readable, owing to the self-explanatory
class names, and the use of '+', '|' and '^' operators.
 
The L{ParseResults} object returned from L{ParserElement.parseString<ParserElement.parseString>} can be accessed as a nested list, a dictionary, or an
object with named attributes.
 
The pyparsing module handles some of the problems that are typically vexing when writing text parsers:
 - extra or missing whitespace (the above program will also handle "Hello,World!", "Hello  ,  World  !", etc.)
 - quoted strings
 - embedded comments
 
 
Getting Started -
-----------------
Visit the classes L{ParserElement} and L{ParseResults} to see the base classes that most other pyparsing
classes inherit from. Use the docstrings for examples of how to:
 - construct literal match expressions from L{Literal} and L{CaselessLiteral} classes
 - construct character word-group expressions using the L{Word} class
 - see how to create repetitive expressions using L{ZeroOrMore} and L{OneOrMore} classes
 - use L{'+'<And>}, L{'|'<MatchFirst>}, L{'^'<Or>}, and L{'&'<Each>} operators to combine simple expressions into more complex ones
 - associate names with your parsed results using L{ParserElement.setResultsName}
 - find some helpful expression short-cuts like L{delimitedList} and L{oneOf}
 - find more useful common expressions in the L{pyparsing_common} namespace class
z2.2.1z18 Sep 2018 00:49 UTCz*Paul McGuire <ptmcg@users.sourceforge.net>éN)Úref)Údatetime)ÚRLock)ÚIterable)ÚMutableMapping)Ú OrderedDictÚAndÚCaselessKeywordÚCaselessLiteralÚ
CharsNotInÚCombineÚDictÚEachÚEmptyÚ
FollowedByÚForwardÚ
GoToColumnÚGroupÚKeywordÚLineEndÚ    LineStartÚLiteralÚ
MatchFirstÚNoMatchÚNotAnyÚ    OneOrMoreÚOnlyOnceÚOptionalÚOrÚParseBaseExceptionÚParseElementEnhanceÚParseExceptionÚParseExpressionÚParseFatalExceptionÚ ParseResultsÚParseSyntaxExceptionÚ ParserElementÚ QuotedStringÚRecursiveGrammarExceptionÚRegexÚSkipToÚ    StringEndÚ StringStartÚSuppressÚTokenÚTokenConverterÚWhiteÚWordÚWordEndÚ    WordStartÚ
ZeroOrMoreÚ    alphanumsÚalphasÚ
alphas8bitÚ anyCloseTagÚ
anyOpenTagÚ cStyleCommentÚcolÚcommaSeparatedListÚcommonHTMLEntityÚ countedArrayÚcppStyleCommentÚdblQuotedStringÚdblSlashCommentÚ delimitedListÚdictOfÚdowncaseTokensÚemptyÚhexnumsÚ htmlCommentÚjavaStyleCommentÚlineÚlineEndÚ    lineStartÚlinenoÚ makeHTMLTagsÚ makeXMLTagsÚmatchOnlyAtColÚmatchPreviousExprÚmatchPreviousLiteralÚ
nestedExprÚnullDebugActionÚnumsÚoneOfÚopAssocÚoperatorPrecedenceÚ
printablesÚpunc8bitÚpythonStyleCommentÚ quotedStringÚ removeQuotesÚreplaceHTMLEntityÚ replaceWithÚ
restOfLineÚsglQuotedStringÚsrangeÚ    stringEndÚ stringStartÚtraceParseActionÚ unicodeStringÚ upcaseTokensÚ withAttributeÚ indentedBlockÚoriginalTextForÚungroupÚ infixNotationÚ locatedExprÚ    withClassÚ
CloseMatchÚtokenMapÚpyparsing_commonécCsft|tƒr|Sz
t|ƒWStk
r`t|ƒ t ¡d¡}tdƒ}| dd„¡|     |¡YSXdS)aDrop-in replacement for str(obj) that tries to be Unicode friendly. It first tries
           str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It
           then < returns the unicode object | encodes it with the default encoding | ... >.
        Úxmlcharrefreplacez&#\d+;cSs$dtt|ddd…ƒƒdd…S)Nz\urééÿÿÿÿ)ÚhexÚint©Út©ryúVD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pkg_resources/_vendor/pyparsing.pyÚ<lambda>«óz_ustr.<locals>.<lambda>N)
Ú
isinstanceÚunicodeÚstrÚUnicodeEncodeErrorÚencodeÚsysÚgetdefaultencodingr)ÚsetParseActionÚtransformString)ÚobjÚretZ
xmlcharrefryryrzÚ_ustršs
 
rˆz6sum len sorted reversed list tuple set any all min maxccs|]
}|VqdS©Nry)Ú.0ÚyryryrzÚ    <genexpr>·srŒécCs:d}dd„d ¡Dƒ}t||ƒD]\}}| ||¡}q |S)z/Escape &, <, >, ", ', etc. in a string of data.z&><"'css|]}d|dVqdS)ú&ú;Nry)rŠÚsryryrzrŒ¾sz_xml_escape.<locals>.<genexpr>zamp gt lt quot apos)ÚsplitÚzipÚreplace)ÚdataÚ from_symbolsÚ
to_symbolsÚfrom_Úto_ryryrzÚ _xml_escape¹s
r™c@s eZdZdS)Ú
_ConstantsN)Ú__name__Ú
__module__Ú __qualname__ryryryrzršÃsršÚ
0123456789Z ABCDEFabcdefé\Úccs|]}|tjkr|VqdSr‰)ÚstringÚ
whitespace©rŠÚcryryrzrŒËs
c@sPeZdZdZddd„Zedd„ƒZdd    „Zd
d „Zd d „Z    ddd„Z
dd„Z dS)rz7base exception class for all parsing runtime exceptionsrNcCs>||_|dkr||_d|_n ||_||_||_|||f|_dS©Nr )ÚlocÚmsgÚpstrÚ parserElementÚargs)Úselfr¨r¦r§ÚelemryryrzÚ__init__ÑszParseBaseException.__init__cCs||j|j|j|jƒS)z­
        internal factory method to simplify creating one type of ParseException 
        from another - avoids having __init__ signature conflicts among subclasses
        )r¨r¦r§r©)ÚclsÚperyryrzÚ_from_exceptionÜsz"ParseBaseException._from_exceptioncCsN|dkrt|j|jƒS|dkr,t|j|jƒS|dkrBt|j|jƒSt|ƒ‚dS)z÷supported attributes by name are:
            - lineno - returns the line number of the exception text
            - col - returns the column number of the exception text
            - line - returns the line containing the exception text
        rL)r;ÚcolumnrIN)rLr¦r¨r;rIÚAttributeError)r«ÚanameryryrzÚ __getattr__äszParseBaseException.__getattr__cCsd|j|j|j|jfS)Nz"%s (at char %d), (line:%d, col:%d))r§r¦rLr±©r«ryryrzÚ__str__ósÿzParseBaseException.__str__cCst|ƒSr‰©rˆrµryryrzÚ__repr__öszParseBaseException.__repr__ú>!<cCs<|j}|jd}|r4d |d|…|||d…f¡}| ¡S)z…Extracts the exception line from the input string, and marks
           the location of the exception with a special symbol.
        rr N)rIr±ÚjoinÚstrip)r«Ú markerStringÚline_strÚ line_columnryryrzÚ markInputlineøs
 
ÿz ParseBaseException.markInputlinecCsd ¡tt|ƒƒS)Nzlineno col line)r‘ÚdirÚtyperµryryrzÚ__dir__szParseBaseException.__dir__)rNN)r¹) r›rœrÚ__doc__r­Ú classmethodr°r´r¶r¸r¿rÂryryryrzrÍs
 
 
 
c@seZdZdZdS)r!aN
    Exception thrown when parse expressions don't match class;
    supported attributes by name are:
     - lineno - returns the line number of the exception text
     - col - returns the column number of the exception text
     - line - returns the line containing the exception text
        
    Example::
        try:
            Word(nums).setName("integer").parseString("ABC")
        except ParseException as pe:
            print(pe)
            print("column: {}".format(pe.col))
            
    prints::
       Expected integer (at char 0), (line:1, col:1)
        column: 1
    N©r›rœrrÃryryryrzr!sc@seZdZdZdS)r#znuser-throwable exception thrown when inconsistent parse content
       is found; stops all parsing immediatelyNrÅryryryrzr#sc@seZdZdZdS)r%zßjust like L{ParseFatalException}, but thrown internally when an
       L{ErrorStop<And._ErrorStop>} ('-' operator) indicates that parsing is to stop 
       immediately because an unbacktrackable syntax error has been foundNrÅryryryrzr%sc@s eZdZdZdd„Zdd„ZdS)r(zZexception thrown by L{ParserElement.validate} if the grammar could be improperly recursivecCs
||_dSr‰©ÚparseElementTrace©r«ÚparseElementListryryrzr­4sz"RecursiveGrammarException.__init__cCs
d|jS)NzRecursiveGrammarException: %srÆrµryryrzr¶7sz!RecursiveGrammarException.__str__N)r›rœrrÃr­r¶ryryryrzr(2sc@s,eZdZdd„Zdd„Zdd„Zdd„Zd    S)
Ú_ParseResultsWithOffsetcCs||f|_dSr‰©Útup)r«Úp1Úp2ryryrzr­;sz _ParseResultsWithOffset.__init__cCs
|j|Sr‰rË©r«ÚiryryrzÚ __getitem__=sz#_ParseResultsWithOffset.__getitem__cCst|jdƒS©Nr)ÚreprrÌrµryryrzr¸?sz _ParseResultsWithOffset.__repr__cCs|jd|f|_dSrÒrËrÏryryrzÚ    setOffsetAsz!_ParseResultsWithOffset.setOffsetN)r›rœrr­rÑr¸rÔryryryrzrÊ:srÊc@sœeZdZdZd[dd„Zddddefdd„Zdd    „Zefd
d „Zd d „Z    dd„Z
dd„Z dd„Z e Z dd„Zdd„Zdd„Zdd„Zdd„ZerœeZeZeZn$eZeZeZdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd\d(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Z d2d3„Z!d4d5„Z"d6d7„Z#d8d9„Z$d:d;„Z%d<d=„Z&d]d?d@„Z'dAdB„Z(dCdD„Z)dEdF„Z*d^dHdI„Z+dJdK„Z,dLdM„Z-d_dOdP„Z.dQdR„Z/dSdT„Z0dUdV„Z1dWdX„Z2dYdZ„Z3dS)`r$aI
    Structured parse results, to provide multiple means of access to the parsed data:
       - as a list (C{len(results)})
       - by list index (C{results[0], results[1]}, etc.)
       - by attribute (C{results.<resultsName>} - see L{ParserElement.setResultsName})
 
    Example::
        integer = Word(nums)
        date_str = (integer.setResultsName("year") + '/' 
                        + integer.setResultsName("month") + '/' 
                        + integer.setResultsName("day"))
        # equivalent form:
        # date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
 
        # parseString returns a ParseResults object
        result = date_str.parseString("1999/12/31")
 
        def test(s, fn=repr):
            print("%s -> %s" % (s, fn(eval(s))))
        test("list(result)")
        test("result[0]")
        test("result['month']")
        test("result.day")
        test("'month' in result")
        test("'minutes' in result")
        test("result.dump()", str)
    prints::
        list(result) -> ['1999', '/', '12', '/', '31']
        result[0] -> '1999'
        result['month'] -> '12'
        result.day -> '31'
        'month' in result -> True
        'minutes' in result -> False
        result.dump() -> ['1999', '/', '12', '/', '31']
        - day: 31
        - month: 12
        - year: 1999
    NTcCs"t||ƒr|St |¡}d|_|S©NT)r}ÚobjectÚ__new__Ú_ParseResults__doinit)r®ÚtoklistÚnameÚasListÚmodalÚretobjryryrzr×ks
 
 
zParseResults.__new__c
Csb|jrvd|_d|_d|_i|_||_||_|dkr6g}||tƒrP|dd…|_n||tƒrft|ƒ|_n|g|_t    ƒ|_
|dk    r^|r^|s”d|j|<||t ƒr¦t |ƒ}||_||t dƒttfƒrÐ|ddgfks^||tƒrà|g}|r(||tƒrt| ¡dƒ||<ntt|dƒdƒ||<|||_n6z|d||<Wn$tttfk
r\|||<YnXdS)NFrr )rØÚ_ParseResults__nameÚ_ParseResults__parentÚ_ParseResults__accumNamesÚ_ParseResults__asListÚ_ParseResults__modalÚlistÚ_ParseResults__toklistÚ_generatorTypeÚdictÚ_ParseResults__tokdictrvrˆrÁÚ
basestringr$rÊÚcopyÚKeyErrorÚ    TypeErrorÚ
IndexError)r«rÙrÚrÛrÜr}ryryrzr­tsB
 
 
 
$
  zParseResults.__init__cCsPt|ttfƒr|j|S||jkr4|j|ddStdd„|j|DƒƒSdS)NrtrcSsg|] }|d‘qS©rry©rŠÚvryryrzÚ
<listcomp>¢sz,ParseResults.__getitem__.<locals>.<listcomp>)r}rvÚsliceräràrçr$rÏryryrzrћs
 
 
zParseResults.__getitem__cCsŒ||tƒr0|j |tƒ¡|g|j|<|d}nD||ttfƒrN||j|<|}n&|j |tƒ¡t|dƒg|j|<|}||tƒrˆt|ƒ|_    dSrÒ)
rÊrçÚgetrãrvrñrär$Úwkrefrß)r«Úkrïr}ÚsubryryrzÚ __setitem__¤s
 
 
"
zParseResults.__setitem__c
Csºt|ttfƒr®t|jƒ}|j|=t|tƒrH|dkr:||7}t||dƒ}tt| |¡Žƒ}| ¡|j     
¡D]>\}}|D]0}t |ƒD]"\}\}}    t ||    |    |kƒ||<q„qxqln|j    |=dS©Nrr) r}rvrñÚlenrärãÚrangeÚindicesÚreverserçÚitemsÚ    enumeraterÊ)
r«rÐÚmylenÚremovedrÚÚ occurrencesÚjrôÚvalueÚpositionryryrzÚ __delitem__±s
 
zParseResults.__delitem__cCs
||jkSr‰)rç)r«rôryryrzÚ __contains__ÆszParseResults.__contains__cCs
t|jƒSr‰)rørärµryryrzÚ__len__Ér|zParseResults.__len__cCs
|j Sr‰©rärµryryrzÚ__bool__Êr|zParseResults.__bool__cCs
t|jƒSr‰©ÚiterrärµryryrzÚ__iter__Ìr|zParseResults.__iter__cCst|jddd…ƒS©Nrtr    rµryryrzÚ __reversed__Ír|zParseResults.__reversed__cCs$t|jdƒr|j ¡St|jƒSdS)NÚiterkeys)Úhasattrrçrr
rµryryrzÚ    _iterkeysÎs 
zParseResults._iterkeyscs‡fdd„ˆ ¡DƒS)Nc3s|]}ˆ|VqdSr‰ry©rŠrôrµryrzrŒÕsz+ParseResults._itervalues.<locals>.<genexpr>©rrµryrµrzÚ _itervaluesÔszParseResults._itervaluescs‡fdd„ˆ ¡DƒS)Nc3s|]}|ˆ|fVqdSr‰ryrrµryrzrŒØsz*ParseResults._iteritems.<locals>.<genexpr>rrµryrµrzÚ
_iteritems×szParseResults._iteritemscCs t| ¡ƒS)zVReturns all named result keys (as a list in Python 2.x, as an iterator in Python 3.x).)rãrrµryryrzÚkeysîszParseResults.keyscCs t| ¡ƒS)zXReturns all named result values (as a list in Python 2.x, as an iterator in Python 3.x).)rãÚ
itervaluesrµryryrzÚvaluesòszParseResults.valuescCs t| ¡ƒS)zfReturns all named result key-values (as a list of tuples in Python 2.x, as an iterator in Python 3.x).)rãÚ    iteritemsrµryryrzrüöszParseResults.itemscCs
t|jƒS)zSince keys() returns an iterator, this method is helpful in bypassing
           code that looks for the existence of any defined results names.)ÚboolrçrµryryrzÚhaskeysúszParseResults.haskeyscOsŽ|s
dg}| ¡D]*\}}|dkr0|d|f}qtd|ƒ‚qt|dtƒsdt|ƒdksd|d|kr~|d}||}||=|S|d}|SdS)a¹
        Removes and returns item at specified index (default=C{last}).
        Supports both C{list} and C{dict} semantics for C{pop()}. If passed no
        argument or an integer argument, it will use C{list} semantics
        and pop tokens from the list of parsed tokens. If passed a 
        non-integer argument (most likely a string), it will use C{dict}
        semantics and pop the corresponding value from any defined 
        results names. A second default return value argument is 
        supported, just as in C{dict.pop()}.
 
        Example::
            def remove_first(tokens):
                tokens.pop(0)
            print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
            print(OneOrMore(Word(nums)).addParseAction(remove_first).parseString("0 123 321")) # -> ['123', '321']
 
            label = Word(alphas)
            patt = label("LABEL") + OneOrMore(Word(nums))
            print(patt.parseString("AAB 123 321").dump())
 
            # Use pop() in a parse action to remove named result (note that corresponding value is not
            # removed from list form of results)
            def remove_LABEL(tokens):
                tokens.pop("LABEL")
                return tokens
            patt.addParseAction(remove_LABEL)
            print(patt.parseString("AAB 123 321").dump())
        prints::
            ['AAB', '123', '321']
            - LABEL: AAB
 
            ['AAB', '123', '321']
        rtÚdefaultrz-pop() got an unexpected keyword argument '%s'rN)rürër}rvrø)r«rªÚkwargsrôrïÚindexr‡Ú defaultvalueryryrzÚpopÿs""
ÿ
þzParseResults.popcCs||kr||S|SdS)ai
        Returns named result matching the given key, or if there is no
        such name, then returns the given C{defaultValue} or C{None} if no
        C{defaultValue} is specified.
 
        Similar to C{dict.get()}.
        
        Example::
            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")           
 
            result = date_str.parseString("1999/12/31")
            print(result.get("year")) # -> '1999'
            print(result.get("hour", "not specified")) # -> 'not specified'
            print(result.get("hour")) # -> None
        Nry)r«ÚkeyÚ defaultValueryryrzrò3szParseResults.getcCsR|j ||¡|j ¡D]4\}}t|ƒD]"\}\}}t||||kƒ||<q(qdS)a
        Inserts new element at location index in the list of parsed tokens.
        
        Similar to C{list.insert()}.
 
        Example::
            print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
 
            # use a parse action to insert the parse location in the front of the parsed results
            def insert_locn(locn, tokens):
                tokens.insert(0, locn)
            print(OneOrMore(Word(nums)).addParseAction(insert_locn).parseString("0 123 321")) # -> [0, '0', '123', '321']
        N)räÚinsertrçrürýrÊ)r«rÚinsStrrÚrrôrrryryrzr"IszParseResults.insertcCs|j |¡dS)aþ
        Add single element to end of ParseResults list of elements.
 
        Example::
            print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321']
            
            # use a parse action to compute the sum of the parsed integers, and add it to the end
            def append_sum(tokens):
                tokens.append(sum(map(int, tokens)))
            print(OneOrMore(Word(nums)).addParseAction(append_sum).parseString("0 123 321")) # -> ['0', '123', '321', 444]
        N)räÚappend)r«Úitemryryrzr$]s zParseResults.appendcCs$t|tƒr||7}n |j |¡dS)a
        Add sequence of elements to end of ParseResults list of elements.
 
        Example::
            patt = OneOrMore(Word(alphas))
            
            # use a parse action to append the reverse of the matched strings, to make a palindrome
            def make_palindrome(tokens):
                tokens.extend(reversed([t[::-1] for t in tokens]))
                return ''.join(tokens)
            print(patt.addParseAction(make_palindrome).parseString("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl'
        N)r}r$räÚextend)r«Úitemseqryryrzr&ks
 
zParseResults.extendcCs|jdd…=|j ¡dS)z7
        Clear all elements and results names.
        N)rärçÚclearrµryryrzr(}s zParseResults.clearcCsjz
||WStk
r YdSX||jkrb||jkrH|j|ddStdd„|j|DƒƒSndSdS)Nr rtrcSsg|] }|d‘qSríryrîryryrzrðŽsz,ParseResults.__getattr__.<locals>.<listcomp>)rêrçràr$©r«rÚryryrzr´„s
 
 
zParseResults.__getattr__cCs| ¡}||7}|Sr‰©ré)r«Úotherr‡ryryrzÚ__add__’szParseResults.__add__csŒ|jrjt|jƒ‰‡fdd„‰|j ¡}‡fdd„|Dƒ}|D],\}}|||<t|dtƒr<t|ƒ|d_q<|j|j7_|j     |j¡|S)Ncs|dkr ˆS|ˆSrÒry)Úa)Úoffsetryrzr{šr|z'ParseResults.__iadd__.<locals>.<lambda>c    s4g|],\}}|D]}|t|dˆ|dƒƒf‘qqS©rr)rÊ©rŠrôÚvlistrï)Ú    addoffsetryrzrðœsÿz)ParseResults.__iadd__.<locals>.<listcomp>r)
rçrørärür}r$rórßràÚupdate)r«r+Ú
otheritemsÚotherdictitemsrôrïry)r2r.rzÚ__iadd__—s
 
 
ÿ zParseResults.__iadd__cCs&t|tƒr|dkr| ¡S||SdSrÒ)r}rvré©r«r+ryryrzÚ__radd__§szParseResults.__radd__cCsdt|jƒt|jƒfS)Nz(%s, %s))rÓrärçrµryryrzr¸¯szParseResults.__repr__cCsdd dd„|jDƒ¡dS)Nú[ú, css(|] }t|tƒrt|ƒnt|ƒVqdSr‰)r}r$rˆrÓ©rŠrÐryryrzrŒ³sz'ParseResults.__str__.<locals>.<genexpr>ú])rºrärµryryrzr¶²szParseResults.__str__r cCsLg}|jD]<}|r |r | |¡t|tƒr8|| ¡7}q
| t|ƒ¡q
|Sr‰)rär$r}r$Ú _asStringListrˆ)r«ÚsepÚoutr%ryryrzr=µs
 
 
zParseResults._asStringListcCsdd„|jDƒS)aƒ
        Returns the parse results as a nested list of matching tokens, all converted to strings.
 
        Example::
            patt = OneOrMore(Word(alphas))
            result = patt.parseString("sldkj lsdkj sldkj")
            # even though the result prints in string-like form, it is actually a pyparsing ParseResults
            print(type(result), result) # -> <class 'pyparsing.ParseResults'> ['sldkj', 'lsdkj', 'sldkj']
            
            # Use asList() to create an actual list
            result_list = result.asList()
            print(type(result_list), result_list) # -> <class 'list'> ['sldkj', 'lsdkj', 'sldkj']
        cSs"g|]}t|tƒr| ¡n|‘qSry)r}r$rÛ)rŠÚresryryrzrðÎsz'ParseResults.asList.<locals>.<listcomp>rrµryryrzrÛÀszParseResults.asListcs6tr |j}n|j}‡fdd„‰t‡fdd„|ƒDƒƒS)aÃ
        Returns the named parse results as a nested dictionary.
 
        Example::
            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
            
            result = date_str.parseString('12/31/1999')
            print(type(result), repr(result)) # -> <class 'pyparsing.ParseResults'> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]})
            
            result_dict = result.asDict()
            print(type(result_dict), repr(result_dict)) # -> <class 'dict'> {'day': '1999', 'year': '12', 'month': '31'}
 
            # even though a ParseResults supports dict-like access, sometime you just need to have a dict
            import json
            print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable
            print(json.dumps(result.asDict())) # -> {"month": "31", "day": "1999", "year": "12"}
        cs6t|tƒr.| ¡r| ¡S‡fdd„|DƒSn|SdS)Ncsg|] }ˆ|ƒ‘qSryryrî©ÚtoItemryrzrðísz7ParseResults.asDict.<locals>.toItem.<locals>.<listcomp>)r}r$rÚasDict)r†rAryrzrBès
 
z#ParseResults.asDict.<locals>.toItemc3s|]\}}|ˆ|ƒfVqdSr‰ry©rŠrôrïrAryrzrŒñsz&ParseResults.asDict.<locals>.<genexpr>)ÚPY_3rürræ)r«Úitem_fnryrArzrCÐs
     zParseResults.asDictcCs8t|jƒ}|j ¡|_|j|_|j |j¡|j|_|S)zA
        Returns a new copy of a C{ParseResults} object.
        )r$rärçrérßràr3rÞ©r«r‡ryryrzréós 
 zParseResults.copyFc CsLd}g}tdd„|j ¡Dƒƒ}|d}|s8d}d}d}d}    |dk    rJ|}    n |jrV|j}    |    sf|rbdSd}    |||d|    d    g7}t|jƒD]¬\}
} t| tƒrà|
|krÀ||  ||
|o²|dk||¡g7}n||  d|oÒ|dk||¡g7}q‚d} |
|krô||
} | s|rq‚nd} t    t
| ƒƒ} |||d| d    | d
| d    g    7}q‚|||d
|    d    g7}d  |¡S) z‡
        (Deprecated) Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.
        Ú
css(|] \}}|D]}|d|fVqqdS©rNryr0ryryrzrŒsÿz%ParseResults.asXML.<locals>.<genexpr>ú  r NÚITEMú<ú>ú</) rærçrürÞrýrär}r$ÚasXMLr™rˆrº)r«ÚdoctagÚnamedItemsOnlyÚindentÚ    formattedÚnlr?Ú
namedItemsÚnextLevelIndentÚselfTagrÐr@ÚresTagÚ xmlBodyTextryryrzrOþs^
 
ý
 
ý
  þzParseResults.asXMLcCs:|j ¡D]*\}}|D]\}}||kr|Sqq
dSr‰)rçrü)r«rõrôr1rïr¦ryryrzÚ__lookup;s
 zParseResults.__lookupcCs€|jr |jS|jr.| ¡}|r(| |¡SdSnNt|ƒdkrxt|jƒdkrxtt|j ¡ƒƒdddkrxtt|j ¡ƒƒSdSdS)a(
        Returns the results name for this token expression. Useful when several 
        different expressions might match at a particular location.
 
        Example::
            integer = Word(nums)
            ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d")
            house_number_expr = Suppress('#') + Word(nums, alphanums)
            user_data = (Group(house_number_expr)("house_number") 
                        | Group(ssn_expr)("ssn")
                        | Group(integer)("age"))
            user_info = OneOrMore(user_data)
            
            result = user_info.parseString("22 111-22-3333 #221B")
            for item in result:
                print(item.getName(), ':', item[0])
        prints::
            age : 22
            ssn : 111-22-3333
            house_number : 221B
        Nrr)rrt)    rÞrßÚ_ParseResults__lookuprørçÚnextr
rr)r«ÚparryryrzÚgetNameBs
  ÿþzParseResults.getNamerc CsZg}d}| |t| ¡ƒ¡|rP| ¡r¼tdd„| ¡Dƒƒ}|D]r\}}|r\| |¡| d|d||f¡t|tƒrª|rš| | ||d¡¡q¸| t|ƒ¡qF| t    |ƒ¡qFn”t
dd„|DƒƒrP|}t |ƒD]r\}    }
t|
tƒr$| d|d||    |d|d|
 ||d¡f¡qÜ| d|d||    |d|dt|
ƒf¡qÜd      |¡S)
aH
        Diagnostic method for listing out the contents of a C{ParseResults}.
        Accepts an optional C{indent} argument so that this string can be embedded
        in a nested display of other data.
 
        Example::
            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
            
            result = date_str.parseString('12/31/1999')
            print(result.dump())
        prints::
            ['12', '/', '31', '/', '1999']
            - day: 1999
            - month: 31
            - year: 12
        rHcss|]\}}t|ƒ|fVqdSr‰)rrDryryrzrŒ~sz$ParseResults.dump.<locals>.<genexpr>z
%s%s- %s: rJrcss|]}t|tƒVqdSr‰)r}r$)rŠÚvvryryrzrŒŠsz
%s%s[%d]:
%s%s%sr ) r$rˆrÛrÚsortedrür}r$ÚdumprÓÚanyrýrº) r«rRÚdepthÚfullr?ÚNLrürôrïrÐr_ryryrzrags, 
 
 4,zParseResults.dumpcOstj| ¡f|ž|ŽdS)aõ
        Pretty-printer for parsed results as a list, using the C{pprint} module.
        Accepts additional positional or keyword args as defined for the 
        C{pprint.pprint} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pprint})
 
        Example::
            ident = Word(alphas, alphanums)
            num = Word(nums)
            func = Forward()
            term = ident | num | Group('(' + func + ')')
            func <<= ident + Group(Optional(delimitedList(term)))
            result = func.parseString("fna a,b,(fnb c,d,200),100")
            result.pprint(width=40)
        prints::
            ['fna',
             ['a',
              'b',
              ['(', 'fnb', ['c', 'd', '200'], ')'],
              '100']]
        N)ÚpprintrÛ©r«rªrryryrzrf”szParseResults.pprintcCs.|j|j ¡|jdk    r| ¡p d|j|jffSr‰)rärçrérßràrÞrµryryrzÚ __getstate__¬sýÿzParseResults.__getstate__cCsN|d|_|d\|_}}|_i|_|j |¡|dk    rDt|ƒ|_nd|_dSr÷)rärçrÞràr3rórß)r«Ústater]Ú inAccumNamesryryrzÚ __setstate__³s
ý  zParseResults.__setstate__cCs|j|j|j|jfSr‰)rärÞrárârµryryrzÚ__getnewargs__ÀszParseResults.__getnewargs__cCstt|ƒƒt| ¡ƒSr‰)rÀrÁrãrrµryryrzrÂÃszParseResults.__dir__)NNTT)N)r )NFr T)r rT)4r›rœrrÃr×r}r­rÑrörrrrÚ __nonzero__r r rrrrErrrürrrrrròr"r$r&r(r´r,r6r8r¸r¶r=rÛrCrérOr[r^rarfrhrkrlrÂryryryrzr$Dsh&
    '     4
 
#
=%
- cCsF|}d|krt|ƒkr4nn||ddkr4dS|| dd|¡S)aReturns current column within a string, counting newlines as line separators.
   The first column is number 1.
 
   Note: the default parsing behavior is to expand tabs in the input string
   before starting the parsing process.  See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
   on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
   consistent view of the parsed string, the parse location, and line and column
   positions within the parsed string.
   rrrH)røÚrfind)r¦Ústrgrryryrzr;Ès
cCs| dd|¡dS)aReturns current line number within a string, counting newlines as line separators.
   The first line is number 1.
 
   Note: the default parsing behavior is to expand tabs in the input string
   before starting the parsing process.  See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
   on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
   consistent view of the parsed string, the parse location, and line and column
   positions within the parsed string.
   rHrr)Úcount)r¦roryryrzrLÕs
cCsF| dd|¡}| d|¡}|dkr2||d|…S||dd…SdS)zfReturns the line of text containing loc within a string, counting newlines as line separators.
       rHrrN)rnÚfind)r¦roÚlastCRÚnextCRryryrzrIás
 cCs8tdt|ƒdt|ƒdt||ƒt||ƒfƒdS)NzMatch z at loc z(%d,%d))ÚprintrˆrLr;)Úinstringr¦ÚexprryryrzÚ_defaultStartDebugActionësrwcCs$tdt|ƒdt| ¡ƒƒdS)NzMatched z -> )rtrˆrrÛ)ruÚstartlocÚendlocrvÚtoksryryrzÚ_defaultSuccessDebugActionîsr{cCstdt|ƒƒdS)NzException raised:)rtrˆ)rur¦rvÚexcryryrzÚ_defaultExceptionDebugActionñsr}cGsdS)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nry)rªryryrzrSôsrscs҈tkr‡fdd„Sdg‰dg‰tdd…dkrFddd„}dd    d
„‰n tj}tj‰d }|dd d }|d|d|f‰‡‡‡‡‡‡fdd„}d}ztˆdtˆdƒjƒ}Wntk
rÆtˆƒ}YnX||_|S)Ncsˆ|ƒSr‰ry©rÚlrx)Úfuncryrzr{r|z_trim_arity.<locals>.<lambda>rFrs)rqécSs8tdkr dnd}tj| |dd|}|dd…gS)N)rqrréýÿÿÿéþÿÿÿr©Úlimitrs)Úsystem_versionÚ    tracebackÚ extract_stack)r…r.Ú frame_summaryryryrzrˆsz"_trim_arity.<locals>.extract_stackcSs$tj||d}|d}|dd…gS)Nr„rtrs)r‡Ú
extract_tb)Útbr…Úframesr‰ryryrzrŠsz_trim_arity.<locals>.extract_tbér„rtrc    s z"ˆ|ˆdd…Ž}dˆd<|WStk
r˜ˆdr>‚n4z.t ¡d}ˆ|ddddd…ˆksj‚W5~Xˆdˆkr’ˆdd7<Yq‚YqXqdS)NrTrtrsr„r)rër‚Úexc_info)rªr‡r‹©rŠÚ
foundArityr€r…ÚmaxargsÚpa_call_line_synthryrzÚwrapper-s   z_trim_arity.<locals>.wrapperz<parse action>r›Ú    __class__)r)r)    ÚsingleArgBuiltinsr†r‡rˆrŠÚgetattrr›Ú    Exceptionr)r€r‘rˆÚ    LINE_DIFFÚ    this_liner“Ú    func_nameryrrzÚ _trim_aritys, 
 
ÿr›cs’eZdZdZdZdZedd„ƒZedd„ƒZd†dd    „Z    d
d „Z
d d „Z d‡dd„Z dˆdd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd‰dd „Zd!d"„ZdŠd#d$„Zd%d&„Zd'd(„ZGd)d*„d*eƒZed+k    ràGd,d-„d-eƒZnGd.d-„d-eƒZiZeƒZd/d/gZ d‹d0d1„Z!eZ"ed2d3„ƒZ#dZ$edŒd5d6„ƒZ%dd7d8„Z&e'dfd9d:„Z(d;d<„Z)e'fd=d>„Z*e'dfd?d@„Z+dAdB„Z,dCdD„Z-dEdF„Z.dGdH„Z/dIdJ„Z0dKdL„Z1dMdN„Z2dOdP„Z3dQdR„Z4dSdT„Z5dUdV„Z6dWdX„Z7dYdZ„Z8dŽd[d\„Z9d]d^„Z:d_d`„Z;dadb„Z<dcdd„Z=dedf„Z>dgdh„Z?ddidj„Z@dkdl„ZAdmdn„ZBdodp„ZCdqdr„ZDgfdsdt„ZEddudv„ZF‡fdwdx„ZGdydz„ZHd{d|„ZId}d~„ZJdd€„ZKd‘dd‚„ZLd’d„d…„ZM‡ZNS)“r&z)Abstract base level parser element class.z 
     FcCs
|t_dS)aÑ
        Overrides the default whitespace chars
 
        Example::
            # default whitespace chars are space, <TAB> and newline
            OneOrMore(Word(alphas)).parseString("abc def\nghi jkl")  # -> ['abc', 'def', 'ghi', 'jkl']
            
            # change to just treat newline as significant
            ParserElement.setDefaultWhitespaceChars(" \t")
            OneOrMore(Word(alphas)).parseString("abc def\nghi jkl")  # -> ['abc', 'def']
        N)r&ÚDEFAULT_WHITE_CHARS©ÚcharsryryrzÚsetDefaultWhitespaceCharsTs z'ParserElement.setDefaultWhitespaceCharscCs
|t_dS)a…
        Set class to be used for inclusion of string literals into a parser.
        
        Example::
            # default literal class used is Literal
            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")           
 
            date_str.parseString("1999/12/31")  # -> ['1999', '/', '12', '/', '31']
 
 
            # change to Suppress
            ParserElement.inlineLiteralsUsing(Suppress)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")           
 
            date_str.parseString("1999/12/31")  # -> ['1999', '12', '31']
        N)r&Ú_literalStringClass)r®ryryrzÚinlineLiteralsUsingcsz!ParserElement.inlineLiteralsUsingcCs‚tƒ|_d|_d|_d|_||_d|_tj|_    d|_
d|_ d|_ tƒ|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_dS)NTFr )NNN)rãÚ parseActionÚ
failActionÚstrReprÚ resultsNameÚ
saveAsListÚskipWhitespacer&rœÚ
whiteCharsÚcopyDefaultWhiteCharsÚmayReturnEmptyÚkeepTabsÚ ignoreExprsÚdebugÚ streamlinedÚ mayIndexErrorÚerrmsgÚ modalResultsÚ debugActionsÚreÚ callPreparseÚ callDuringTry)r«Úsavelistryryrzr­xs(zParserElement.__init__cCs<t |¡}|jdd…|_|jdd…|_|jr8tj|_|S)a$
        Make a copy of this C{ParserElement}.  Useful for defining different parse actions
        for the same parsing pattern, using copies of the original parse element.
        
        Example::
            integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
            integerK = integer.copy().addParseAction(lambda toks: toks[0]*1024) + Suppress("K")
            integerM = integer.copy().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M")
            
            print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M"))
        prints::
            [5120, 100, 655360, 268435456]
        Equivalent form of C{expr.copy()} is just C{expr()}::
            integerM = integer().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M")
        N)rér¢r¬r©r&rœr¨)r«Úcpyryryrzrés 
zParserElement.copycCs*||_d|j|_t|dƒr&|j|j_|S)af
        Define name for this expression, makes debugging and exception messages clearer.
        
        Example::
            Word(nums).parseString("ABC")  # -> Exception: Expected W:(0123...) (at char 0), (line:1, col:1)
            Word(nums).setName("integer").parseString("ABC")  # -> Exception: Expected integer (at char 0), (line:1, col:1)
        ú    Expected Ú    exception)rÚr°rr¹r§r)ryryrzÚsetName¦s
 
 
zParserElement.setNamecCs4| ¡}| d¡r"|dd…}d}||_| |_|S)aP
        Define name for referencing matching tokens as a nested attribute
        of the returned parse results.
        NOTE: this returns a *copy* of the original C{ParserElement} object;
        this is so that the client can define a basic element, such as an
        integer, and reference it in multiple places with different names.
 
        You can also set results names using the abbreviated syntax,
        C{expr("name")} in place of C{expr.setResultsName("name")} - 
        see L{I{__call__}<__call__>}.
 
        Example::
            date_str = (integer.setResultsName("year") + '/' 
                        + integer.setResultsName("month") + '/' 
                        + integer.setResultsName("day"))
 
            # equivalent form:
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")
        Ú*NrtT)réÚendswithr¥r±)r«rÚÚlistAllMatchesÚnewselfryryrzÚsetResultsName´s
 zParserElement.setResultsNameTcs@|r&|j‰d‡fdd„    }ˆ|_||_nt|jdƒr<|jj|_|S)z¦Method to invoke the Python pdb debugger when this element is
           about to be parsed. Set C{breakFlag} to True to enable, False to
           disable.
        Tcsddl}| ¡ˆ||||ƒSrÒ)ÚpdbÚ    set_trace)rur¦Ú    doActionsÚ callPreParserÀ©Ú _parseMethodryrzÚbreaker×sz'ParserElement.setBreak.<locals>.breakerÚ_originalParseMethod)TT)Ú_parserÇr)r«Ú    breakFlagrÆryrÄrzÚsetBreakÐs 
zParserElement.setBreakcOs&tttt|ƒƒƒ|_| dd¡|_|S)a
        Define one or more actions to perform when successfully matching parse element definition.
        Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)},
        C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where:
         - s   = the original string being parsed (see note below)
         - loc = the location of the matching substring
         - toks = a list of the matched tokens, packaged as a C{L{ParseResults}} object
        If the functions in fns modify the tokens, they can return them as the return
        value from fn, and the modified list of tokens will replace the original.
        Otherwise, fn does not need to return any value.
 
        Optional keyword arguments:
         - callDuringTry = (default=C{False}) indicate if parse action should be run during lookaheads and alternate testing
 
        Note: the default parsing behavior is to expand tabs in the input string
        before starting the parsing process.  See L{I{parseString}<parseString>} for more information
        on parsing strings containing C{<TAB>}s, and suggested methods to maintain a
        consistent view of the parsed string, the parse location, and line and column
        positions within the parsed string.
        
        Example::
            integer = Word(nums)
            date_str = integer + '/' + integer + '/' + integer
 
            date_str.parseString("1999/12/31")  # -> ['1999', '/', '12', '/', '31']
 
            # use parse action to convert to ints at parse time
            integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
            date_str = integer + '/' + integer + '/' + integer
 
            # note that integer fields are now ints, not strings
            date_str.parseString("1999/12/31")  # -> [1999, '/', 12, '/', 31]
        rµF)rãÚmapr›r¢ròrµ©r«Úfnsrryryrzr„âs"zParserElement.setParseActioncOs4|jtttt|ƒƒƒ7_|jp,| dd¡|_|S)z³
        Add one or more parse actions to expression's list of parse actions. See L{I{setParseAction}<setParseAction>}.
        
        See examples in L{I{copy}<copy>}.
        rµF)r¢rãrËr›rµròrÌryryrzÚaddParseActionszParserElement.addParseActioncs^| dd¡‰| dd¡rtnt‰|D] ‰‡‡‡fdd„}|j |¡q$|jpV| dd¡|_|S)aÓAdd a boolean predicate function to expression's list of parse actions. See 
        L{I{setParseAction}<setParseAction>} for function call signatures. Unlike C{setParseAction}, 
        functions passed to C{addCondition} need to return boolean success/fail of the condition.
 
        Optional keyword arguments:
         - message = define a custom message to be used in the raised exception
         - fatal   = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException
         
        Example::
            integer = Word(nums).setParseAction(lambda toks: int(toks[0]))
            year_int = integer.copy()
            year_int.addCondition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later")
            date_str = year_int + '/' + integer + '/' + integer
 
            result = date_str.parseString("1999/12/31")  # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1)
        Úmessagezfailed user-defined conditionÚfatalFcs$ttˆƒ|||ƒƒs ˆ||ˆƒ‚dSr‰)rr›r~©Úexc_typeÚfnr§ryrzÚpa&sz&ParserElement.addCondition.<locals>.parµ)ròr#r!r¢r$rµ)r«rÍrrÔryrÑrzÚ addConditions zParserElement.addConditioncCs
||_|S)a Define action to perform if parsing fails at this expression.
           Fail acton fn is a callable function that takes the arguments
           C{fn(s,loc,expr,err)} where:
            - s = string being parsed
            - loc = location where expression match was attempted and failed
            - expr = the parse expression that failed
            - err = the exception thrown
           The function returns no value.  It may throw C{L{ParseFatalException}}
           if it is desired to stop parsing immediately.)r£)r«rÓryryrzÚ setFailAction-s
zParserElement.setFailActionc    CsNd}|rJd}|jD]4}z| ||¡\}}d}qWqtk
rDYqXqq|S©NTF)r¬rÈr!)r«rur¦Ú
exprsFoundÚeÚdummyryryrzÚ_skipIgnorables:s
 
 
zParserElement._skipIgnorablescCsH|jr| ||¡}|jrD|j}t|ƒ}||krD|||krD|d7}q&|S©Nr)r¬rÛr§r¨rø)r«rur¦ÚwtÚinstrlenryryrzÚpreParseGs 
zParserElement.preParsecCs|gfSr‰ry©r«rur¦rÂryryrzÚ    parseImplSszParserElement.parseImplcCs|Sr‰ry©r«rur¦Ú    tokenlistryryrzÚ    postParseVszParserElement.postParsec
CsÎ|j}|s|jrì|jdr,|jd|||ƒ|rD|jrD| ||¡}n|}|}zDz| |||¡\}}Wn(tk
rŒt|t|ƒ|j    |ƒ‚YnXWnXt
k
rè}    z:|jdrÀ|jd||||    ƒ|jrÖ| ||||    ¡‚W5d}    ~    XYnXn|r|jr| ||¡}n|}|}|j s&|t|ƒkrjz| |||¡\}}Wn*tk
rft|t|ƒ|j    |ƒ‚YnXn| |||¡\}}|  |||¡}t ||j|j|jd}
|jrž|s¶|jrž|rTzN|jD]B} | |||
ƒ}|dk    rÄt ||j|joút|t tfƒ|jd}
qÄWnFt
k
rP}    z&|jdr>|jd||||    ƒ‚W5d}    ~    XYnXnJ|jD]B} | |||
ƒ}|dk    rZt ||j|jot|t tfƒ|jd}
qZ|rÆ|jdrÆ|jd|||||
ƒ||
fS)Nrrs)rÛrÜr)r­r£r²r´rßrárìr!rør°rr¯rär$r¥r¦r±r¢rµr}rã) r«rur¦rÂrÃÚ    debuggingÚprelocÚ tokensStartÚtokensÚerrÚ    retTokensrÓryryrzÚ _parseNoCacheZst
 
 
 
 
 
ý 
 
ý
 zParserElement._parseNoCachecCs@z|j||dddWStk
r:t|||j|ƒ‚YnXdS)NF)rÂr)rÈr#r!r°©r«rur¦ryryrzÚtryParse¡szParserElement.tryParsec    Cs4z| ||¡Wnttfk
r*YdSXdSdS)NFT)rír!rìrìryryrzÚ canParseNext§s
zParserElement.canParseNextc@seZdZdd„ZdS)zParserElement._UnboundedCachecs~i‰tƒ|_‰‡‡fdd„}‡fdd„}‡fdd„}‡fdd„}t ||¡|_t ||¡|_t ||¡|_t ||¡|_dS)    Ncs ˆ |ˆ¡Sr‰©rò©r«r ©ÚcacheÚ not_in_cacheryrzrò´sz3ParserElement._UnboundedCache.__init__.<locals>.getcs |ˆ|<dSr‰ry©r«r r©ròryrzÚset·sz3ParserElement._UnboundedCache.__init__.<locals>.setcs ˆ ¡dSr‰©r(rµrõryrzr(ºsz5ParserElement._UnboundedCache.__init__.<locals>.clearcstˆƒSr‰©rørµrõryrzÚ    cache_len½sz9ParserElement._UnboundedCache.__init__.<locals>.cache_len)rÖróÚtypesÚ
MethodTyperòrör(r)r«ròrör(rùryrñrzr­°s    z&ParserElement._UnboundedCache.__init__N©r›rœrr­ryryryrzÚ_UnboundedCache¯srýNc@seZdZdd„ZdS)úParserElement._FifoCachecs‚tƒ|_‰tƒ‰‡‡fdd„}‡‡fdd„}‡fdd„}‡fdd„}t ||¡|_t ||¡|_t ||¡|_t ||¡|_dS)    Ncs ˆ |ˆ¡Sr‰rïrðrñryrzròÌsú.ParserElement._FifoCache.__init__.<locals>.getcs>|ˆ|<tˆƒˆkr:zˆ d¡Wqtk
r6YqXqdS©NF)røÚpopitemrêrô)ròÚsizeryrzröÏs  ú.ParserElement._FifoCache.__init__.<locals>.setcs ˆ ¡dSr‰r÷rµrõryrzr(×sú0ParserElement._FifoCache.__init__.<locals>.clearcstˆƒSr‰rørµrõryrzrùÚsú4ParserElement._FifoCache.__init__.<locals>.cache_len)    rÖróÚ _OrderedDictrúrûròrör(r©r«rròrör(rùry)ròrórrzr­Çs   ú!ParserElement._FifoCache.__init__NrüryryryrzÚ
_FifoCacheÆsr    c@seZdZdd„ZdS)rþcstƒ|_‰i‰t gˆ¡‰‡‡fdd„}‡‡‡fdd„}‡‡fdd„}‡fdd„}t ||¡|_t ||¡|_t ||¡|_t ||¡|_    dS)    Ncs ˆ |ˆ¡Sr‰rïrðrñryrzròêsrÿcs4|ˆ|<tˆƒˆkr&ˆ ˆ ¡d¡qˆ |¡dSr‰)rørÚpopleftr$rô)ròÚkey_fiforryrzröís rcsˆ ¡ˆ ¡dSr‰r÷rµ)ròr ryrzr(ósrcstˆƒSr‰rørµrõryrzrù÷sr)
rÖróÚ collectionsÚdequerúrûròrör(rrry)ròr rórrzr­äs   rNrüryryryrzr    ãsrc Csd\}}|||||f}tjîtj}| |¡}    |    |jkrÆtj|d7<z| ||||¡}    Wn8tk
r–}
z| ||
j    |
j
Ž¡‚W5d}
~
XYn.X| ||    d|    d  ¡f¡|    W5QR£Sn@tj|d7<t |    t ƒræ|    ‚|    d|    d  ¡fW5QR£SW5QRXdS)Nr/rr)r&Úpackrat_cache_lockÚ packrat_cacheròróÚpackrat_cache_statsrërrör”rªrér}r—) r«rur¦rÂrÃÚHITÚMISSÚlookupròrr¯ryryrzÚ _parseCaches$
 
 
zParserElement._parseCachecCs(tj ¡dgttjƒtjdd…<dSrÒ)r&rr(rørryryryrzÚ
resetCaches
zParserElement.resetCacheé€cCs8tjs4dt_|dkr t ¡t_n t |¡t_tjt_dS)a–Enables "packrat" parsing, which adds memoizing to the parsing logic.
           Repeated parse attempts at the same string location (which happens
           often in many complex grammars) can immediately return a cached value,
           instead of re-executing parsing/validating code.  Memoizing is done of
           both valid results and parsing exceptions.
           
           Parameters:
            - cache_size_limit - (default=C{128}) - if an integer value is provided
              will limit the size of the packrat cache; if None is passed, then
              the cache size will be unbounded; if 0 is passed, the cache will
              be effectively disabled.
            
           This speedup may break existing programs that use parse actions that
           have side-effects.  For this reason, packrat parsing is disabled when
           you first import pyparsing.  To activate the packrat feature, your
           program must call the class method C{ParserElement.enablePackrat()}.  If
           your program uses C{psyco} to "compile as you go", you must call
           C{enablePackrat} before calling C{psyco.full()}.  If you do not do this,
           Python will crash.  For best results, call C{enablePackrat()} immediately
           after importing pyparsing.
           
           Example::
               import pyparsing
               pyparsing.ParserElement.enablePackrat()
        TN)r&Ú_packratEnabledrýrr    rrÈ)Úcache_size_limitryryrzÚ enablePackrat%s   zParserElement.enablePackratc
Cs®t ¡|js| ¡|jD] }| ¡q|js8| ¡}z<| |d¡\}}|rr| ||¡}t    ƒt
ƒ}| ||¡Wn0t k
r¤}ztj r‚n|‚W5d}~XYnX|SdS)aB
        Execute the parse expression with the given string.
        This is the main interface to the client code, once the complete
        expression has been built.
 
        If you want the grammar to require that the entire input string be
        successfully parsed, then set C{parseAll} to True (equivalent to ending
        the grammar with C{L{StringEnd()}}).
 
        Note: C{parseString} implicitly calls C{expandtabs()} on the input string,
        in order to report proper column numbers in parse actions.
        If the input string contains tabs and
        the grammar uses parse actions that use the C{loc} argument to index into the
        string being parsed, you can ensure you have a consistent view of the input
        string by:
         - calling C{parseWithTabs} on your grammar before calling C{parseString}
           (see L{I{parseWithTabs}<parseWithTabs>})
         - define your parse action using the full C{(s,loc,toks)} signature, and
           reference the input string using the parse action's C{s} argument
         - explictly expand the tabs in your input string before calling
           C{parseString}
        
        Example::
            Word('a').parseString('aaaaabaaa')  # -> ['aaaaa']
            Word('a').parseString('aaaaabaaa', parseAll=True)  # -> Exception: Expected end of text
        rN) r&rr®Ú
streamliner¬r«Ú
expandtabsrÈrßrr+rÚverbose_stacktrace)r«ruÚparseAllrÙr¦rèÚser|ryryrzÚ parseStringHs$
 
  zParserElement.parseStringc
cs6|js| ¡|jD] }| ¡q|js4t|ƒ ¡}t|ƒ}d}|j}|j}t     
¡d}    z¤||krú|    |krúz |||ƒ}
|||
dd\} } Wnt k
r¦|
d}YqZX| |krð|    d7}    | |
| fV|rê|||ƒ} | |krà| }qî|d7}qø| }qZ|
d}qZWn4t k
r0}zt    j r‚n|‚W5d}~XYnXdS)a†
        Scan the input string for expression matches.  Each match will return the
        matching tokens, start location, and end location.  May be called with optional
        C{maxMatches} argument, to clip scanning after 'n' matches are found.  If
        C{overlap} is specified, then overlapping matches will be reported.
 
        Note that the start and end locations are reported relative to the string
        being parsed.  See L{I{parseString}<parseString>} for more information on parsing
        strings with embedded tabs.
 
        Example::
            source = "sldjf123lsdjjkf345sldkjf879lkjsfd987"
            print(source)
            for tokens,start,end in Word(alphas).scanString(source):
                print(' '*start + '^'*(end-start))
                print(' '*start + tokens[0])
        
        prints::
        
            sldjf123lsdjjkf345sldkjf879lkjsfd987
            ^^^^^
            sldjf
                    ^^^^^^^
                    lsdjjkf
                              ^^^^^^
                              sldkjf
                                       ^^^^^^
                                       lkjsfd
        rF©rÃrN)r®rr¬r«rˆrrørßrÈr&rr!rr)r«ruÚ
maxMatchesÚoverlaprÙrÞr¦Ú
preparseFnÚparseFnÚmatchesræÚnextLocrèÚnextlocr|ryryrzÚ
scanStringzsB
 
 
 
 
zParserElement.scanStringc
Csàg}d}d|_zœ| |¡D]Z\}}}| |||…¡|rpt|tƒrR|| ¡7}nt|tƒrf||7}n
| |¡|}q| ||d…¡dd„|Dƒ}d tt    t
|ƒƒ¡WSt k
rÚ}zt j rƂn|‚W5d}~XYnXdS)af
        Extension to C{L{scanString}}, to modify matching text with modified tokens that may
        be returned from a parse action.  To use C{transformString}, define a grammar and
        attach a parse action to it that modifies the returned token list.
        Invoking C{transformString()} on a target string will then scan for matches,
        and replace the matched text patterns according to the logic in the parse
        action.  C{transformString()} returns the resulting transformed string.
        
        Example::
            wd = Word(alphas)
            wd.setParseAction(lambda toks: toks[0].title())
            
            print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york."))
        Prints::
            Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York.
        rTNcSsg|] }|r|‘qSryry)rŠÚoryryrzrðãsz1ParserElement.transformString.<locals>.<listcomp>r )r«r(r$r}r$rÛrãrºrËrˆÚ_flattenrr&r)r«rur?ÚlastErxrrÙr|ryryrzr…Ás(
 
 
 
zParserElement.transformStringc
CsRztdd„| ||¡DƒƒWStk
rL}ztjr8‚n|‚W5d}~XYnXdS)a­
        Another extension to C{L{scanString}}, simplifying the access to the tokens found
        to match the given parse expression.  May be called with optional
        C{maxMatches} argument, to clip searching after 'n' matches are found.
        
        Example::
            # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters
            cap_word = Word(alphas.upper(), alphas.lower())
            
            print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity"))
 
            # the sum() builtin can be used to merge results into a single ParseResults object
            print(sum(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")))
        prints::
            [['More'], ['Iron'], ['Lead'], ['Gold'], ['I'], ['Electricity']]
            ['More', 'Iron', 'Lead', 'Gold', 'I', 'Electricity']
        cSsg|]\}}}|‘qSryry)rŠrxrrÙryryrzrðÿsz.ParserElement.searchString.<locals>.<listcomp>N)r$r(rr&r)r«rur!r|ryryrzÚ searchStringìs zParserElement.searchStringc    csTd}d}|j||dD]*\}}}|||…V|r<|dV|}q||d…VdS)a[
        Generator method to split a string using the given expression as a separator.
        May be called with optional C{maxsplit} argument, to limit the number of splits;
        and the optional C{includeSeparators} argument (default=C{False}), if the separating
        matching text should be included in the split results.
        
        Example::        
            punc = oneOf(list(".,;:/-!?"))
            print(list(punc.split("This, this?, this sentence, is badly punctuated!")))
        prints::
            ['This', ' this', '', ' this sentence', ' is badly punctuated', '']
        r)r!N)r()    r«ruÚmaxsplitÚincludeSeparatorsÚsplitsÚlastrxrrÙryryrzr‘s 
zParserElement.splitcCsFt|tƒrt |¡}t|tƒs:tjdt|ƒtdddSt||gƒS)a–
        Implementation of + operator - returns C{L{And}}. Adding strings to a ParserElement
        converts them to L{Literal}s by default.
        
        Example::
            greet = Word(alphas) + "," + Word(alphas) + "!"
            hello = "Hello, World!"
            print (hello, "->", greet.parseString(hello))
        Prints::
            Hello, World! -> ['Hello', ',', 'World', '!']
        ú4Cannot combine element of type %s with ParserElementrs©Ú
stacklevelN)    r}rèr&r ÚwarningsÚwarnrÁÚ SyntaxWarningrr7ryryrzr,s
 
 
ÿzParserElement.__add__cCsBt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS||S)z]
        Implementation of + operator when left operand is not a C{L{ParserElement}}
        r1rsr2N©r}rèr&r r4r5rÁr6r7ryryrzr81s
 
 
ÿzParserElement.__radd__cCsJt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS|t     ¡|S)zQ
        Implementation of - operator, returns C{L{And}} with error stop
        r1rsr2N)
r}rèr&r r4r5rÁr6rÚ
_ErrorStopr7ryryrzÚ__sub__=s
 
 
ÿzParserElement.__sub__cCsBt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS||S)z]
        Implementation of - operator when left operand is not a C{L{ParserElement}}
        r1rsr2Nr7r7ryryrzÚ__rsub__Is
 
 
ÿzParserElement.__rsub__cs¸t|tƒr|d}}nät|tƒrì|ddd…}|ddkrHd|df}t|dtƒr |ddkr |ddkrvtˆƒS|ddkrŠtˆƒSˆ|dtˆƒSqút|dtƒrÎt|dtƒrÎ|\}}||8}qútdt|dƒt|dƒƒ‚ntdt|ƒƒ‚|dkr tdƒ‚|dkrtd    ƒ‚||kr6dkrBnntd
ƒ‚|r–‡‡fd d „‰|rŒ|dkrtˆˆ|ƒ}ntˆg|ƒˆ|ƒ}nˆ|ƒ}n|dkr¦ˆ}ntˆg|ƒ}|S) aå
        Implementation of * operator, allows use of C{expr * 3} in place of
        C{expr + expr + expr}.  Expressions may also me multiplied by a 2-integer
        tuple, similar to C{{min,max}} multipliers in regular expressions.  Tuples
        may also include C{None} as in:
         - C{expr*(n,None)} or C{expr*(n,)} is equivalent
              to C{expr*n + L{ZeroOrMore}(expr)}
              (read as "at least n instances of C{expr}")
         - C{expr*(None,n)} is equivalent to C{expr*(0,n)}
              (read as "0 to n instances of C{expr}")
         - C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)}
         - C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)}
 
        Note that C{expr*(None,n)} does not raise an exception if
        more than n exprs exist in the input stream; that is,
        C{expr*(None,n)} does not enforce a maximum number of expr
        occurrences.  If this behavior is desired, then write
        C{expr*(None,n) + ~expr}
        r)NNNrsrz7cannot multiply 'ParserElement' and ('%s','%s') objectsz0cannot multiply 'ParserElement' and '%s' objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuez+cannot multiply ParserElement by 0 or (0,0)cs(|dkrtˆˆ|dƒƒStˆƒSdSrÜ)r©Ún©ÚmakeOptionalListr«ryrzr>†sz/ParserElement.__mul__.<locals>.makeOptionalList)    r}rvÚtupler4rrërÁÚ
ValueErrorr)r«r+Ú minElementsÚ optElementsr‡ryr=rzÚ__mul__UsD
 
 
 
 
 
 
 
zParserElement.__mul__cCs
| |¡Sr‰)rCr7ryryrzÚ__rmul__™szParserElement.__rmul__cCsFt|tƒrt |¡}t|tƒs:tjdt|ƒtdddSt||gƒS)zI
        Implementation of | operator - returns C{L{MatchFirst}}
        r1rsr2N)    r}rèr&r r4r5rÁr6rr7ryryrzÚ__or__œs
 
 
ÿzParserElement.__or__cCsBt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS||BS)z]
        Implementation of | operator when left operand is not a C{L{ParserElement}}
        r1rsr2Nr7r7ryryrzÚ__ror__¨s
 
 
ÿzParserElement.__ror__cCsFt|tƒrt |¡}t|tƒs:tjdt|ƒtdddSt||gƒS)zA
        Implementation of ^ operator - returns C{L{Or}}
        r1rsr2N)    r}rèr&r r4r5rÁr6rr7ryryrzÚ__xor__´s
 
 
ÿzParserElement.__xor__cCsBt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS||AS)z]
        Implementation of ^ operator when left operand is not a C{L{ParserElement}}
        r1rsr2Nr7r7ryryrzÚ__rxor__Às
 
 
ÿzParserElement.__rxor__cCsFt|tƒrt |¡}t|tƒs:tjdt|ƒtdddSt||gƒS)zC
        Implementation of & operator - returns C{L{Each}}
        r1rsr2N)    r}rèr&r r4r5rÁr6rr7ryryrzÚ__and__Ìs
 
 
ÿzParserElement.__and__cCsBt|tƒrt |¡}t|tƒs:tjdt|ƒtdddS||@S)z]
        Implementation of & operator when left operand is not a C{L{ParserElement}}
        r1rsr2Nr7r7ryryrzÚ__rand__Øs
 
 
ÿzParserElement.__rand__cCst|ƒS)zE
        Implementation of ~ operator - returns C{L{NotAny}}
        )rrµryryrzÚ
__invert__äszParserElement.__invert__cCs|dk    r| |¡S| ¡SdS)a 
        Shortcut for C{L{setResultsName}}, with C{listAllMatches=False}.
        
        If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be
        passed as C{True}.
           
        If C{name} is omitted, same as calling C{L{copy}}.
 
        Example::
            # these are equivalent
            userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno")
            userdata = Word(alphas)("name") + Word(nums+"-")("socsecno")             
        N)r¿rér)ryryrzÚ__call__ês
zParserElement.__call__cCst|ƒS)zˆ
        Suppresses the output of this C{ParserElement}; useful to keep punctuation from
        cluttering up returned output.
        )r-rµryryrzÚsuppressýszParserElement.suppresscCs
d|_|S)a
        Disables the skipping of whitespace before matching the characters in the
        C{ParserElement}'s defined pattern.  This is normally only used internally by
        the pyparsing module, but may be needed in some whitespace-sensitive grammars.
        F©r§rµryryrzÚleaveWhitespaceszParserElement.leaveWhitespacecCsd|_||_d|_|S)z8
        Overrides the default whitespace chars
        TF)r§r¨r©)r«ržryryrzÚsetWhitespaceChars sz ParserElement.setWhitespaceCharscCs
d|_|S)zé
        Overrides default behavior to expand C{<TAB>}s to spaces before parsing the input string.
        Must be called before C{parseString} when the input grammar contains elements that
        match C{<TAB>} characters.
        T)r«rµryryrzÚ parseWithTabsszParserElement.parseWithTabscCsLt|tƒrt|ƒ}t|tƒr4||jkrH|j |¡n|j t| ¡ƒ¡|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 = OneOrMore(Word(alphas))
            patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj']
            
            patt.ignore(cStyleComment)
            patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd']
        )r}rèr-r¬r$rér7ryryrzÚignores
 
 
zParserElement.ignorecCs"|pt|p t|ptf|_d|_|S)zT
        Enable display of debugging messages while doing pattern matching.
        T)rwr{r}r²r­)r«Ú startActionÚ successActionÚexceptionActionryryrzÚsetDebugActions6s þzParserElement.setDebugActionscCs|r| ttt¡nd|_|S)aŽ
        Enable display of debugging messages while doing pattern matching.
        Set C{flag} to True to enable, False to disable.
 
        Example::
            wd = Word(alphas).setName("alphaword")
            integer = Word(nums).setName("numword")
            term = wd | integer
            
            # turn on debugging for wd
            wd.setDebug()
 
            OneOrMore(term).parseString("abc 123 xyz 890")
        
        prints::
            Match alphaword at loc 0(1,1)
            Matched alphaword -> ['abc']
            Match alphaword at loc 3(1,4)
            Exception raised:Expected alphaword (at char 4), (line:1, col:5)
            Match alphaword at loc 7(1,8)
            Matched alphaword -> ['xyz']
            Match alphaword at loc 11(1,12)
            Exception raised:Expected alphaword (at char 12), (line:1, col:13)
            Match alphaword at loc 15(1,16)
            Exception raised:Expected alphaword (at char 15), (line:1, col:16)
 
        The output shown is that produced by the default debug actions - custom debug actions can be
        specified using L{setDebugActions}. Prior to attempting
        to match the C{wd} expression, the debugging message C{"Match <exprname> at loc <n>(<line>,<col>)"}
        is shown. Then if the parse succeeds, a C{"Matched"} message is shown, or an C{"Exception raised"}
        message is shown. Also note the use of L{setName} to assign a human-readable name to the expression,
        which makes debugging and exception messages easier to understand - for instance, the default
        name created for the C{Word} expression without calling C{setName} is C{"W:(ABCD...)"}.
        F)rVrwr{r}r­)r«ÚflagryryrzÚsetDebug@s#zParserElement.setDebugcCs|jSr‰)rÚrµryryrzr¶iszParserElement.__str__cCst|ƒSr‰r·rµryryrzr¸lszParserElement.__repr__cCsd|_d|_|SrÕ)r®r¤rµryryrzroszParserElement.streamlinecCsdSr‰ryrÈryryrzÚcheckRecursiontszParserElement.checkRecursioncCs| g¡dS)zj
        Check defined expressions for valid structure, check for infinite recursive definitions.
        N)rY)r«Ú validateTraceryryrzÚvalidatewszParserElement.validatec Cs„z | ¡}Wn2tk
r>t|dƒ}| ¡}W5QRXYnXz| ||¡WStk
r~}ztjrj‚n|‚W5d}~XYnXdS)zÐ
        Execute the parse expression on the given file or filename.
        If a filename is specified (instead of a file object),
        the entire file is opened, read, and closed before parsing.
        ÚrN)Úreadr²Úopenrrr&r)r«Úfile_or_filenamerÚ file_contentsÚfr|ryryrzÚ    parseFile}s  zParserElement.parseFilecsHt|tƒr"||kp t|ƒt|ƒkSt|tƒr6| |¡Stt|ƒ|kSdSr‰)r}r&Úvarsrèr%Úsuperr7©r”ryrzÚ__eq__‘s
 
 
 
zParserElement.__eq__cCs
||k Sr‰ryr7ryryrzÚ__ne__™szParserElement.__ne__cCs tt|ƒƒSr‰)ÚhashÚidrµryryrzÚ__hash__œszParserElement.__hash__cCs||kSr‰ryr7ryryrzÚ__req__ŸszParserElement.__req__cCs
||k Sr‰ryr7ryryrzÚ__rne__¢szParserElement.__rne__cCs4z|jt|ƒ|dWdStk
r.YdSXdS)aÓ
        Method for quick testing of a parser against a test string. Good for simple 
        inline microtests of sub expressions while building up larger parser.
           
        Parameters:
         - testString - to test against this expression for a match
         - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests
            
        Example::
            expr = Word(nums)
            assert expr.matches("100")
        ©rTFN)rrˆr)r«Ú
testStringrryryrzr%¥s
zParserElement.matchesú#c Csòt|tƒr"tttj| ¡ ¡ƒƒ}t|tƒr4t|ƒ}g}g}d}    |D]¢}
|dk    r^|     |
d¡sf|rr|
sr| 
|
¡qD|
sxqDd  |¡|
g} g}z:|
  dd¡}
|j |
|d} |  
| j|d¡|    oÀ| }    Wnðtk
rr} zŽt| tƒrædnd    }d|
kr*|  
t| j|
ƒ¡|  
d
t| j|
ƒd d |¡n|  
d
| jd |¡|  
d t| ƒ¡|    o\|}    | } W5d} ~ XYnDtk
r´}z$|  
dt|ƒ¡|    ož|}    |} W5d}~XYnX|rÚ|rÌ|  
d    ¡td  | ¡ƒ| 
|
| f¡qD|    |fS)a3
        Execute the parse expression on a series of test strings, showing each
        test, the parsed results or where the parse failed. Quick and easy way to
        run a parse expression against a list of sample strings.
           
        Parameters:
         - tests - a list of separate test strings, or a multiline string of test strings
         - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests           
         - comment - (default=C{'#'}) - expression for indicating embedded comments in the test 
              string; pass None to disable comment filtering
         - fullDump - (default=C{True}) - dump results as list followed by results names in nested outline;
              if False, only dump nested list
         - printResults - (default=C{True}) prints test output to stdout
         - failureTests - (default=C{False}) indicates if these tests are expected to fail parsing
 
        Returns: a (success, results) tuple, where success indicates that all tests succeeded
        (or failed if C{failureTests} is True), and the results contain a list of lines of each 
        test's output
        
        Example::
            number_expr = pyparsing_common.number.copy()
 
            result = number_expr.runTests('''
                # unsigned integer
                100
                # negative integer
                -100
                # float with scientific notation
                6.02e23
                # integer with scientific notation
                1e-12
                ''')
            print("Success" if result[0] else "Failed!")
 
            result = number_expr.runTests('''
                # stray character
                100Z
                # missing leading digit before '.'
                -.100
                # too many '.'
                3.14.159
                ''', failureTests=True)
            print("Success" if result[0] else "Failed!")
        prints::
            # unsigned integer
            100
            [100]
 
            # negative integer
            -100
            [-100]
 
            # float with scientific notation
            6.02e23
            [6.02e+23]
 
            # integer with scientific notation
            1e-12
            [1e-12]
 
            Success
            
            # stray character
            100Z
               ^
            FAIL: Expected end of text (at char 3), (line:1, col:4)
 
            # missing leading digit before '.'
            -.100
            ^
            FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1)
 
            # too many '.'
            3.14.159
                ^
            FAIL: Expected end of text (at char 4), (line:1, col:5)
 
            Success
 
        Each test string must be on a single line. If you want to test a string that spans multiple
        lines, create a test like this::
 
            expr.runTest(r"this is a test\n of strings that spans \n 3 lines")
        
        (Note that this is a raw string literal, you must include the leading 'r'.)
        TNFrHú\nrm)rdz(FATAL)r ú rú^zFAIL: zFAIL-EXCEPTION: )r}rèrãrËrr»ÚrstripÚ
splitlinesrr%r$rºr“rrarr#rIr¦r;r—rt)r«ÚtestsrÚcommentÚfullDumpÚ printResultsÚ failureTestsÚ
allResultsÚcommentsÚsuccessrxr?Úresultr¯rÐr|ryryrzÚrunTests¸sNW
 
 
 
 
$
 
 
zParserElement.runTests)F)F)T)T)TT)TT)r)F)N)T)F)T)TroTTF)Or›rœrrÃrœrÚ staticmethodrŸr¡r­rérºr¿rÊr„rÎrÕrÖrÛrßrárärërírîrÖrýrr    rrrrrrÈrrrrÚ_MAX_INTr(r…r,r‘r,r8r9r:rCrDrErFrGrHrIrJrKrLrMrOrPrQrRrVrXr¶r¸rrYr[rbrfrgrjrkrlr%r~Ú __classcell__ryryrerzr&Os˜
 
 
 
 
&
 
 
G
 
 "
2G+    D      
            
 
) 
 
cs eZdZdZ‡fdd„Z‡ZS)r.zT
    Abstract C{ParserElement} subclass, for defining atomic matching patterns.
    cstt|ƒjdddS©NF©r¶)rdr.r­rµreryrzr­@    szToken.__init__©r›rœrrÃr­rryryrerzr.<    scs eZdZdZ‡fdd„Z‡ZS)rz,
    An empty token, will always match.
    cs$tt|ƒ ¡d|_d|_d|_dS)NrTF)rdrr­rÚrªr¯rµreryrzr­H    szEmpty.__init__r„ryryrerzrD    scs*eZdZdZ‡fdd„Zddd„Z‡ZS)rz(
    A token that will never match.
    cs*tt|ƒ ¡d|_d|_d|_d|_dS)NrTFzUnmatchable token)rdrr­rÚrªr¯r°rµreryrzr­S    s
zNoMatch.__init__TcCst|||j|ƒ‚dSr‰)r!r°ràryryrzráZ    szNoMatch.parseImpl)T©r›rœrrÃr­rárryryrerzrO    s cs*eZdZdZ‡fdd„Zddd„Z‡ZS)raÐ
    Token to exactly match a specified string.
    
    Example::
        Literal('blah').parseString('blah')  # -> ['blah']
        Literal('blah').parseString('blahfooblah')  # -> ['blah']
        Literal('blah').parseString('bla')  # -> Exception: Expected "blah"
    
    For case-insensitive matching, use L{CaselessLiteral}.
    
    For keyword matching (force word break before and after the matched string),
    use L{Keyword} or L{CaselessKeyword}.
    cs„tt|ƒ ¡||_t|ƒ|_z|d|_Wn*tk
rVtj    dt
ddt |_ YnXdt |jƒ|_d|j|_d|_d|_dS)Nrz2null string passed to Literal; use Empty() insteadrsr2ú"%s"r¸F)rdrr­ÚmatchrøÚmatchLenÚfirstMatchCharrìr4r5r6rr”rˆrÚr°rªr¯©r«Ú matchStringreryrzr­l    s
ÿ  zLiteral.__init__TcCsJ|||jkr6|jdks&| |j|¡r6||j|jfSt|||j|ƒ‚dSrÜ)r‰rˆÚ
startswithr‡r!r°ràryryrzrá    sÿ ÿzLiteral.parseImpl)Tr…ryryrerzr^    s csLeZdZdZedZd‡fdd„    Zddd    „Z‡fd
d „Ze    d d „ƒZ
‡Z S)ra\
    Token to exactly match a specified string as a keyword, that is, it must be
    immediately followed by a non-keyword character.  Compare with C{L{Literal}}:
     - C{Literal("if")} will match the leading C{'if'} in C{'ifAndOnlyIf'}.
     - C{Keyword("if")} will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'}
    Accepts two optional constructor arguments in addition to the keyword string:
     - C{identChars} is a string of characters that would be valid identifier characters,
          defaulting to all alphanumerics + "_" and "$"
     - C{caseless} allows case-insensitive matching, default is C{False}.
       
    Example::
        Keyword("start").parseString("start")  # -> ['start']
        Keyword("start").parseString("starting")  # -> Exception
 
    For case-insensitive matching, use L{CaselessKeyword}.
    ú_$NFcs®tt|ƒ ¡|dkrtj}||_t|ƒ|_z|d|_Wn$tk
r^t    j
dt ddYnXd|j|_ d|j |_ d|_d|_||_|r | ¡|_| ¡}t|ƒ|_dS)Nrz2null string passed to Keyword; use Empty() insteadrsr2r†r¸F)rdrr­ÚDEFAULT_KEYWORD_CHARSr‡rørˆr‰rìr4r5r6rÚr°rªr¯ÚcaselessÚupperÚ caselessmatchröÚ
identChars)r«r‹r’rreryrzr­š    s*
ÿ   
zKeyword.__init__TcCs|jr|||||j… ¡|jkrò|t|ƒ|jksL|||j ¡|jkrò|dksj||d ¡|jkrò||j|jfSnv|||jkrò|jdks¢| |j|¡rò|t|ƒ|jksÈ|||j|jkrò|dksâ||d|jkrò||j|jfSt    |||j
|ƒ‚dSr÷) rrˆrr‘rør’r‡r‰rŒr!r°ràryryrzrᯠ   s4ÿÿþþÿ ÿþþýýzKeyword.parseImplcstt|ƒ ¡}tj|_|Sr‰)rdrrérŽr’)r«r¤reryrzré½    sz Keyword.copycCs
|t_dS)z,Overrides the default Keyword chars
        N)rrŽrryryrzÚsetDefaultKeywordChars    szKeyword.setDefaultKeywordChars)NF)T) r›rœrrÃr5rŽr­rárérr“rryryrerzr‡    s
 cs*eZdZdZ‡fdd„Zddd„Z‡ZS)r
al
    Token to match a specified string, ignoring case of letters.
    Note: the matched results will always be in the case of the given
    match string, NOT the case of the input text.
 
    Example::
        OneOrMore(CaselessLiteral("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD', 'CMD']
        
    (Contrast with example for L{CaselessKeyword}.)
    cs6tt|ƒ | ¡¡||_d|j|_d|j|_dS)Nz'%s'r¸)rdr
r­rÚ returnStringrÚr°rŠreryrzr­Ó    s zCaselessLiteral.__init__TcCs@||||j… ¡|jkr,||j|jfSt|||j|ƒ‚dSr‰)rˆrr‡r”r!r°ràryryrzráÚ    szCaselessLiteral.parseImpl)Tr…ryryrerzr
È    s
cs,eZdZdZd‡fdd„    Zd    dd„Z‡ZS)
r    zÐ
    Caseless version of L{Keyword}.
 
    Example::
        OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD']
        
    (Contrast with example for L{CaselessLiteral}.)
    Ncstt|ƒj||dddS)NT©r)rdr    r­)r«r‹r’reryrzr­è    szCaselessKeyword.__init__TcCsj||||j… ¡|jkrV|t|ƒ|jksF|||j ¡|jkrV||j|jfSt|||j|ƒ‚dSr‰)rˆrr‘rør’r‡r!r°ràryryrzráë    sÿÿzCaselessKeyword.parseImpl)N)Tr…ryryrerzr    ß    scs,eZdZdZd‡fdd„    Zd    dd„Z‡ZS)
rnax
    A variation on L{Literal} which matches "close" matches, that is, 
    strings with at most 'n' mismatching characters. C{CloseMatch} takes parameters:
     - C{match_string} - string to be matched
     - C{maxMismatches} - (C{default=1}) maximum number of mismatches allowed to count as a match
    
    The results from a successful parse will contain the matched text from the input string and the following named results:
     - C{mismatches} - a list of the positions within the match_string where mismatches were found
     - C{original} - the original match_string used to compare against the input string
    
    If C{mismatches} is an empty list, then the match was an exact match.
    
    Example::
        patt = CloseMatch("ATCATCGAATGGA")
        patt.parseString("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']})
        patt.parseString("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1)
 
        # exact match
        patt.parseString("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']})
 
        # close match allowing up to 2 mismatches
        patt = CloseMatch("ATCATCGAATGGA", maxMismatches=2)
        patt.parseString("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']})
    rcsBtt|ƒ ¡||_||_||_d|j|jf|_d|_d|_dS)Nz&Expected %r (with up to %d mismatches)F)    rdrnr­rÚÚ match_stringÚ maxMismatchesr°r¯rª)r«r–r—reryrzr­
 
szCloseMatch.__init__TcCsÊ|}t|ƒ}|t|jƒ}||kr¶|j}d}g}    |j}
tt|||…|jƒƒD]2\}} | \} } | | krN|     |¡t|    ƒ|
krNq¶qN|d}t|||…gƒ}|j|d<|    |d<||fSt|||j|ƒ‚dS)NrrÚoriginalÚ
mismatches)    rør–r—rýr’r$r$r!r°)r«rur¦rÂÚstartrÞÚmaxlocr–Úmatch_stringlocr™r—Ús_mÚsrcÚmatÚresultsryryrzrá
s( 
 
zCloseMatch.parseImpl)r)Tr…ryryrerzrnñ    s    cs8eZdZdZd ‡fdd„    Zdd    d
„Z‡fd d „Z‡ZS)r1a    
    Token for matching words composed of allowed character sets.
    Defined with string containing all allowed initial characters,
    an optional string containing allowed body characters (if omitted,
    defaults to the initial character set), and an optional minimum,
    maximum, and/or exact length.  The default value for C{min} is 1 (a
    minimum value < 1 is not valid); the default values for C{max} and C{exact}
    are 0, meaning no maximum or exact length restriction. An optional
    C{excludeChars} parameter can list characters that might be found in 
    the input C{bodyChars} string; useful to define a word of all printables
    except for one or two characters, for instance.
    
    L{srange} is useful for defining custom character set strings for defining 
    C{Word} expressions, using range notation from regular expression character sets.
    
    A common mistake is to use C{Word} to match a specific literal string, as in 
    C{Word("Address")}. Remember that C{Word} uses the string argument to define
    I{sets} of matchable characters. This expression would match "Add", "AAA",
    "dAred", or any other word made up of the characters 'A', 'd', 'r', 'e', and 's'.
    To match an exact literal string, use L{Literal} or L{Keyword}.
 
    pyparsing includes helper strings for building Words:
     - L{alphas}
     - L{nums}
     - L{alphanums}
     - L{hexnums}
     - L{alphas8bit} (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.)
     - L{punc8bit} (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.)
     - L{printables} (any non-whitespace character)
 
    Example::
        # a word composed of digits
        integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9"))
        
        # a word with a leading capital, and zero or more lowercase
        capital_word = Word(alphas.upper(), alphas.lower())
 
        # hostnames are alphanumeric, with leading alpha, and '-'
        hostname = Word(alphas, alphanums+'-')
        
        # roman numeral (not a strict parser, accepts invalid mix of characters)
        roman = Word("IVXLCDM")
        
        # any string of non-whitespace characters, except for ','
        csv_value = Word(printables, excludeChars=",")
    NrrFcsÌtt|ƒ ¡ˆrFd ‡fdd„|Dƒ¡}|rFd ‡fdd„|Dƒ¡}||_t|ƒ|_|rl||_t|ƒ|_n||_t|ƒ|_|dk|_    |dkr–t
dƒ‚||_ |dkr¬||_ nt |_ |dkrÆ||_ ||_ t|ƒ|_d|j|_d    |_||_d
|j|jkrÈ|dkrÈ|dkrÈ|dkrÈ|j|jkr8d t|jƒ|_nHt|jƒdkrfd t |j¡t|jƒf|_nd t|jƒt|jƒf|_|jr˜d|jd|_zt |j¡|_Wntk
rÆd|_YnXdS)Nr c3s|]}|ˆkr|VqdSr‰ryr£©Ú excludeCharsryrzrŒ`
sz Word.__init__.<locals>.<genexpr>c3s|]}|ˆkr|VqdSr‰ryr£r¡ryrzrŒb
srrzZcannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permittedr¸Frqz[%s]+z%s[%s]*z    [%s][%s]*z\b)rdr1r­rºÚ initCharsOrigröÚ    initCharsÚ bodyCharsOrigÚ    bodyCharsÚ maxSpecifiedr@ÚminLenÚmaxLenr€rˆrÚr°r¯Ú    asKeywordÚ_escapeRegexRangeCharsÚreStringrør³ÚescapeÚcompiler—)r«r¤r¦ÚminÚmaxÚexactrªr¢rer¡rzr­]
s\
 
 
 
 0
ÿÿÿÿz Word.__init__Tc
Cs>|jr<|j ||¡}|s(t|||j|ƒ‚| ¡}|| ¡fS|||jkrZt|||j|ƒ‚|}|d7}t|ƒ}|j}||j    }t
||ƒ}||kr¦|||kr¦|d7}qˆd}    |||j kr¼d}    |j rÚ||krÚ|||krÚd}    |j r|dkrü||d|ks||kr|||krd}    |    r.t|||j|ƒ‚||||…fS)NrFTr)r³r‡r!r°ÚendÚgroupr¤rør¦r©r¯r¨r§rª)
r«rur¦rÂr}ršrÞÚ    bodycharsr›ÚthrowExceptionryryrzrá“
s6 
 
 
2zWord.parseImplcsvztt|ƒ ¡WStk
r$YnX|jdkrpdd„}|j|jkr`d||jƒ||jƒf|_nd||jƒ|_|jS)NcSs$t|ƒdkr|dd…dS|SdS)Néú...rø©rryryrzÚ
charsAsStr¿
s z Word.__str__.<locals>.charsAsStrz    W:(%s,%s)zW:(%s))rdr1r¶r—r¤r£r¥)r«r¹reryrzr¶¶
s
 z Word.__str__)NrrrFN)T©r›rœrrÃr­rár¶rryryrerzr1.
s.6
#csFeZdZdZee d¡ƒZd ‡fdd„    Zd dd„Z    ‡fd    d
„Z
‡Z S) r)a
    Token for matching strings that match a given regular expression.
    Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module.
    If the given regex contains named groups (defined using C{(?P<name>...)}), these will be preserved as 
    named parse results.
 
    Example::
        realnum = Regex(r"[+-]?\d+\.\d*")
        date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
        # ref: http://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
        roman = Regex(r"M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")
    z[A-Z]rcsÞtt|ƒ ¡t|tƒr†|s,tjdtdd||_||_    zt
  |j|j    ¡|_
|j|_ Wq¸t jk
r‚tjd|tdd‚Yq¸Xn2t|tjƒr°||_
t|ƒ|_|_ ||_    ntdƒ‚t|ƒ|_d|j|_d|_d|_d    S)
z­The parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags.z0null string passed to Regex; use Empty() insteadrsr2ú$invalid pattern (%s) passed to RegexzCRegex may only be constructed with a string or a compiled RE objectr¸FTN)rdr)r­r}rèr4r5r6ÚpatternÚflagsr³r®r¬Ú sre_constantsÚerrorÚcompiledREtyperr@rˆrÚr°r¯rª)r«r¼r½reryrzr­Û
s:
ÿ 
ÿ
 ÿ
 zRegex.__init__TcCs`|j ||¡}|s"t|||j|ƒ‚| ¡}| ¡}t| ¡ƒ}|rX|D]}||||<qF||fSr‰)r³r‡r!r°r²Ú    groupdictr$r³)r«rur¦rÂr}Údr‡rôryryrzráý
s zRegex.parseImplcsFztt|ƒ ¡WStk
r$YnX|jdkr@dt|jƒ|_|jS)NzRe:(%s))rdr)r¶r—r¤rÓr¼rµreryrzr¶
s
z Regex.__str__)r)T) r›rœrrÃrÁr³r®rÀr­rár¶rryryrerzr)Í
s
 "
cs8eZdZdZd ‡fdd„    Zd dd„Z‡fd    d
„Z‡ZS) r'a«
    Token for matching strings that are delimited by quoting characters.
    
    Defined with the following parameters:
        - quoteChar - string of one or more characters defining the quote delimiting string
        - escChar - character to escape quotes, typically backslash (default=C{None})
        - escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=C{None})
        - multiline - boolean indicating whether quotes can span multiple lines (default=C{False})
        - unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True})
        - endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar)
        - convertWhitespaceEscapes - convert escaped whitespace (C{'\t'}, C{'\n'}, etc.) to actual whitespace (default=C{True})
 
    Example::
        qs = QuotedString('"')
        print(qs.searchString('lsjdf "This is the quote" sldjf'))
        complex_qs = QuotedString('{{', endQuoteChar='}}')
        print(complex_qs.searchString('lsjdf {{This is the "quote"}} sldjf'))
        sql_qs = QuotedString('"', escQuote='""')
        print(sql_qs.searchString('lsjdf "This is the quote with ""embedded"" quotes" sldjf'))
    prints::
        [['This is the quote']]
        [['This is the "quote"']]
        [['This is the quote with "embedded" quotes']]
    NFTc
sNttˆƒ ¡| ¡}|s0tjdtddtƒ‚|dkr>|}n"| ¡}|s`tjdtddtƒ‚|ˆ_t    |ƒˆ_
|dˆ_ |ˆ_ t    |ƒˆ_ |ˆ_|ˆ_|ˆ_|ˆ_|rètjtjBˆ_dt ˆj¡tˆj dƒ|dk    rÜt|ƒpÞdfˆ_n<dˆ_dt ˆj¡tˆj dƒ|dk    rt|ƒpdfˆ_t    ˆj ƒd    krpˆjd
d  ‡fd d „tt    ˆj ƒd    ddƒDƒ¡d7_|rŽˆjdt |¡7_|r¾ˆjdt |¡7_t ˆj¡dˆ_ˆjdt ˆj ¡7_zt ˆjˆj¡ˆ_ˆjˆ_Wn0tjk
r&tjdˆjtdd‚YnXt ˆƒˆ_!dˆj!ˆ_"dˆ_#dˆ_$dS)Nz$quoteChar cannot be the empty stringrsr2z'endQuoteChar cannot be the empty stringrz %s(?:[^%s%s]r z%s(?:[^%s\n\r%s]rz|(?:z)|(?:c3s4|],}dt ˆjd|…¡tˆj|ƒfVqdS)z%s[^%s]N)r³r­Ú endQuoteCharr«r;rµryrzrŒX sþ ÿz(QuotedString.__init__.<locals>.<genexpr>rtú)z|(?:%s)z|(?:%s.)z(.)z)*%sr»r¸FT)%rdr'r­r»r4r5r6Ú SyntaxErrorÚ    quoteCharrøÚ quoteCharLenÚfirstQuoteCharrÃÚendQuoteCharLenÚescCharÚescQuoteÚunquoteResultsÚconvertWhitespaceEscapesr³Ú    MULTILINEÚDOTALLr½r­r«r¼rºrùÚescCharReplacePatternr®r¬r¾r¿rˆrÚr°r¯rª)r«rÆrÊrËÚ    multilinerÌrÃrÍrerµrzr­/ s|
 
 
 
 þÿ
 þÿþþÿ  ÿ
 zQuotedString.__init__c    CsÔ|||jkr|j ||¡pd}|s4t|||j|ƒ‚| ¡}| ¡}|jrÌ||j|j     …}t
|t ƒrÌd|kr |j r dddddœ}|  ¡D]\}}| ||¡}qŠ|jr¶t |jd|¡}|jrÌ| |j|j¡}||fS)Nú\ú    rHú ú )ú\trpz\fz\rz\g<1>)rÈr³r‡r!r°r²r³rÌrÇrÉr}rèrÍrür“rÊrõrÐrËrÃ)    r«rur¦rÂr}r‡Úws_mapÚwslitÚwscharryryrzráp s* 
üzQuotedString.parseImplcsHztt|ƒ ¡WStk
r$YnX|jdkrBd|j|jf|_|jS)Nz.quoted string, starting with %s ending with %s)rdr'r¶r—r¤rÆrÃrµreryrzr¶“ s
zQuotedString.__str__)NNFTNT)Trºryryrerzr' sA
#cs8eZdZdZd ‡fdd„    Zd dd„Z‡fd    d
„Z‡ZS) r aô
    Token for matching words composed of characters I{not} in a given set (will
    include whitespace in matched characters if not listed in the provided exclusion set - see example).
    Defined with string containing all disallowed characters, and an optional
    minimum, maximum, and/or exact length.  The default value for C{min} is 1 (a
    minimum value < 1 is not valid); the default values for C{max} and C{exact}
    are 0, meaning no maximum or exact length restriction.
 
    Example::
        # define a comma-separated-value as anything that is not a ','
        csv_value = CharsNotIn(',')
        print(delimitedList(csv_value).parseString("dkls,lsdkjf,s12 34,@!#,213"))
    prints::
        ['dkls', 'lsdkjf', 's12 34', '@!#', '213']
    rrcs†tt|ƒ ¡d|_||_|dkr*tdƒ‚||_|dkr@||_nt|_|dkrZ||_||_t    |ƒ|_
d|j
|_ |jdk|_ d|_ dS)NFrzfcannot specify a minimum length < 1; use Optional(CharsNotIn()) if zero-length char group is permittedrr¸)rdr r­r§ÚnotCharsr@r¨r©r€rˆrÚr°rªr¯)r«rÚr¯r°r±reryrzr­¯ s 
  zCharsNotIn.__init__TcCs|||jkrt|||j|ƒ‚|}|d7}|j}t||jt|ƒƒ}||krb|||krb|d7}qD|||jkr€t|||j|ƒ‚||||…fSrÜ)rÚr!r°r¯r©rør¨)r«rur¦rÂršÚnotcharsÚmaxlenryryrzráÇ s
ÿ
zCharsNotIn.parseImplcsfztt|ƒ ¡WStk
r$YnX|jdkr`t|jƒdkrTd|jdd…|_n d|j|_|jS)Nr¶z
!W:(%s...)z!W:(%s))rdr r¶r—r¤rørÚrµreryrzr¶Ø s
 zCharsNotIn.__str__)rrr)Trºryryrerzr Ÿ s
cs<eZdZdZddddddœZd‡fd d „    Zddd„Z‡ZS)r0a
    Special matching class for matching whitespace.  Normally, whitespace is ignored
    by pyparsing grammars.  This class is included when some whitespace structures
    are significant.  Define with a string containing the whitespace characters to be
    matched; default is C{" \t\r\n"}.  Also takes optional C{min}, C{max}, and C{exact} arguments,
    as defined for the C{L{Word}} class.
    z<SPC>z<TAB>z<LF>z<CR>z<FF>)rqrÓrHrÕrÔú     
rrcs’ttˆƒ ¡|ˆ_ˆ d ‡fdd„ˆjDƒ¡¡d dd„ˆjDƒ¡ˆ_dˆ_dˆjˆ_    |ˆ_
|dkrt|ˆ_ nt ˆ_ |dkrŽ|ˆ_ |ˆ_
dS)Nr c3s|]}|ˆjkr|VqdSr‰)Ú
matchWhiter£rµryrzrŒø s
z!White.__init__.<locals>.<genexpr>css|]}tj|VqdSr‰)r0Ú    whiteStrsr£ryryrzrŒú sTr¸r) rdr0r­rÞrPrºr¨rÚrªr°r¨r©r€)r«Úwsr¯r°r±rerµrzr­õ s  zWhite.__init__TcCs|||jkrt|||j|ƒ‚|}|d7}||j}t|t|ƒƒ}||krb|||jkrb|d7}qB|||jkr€t|||j|ƒ‚||||…fSrÜ)rÞr!r°r©r¯rør¨)r«rur¦rÂršr›ryryrzrá     s
 
zWhite.parseImpl)rÝrrr)T)r›rœrrÃrßr­rárryryrerzr0æ sûcseZdZ‡fdd„Z‡ZS)Ú_PositionTokencs(tt|ƒ ¡|jj|_d|_d|_dSr×)rdrár­r”r›rÚrªr¯rµreryrzr­ s
z_PositionToken.__init__©r›rœrr­rryryrerzrá srács2eZdZdZ‡fdd„Zdd„Zd    dd„Z‡ZS)
rzb
    Token to advance to a specific column of input text; useful for tabular report scraping.
    cstt|ƒ ¡||_dSr‰)rdrr­r;)r«Úcolnoreryrzr­$ szGoToColumn.__init__cCs\t||ƒ|jkrXt|ƒ}|jr*| ||¡}||krX|| ¡rXt||ƒ|jkrX|d7}q*|SrÜ)r;rør¬rÛÚisspace)r«rur¦rÞryryrzrß( s $
zGoToColumn.preParseTcCsDt||ƒ}||jkr"t||d|ƒ‚||j|}|||…}||fS)NzText not in expected column©r;r!)r«rur¦rÂÚthiscolÚnewlocr‡ryryrzrá1 s 
 
 zGoToColumn.parseImpl)T)r›rœrrÃr­rßrárryryrerzr  s     cs*eZdZdZ‡fdd„Zddd„Z‡ZS)ra¿
    Matches if current position is at the beginning of a line within the parse string
    
    Example::
    
        test = '''        AAA this line
        AAA and this line
          AAA but not this one
        B AAA and definitely not this one
        '''
 
        for t in (LineStart() + 'AAA' + restOfLine).searchString(test):
            print(t)
    
    Prints::
        ['AAA', ' this line']
        ['AAA', ' and this line']    
 
    cstt|ƒ ¡d|_dS)NzExpected start of line)rdrr­r°rµreryrzr­O szLineStart.__init__TcCs*t||ƒdkr|gfSt|||j|ƒ‚dSrÜ)r;r!r°ràryryrzráS szLineStart.parseImpl)Tr…ryryrerzr: s cs*eZdZdZ‡fdd„Zddd„Z‡ZS)rzU
    Matches if current position is at the end of a line within the parse string
    cs,tt|ƒ ¡| tj dd¡¡d|_dS)NrHr zExpected end of line)rdrr­rPr&rœr“r°rµreryrzr­\ szLineEnd.__init__TcCsb|t|ƒkr6||dkr$|ddfSt|||j|ƒ‚n(|t|ƒkrN|dgfSt|||j|ƒ‚dS)NrHr©rør!r°ràryryrzráa s     zLineEnd.parseImpl)Tr…ryryrerzrX s cs*eZdZdZ‡fdd„Zddd„Z‡ZS)r,zM
    Matches if current position is at the beginning of the parse string
    cstt|ƒ ¡d|_dS)NzExpected start of text)rdr,r­r°rµreryrzr­p szStringStart.__init__TcCs0|dkr(|| |d¡kr(t|||j|ƒ‚|gfSrÒ)rßr!r°ràryryrzrát szStringStart.parseImpl)Tr…ryryrerzr,l s cs*eZdZdZ‡fdd„Zddd„Z‡ZS)r+zG
    Matches if current position is at the end of the parse string
    cstt|ƒ ¡d|_dS)NzExpected end of text)rdr+r­r°rµreryrzr­ szStringEnd.__init__TcCs^|t|ƒkrt|||j|ƒ‚n<|t|ƒkr6|dgfS|t|ƒkrJ|gfSt|||j|ƒ‚dSrÜrèràryryrzrრs    zStringEnd.parseImpl)Tr…ryryrerzr+{ s cs.eZdZdZef‡fdd„    Zddd„Z‡ZS)r3ap
    Matches if the current position is at the beginning of a Word, and
    is not preceded by any character in a given set of C{wordChars}
    (default=C{printables}). To emulate the C{} behavior of regular expressions,
    use C{WordStart(alphanums)}. C{WordStart} will also match at the beginning of
    the string being parsed, or at the beginning of a line.
    cs"tt|ƒ ¡t|ƒ|_d|_dS)NzNot at the start of a word)rdr3r­röÚ    wordCharsr°©r«réreryrzr­• s
zWordStart.__init__TcCs@|dkr8||d|jks(|||jkr8t|||j|ƒ‚|gfSr÷)rér!r°ràryryrzráš s  ÿzWordStart.parseImpl)T©r›rœrrÃrXr­rárryryrerzr3 scs.eZdZdZef‡fdd„    Zddd„Z‡ZS)r2aZ
    Matches if the current position is at the end of a Word, and
    is not followed by any character in a given set of C{wordChars}
    (default=C{printables}). To emulate the C{} behavior of regular expressions,
    use C{WordEnd(alphanums)}. C{WordEnd} will also match at the end of
    the string being parsed, or at the end of a line.
    cs(tt|ƒ ¡t|ƒ|_d|_d|_dS)NFzNot at the end of a word)rdr2r­rörér§r°rêreryrzr­© s
zWordEnd.__init__TcCsPt|ƒ}|dkrH||krH|||jks8||d|jkrHt|||j|ƒ‚|gfSr÷)rørér!r°)r«rur¦rÂrÞryryrzrᯠsÿzWordEnd.parseImpl)Trëryryrerzr2¡ scs„eZdZdZd‡fdd„    Zdd„Zdd„Zd    d
„Z‡fd d „Z‡fd d„Z    ‡fdd„Z
d‡fdd„    Z gfdd„Z ‡fdd„Z ‡ZS)r"z^
    Abstract subclass of ParserElement, for combining and post-processing parsed tokens.
    Fcs®tt|ƒ |¡t|tƒr"t|ƒ}t|tƒr<t |¡g|_    nht|t
ƒrxt|ƒ}t dd„|Dƒƒrlt tj|ƒ}t|ƒ|_    n,zt|ƒ|_    Wnt k
r¢|g|_    YnXd|_dS)Ncss|]}t|tƒVqdSr‰)r}rè)rŠrvryryrzrŒÆ sz+ParseExpression.__init__.<locals>.<genexpr>F)rdr"r­r}rårãrèr&r ÚexprsrÚallrËrër´©r«rìr¶reryrzr­¼ s
 
 
  zParseExpression.__init__cCs
|j|Sr‰)rìrÏryryrzrÑÐ szParseExpression.__getitem__cCs|j |¡d|_|Sr‰)rìr$r¤r7ryryrzr$Ó s zParseExpression.appendcCs0d|_dd„|jDƒ|_|jD] }| ¡q|S)z~Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on
           all contained expressions.FcSsg|] }| ¡‘qSryr*©rŠrÙryryrzrðÜ sz3ParseExpression.leaveWhitespace.<locals>.<listcomp>)r§rìrO)r«rÙryryrzrOØ s
 
 
zParseExpression.leaveWhitespacecsrt|tƒrB||jkrntt|ƒ |¡|jD]}| |jd¡q*n,tt|ƒ |¡|jD]}| |jd¡qX|Sr )r}r-r¬rdr"rRrì)r«r+rÙreryrzrRá s
 
 
 
zParseExpression.ignorecsNztt|ƒ ¡WStk
r$YnX|jdkrHd|jjt|jƒf|_|jS©Nz%s:(%s))    rdr"r¶r—r¤r”r›rˆrìrµreryrzr¶í s
zParseExpression.__str__cs*tt|ƒ ¡|jD] }| ¡qt|jƒdkr|jd}t||jƒr |js |jdkr |j    s |jdd…|jdg|_d|_
|j |j O_ |j |j O_ |jd}t||jƒr|js|jdkr|j    s|jdd…|jdd…|_d|_
|j |j O_ |j |j O_ dt |ƒ|_|S)Nrsrrrtr¸)rdr"rrìrør}r”r¢r¥r­r¤rªr¯rˆr°)r«rÙr+reryrzr÷ s<
 
 
 ÿþý
ÿþýzParseExpression.streamlinecstt|ƒ ||¡}|Sr‰)rdr"r¿)r«rÚr½r‡reryrzr¿ szParseExpression.setResultsNamecCs6|dd…|g}|jD]}| |¡q| g¡dSr‰)rìr[rY)r«rZÚtmprÙryryrzr[ s
 zParseExpression.validatecs$tt|ƒ ¡}dd„|jDƒ|_|S)NcSsg|] }| ¡‘qSryr*rïryryrzrð% sz(ParseExpression.copy.<locals>.<listcomp>)rdr"rérìrGreryrzré# szParseExpression.copy)F)F)r›rœrrÃr­rÑr$rOrRr¶rr¿r[rérryryrerzr"¸ s    
" csTeZdZdZGdd„deƒZd‡fdd„    Zddd„Zd    d
„Zd d „Z    d d„Z
‡Z S)ra 
    Requires all given C{ParseExpression}s to be found in the given order.
    Expressions may be separated by whitespace.
    May be constructed using the C{'+'} operator.
    May also be constructed using the C{'-'} operator, which will suppress backtracking.
 
    Example::
        integer = Word(nums)
        name_expr = OneOrMore(Word(alphas))
 
        expr = And([integer("id"),name_expr("name"),integer("age")])
        # more easily written as:
        expr = integer("id") + name_expr("name") + integer("age")
    cseZdZ‡fdd„Z‡ZS)zAnd._ErrorStopcs&ttj|ƒj||Žd|_| ¡dS)Nú-)rdrr8r­rÚrOrgreryrzr­9 szAnd._ErrorStop.__init__râryryrerzr88 sr8TcsRtt|ƒ ||¡tdd„|jDƒƒ|_| |jdj¡|jdj|_d|_    dS)Ncss|] }|jVqdSr‰©rªrïryryrzrŒ@ szAnd.__init__.<locals>.<genexpr>rT)
rdrr­rírìrªrPr¨r§r´rîreryrzr­> s
z And.__init__c     Csþ|jdj|||dd\}}d}|jdd…D]Æ}t|tjƒrDd}q.|rÎz| |||¡\}}Wqàtk
rt‚Yqàtk
r¤}zd|_t |¡‚W5d}~XYqàt    k
rÊt|t
|ƒ|j |ƒ‚YqàXn| |||¡\}}|sì|  ¡r.||7}q.||fS)NrFr rT) rìrÈr}rr8r%rÚ __traceback__r°rìrør°r)    r«rur¦rÂÚ
resultlistÚ    errorStoprÙÚ
exprtokensr¯ryryrzráE s(  
z And.parseImplcCst|tƒrt |¡}| |¡Sr‰©r}rèr&r r$r7ryryrzr6^ s
 
z And.__iadd__cCs6|dd…|g}|jD]}| |¡|jsq2qdSr‰)rìrYrª©r«rÉÚsubRecCheckListrÙryryrzrYc s
 
 
zAnd.checkRecursioncCs@t|dƒr|jS|jdkr:dd dd„|jDƒ¡d|_|jS)NrÚÚ{rqcss|]}t|ƒVqdSr‰r·rïryryrzrŒo szAnd.__str__.<locals>.<genexpr>Ú}©rrÚr¤rºrìrµryryrzr¶j s
 
 
 z And.__str__)T)T) r›rœrrÃrr8r­rár6rYr¶rryryrerzr( s
csDeZdZdZd‡fdd„    Zddd„Zdd    „Zd
d „Zd d „Z‡Z    S)ra¾
    Requires that at least one C{ParseExpression} is found.
    If two expressions match, the expression that matches the longest string will be used.
    May be constructed using the C{'^'} operator.
 
    Example::
        # construct Or using '^' operator
        
        number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums))
        print(number.searchString("123 3.1416 789"))
    prints::
        [['123'], ['3.1416'], ['789']]
    Fcs:tt|ƒ ||¡|jr0tdd„|jDƒƒ|_nd|_dS)Ncss|] }|jVqdSr‰rórïryryrzrŒ… szOr.__init__.<locals>.<genexpr>T)rdrr­rìrbrªrîreryrzr­‚ sz Or.__init__Tc CsRd}d}g}|jD]š}z| ||¡}Wnvtk
rb}    zd|    _|    j|krR|    }|    j}W5d}    ~    XYqtk
rœt|ƒ|kr˜t|t|ƒ|j|ƒ}t|ƒ}YqX| ||f¡q|r(|j    dd„d|D]^\}
}z| 
|||¡WStk
r$}    z d|    _|    j|kr|    }|    j}W5d}    ~    XYqÈXqÈ|dk    r@|j|_ |‚nt||d|ƒ‚dS)NrtcSs
|d SrÒry)Úxryryrzr{ž r|zOr.parseImpl.<locals>.<lambda>)r ú no defined alternatives to match) rìrír!rôr¦rìrør°r$ÚsortrÈr§) r«rur¦rÂÚ    maxExcLocÚ maxExceptionr%rÙÚloc2réÚ_ryryrzrበs<
 
 
z Or.parseImplcCst|tƒrt |¡}| |¡Sr‰rør7ryryrzÚ__ixor__¯ s
 
z Or.__ixor__cCs@t|dƒr|jS|jdkr:dd dd„|jDƒ¡d|_|jS)NrÚrûz ^ css|]}t|ƒVqdSr‰r·rïryryrzrŒ¹ szOr.__str__.<locals>.<genexpr>rürýrµryryrzr¶´ s
 
 
 z
Or.__str__cCs,|dd…|g}|jD]}| |¡qdSr‰©rìrYrùryryrzrY½ s
zOr.checkRecursion)F)T)
r›rœrrÃr­rárr¶rYrryryrerzrt s  
&    csDeZdZdZd‡fdd„    Zddd„Zdd    „Zd
d „Zd d „Z‡Z    S)ra½
    Requires that at least one C{ParseExpression} is found.
    If two expressions match, the first one listed is the one that will match.
    May be constructed using the C{'|'} operator.
 
    Example::
        # construct MatchFirst using '|' operator
        
        # watch the order of expressions to match
        number = Word(nums) | Combine(Word(nums) + '.' + Word(nums))
        print(number.searchString("123 3.1416 789")) #  Fail! -> [['123'], ['3'], ['1416'], ['789']]
 
        # put more selective expression first
        number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums)
        print(number.searchString("123 3.1416 789")) #  Better -> [['123'], ['3.1416'], ['789']]
    Fcs:tt|ƒ ||¡|jr0tdd„|jDƒƒ|_nd|_dS)Ncss|] }|jVqdSr‰rórïryryrzrŒ× sz&MatchFirst.__init__.<locals>.<genexpr>T)rdrr­rìrbrªrîreryrzr­Ô szMatchFirst.__init__Tc     CsÆd}d}|jD]Ž}z| |||¡}|WStk
r`}z|j|krP|}|j}W5d}~XYqtk
ršt|ƒ|kr–t|t|ƒ|j|ƒ}t|ƒ}YqXq|dk    r´|j|_|‚nt||d|ƒ‚dS)Nrtrÿ)rìrÈr!r¦rìrør°r§)    r«rur¦rÂrrrÙr‡réryryrzráÛ s$
 
 
 zMatchFirst.parseImplcCst|tƒrt |¡}| |¡Sr‰rør7ryryrzÚ__ior__ó s
 
zMatchFirst.__ior__cCs@t|dƒr|jS|jdkr:dd dd„|jDƒ¡d|_|jS)NrÚrûú | css|]}t|ƒVqdSr‰r·rïryryrzrŒý sz%MatchFirst.__str__.<locals>.<genexpr>rürýrµryryrzr¶ø s
 
 
 zMatchFirst.__str__cCs,|dd…|g}|jD]}| |¡qdSr‰rrùryryrzrYs
zMatchFirst.checkRecursion)F)T)
r›rœrrÃr­rárr¶rYrryryrerzrà s 
    cs<eZdZdZd ‡fdd„    Zd dd„Zdd„Zd    d
„Z‡ZS) ram
    Requires all given C{ParseExpression}s to be found, but in any order.
    Expressions may be separated by whitespace.
    May be constructed using the C{'&'} operator.
 
    Example::
        color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN")
        shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON")
        integer = Word(nums)
        shape_attr = "shape:" + shape_type("shape")
        posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn")
        color_attr = "color:" + color("color")
        size_attr = "size:" + integer("size")
 
        # use Each (using operator '&') to accept attributes in any order 
        # (shape and posn are required, color and size are optional)
        shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr)
 
        shape_spec.runTests('''
            shape: SQUARE color: BLACK posn: 100, 120
            shape: CIRCLE size: 50 color: BLUE posn: 50,80
            color:GREEN size:20 shape:TRIANGLE posn:20,40
            '''
            )
    prints::
        shape: SQUARE color: BLACK posn: 100, 120
        ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']]
        - color: BLACK
        - posn: ['100', ',', '120']
          - x: 100
          - y: 120
        - shape: SQUARE
 
 
        shape: CIRCLE size: 50 color: BLUE posn: 50,80
        ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']]
        - color: BLUE
        - posn: ['50', ',', '80']
          - x: 50
          - y: 80
        - shape: CIRCLE
        - size: 50
 
 
        color: GREEN size: 20 shape: TRIANGLE posn: 20,40
        ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']]
        - color: GREEN
        - posn: ['20', ',', '40']
          - x: 20
          - y: 40
        - shape: TRIANGLE
        - size: 20
    Tcs8tt|ƒ ||¡tdd„|jDƒƒ|_d|_d|_dS)Ncss|] }|jVqdSr‰rórïryryrzrŒ?sz Each.__init__.<locals>.<genexpr>T)rdrr­rírìrªr§ÚinitExprGroupsrîreryrzr­=sz Each.__init__c    sî|jr’tdd„|jDƒƒ|_dd„|jDƒ}dd„|jDƒ}|||_dd„|jDƒ|_dd„|jDƒ|_dd„|jDƒ|_|j|j7_d    |_|}|jdd…}|jdd…‰g}d
}    |    rj|ˆ|j|j}
g} |
D]v} z|  ||¡}Wn t    k
r|  
| ¡YqÜX| 
|j  t | ƒ| ¡¡| |kr@|  | ¡qÜ| ˆkr܈  | ¡qÜt| ƒt|
ƒkrºd    }    qº|r”d  d d„|Dƒ¡} t    ||d | ƒ‚|‡fdd„|jDƒ7}g}|D]"} |  |||¡\}}| 
|¡q´t|tgƒƒ}||fS)Ncss&|]}t|tƒrt|jƒ|fVqdSr‰)r}rrirvrïryryrzrŒEs
z!Each.parseImpl.<locals>.<genexpr>cSsg|]}t|tƒr|j‘qSry©r}rrvrïryryrzrðFs
z"Each.parseImpl.<locals>.<listcomp>cSs g|]}|jrt|tƒs|‘qSry)rªr}rrïryryrzrðGs
cSsg|]}t|tƒr|j‘qSry)r}r4rvrïryryrzrðIs
cSsg|]}t|tƒr|j‘qSry)r}rrvrïryryrzrðJs
cSs g|]}t|tttfƒs|‘qSry)r}rr4rrïryryrzrðKsFTr:css|]}t|ƒVqdSr‰r·rïryryrzrŒfsz*Missing one or more required elements (%s)cs$g|]}t|tƒr|jˆkr|‘qSryr
rï©ÚtmpOptryrzrðjs
 
)r    rærìÚopt1mapÚ    optionalsÚmultioptionalsÚ multirequiredÚrequiredrír!r$ròriÚremoverørºrÈÚsumr$)r«rur¦rÂÚopt1Úopt2ÚtmpLocÚtmpReqdÚ
matchOrderÚ keepMatchingÚtmpExprsÚfailedrÙÚmissingrõr Ú finalResultsryr rzráCsP
 
  zEach.parseImplcCs@t|dƒr|jS|jdkr:dd dd„|jDƒ¡d|_|jS)NrÚrûz & css|]}t|ƒVqdSr‰r·rïryryrzrŒyszEach.__str__.<locals>.<genexpr>rürýrµryryrzr¶ts
 
 
 z Each.__str__cCs,|dd…|g}|jD]}| |¡qdSr‰rrùryryrzrY}s
zEach.checkRecursion)T)T)    r›rœrrÃr­rár¶rYrryryrerzrs
5
1    csleZdZdZd‡fdd„    Zddd„Zdd    „Z‡fd
d „Z‡fd d „Zdd„Z    gfdd„Z
‡fdd„Z ‡Z S)r za
    Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens.
    Fcsštt|ƒ |¡t|tƒr@ttjtƒr2t |¡}nt t    |ƒ¡}||_
d|_ |dk    r–|j |_ |j |_ | |j¡|j|_|j|_|j|_|j |j¡dSr‰)rdr r­r}rèÚ
issubclassr&r r.rrvr¤r¯rªrPr¨r§r¦r´r¬r&©r«rvr¶reryrzr­‡s
   zParseElementEnhance.__init__TcCs2|jdk    r|jj|||ddStd||j|ƒ‚dS)NFr r )rvrÈr!r°ràryryrzrá™s
zParseElementEnhance.parseImplcCs*d|_|j ¡|_|jdk    r&|j ¡|Sr)r§rvrérOrµryryrzrOŸs
 
 
z#ParseElementEnhance.leaveWhitespacecsrt|tƒrB||jkrntt|ƒ |¡|jdk    rn|j |jd¡n,tt|ƒ |¡|jdk    rn|j |jd¡|Sr )r}r-r¬rdr rRrvr7reryrzrR¦s
 
 
 
zParseElementEnhance.ignorecs&tt|ƒ ¡|jdk    r"|j ¡|Sr‰)rdr rrvrµreryrzr²s
 
zParseElementEnhance.streamlinecCsB||krt||gƒ‚|dd…|g}|jdk    r>|j |¡dSr‰)r(rvrY)r«rÉrúryryrzrY¸s
 
z"ParseElementEnhance.checkRecursioncCs6|dd…|g}|jdk    r(|j |¡| g¡dSr‰©rvr[rY©r«rZrñryryrzr[¿s
 zParseElementEnhance.validatecsXztt|ƒ ¡WStk
r$YnX|jdkrR|jdk    rRd|jjt|jƒf|_|jSrð)    rdr r¶r—r¤rvr”r›rˆrµreryrzr¶ÅszParseElementEnhance.__str__)F)T) r›rœrrÃr­rárOrRrrYr[r¶rryryrerzr ƒs
  cs*eZdZdZ‡fdd„Zddd„Z‡ZS)raõ
    Lookahead matching of the given parse expression.  C{FollowedBy}
    does I{not} advance the parsing position within the input string, it only
    verifies that the specified parse expression matches at the current
    position.  C{FollowedBy} always returns a null token list.
 
    Example::
        # use FollowedBy to match a label only if it is followed by a ':'
        data_word = Word(alphas)
        label = data_word + FollowedBy(':')
        attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
        
        OneOrMore(attr_expr).parseString("shape: SQUARE color: BLACK posn: upper left").pprint()
    prints::
        [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']]
    cstt|ƒ |¡d|_dSrÕ)rdrr­rª©r«rvreryrzr­ászFollowedBy.__init__TcCs|j ||¡|gfSr‰)rvríràryryrzráåszFollowedBy.parseImpl)Tr…ryryrerzrÐs cs2eZdZdZ‡fdd„Zd    dd„Zdd„Z‡ZS)
ra±
    Lookahead to disallow matching with the given parse expression.  C{NotAny}
    does I{not} advance the parsing position within the input string, it only
    verifies that the specified parse expression does I{not} match at the current
    position.  Also, C{NotAny} does I{not} skip over leading whitespace. C{NotAny}
    always returns a null token list.  May be constructed using the '~' operator.
 
    Example::
        
    cs0tt|ƒ |¡d|_d|_dt|jƒ|_dS)NFTzFound unwanted token, )rdrr­r§rªrˆrvr°r"reryrzr­õszNotAny.__init__TcCs&|j ||¡rt|||j|ƒ‚|gfSr‰)rvrîr!r°ràryryrzráüszNotAny.parseImplcCs4t|dƒr|jS|jdkr.dt|jƒd|_|jS)NrÚz~{rü©rrÚr¤rˆrvrµryryrzr¶s
 
 
zNotAny.__str__)Trºryryrerzrês
 
cs(eZdZd‡fdd„    Zddd„Z‡ZS)    Ú_MultipleMatchNcsFtt|ƒ |¡d|_|}t|tƒr.t |¡}|dk    r<|nd|_dSrÕ)    rdr$r­r¦r}rèr&r Ú    not_ender)r«rvÚstopOnÚenderreryrzr­ s 
 
z_MultipleMatch.__init__Tc     Cs¾|jj}|j}|jdk    }|r$|jj}|r2|||ƒ||||dd\}}zV|j }    |r`|||ƒ|    rp|||ƒ}
n|}
|||
|ƒ\}} | s|  ¡rR|| 7}qRWnttfk
r´YnX||fS©NFr )    rvrÈrÛr%rír¬rr!rì) r«rur¦rÂÚself_expr_parseÚself_skip_ignorablesÚ check_enderÚ try_not_enderrèÚhasIgnoreExprsræÚ    tmptokensryryrzrás*
 
 
 
  z_MultipleMatch.parseImpl)N)T)r›rœrr­rárryryrerzr$
sr$c@seZdZdZdd„ZdS)raƒ
    Repetition of one or more of the given expression.
    
    Parameters:
     - expr - expression that must match one or more times
     - stopOn - (default=C{None}) - expression for a terminating sentinel
          (only required if the sentinel would ordinarily match the repetition 
          expression)          
 
    Example::
        data_word = Word(alphas)
        label = data_word + FollowedBy(':')
        attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))
 
        text = "shape: SQUARE posn: upper left color: BLACK"
        OneOrMore(attr_expr).parseString(text).pprint()  # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]
 
        # use stopOn attribute for OneOrMore to avoid reading label string as part of the data
        attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
        OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']]
        
        # could also be written as
        (attr_expr * (1,)).parseString(text).pprint()
    cCs4t|dƒr|jS|jdkr.dt|jƒd|_|jS)NrÚrûz}...r#rµryryrzr¶Js
 
 
zOneOrMore.__str__N)r›rœrrÃr¶ryryryrzr0scs8eZdZdZd
‡fdd„    Zd ‡fdd„    Zdd    „Z‡ZS) r4aw
    Optional repetition of zero or more of the given expression.
    
    Parameters:
     - expr - expression that must match zero or more times
     - stopOn - (default=C{None}) - expression for a terminating sentinel
          (only required if the sentinel would ordinarily match the repetition 
          expression)          
 
    Example: similar to L{OneOrMore}
    Ncstt|ƒj||dd|_dS)N)r&T)rdr4r­rª)r«rvr&reryrzr­_szZeroOrMore.__init__Tc    s<ztt|ƒ |||¡WSttfk
r6|gfYSXdSr‰)rdr4rár!rìràreryrzrácszZeroOrMore.parseImplcCs4t|dƒr|jS|jdkr.dt|jƒd|_|jS)NrÚr9ú]...r#rµryryrzr¶is
 
 
zZeroOrMore.__str__)N)Trºryryrerzr4Ss c@s eZdZdd„ZeZdd„ZdS)Ú
_NullTokencCsdSrryrµryryrzrssz_NullToken.__bool__cCsdSr¥ryrµryryrzr¶vsz_NullToken.__str__N)r›rœrrrmr¶ryryryrzr0rsr0cs6eZdZdZef‡fdd„    Zd    dd„Zdd„Z‡ZS)
raa
    Optional matching of the given expression.
 
    Parameters:
     - expr - expression that must match zero or more times
     - default (optional) - value to be returned if the optional expression is not found.
 
    Example::
        # US postal code can be a 5-digit zip, plus optional 4-digit qualifier
        zip = Combine(Word(nums, exact=5) + Optional('-' + Word(nums, exact=4)))
        zip.runTests('''
            # traditional ZIP code
            12345
            
            # ZIP+4 form
            12101-0001
            
            # invalid ZIP
            98765-
            ''')
    prints::
        # traditional ZIP code
        12345
        ['12345']
 
        # ZIP+4 form
        12101-0001
        ['12101-0001']
 
        # invalid ZIP
        98765-
             ^
        FAIL: Expected end of text (at char 5), (line:1, col:6)
    cs.tt|ƒj|dd|jj|_||_d|_dS)NFrƒT)rdrr­rvr¦r!rª)r«rvrreryrzr­s
zOptional.__init__Tc    Cszz|jj|||dd\}}WnTttfk
rp|jtk    rh|jjr^t|jgƒ}|j||jj<ql|jg}ng}YnX||fSr()rvrÈr!rìr!Ú_optionalNotMatchedr¥r$)r«rur¦rÂrèryryrzrá£s
 
 
zOptional.parseImplcCs4t|dƒr|jS|jdkr.dt|jƒd|_|jS)NrÚr9r<r#rµryryrzr¶±s
 
 
zOptional.__str__)T)    r›rœrrÃr1r­rár¶rryryrerzrzs"
cs,eZdZdZd    ‡fdd„    Zd
dd„Z‡ZS) r*aÿ    
    Token for skipping over all undefined text until the matched expression is found.
 
    Parameters:
     - expr - target expression marking the end of the data to be skipped
     - include - (default=C{False}) if True, the target expression is also parsed 
          (the skipped text and target expression are returned as a 2-element list).
     - ignore - (default=C{None}) used to define grammars (typically quoted strings and 
          comments) that might contain false matches to the target expression
     - failOn - (default=C{None}) define expressions that are not allowed to be 
          included in the skipped test; if found before the target expression is found, 
          the SkipTo is not a match
 
    Example::
        report = '''
            Outstanding Issues Report - 1 Jan 2000
 
               # | Severity | Description                               |  Days Open
            -----+----------+-------------------------------------------+-----------
             101 | Critical | Intermittent system crash                 |          6
              94 | Cosmetic | Spelling error on Login ('log|n')         |         14
              79 | Minor    | System slow when running too many reports |         47
            '''
        integer = Word(nums)
        SEP = Suppress('|')
        # use SkipTo to simply match everything up until the next SEP
        # - ignore quoted strings, so that a '|' character inside a quoted string does not match
        # - parse action will call token.strip() for each matched token, i.e., the description body
        string_data = SkipTo(SEP, ignore=quotedString)
        string_data.setParseAction(tokenMap(str.strip))
        ticket_expr = (integer("issue_num") + SEP 
                      + string_data("sev") + SEP 
                      + string_data("desc") + SEP 
                      + integer("days_open"))
        
        for tkt in ticket_expr.searchString(report):
            print tkt.dump()
    prints::
        ['101', 'Critical', 'Intermittent system crash', '6']
        - days_open: 6
        - desc: Intermittent system crash
        - issue_num: 101
        - sev: Critical
        ['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14']
        - days_open: 14
        - desc: Spelling error on Login ('log|n')
        - issue_num: 94
        - sev: Cosmetic
        ['79', 'Minor', 'System slow when running too many reports', '47']
        - days_open: 47
        - desc: System slow when running too many reports
        - issue_num: 79
        - sev: Minor
    FNcs`tt|ƒ |¡||_d|_d|_||_d|_t|t    ƒrFt
  |¡|_ n||_ dt |jƒ|_dS)NTFzNo match found for )rdr*r­Ú
ignoreExprrªr¯Ú includeMatchrÛr}rèr&r ÚfailOnrˆrvr°)r«r+ÚincluderRr4reryrzr­ñs
zSkipTo.__init__Tc    Cs&|}t|ƒ}|j}|jj}|jdk    r,|jjnd}|jdk    rB|jjnd}    |}
|
|krÒ|dk    rf|||
ƒrfqâ|    dk    r˜z|    ||
ƒ}
Wqntk
r”Yq˜YqnXqnz|||
dddWqâtt    fk
rÌ|
d7}
YqJXqâqJt|||j
|ƒ‚|
}|||…} t | ƒ} |j r||||dd\}} | | 7} || fS)NF)rÂrÃrr ) rørvrÈr4rîr2rírr!rìr°r$r3)r«rur¦rÂrxrÞrvÚ
expr_parseÚself_failOn_canParseNextÚself_ignoreExpr_tryParseÚtmplocÚskiptextÚ
skipresultrŸryryrzráþs:
  zSkipTo.parseImpl)FNN)Tr…ryryrerzr*ºs6 csbeZdZdZd‡fdd„    Zdd„Zdd„Zd    d
„Zd d „Zgfd d„Z    dd„Z
‡fdd„Z ‡Z S)raK
    Forward declaration of an expression to be defined later -
    used for recursive grammars, such as algebraic infix notation.
    When the expression is known, it is assigned to the C{Forward} variable using the '<<' operator.
 
    Note: take care when assigning to C{Forward} not to overlook precedence of operators.
    Specifically, '|' has a lower precedence than '<<', so that::
        fwdExpr << a | b | c
    will actually be evaluated as::
        (fwdExpr << a) | b | c
    thereby leaving b and c out as parseable alternatives.  It is recommended that you
    explicitly group the values inserted into the C{Forward}::
        fwdExpr << (a | b | c)
    Converting to use the '<<=' operator instead will avoid this problem.
 
    See L{ParseResults.pprint} for an example of a recursive parser created using
    C{Forward}.
    Ncstt|ƒj|dddSr‚)rdrr­r7reryrzr­@szForward.__init__cCsjt|tƒrt |¡}||_d|_|jj|_|jj|_| |jj    ¡|jj
|_
|jj |_ |j   |jj ¡|Sr‰)r}rèr&r rvr¤r¯rªrPr¨r§r¦r¬r&r7ryryrzÚ
__lshift__Cs
 
 
 
 
 
zForward.__lshift__cCs||>Sr‰ryr7ryryrzÚ __ilshift__PszForward.__ilshift__cCs
d|_|SrrNrµryryrzrOSszForward.leaveWhitespacecCs$|js d|_|jdk    r |j ¡|SrÕ)r®rvrrµryryrzrWs
 
 
zForward.streamlinecCs>||kr0|dd…|g}|jdk    r0|j |¡| g¡dSr‰r r!ryryrzr[^s
 
 zForward.validatecCsVt|dƒr|jS|jjdSz|jdk    r4t|jƒ}nd}W5|j|_X|jjd|S)NrÚz: ...ÚNonez: )rrÚr”r›Z _revertClassÚ_ForwardNoRecurservrˆ)r«Ú    retStringryryrzr¶es
 
 
zForward.__str__cs.|jdk    rtt|ƒ ¡Stƒ}||K}|SdSr‰)rvrdrrérGreryrzrévs
 
z Forward.copy)N) r›rœrrÃr­r<r=rOrr[r¶rérryryrerzr-s  c@seZdZdd„ZdS)r?cCsdS)Nr·ryrµryryrzr¶sz_ForwardNoRecurse.__str__N)r›rœrr¶ryryryrzr?~sr?cs"eZdZdZd‡fdd„    Z‡ZS)r/zQ
    Abstract subclass of C{ParseExpression}, for converting parsed results.
    Fcstt|ƒ |¡d|_dSr)rdr/r­r¦rreryrzr­†szTokenConverter.__init__)Fr„ryryrerzr/‚scs6eZdZdZd
‡fdd„    Z‡fdd„Zdd    „Z‡ZS) r aÔ
    Converter to concatenate all matching tokens to a single string.
    By default, the matching patterns must also be contiguous in the input string;
    this can be disabled by specifying C{'adjacent=False'} in the constructor.
 
    Example::
        real = Word(nums) + '.' + Word(nums)
        print(real.parseString('3.1416')) # -> ['3', '.', '1416']
        # will also erroneously match the following
        print(real.parseString('3. 1416')) # -> ['3', '.', '1416']
 
        real = Combine(Word(nums) + '.' + Word(nums))
        print(real.parseString('3.1416')) # -> ['3.1416']
        # no match when there are internal spaces
        print(real.parseString('3. 1416')) # -> Exception: Expected W:(0123...)
    r Tcs8tt|ƒ |¡|r| ¡||_d|_||_d|_dSrÕ)rdr r­rOÚadjacentr§Ú
joinStringr´)r«rvrBrAreryrzr­›szCombine.__init__cs(|jrt ||¡ntt|ƒ |¡|Sr‰)rAr&rRrdr r7reryrzrR¥szCombine.ignorecCsP| ¡}|dd…=|td | |j¡¡g|jd7}|jrH| ¡rH|gS|SdS)Nr )rÜ)rér$rºr=rBr±r¥r)r«rur¦rãÚretToksryryrzrä¬s 
"zCombine.postParse)r T)r›rœrrÃr­rRrärryryrerzr Šs
cs(eZdZdZ‡fdd„Zdd„Z‡ZS)raù
    Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{OneOrMore}} expressions.
 
    Example::
        ident = Word(alphas)
        num = Word(nums)
        term = ident | num
        func = ident + Optional(delimitedList(term))
        print(func.parseString("fn a,b,100"))  # -> ['fn', 'a', 'b', '100']
 
        func = ident + Group(Optional(delimitedList(term)))
        print(func.parseString("fn a,b,100"))  # -> ['fn', ['a', 'b', '100']]
    cstt|ƒ |¡d|_dSrÕ)rdrr­r¦r"reryrzr­ÄszGroup.__init__cCs|gSr‰ryrâryryrzräÈszGroup.postParse©r›rœrrÃr­rärryryrerzr¶s cs(eZdZdZ‡fdd„Zdd„Z‡ZS)r aW
    Converter to return a repetitive expression as a list, but also as a dictionary.
    Each element can also be referenced using the first token in the expression as its key.
    Useful for tabular report scraping when the first column can be used as a item key.
 
    Example::
        data_word = Word(alphas)
        label = data_word + FollowedBy(':')
        attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))
 
        text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
        attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
        
        # print attributes as plain groups
        print(OneOrMore(attr_expr).parseString(text).dump())
        
        # instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names
        result = Dict(OneOrMore(Group(attr_expr))).parseString(text)
        print(result.dump())
        
        # access named fields as dict entries, or output as dict
        print(result['shape'])        
        print(result.asDict())
    prints::
        ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']
 
        [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
        - color: light blue
        - posn: upper left
        - shape: SQUARE
        - texture: burlap
        SQUARE
        {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}
    See more examples at L{ParseResults} of accessing fields by results name.
    cstt|ƒ |¡d|_dSrÕ)rdr r­r¦r"reryrzr­ïsz Dict.__init__cCsît|ƒD]Ð\}}t|ƒdkrq|d}t|tƒr@t|dƒ ¡}t|ƒdkr\td|ƒ||<qt|ƒdkrŠt|dtƒsŠt|d|ƒ||<q| ¡}|d=t|ƒdks¶t|tƒrÆ|     ¡rÆt||ƒ||<qt|d|ƒ||<q|j
ræ|gS|SdS)Nrrr rs) rýrør}rvrˆr»rÊr$rérr¥)r«rur¦rãrÐÚtokÚikeyÚ    dictvalueryryrzräós$ 
 zDict.postParserDryryrerzr Ës# c@s eZdZdZdd„Zdd„ZdS)r-aV
    Converter for ignoring the results of a parsed expression.
 
    Example::
        source = "a, b, c,d"
        wd = Word(alphas)
        wd_list1 = wd + ZeroOrMore(',' + wd)
        print(wd_list1.parseString(source))
 
        # often, delimiters that are useful during parsing are just in the
        # way afterward - use Suppress to keep them out of the parsed output
        wd_list2 = wd + ZeroOrMore(Suppress(',') + wd)
        print(wd_list2.parseString(source))
    prints::
        ['a', ',', 'b', ',', 'c', ',', 'd']
        ['a', 'b', 'c', 'd']
    (See also L{delimitedList}.)
    cCsgSr‰ryrâryryrzräszSuppress.postParsecCs|Sr‰ryrµryryrzrM"szSuppress.suppressN)r›rœrrÃrärMryryryrzr- sc@s(eZdZdZdd„Zdd„Zdd„ZdS)    rzI
    Wrapper for parse actions, to ensure they are only called once.
    cCst|ƒ|_d|_dSr)r›ÚcallableÚcalled)r«Ú
methodCallryryrzr­*s
zOnlyOnce.__init__cCs.|js| |||¡}d|_|St||dƒ‚dS)NTr )rIrHr!)r«rrrxr ryryrzrL-s
zOnlyOnce.__call__cCs
d|_dSr)rIrµryryrzÚreset3szOnlyOnce.resetN)r›rœrrÃr­rLrKryryryrzr&scs:tˆƒ‰‡fdd„}z ˆj|_Wntk
r4YnX|S)at
    Decorator for debugging parse actions. 
    
    When the parse action is called, this decorator will print C{">> entering I{method-name}(line:I{current_source_line}, I{parse_location}, I{matched_tokens})".}
    When the parse action completes, the decorator will print C{"<<"} followed by the returned value, or any exception that the parse action raised.
 
    Example::
        wd = Word(alphas)
 
        @traceParseAction
        def remove_duplicate_chars(tokens):
            return ''.join(sorted(set(''.join(tokens))))
 
        wds = OneOrMore(wd).setParseAction(remove_duplicate_chars)
        print(wds.parseString("slkdjs sld sldd sdlf sdljf"))
    prints::
        >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {}))
        <<leaving remove_duplicate_chars (ret: 'dfjkls')
        ['dfjkls']
    c
s´ˆj}|dd…\}}}t|ƒdkr8|djjd|}tj d|t||ƒ||f¡z ˆ|Ž}Wn8tk
rš}ztj d||f¡‚W5d}~XYnXtj d||f¡|S)Nr‚rqrÚ.z">>entering %s(line: '%s', %d, %r)
z<<leaving %s (exception: %s)
z<<leaving %s (ret: %r)
)r›rør”r‚ÚstderrÚwriterIr—)ÚpaArgsÚthisFuncrrrxr‡r|©raryrzÚzLs  ztraceParseAction.<locals>.z)r›r›r²)rarRryrQrzrd6s  ú,FcCs`t|ƒdt|ƒdt|ƒd}|rBt|t||ƒƒ |¡S|tt|ƒ|ƒ |¡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 C{combine=True} in the constructor.
    If C{combine} is set to C{True}, the matching tokens are returned as a single token
    string, with the delimiters included; otherwise, the matching tokens are returned
    as a list of tokens, with the delimiters suppressed.
 
    Example::
        delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc']
        delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
    z [rqr/N)rˆr r4rºr-)rvÚdelimÚcombineÚdlNameryryrzrBbs $csjtƒ‰‡‡fdd„}|dkr0ttƒ dd„¡}n| ¡}| d¡|j|dd|ˆ d    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 C{intExpr} is specified, it should be a pyparsing expression that produces an integer value.
 
    Example::
        countedArray(Word(alphas)).parseString('2 ab cd ef')  # -> ['ab', 'cd']
 
        # in this parser, the leading integer value is given in binary,
        # '10' indicating that 2 values are in the array
        binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2))
        countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef')  # -> ['ab', 'cd']
    cs.|d}ˆ|r ttˆg|ƒƒp&ttƒ>gSrÒ)rrrE)rrrxr<©Ú    arrayExprrvryrzÚcountFieldParseActionˆs"z+countedArray.<locals>.countFieldParseActionNcSs t|dƒSrÒ)rvrwryryrzr{r|zcountedArray.<locals>.<lambda>ÚarrayLenT©rµz(len) r·)rr1rTr„rérºrÎrˆ)rvÚintExprrYryrWrzr>us
cCs6g}|D](}t|tƒr&| t|ƒ¡q| |¡q|Sr‰)r}rãr&r*r$)ÚLr‡rÐryryrzr*”s 
 r*cs6tƒ‰‡fdd„}|j|ddˆ dt|ƒ¡ˆS)a*
    Helper to define an expression that is indirectly defined from
    the tokens matched in a previous expression, that is, it looks
    for a 'repeat' of a previous expression.  For example::
        first = Word(nums)
        second = matchPreviousLiteral(first)
        matchExpr = first + ":" + second
    will match C{"1:1"}, but not C{"1:2"}.  Because this matches a
    previous literal, will also match the leading C{"1:1"} in C{"1:10"}.
    If this is not desired, use C{matchPreviousExpr}.
    Do I{not} use with packrat parsing enabled.
    csP|rBt|ƒdkrˆ|d>qLt| ¡ƒ}ˆtdd„|Dƒƒ>n
ˆtƒ>dS)Nrrcss|]}t|ƒVqdSr‰)r©rŠÚttryryrzrŒ²szDmatchPreviousLiteral.<locals>.copyTokenToRepeater.<locals>.<genexpr>)rør*rÛrr)rrrxÚtflat©ÚrepryrzÚcopyTokenToRepeater«s   z1matchPreviousLiteral.<locals>.copyTokenToRepeaterTr[ú(prev) )rrÎrºrˆ)rvrcryrarzrQs
 
csFtƒ‰| ¡}ˆ|K‰‡fdd„}|j|ddˆ dt|ƒ¡ˆS)aS
    Helper to define an expression that is indirectly defined from
    the tokens matched in a previous expression, that is, it looks
    for a 'repeat' of a previous expression.  For example::
        first = Word(nums)
        second = matchPreviousExpr(first)
        matchExpr = first + ":" + second
    will match C{"1:1"}, but not C{"1:2"}.  Because this matches by
    expressions, will I{not} match the leading C{"1:1"} in C{"1:10"};
    the expressions are evaluated first, and then compared, so
    C{"1"} is compared with C{"10"}.
    Do I{not} use with packrat parsing enabled.
    cs*t| ¡ƒ‰‡fdd„}ˆj|dddS)Ncs$t| ¡ƒ}|ˆkr tdddƒ‚dS)Nr r)r*rÛr!)rrrxÚ theseTokens©Ú matchTokensryrzÚmustMatchTheseTokensÌs zLmatchPreviousExpr.<locals>.copyTokenToRepeater.<locals>.mustMatchTheseTokensTr[)r*rÛr„)rrrxrhrarfrzrcÊs  z.matchPreviousExpr.<locals>.copyTokenToRepeaterTr[rd)rrérÎrºrˆ)rvÚe2rcryrarzrP¹s cCs:dD]}| |t|¡}q| dd¡}| dd¡}t|ƒS)Nz\^-]rHrprÓrÖ)r“Ú_bslashrˆ)rr¤ryryrzr«Õs
  r«Tc
sÆ|rdd„}dd„}t‰ndd„}dd„}t‰g}t|tƒrF| ¡}n$t|tƒrZt|ƒ}ntjdt    dd|stt
ƒSd    }|t |ƒd
kr||}t ||d
d …ƒD]R\}}    ||    |ƒrÌ|||d
=qxq¦|||    ƒr¦|||d
=|  ||    ¡|    }qxq¦|d
7}qx|s¤|r¤zlt |ƒt d  |¡ƒkrTtd d  dd„|Dƒ¡ƒ d |¡¡WStd dd„|Dƒ¡ƒ d |¡¡WSWn&tk
r¢tjdt    ddYnXt‡fdd„|Dƒƒ d |¡¡S)aÛ
    Helper to quickly define a set of alternative Literals, and makes sure to do
    longest-first testing when there is a conflict, regardless of the input order,
    but returns a C{L{MatchFirst}} for best performance.
 
    Parameters:
     - strs - a string of space-delimited literals, or a collection of string literals
     - caseless - (default=C{False}) - treat all literals as caseless
     - useRegex - (default=C{True}) - as an optimization, will generate a Regex
          object; otherwise, will generate a C{MatchFirst} object (if C{caseless=True}, or
          if creating a C{Regex} raises an exception)
 
    Example::
        comp_oper = oneOf("< = > <= >= !=")
        var = Word(alphas)
        number = Word(nums)
        term = var | number
        comparison_expr = term + comp_oper + term
        print(comparison_expr.searchString("B = 12  AA=23 B<=AA AA>12"))
    prints::
        [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']]
    cSs| ¡| ¡kSr‰)r©r-Úbryryrzr{õr|zoneOf.<locals>.<lambda>cSs| ¡ | ¡¡Sr‰)rrŒrkryryrzr{ör|cSs||kSr‰ryrkryryrzr{ùr|cSs
| |¡Sr‰)rŒrkryryrzr{úr|z6Invalid argument to oneOf, expected string or iterablersr2rrNr z[%s]css|]}t|ƒVqdSr‰)r«©rŠÚsymryryrzrŒszoneOf.<locals>.<genexpr>rú|css|]}t |¡VqdSr‰)r³r­rmryryrzrŒsz7Exception creating Regex for oneOf, building MatchFirstc3s|]}ˆ|ƒVqdSr‰ryrm©ÚparseElementClassryrzrŒ$s)r
rr}rèr‘rrãr4r5r6rrørýr"rºr)rºr—r)
ÚstrsrÚuseRegexÚisequalÚmasksÚsymbolsrÐÚcurrr+ryrprzrUÝsT
 
 
 
ÿ
 
 
 **ÿ cCsttt||ƒƒƒ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 C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens
    in the proper order.  The key pattern can include delimiting markers or punctuation,
    as long as they are suppressed, thereby leaving the significant key text.  The value
    pattern can include named results, so that the C{Dict} results can include named token
    fields.
 
    Example::
        text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
        attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
        print(OneOrMore(attr_expr).parseString(text).dump())
        
        attr_label = label
        attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)
 
        # similar to Dict, but simpler call format
        result = dictOf(attr_label, attr_value).parseString(text)
        print(result.dump())
        print(result['shape'])
        print(result.shape)  # object attribute access works too
        print(result.asDict())
    prints::
        [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
        - color: light blue
        - posn: upper left
        - shape: SQUARE
        - texture: burlap
        SQUARE
        SQUARE
        {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'}
    )r r4r)r rryryrzrC&s!cCs^tƒ dd„¡}| ¡}d|_|dƒ||dƒ}|r@dd„}ndd„}| |¡|j|_|S)    a
    Helper to return the original, untokenized text for a given expression.  Useful to
    restore the parsed fields of an HTML start tag into the raw tag text itself, or to
    revert separate tokens with intervening whitespace back to the original matching
    input text. By default, returns astring containing the original parsed text.  
       
    If the optional C{asString} argument is passed as C{False}, then the return value is a 
    C{L{ParseResults}} containing any results names that were originally matched, and a 
    single token containing the original matched text from the input string.  So if 
    the expression passed to C{L{originalTextFor}} contains expressions with defined
    results names, you must set C{asString} to C{False} if you want to preserve those
    results name values.
 
    Example::
        src = "this is test <b> bold <i>text</i> </b> normal text "
        for tag in ("b","i"):
            opener,closer = makeHTMLTags(tag)
            patt = originalTextFor(opener + SkipTo(closer) + closer)
            print(patt.searchString(src)[0])
    prints::
        ['<b> bold <i>text</i> </b>']
        ['<i>text</i>']
    cSs|Sr‰ry)rr¦rxryryrzr{ar|z!originalTextFor.<locals>.<lambda>FÚ_original_startÚ _original_endcSs||j|j…Sr‰)rxryr~ryryrzr{fr|cSs&|| d¡| d¡…g|dd…<dS)Nrxry)rr~ryryrzÚ extractTexthsz$originalTextFor.<locals>.extractText)rr„rér´r¬)rvÚasStringÚ    locMarkerÚ endlocMarkerÚ    matchExprrzryryrzriIs
 
cCst|ƒ dd„¡S)zp
    Helper to undo pyparsing's default grouping of And expressions, even
    if all but one are non-empty.
    cSs|dSrÒryrwryryrzr{sr|zungroup.<locals>.<lambda>)r/r„)rvryryrzrjnscCs4tƒ dd„¡}t|dƒ|dƒ| ¡ ¡dƒƒS)a©
    Helper to decorate a returned token with its starting and ending locations in the input string.
    This helper adds the following results names:
     - locn_start = location where matched expression begins
     - locn_end = location where matched expression ends
     - value = the actual parsed results
 
    Be careful if the input text contains C{<TAB>} characters, you may want to call
    C{L{ParserElement.parseWithTabs}}
 
    Example::
        wd = Word(alphas)
        for match in locatedExpr(wd).searchString("ljsdf123lksdjjf123lkkjj1222"):
            print(match)
    prints::
        [[0, 'ljsdf', 5]]
        [[8, 'lksdjjf', 15]]
        [[18, 'lkkjj', 23]]
    cSs|Sr‰ryr~ryryrzr{‰r|zlocatedExpr.<locals>.<lambda>Ú
locn_startrÚlocn_end)rr„rrérO)rvÚlocatorryryrzrlusz\[]-*.$+^?()~ ©r±cCs |ddSr÷ryr~ryryrzr{”r|r{z\\0?[xX][0-9a-fA-F]+cCstt|d d¡dƒƒS)Nrz\0xé)ÚunichrrvÚlstripr~ryryrzr{•r|z    \\0[0-7]+cCstt|ddd…dƒƒS)Nrré)r„rvr~ryryrzr{–r|z\]ròr9rrÚnegateÚbodyr<csFdd„‰z"d ‡fdd„t |¡jDƒ¡WStk
r@YdSXdS)aÜ
    Helper to easily define string ranges for use in Word construction.  Borrows
    syntax from regexp '[]' string range definitions::
        srange("[0-9]")   -> "0123456789"
        srange("[a-z]")   -> "abcdefghijklmnopqrstuvwxyz"
        srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_"
    The input string must be enclosed in []'s, and the returned string is the expanded
    character set joined into a single string.
    The values enclosed in the []'s may be:
     - a single character
     - an escaped character with a leading backslash (such as C{\-} or C{\]})
     - an escaped hex character with a leading C{'\x'} (C{\x21}, which is a C{'!'} character) 
         (C{\0x##} is also supported for backwards compatibility) 
     - an escaped octal character with a leading C{'\0'} (C{\041}, which is a C{'!'} character)
     - a range of any of the above, separated by a dash (C{'a-z'}, etc.)
     - any combination of the above (C{'aeiouy'}, C{'a-zA-Z0-9_$'}, etc.)
    cSs<t|tƒs|Sd dd„tt|dƒt|dƒdƒDƒ¡S)Nr css|]}t|ƒVqdSr‰)r„r£ryryrzrŒ­sz+srange.<locals>.<lambda>.<locals>.<genexpr>rr)r}r$rºrùÚord)Úpryryrzr{­r|zsrange.<locals>.<lambda>r c3s|]}ˆ|ƒVqdSr‰ry)rŠÚpart©Ú    _expandedryrzrŒ¯szsrange.<locals>.<genexpr>N)rºÚ_reBracketExprrrˆr—r¸ryrŒrzra›s
"cs‡fdd„}|S)zt
    Helper method for defining parse actions that require matching at a specific
    column in the input text.
    cs"t||ƒˆkrt||dˆƒ‚dS)Nzmatched token not at column %drå)roÚlocnrzr;ryrzÚ    verifyCol¸sz!matchOnlyAtCol.<locals>.verifyColry)r<rryr;rzrO³s cs ‡fdd„S)a¹
    Helper method for common parse actions that simply return a literal value.  Especially
    useful when used with C{L{transformString<ParserElement.transformString>}()}.
 
    Example::
        num = Word(nums).setParseAction(lambda toks: int(toks[0]))
        na = oneOf("N/A NA").setParseAction(replaceWith(math.nan))
        term = na | num
        
        OneOrMore(term).parseString("324 234 N/A 234") # -> [324, 234, nan, 234]
    csˆgSr‰ryr~©ÚreplStrryrzr{Ér|zreplaceWith.<locals>.<lambda>ryr‘ryr‘rzr^½s cCs|ddd…S)a
    Helper parse action for removing quotation marks from parsed quoted strings.
 
    Example::
        # by default, quotation marks are included in parsed results
        quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"]
 
        # use removeQuotes to strip quotation marks from parsed results
        quotedString.setParseAction(removeQuotes)
        quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"]
    rrrtryr~ryryrzr\Ës csN‡‡fdd„}ztˆdtˆdƒjƒ}Wntk
rBtˆƒ}YnX||_|S)aG
    Helper to define a parse action by mapping a function to all elements of a ParseResults list.If any additional 
    args are passed, they are forwarded to the given function as additional arguments after
    the token, as in C{hex_integer = Word(hexnums).setParseAction(tokenMap(int, 16))}, which will convert the
    parsed data to an integer using base 16.
 
    Example (compare the last to example in L{ParserElement.transformString}::
        hex_ints = OneOrMore(Word(hexnums)).setParseAction(tokenMap(int, 16))
        hex_ints.runTests('''
            00 11 22 aa FF 0a 0d 1a
            ''')
        
        upperword = Word(alphas).setParseAction(tokenMap(str.upper))
        OneOrMore(upperword).runTests('''
            my kingdom for a horse
            ''')
 
        wd = Word(alphas).setParseAction(tokenMap(str.title))
        OneOrMore(wd).setParseAction(' '.join).runTests('''
            now is the winter of our discontent made glorious summer by this sun of york
            ''')
    prints::
        00 11 22 aa FF 0a 0d 1a
        [0, 17, 34, 170, 255, 10, 13, 26]
 
        my kingdom for a horse
        ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE']
 
        now is the winter of our discontent made glorious summer by this sun of york
        ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York']
    cs‡‡fdd„|DƒS)Ncsg|]}ˆ|fˆžŽ‘qSryry)rŠÚtokn©rªr€ryrzrðúsz(tokenMap.<locals>.pa.<locals>.<listcomp>ryr~r”ryrzrÔùsztokenMap.<locals>.par›r”)r–r›r—r)r€rªrÔršryr”rzroÙs 
ÿcCs t|ƒ ¡Sr‰©rˆrrwryryrzr{r|cCs t|ƒ ¡Sr‰©rˆÚlowerrwryryrzr{r|c    Cs¢t|tƒr|}t|| d}n|j}tttdƒ}|r˜t ¡     t
¡}t dƒ|dƒt t t|t dƒ|ƒƒƒtddgd d    ¡     d
d „¡t d ƒ}n†d  dd„tDƒ¡}t ¡     t
¡t|ƒB}t dƒ|dƒt t t|     t¡tt dƒ|ƒƒƒƒtddgd d    ¡     dd „¡t d ƒ}ttdƒ|d ƒ}| dd  | dd¡ ¡ ¡¡¡ d|¡}| dd  | dd¡ ¡ ¡¡¡ d|¡}||_||_||fS)zRInternal helper to construct opening and closing tag expressions, given a tag namer•z_-:rLÚtagú=ú/F©rrEcSs |ddkS©Nrršryr~ryryrzr{r|z_makeTags.<locals>.<lambda>rMr css|]}|dkr|VqdS)rMNryr£ryryrzrŒsz_makeTags.<locals>.<genexpr>cSs |ddkSrœryr~ryryrzr{r|rNršú:rqz<%s>r²z</%s>)r}rèrrÚr1r6r5r@rér„r\r-r r4rrr¿rºrXr[rDr Ú_Lr“Útitler‘rºr˜)ÚtagStrÚxmlÚresnameÚ tagAttrNameÚ tagAttrValueÚopenTagZprintablesLessRAbrackÚcloseTagryryrzÚ    _makeTags s>
ÿþþÿÿýý..r§cCs
t|dƒS)a 
    Helper to construct opening and closing tag expressions for HTML, given a tag name. Matches
    tags in either upper or lower case, attributes with namespaces and with quoted or unquoted values.
 
    Example::
        text = '<td>More info at the <a href="http://pyparsing.wikispaces.com">pyparsing</a> wiki page</td>'
        # makeHTMLTags returns pyparsing expressions for the opening and closing tags as a 2-tuple
        a,a_end = makeHTMLTags("A")
        link_expr = a + SkipTo(a_end)("link_text") + a_end
        
        for link in link_expr.searchString(text):
            # attributes in the <A> tag (like "href" shown here) are also accessible as named results
            print(link.link_text, '->', link.href)
    prints::
        pyparsing -> http://pyparsing.wikispaces.com
    F©r§©r ryryrzrM(scCs
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 L{makeHTMLTags}
    Tr¨r©ryryrzrN;scs8|r|dd…‰n| ¡‰dd„ˆDƒ‰‡fdd„}|S)a<
    Helper to create a validating parse action to be used with start tags created
    with C{L{makeXMLTags}} or C{L{makeHTMLTags}}. Use C{withAttribute} to qualify a starting tag
    with a required attribute value, to avoid false matches on common tags such as
    C{<TD>} or C{<DIV>}.
 
    Call C{withAttribute} with a series of attribute names and values. Specify the list
    of filter attributes names and values as:
     - keyword arguments, as in C{(align="right")}, or
     - as an explicit dict with C{**} operator, when an attribute name is also a Python
          reserved word, as in C{**{"class":"Customer", "align":"right"}}
     - a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") )
    For attribute names with a namespace prefix, you must use the second form.  Attribute
    names are matched insensitive to upper/lower case.
       
    If just testing for C{class} (with or without a namespace), use C{L{withClass}}.
 
    To verify that the attribute exists, but without specifying a value, pass
    C{withAttribute.ANY_VALUE} as the value.
 
    Example::
        html = '''
            <div>
            Some text
            <div type="grid">1 4 0 1 0</div>
            <div type="graph">1,3 2,3 1,1</div>
            <div>this has no type</div>
            </div>
                
        '''
        div,div_end = makeHTMLTags("div")
 
        # only match div tag having a type attribute with value "grid"
        div_grid = div().setParseAction(withAttribute(type="grid"))
        grid_expr = div_grid + SkipTo(div | div_end)("body")
        for grid_header in grid_expr.searchString(html):
            print(grid_header.body)
        
        # construct a match with any div tag having a type attribute, regardless of the value
        div_any_type = div().setParseAction(withAttribute(type=withAttribute.ANY_VALUE))
        div_expr = div_any_type + SkipTo(div | div_end)("body")
        for div_header in div_expr.searchString(html):
            print(div_header.body)
    prints::
        1 4 0 1 0
 
        1 4 0 1 0
        1,3 2,3 1,1
    NcSsg|]\}}||f‘qSryryrDryryrzrðzsz!withAttribute.<locals>.<listcomp>csZˆD]P\}}||kr$t||d|ƒ‚|tjkr|||krt||d||||fƒ‚qdS)Nzno matching attribute z+attribute '%s' has value '%s', must be '%s')r!rgÚ    ANY_VALUE)rrrèÚattrNameÚ    attrValue©ÚattrsryrzrÔ{s  ÿzwithAttribute.<locals>.pa)rü)rªÚattrDictrÔryr­rzrgDs 2 cCs|r d|nd}tf||iŽS)aã
    Simplified version of C{L{withAttribute}} when matching on a div class - made
    difficult because C{class} is a reserved word in Python.
 
    Example::
        html = '''
            <div>
            Some text
            <div class="grid">1 4 0 1 0</div>
            <div class="graph">1,3 2,3 1,1</div>
            <div>this &lt;div&gt; has no class</div>
            </div>
                
        '''
        div,div_end = makeHTMLTags("div")
        div_grid = div().setParseAction(withClass("grid"))
        
        grid_expr = div_grid + SkipTo(div | div_end)("body")
        for grid_header in grid_expr.searchString(html):
            print(grid_header.body)
        
        div_any_type = div().setParseAction(withClass(withAttribute.ANY_VALUE))
        div_expr = div_any_type + SkipTo(div | div_end)("body")
        for div_header in div_expr.searchString(html):
            print(div_header.body)
    prints::
        1 4 0 1 0
 
        1 4 0 1 0
        1,3 2,3 1,1
    z%s:classÚclass)rg)Ú    classnameÚ    namespaceÚ    classattrryryrzrm…s ú(rÄcCsštƒ}||||B}t|ƒD]l\}}|ddd…\}}    }
} |    dkrPd|nd|} |    dkr„|dkstt|ƒdkr|tdƒ‚|\} }tƒ | ¡}|
tjkr^|    d    krÂt||ƒt|t    |ƒƒ}nš|    dkr|dk    rút|||ƒt|t    ||ƒƒ}nt||ƒt|t    |ƒƒ}nD|    dkrTt|| |||ƒt|| |||ƒ}ntd
ƒ‚nì|
tj
krB|    d    kr¤t |t ƒsˆt |ƒ}t|j |ƒt||ƒ}nœ|    dkrü|dk    rÞt|||ƒt|t    ||ƒƒ}nt||ƒt|t    |ƒƒ}nD|    dkr8t|| |||ƒt|| |||ƒ}ntd
ƒ‚ntd ƒ‚| rvt | ttfƒrl|j| Žn
| | ¡|| | ¡|BK}|}q||K}|S) aD
 
    Helper method for constructing grammars of expressions made up of
    operators working in a precedence hierarchy.  Operators may be unary or
    binary, left- or right-associative.  Parse actions can also be attached
    to operator expressions. The generated parser will also recognize the use 
    of parentheses to override operator precedences (see example below).
    
    Note: if you define a deep operator list, you may see performance issues
    when using infixNotation. See L{ParserElement.enablePackrat} for a
    mechanism to potentially improve your parser performance.
 
    Parameters:
     - baseExpr - expression representing the most basic element for the nested
     - opList - list of tuples, one for each operator precedence level in the
      expression grammar; each tuple is of the form
      (opExpr, numTerms, rightLeftAssoc, parseAction), where:
       - opExpr is the pyparsing expression for the operator;
          may also be a string, which will be converted to a Literal;
          if numTerms is 3, opExpr is a tuple of two expressions, for the
          two operators separating the 3 terms
       - numTerms is the number of terms for this operator (must
          be 1, 2, or 3)
       - rightLeftAssoc is the indicator whether the operator is
          right or left associative, using the pyparsing-defined
          constants C{opAssoc.RIGHT} and C{opAssoc.LEFT}.
       - parseAction is the parse action to be associated with
          expressions matching this operator expression (the
          parse action tuple member may be omitted); if the parse action
          is passed a tuple or list of functions, this is equivalent to
          calling C{setParseAction(*fn)} (L{ParserElement.setParseAction})
     - lpar - expression for matching left-parentheses (default=C{Suppress('(')})
     - rpar - expression for matching right-parentheses (default=C{Suppress(')')})
 
    Example::
        # simple example of four-function arithmetic with ints and variable names
        integer = pyparsing_common.signed_integer
        varname = pyparsing_common.identifier 
        
        arith_expr = infixNotation(integer | varname,
            [
            ('-', 1, opAssoc.RIGHT),
            (oneOf('* /'), 2, opAssoc.LEFT),
            (oneOf('+ -'), 2, opAssoc.LEFT),
            ])
        
        arith_expr.runTests('''
            5+3*6
            (5+3)*6
            -2--11
            ''', fullDump=False)
    prints::
        5+3*6
        [[5, '+', [3, '*', 6]]]
 
        (5+3)*6
        [[[5, '+', 3], '*', 6]]
 
        -2--11
        [[['-', 2], '-', ['-', 11]]]
    r‰Nr¶rqz%s termz    %s%s termrsz@if numterms=3, opExpr must be a tuple or list of two expressionsrz6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)rrýrør@rºrVÚLEFTrrrÚRIGHTr}rrvr?rãr„)ÚbaseExprÚopListÚlparÚrparr‡ÚlastExprrÐÚoperDefÚopExprÚarityÚrightLeftAssocrÔÚtermNameÚopExpr1ÚopExpr2ÚthisExprr~ryryrzrk¬sZ=  
&
ÿ
 
 
 
&
ÿ
 
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 quotesÚuzunicode string literalcCsž||krtdƒ‚|dkr*t|tƒr"t|tƒr"t|ƒdkr¨t|ƒdkr¨|dk    r‚tt|t||tjddƒƒ     dd„¡}n$t
  ¡t||tjƒ     dd„¡}nx|dk    rìtt|t |ƒt |ƒttjddƒƒ     dd„¡}n4ttt |ƒt |ƒttjddƒƒ     d    d„¡}ntd
ƒ‚t ƒ}|dk    rd|tt|ƒt||B|Bƒt|ƒƒK}n$|tt|ƒt||Bƒt|ƒƒK}| d ||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=C{"("}); can also be a pyparsing expression
     - closer - closing character for a nested list (default=C{")"}); can also be a pyparsing expression
     - content - expression for items within the nested lists (default=C{None})
     - ignoreExpr - expression for ignoring opening and closing delimiters (default=C{quotedString})
 
    If an expression is not provided for the content argument, the nested
    expression will capture all whitespace-delimited content between delimiters
    as a list of separate values.
 
    Use the C{ignoreExpr} argument to define expressions that may contain
    opening or closing characters that should not be treated as opening
    or closing characters for nesting, such as quotedString or a comment
    expression.  Specify multiple expressions using an C{L{Or}} or C{L{MatchFirst}}.
    The default is L{quotedString}, but if no expressions are to be ignored,
    then pass C{None} for this argument.
 
    Example::
        data_type = oneOf("void int short long char float double")
        decl_data_type = Combine(data_type + Optional(Word('*')))
        ident = Word(alphas+'_', alphanums+'_')
        number = pyparsing_common.number
        arg = Group(decl_data_type + ident)
        LPAR,RPAR = map(Suppress, "()")
 
        code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment))
 
        c_function = (decl_data_type("type") 
                      + ident("name")
                      + LPAR + Optional(delimitedList(arg), [])("args") + RPAR 
                      + code_body("body"))
        c_function.ignore(cStyleComment)
        
        source_code = '''
            int is_odd(int x) { 
                return (x%2); 
            }
                
            int dec_to_hex(char hchar) { 
                if (hchar >= '0' && hchar <= '9') { 
                    return (ord(hchar)-ord('0')); 
                } else { 
                    return (10+ord(hchar)-ord('A'));
                } 
            }
        '''
        for func in c_function.searchString(source_code):
            print("%(name)s (%(type)s) args: %(args)s" % func)
 
    prints::
        is_odd (int) args: [['int', 'x']]
        dec_to_hex (int) args: [['char', 'hchar']]
    z.opening and closing strings cannot be the sameNrr‚cSs |d ¡SrÒ©r»rwryryrzr{gr|znestedExpr.<locals>.<lambda>cSs |d ¡SrÒrÇrwryryrzr{jr|cSs |d ¡SrÒrÇrwryryrzr{pr|cSs |d ¡SrÒrÇrwryryrzr{tr|zOopening and closing arguments must be strings if no content expression is givenznested %s%s expression)r@r}rèrør rr r&rœr„rErérrrr-r4rº)ÚopenerÚcloserÚcontentr2r‡ryryrzrR%sH:
ÿþÿÿÿ þý ÿþ
*$c sä‡fdd„}‡fdd„}‡fdd„}ttƒ d¡ ¡ƒ}tƒtƒ |¡ d¡}tƒ |¡ d    ¡}tƒ |¡ d
¡}    |r¦tt|ƒ|t|t|ƒt|ƒƒ|    ƒ}
n$tt|ƒt|t|ƒt|ƒƒƒ}
|     t
tƒ¡|
 d ¡S) a
    
    Helper method for defining space-delimited indentation blocks, such as
    those used to define block statements in Python source code.
 
    Parameters:
     - blockStatementExpr - expression defining syntax of statement that
            is repeated within the indented block
     - indentStack - list created by caller to manage indentation stack
            (multiple statementWithIndentedBlock expressions within a single grammar
            should share a common indentStack)
     - indent - boolean indicating whether block must be indented beyond the
            the current level; set to False for block of left-most statements
            (default=C{True})
 
    A valid block must contain at least one C{blockStatement}.
 
    Example::
        data = '''
        def A(z):
          A1
          B = 100
          G = A2
          A2
          A3
        B
        def BB(a,b,c):
          BB1
          def BBA():
            bba1
            bba2
            bba3
        C
        D
        def spam(x,y):
             def eggs(z):
                 pass
        '''
 
 
        indentStack = [1]
        stmt = Forward()
 
        identifier = Word(alphas, alphanums)
        funcDecl = ("def" + identifier + Group( "(" + Optional( delimitedList(identifier) ) + ")" ) + ":")
        func_body = indentedBlock(stmt, indentStack)
        funcDef = Group( funcDecl + func_body )
 
        rvalue = Forward()
        funcCall = Group(identifier + "(" + Optional(delimitedList(rvalue)) + ")")
        rvalue << (funcCall | identifier | Word(nums))
        assignment = Group(identifier + "=" + rvalue)
        stmt << ( funcDef | assignment | identifier )
 
        module_body = OneOrMore(stmt)
 
        parseTree = module_body.parseString(data)
        parseTree.pprint()
    prints::
        [['def',
          'A',
          ['(', 'z', ')'],
          ':',
          [['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]],
         'B',
         ['def',
          'BB',
          ['(', 'a', 'b', 'c', ')'],
          ':',
          [['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]],
         'C',
         'D',
         ['def',
          'spam',
          ['(', 'x', 'y', ')'],
          ':',
          [[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]] 
    csN|t|ƒkrdSt||ƒ}|ˆdkrJ|ˆdkr>t||dƒ‚t||dƒ‚dS)Nrtzillegal nestingznot a peer entry)rør;r#r!©rrrxÚcurCol©Ú indentStackryrzÚcheckPeerIndentÍs 
   z&indentedBlock.<locals>.checkPeerIndentcs2t||ƒ}|ˆdkr"ˆ |¡n t||dƒ‚dS)Nrtznot a subentry)r;r$r!rËrÍryrzÚcheckSubIndentÕs
  z%indentedBlock.<locals>.checkSubIndentcsN|t|ƒkrdSt||ƒ}ˆr6|ˆdkr6|ˆdksBt||dƒ‚ˆ ¡dS)Nrtrƒznot an unindent)rør;r!rrËrÍryrzÚ checkUnindentÜs  
 z$indentedBlock.<locals>.checkUnindentz     ÚINDENTr ÚUNINDENTzindented block) rrrPrMrr„rºrrrRrj) ÚblockStatementExprrÎrRrÏrÐrÑrerÒÚPEERÚUNDENTÚsmExprryrÍrzrhs(N   þþþÿz#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]z_:zany tagzgt lt amp nbsp quot aposz><& "'z &(?P<entity>roz);zcommon HTML entitycCs t |j¡S)zRHelper parser action to replace common HTML entities with their special characters)Ú_htmlEntityMapròÚentityrwryryrzr]÷sz/\*(?:[^*]|\*(?!/))*z*/zC style commentz<!--[\s\S]*?-->z HTML commentz.*z rest of linez//(?:\\\n|[^\n])*z
// commentzC++ style commentz#.*zPython style commentr¡ú     Ú    commaItemr›c@s¨eZdZdZeeƒZeeƒZe    e
ƒ  d¡  e¡Z e    eƒ  d¡  eedƒ¡Zedƒ  d¡  e¡Zeƒ  e¡deƒ  e¡  d¡Ze d    d
„¡eeeed ƒ ¡eƒB  d ¡Ze e¡ed ƒ  d¡  e¡Zedƒ  d¡  e¡ZeeBeB ¡Zedƒ  d¡  e¡Ze    ededƒ  d¡Zedƒ  d¡Z edƒ  d¡Z!e!de!d  d¡Z"ee!de!dƒdee!de!dƒ  d¡Z#e# $dd
„¡d e   d!¡Z%e&e"e%Be#B  d"¡ƒ  d"¡Z'ed#ƒ  d$¡Z(e)d=d&d'„ƒZ*e)d>d)d*„ƒZ+ed+ƒ  d,¡Z,ed-ƒ  d.¡Z-ed/ƒ  d0¡Z.e/ ¡e0 ¡BZ1e)d1d2„ƒZ2e&e3e4d3ƒe5ƒe    e6d3d4ee7d5ƒƒƒƒ ¡  d6¡Z8e9ee: ;¡e8Bd7d8ƒ  d9¡Z<e)ed:d
„ƒƒZ=e)ed;d
„ƒƒZ>d<S)?rpa®
 
    Here are some common low-level expressions that may be useful in jump-starting parser development:
     - numeric forms (L{integers<integer>}, L{reals<real>}, L{scientific notation<sci_real>})
     - common L{programming identifiers<identifier>}
     - network addresses (L{MAC<mac_address>}, L{IPv4<ipv4_address>}, L{IPv6<ipv6_address>})
     - ISO8601 L{dates<iso8601_date>} and L{datetime<iso8601_datetime>}
     - L{UUID<uuid>}
     - L{comma-separated list<comma_separated_list>}
    Parse actions:
     - C{L{convertToInteger}}
     - C{L{convertToFloat}}
     - C{L{convertToDate}}
     - C{L{convertToDatetime}}
     - C{L{stripHTMLTags}}
     - C{L{upcaseTokens}}
     - C{L{downcaseTokens}}
 
    Example::
        pyparsing_common.number.runTests('''
            # any int or real number, returned as the appropriate type
            100
            -100
            +100
            3.14159
            6.02e23
            1e-12
            ''')
 
        pyparsing_common.fnumber.runTests('''
            # any int or real number, returned as float
            100
            -100
            +100
            3.14159
            6.02e23
            1e-12
            ''')
 
        pyparsing_common.hex_integer.runTests('''
            # hex numbers
            100
            FF
            ''')
 
        pyparsing_common.fraction.runTests('''
            # fractions
            1/2
            -3/4
            ''')
 
        pyparsing_common.mixed_integer.runTests('''
            # mixed fractions
            1
            1/2
            -3/4
            1-3/4
            ''')
 
        import uuid
        pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID))
        pyparsing_common.uuid.runTests('''
            # uuid
            12345678-1234-5678-1234-567812345678
            ''')
    prints::
        # any int or real number, returned as the appropriate type
        100
        [100]
 
        -100
        [-100]
 
        +100
        [100]
 
        3.14159
        [3.14159]
 
        6.02e23
        [6.02e+23]
 
        1e-12
        [1e-12]
 
        # any int or real number, returned as float
        100
        [100.0]
 
        -100
        [-100.0]
 
        +100
        [100.0]
 
        3.14159
        [3.14159]
 
        6.02e23
        [6.02e+23]
 
        1e-12
        [1e-12]
 
        # hex numbers
        100
        [256]
 
        FF
        [255]
 
        # fractions
        1/2
        [0.5]
 
        -3/4
        [-0.75]
 
        # mixed fractions
        1
        [1]
 
        1/2
        [0.5]
 
        -3/4
        [-0.75]
 
        1-3/4
        [1.75]
 
        # uuid
        12345678-1234-5678-1234-567812345678
        [UUID('12345678-1234-5678-1234-567812345678')]
    Úintegerz hex integerrƒz[+-]?\d+zsigned integerršÚfractioncCs|d|dS)Nrrtryrwryryrzr{´r|zpyparsing_common.<lambda>ròz"fraction or mixed integer-fractionz [+-]?\d+\.\d*z real numberz+[+-]?\d+([eE][+-]?\d+|\.\d*([eE][+-]?\d+)?)z$real number with scientific notationz[+-]?\d+\.?\d*([eE][+-]?\d+)?ÚfnumberrÚ
identifierzK(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}z IPv4 addressz[0-9a-fA-F]{1,4}Ú hex_integerrézfull IPv6 address)rrz::zshort IPv6 addresscCstdd„|DƒƒdkS)Ncss|]}tj |¡rdVqdSrI)rpÚ
_ipv6_partr%r^ryryrzrŒÐs z,pyparsing_common.<lambda>.<locals>.<genexpr>r†)rrwryryrzr{Ðr|z::ffff:zmixed IPv6 addressz IPv6 addressz:[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}z MAC addressú%Y-%m-%dcs‡fdd„}|S)aØ
        Helper to create a parse action for converting parsed date string to Python datetime.date
 
        Params -
         - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%d"})
 
        Example::
            date_expr = pyparsing_common.iso8601_date.copy()
            date_expr.setParseAction(pyparsing_common.convertToDate())
            print(date_expr.parseString("1999-12-31"))
        prints::
            [datetime.date(1999, 12, 31)]
        c
sNzt |dˆ¡ ¡WStk
rH}zt||t|ƒƒ‚W5d}~XYnXdSrÒ)rÚstrptimeÚdater@r!r©rrrxÚve©ÚfmtryrzÚcvt_fnçsz.pyparsing_common.convertToDate.<locals>.cvt_fnry©rérêryrèrzÚ convertToDateØs zpyparsing_common.convertToDateú%Y-%m-%dT%H:%M:%S.%fcs‡fdd„}|S)a
        Helper to create a parse action for converting parsed datetime string to Python datetime.datetime
 
        Params -
         - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%dT%H:%M:%S.%f"})
 
        Example::
            dt_expr = pyparsing_common.iso8601_datetime.copy()
            dt_expr.setParseAction(pyparsing_common.convertToDatetime())
            print(dt_expr.parseString("1999-12-31T23:59:59.999"))
        prints::
            [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)]
        c
sJzt |dˆ¡WStk
rD}zt||t|ƒƒ‚W5d}~XYnXdSrÒ)rrär@r!rrærèryrzrêýsz2pyparsing_common.convertToDatetime.<locals>.cvt_fnryrëryrèrzÚconvertToDatetimeîs z"pyparsing_common.convertToDatetimez7(?P<year>\d{4})(?:-(?P<month>\d\d)(?:-(?P<day>\d\d))?)?z ISO8601 datez†(?P<year>\d{4})-(?P<month>\d\d)-(?P<day>\d\d)[T ](?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d(\.\d*)?)?)?(?P<tz>Z|[+-]\d\d:?\d\d)?zISO8601 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}ÚUUIDcCstj |d¡S)a
        Parse action to remove HTML tags from web page HTML source
 
        Example::
            # strip HTML links from normal text 
            text = '<td>More info at the <a href="http://pyparsing.wikispaces.com">pyparsing</a> wiki page</td>'
            td,td_end = makeHTMLTags("TD")
            table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end
            
            print(table_text.parseString(text).body) # -> 'More info at the pyparsing wiki page'
        r)rpÚ_html_stripperr…)rrrèryryrzÚ stripHTMLTagss zpyparsing_common.stripHTMLTagsrSr¡rÚrÛr r›zcomma separated listcCs t|ƒ ¡Sr‰r•rwryryrzr{"r|cCs t|ƒ ¡Sr‰r–rwryryrzr{%r|N)rã)rí)?r›rœrrÃrorvÚconvertToIntegerÚfloatÚconvertToFloatr1rTrºr„rÜrFràr)Úsigned_integerrÝrÎrrMÚ mixed_integerrÚrealÚsci_realrÚnumberrÞr6r5rßÚ ipv4_addressrâÚ_full_ipv6_addressÚ_short_ipv6_addressrÕÚ_mixed_ipv6_addressr Ú ipv6_addressÚ mac_addressrrìrîÚ iso8601_dateÚiso8601_datetimeÚuuidr9r8rðrñrrrrXr0Ú _commasepitemrBr[réÚcomma_separated_listrfrDryryryrzrpsV""
2  
 
ÿ ÿÚ__main__ÚselectÚfromrrL)rUÚcolumnsr»ZtablesÚcommandaK
        # '*' as column list and dotted table name
        select * from SYS.XYZZY
 
        # caseless match on "SELECT", and casts back to "select"
        SELECT * from XYZZY, ABC
 
        # list of column names, and mixed case SELECT keyword
        Select AA,BB,CC from Sys.dual
 
        # multiple tables
        Select A, B, C from Sys.dual, Table2
 
        # invalid SELECT keyword - should fail
        Xelect A, B, C from Sys.dual
 
        # incomplete command - should fail
        Select
 
        # invalid column name - should fail
        Select ^^^ frox Sys.dual
 
        z]
        100
        -100
        +100
        3.14159
        6.02e23
        1e-12
        z 
        100
        FF
        z6
        12345678-1234-5678-1234-567812345678
        )rs)rSF)N)FT)T)r )T)ãrÃÚ __version__Ú__versionTime__Ú
__author__r¡Úweakrefrrórér‚r4r³r¾r rfr‡rúrÚ_threadrÚ ImportErrorÚ    threadingÚcollections.abcrrrrZ ordereddictÚ__all__r?Ú version_infor†rEÚmaxsizer€rrèÚchrr„rˆrrør`Úreversedrãrörbrír¯r°r•ZmaxintÚxrangerùÚ __builtin__r‘Úfnamer$r–r²rÁrår™rÖršÚascii_uppercaseÚascii_lowercaser6rTrFr5rjrºÚ    printablerXr—rr!r#r%r(rÊr$Úregisterr;rLrIrwr{r}rSr›r&r.rrrržr rr
r    rnr1r)r'r r0rárrrr,r+r3r2r"rrrrr rrr$rr4r0r1rr*rr?r/r rr r-rrdrBr>r*rQrPr«rUrCrirjrlrºrErKrJrcrbr„Ú _escapedPuncÚ_escapedHexCharÚ_escapedOctCharÚ _singleCharÚ
_charRanger¿rŽrarOr^r\rorfrDr§rMrNrgrªrmrVrµr¶rkrWr@r`r[rerRrhr7rYr9r8rær’rØrr=r]r:rGrOr_rAr?rHrZrrr<rpr›Z selectTokenZ    fromTokenÚidentZ
columnNameZcolumnNameListZ
columnSpecZ    tableNameZ tableNameListZ    simpleSQLr~rùrÞràrrïryryryrzÚ<module>s¦ÿ4    î  
 8

 
 @v &A= I
G3pLOD|M &#@sQ,A,       I# %     0
,      ? #p 
ÿÿZr
 
 (
 
ÿÿÿ þ  
 
 
"