summaryrefslogtreecommitdiff
path: root/runtime/syntax/perl6.vim
blob: 3d82ced89f826348cab621b5957ffd6e5fbe1569 (plain)
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
" Vim syntax file
" Language:      Perl 6
" Maintainer:    vim-perl <vim-perl@googlegroups.com>
" Homepage:      http://github.com/vim-perl/vim-perl/tree/master
" Bugs/requests: http://github.com/vim-perl/vim-perl/issues
" Last Change:   2013-07-21

" Contributors:  Luke Palmer <fibonaci@babylonia.flatirons.org>
"                Moritz Lenz <moritz@faui2k3.org>
"                Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
"
" This is a big undertaking. Perl 6 is the sort of language that only Perl
" can parse. But I'll do my best to get vim to.
"
" You can associate the extension ".pl" with the filetype "perl6" by setting
"     autocmd BufNewFile,BufRead *.pl setf perl6
" in your ~/.vimrc. But that will infringe on Perl 5, so you might want to
" put a modeline near the beginning or end of your Perl 6 files instead:
"     # vim: filetype=perl6

" TODO:
"   * Deal with s:Perl5//
"   * m:s// is a match, not a substitution
"   * Make these highlight as strings, not operators:
"       <==> <=:=> <===> <=~> <« »> «>» «<»
"   * Allow more keywords to match as function calls(leave() is export(), etc)
"   * Optimization: use nextgroup instead of lookaround (:help syn-nextgroup)
"   * Fix s''' substitutions being matched as package names
"   * Match s/// and m/// better, so things like "$s/" won't match
"   * Add more support for folding (:help syn-fold)
"   * Add more syntax syncing hooks (:help syn-sync)
"   * Q//:
"       :to, :heredoc
"       interpolate \q:s{$scalar} (though the spec isn't very clear on it)
"
" Impossible TODO?:
"   * Unspace
"   * Unicode bracketing characters for quoting (there are so many)
"   * Various tricks depending on context. I.e. we can't know when Perl
"     expects «*» to be a string or a hyperoperator. The latter is presumably
"     more common, so that's what we assume.
"   * Selective highlighting of Pod formatting codes with the :allow option
"   * Arbitrary number, order, and negation of adverbs to Q//, q//, qq//.
"     Currently only the first adverb is considered significant. Anything
"     more would require an exponential amount of regexes, making this
"     already slow syntax file even slower.
"
" If you want to have Pir code inside Q:PIR// strings highlighted, do:
"  let perl6_embedded_pir=1
"
" The above requires pir.vim, which you can find in Parrot's repository:
" https://svn.parrot.org/parrot/trunk/editor/
"
" Some less than crucial things have been made optional to speed things up.
" Look at the comments near the if/else branches in this file to see exactly
" which features are affected. "perl6_extended_all" enables everything.
"
" The defaults are:
"
"  unlet perl6_extended_comments
"  unlet perl6_extended_q
"  unlet perl6_extended_all

" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
    syntax clear
elseif exists("b:current_syntax")
    finish
endif
let s:keepcpo= &cpo
set cpo&vim

" identifiers
syn match p6Normal display "\K\%(\k\|[-']\K\@=\)*"

" This is used in the for loops below
" Don't use the "syn keyword" construct because that always has higher
" priority than matches/regions, so the words can't be autoquoted with
" the "=>" and "p5=>" operators. All the lookaround stuff is to make sure
" we don't match them as part of some other identifier.
let s:before_keyword = " display \"\\%(\\k\\|\\K\\@<=[-']\\)\\@<!\\%("
let s:after_keyword = "\\)\\%(\\k\\|[-']\\K\\@=\\)\\@!\""

" Billions of keywords
let s:keywords = {
 \ "p6Attention": [
 \   "ACHTUNG ATTN ATTENTION FIXME NB TODO TBD WTF XXX NOTE",
 \ ],
 \ "p6DeclareRoutine": [
 \   "macro sub submethod method multi proto only rule token regex category",
 \ ],
 \ "p6Module": [
 \   "module class role package enum grammar slang subset",
 \ ],
 \ "p6Variable": [
 \   "self",
 \ ],
 \ "p6Include": [
 \   "use require",
 \ ],
 \ "p6Conditional": [
 \   "if else elsif unless",
 \ ],
 \ "p6VarStorage": [
 \   "let my our state temp has constant",
 \ ],
 \ "p6Repeat": [
 \   "for loop repeat while until gather given",
 \ ],
 \ "p6FlowControl": [
 \   "take do when next last redo return contend maybe defer",
 \   "default exit make continue break goto leave async lift",
 \ ],
 \ "p6TypeConstraint": [
 \   "is as but trusts of returns handles where augment supersede",
 \ ],
 \ "p6ClosureTrait": [
 \   "BEGIN CHECK INIT START FIRST ENTER LEAVE KEEP",
 \   "UNDO NEXT LAST PRE POST END CATCH CONTROL TEMP",
 \ ],
 \ "p6Exception": [
 \   "die fail try warn",
 \ ],
 \ "p6Property": [
 \   "prec irs ofs ors export deep binary unary reparsed rw parsed cached",
 \   "readonly defequiv will ref copy inline tighter looser equiv assoc",
 \   "required",
 \ ],
 \ "p6Number": [
 \   "NaN Inf",
 \ ],
 \ "p6Pragma": [
 \   "oo fatal",
 \ ],
 \ "p6Type": [
 \   "Object Any Junction Whatever Capture Match",
 \   "Signature Proxy Matcher Package Module Class",
 \   "Grammar Scalar Array Hash KeyHash KeySet KeyBag",
 \   "Pair List Seq Range Set Bag Mapping Void Undef",
 \   "Failure Exception Code Block Routine Sub Macro",
 \   "Method Submethod Regex Str Blob Char Byte",
 \   "Codepoint Grapheme StrPos StrLen Version Num",
 \   "Complex num complex Bit bit bool True False",
 \   "Increasing Decreasing Ordered Callable AnyChar",
 \   "Positional Associative Ordering KeyExtractor",
 \   "Comparator OrderingPair IO KitchenSink Role",
 \   "Int int int1 int2 int4 int8 int16 int32 int64",
 \   "Rat rat rat1 rat2 rat4 rat8 rat16 rat32 rat64",
 \   "Buf buf buf1 buf2 buf4 buf8 buf16 buf32 buf64",
 \   "UInt uint uint1 uint2 uint4 uint8 uint16 uint32",
 \   "uint64 Abstraction utf8 utf16 utf32",
 \ ],
 \ "p6Operator": [
 \   "div x xx mod also leg cmp before after eq ne le lt",
 \   "gt ge eqv ff fff and andthen Z X or xor",
 \   "orelse extra m mm rx s tr",
 \ ],
\ }

for [group, words] in items(s:keywords)
    let s:words_space = join(words, " ")
    let s:temp = split(s:words_space)
    let s:words = join(s:temp, "\\|")
    exec "syn match ". group ." ". s:before_keyword . s:words . s:after_keyword
endfor
unlet s:keywords s:words_space s:temp s:words

" More operators
" Don't put a "\+" at the end of the character class. That makes it so
" greedy that the "%" " in "+%foo" won't be allowed to match as a sigil,
" among other things
syn match p6Operator display "[-+/*~?|=^!%&,<>.;\\]"
syn match p6Operator display "\%(:\@<!::\@!\|::=\|\.::\)"
" these require whitespace on the left side
syn match p6Operator display "\%(\s\|^\)\@<=\%(xx=\|p5=>\)"
" "i" requires a digit to the left, and no keyword char to the right
syn match p6Operator display "\d\@<=i\k\@!"
" index overloading
syn match p6Operator display "\%(&\.(\@=\|@\.\[\@=\|%\.{\@=\)"

" all infix operators except nonassocative ones
let s:infix_a = [
    \ "div % mod +& +< +> \\~& ?& \\~< \\~> +| +\\^ \\~| \\~\\^ ?| ?\\^ xx x",
    \ "\\~ && & also <== ==> <<== ==>> == != < <= > >= \\~\\~ eq ne lt le gt",
    \ "ge =:= === eqv before after \\^\\^ min max \\^ff ff\\^ \\^ff\\^",
    \ "\\^fff fff\\^ \\^fff\\^ fff ff ::= := \\.= => , : p5=> Z minmax",
    \ "\\.\\.\\. and andthen or orelse xor \\^ += -= /= \\*= \\~= //= ||=",
    \ "+ - \\*\\* \\* // / \\~ || |",
\ ]
" nonassociative infix operators
let s:infix_n = "but does <=> leg cmp \\.\\. \\.\\.\\^\\^ \\^\\.\\. \\^\\.\\.\\^"

let s:infix_a_long = join(s:infix_a, " ")
let s:infix_a_words = split(s:infix_a_long)
let s:infix_a_pattern = join(s:infix_a_words, "\\|")

let s:infix_n_words = split(s:infix_n)
let s:infix_n_pattern = join(s:infix_n_words, "\\|")

let s:both = [s:infix_a_pattern, s:infix_n_pattern]
let s:infix = join(s:both, "\\|")

let s:infix_assoc = "!\\?\\%(" . s:infix_a_pattern . "\\)"
let s:infix = "!\\?\\%(" . s:infix . "\\)"

unlet s:infix_a s:infix_a_long s:infix_a_words s:infix_a_pattern
unlet s:infix_n s:infix_n_pattern s:both

" [+] reduce
exec "syn match p6ReduceOp display \"\\k\\@<!\\[[R\\\\]\\?!\\?". s:infix_assoc ."]\\%(«\\|<<\\)\\?\""
unlet s:infix_assoc

" Reverse and cross operators (Rop, Xop)
exec "syn match p6ReverseCrossOp display \"[RX]". s:infix ."\""

" q() or whatever() is always a function call
syn match p6Normal display "\K\%(\k\|[-']\K\@=\)*(\@="

" basically all builtins that can be followed by parentheses
let s:routines = [
 \ "eager hyper substr index rindex grep map sort join lines hints chmod",
 \ "split reduce min max reverse truncate zip cat roundrobin classify",
 \ "first sum keys values pairs defined delete exists elems end kv any",
 \ "all one wrap shape key value name pop push shift splice unshift floor",
 \ "ceiling abs exp log log10 rand sign sqrt sin cos tan round strand",
 \ "roots cis unpolar polar atan2 pick chop p5chop chomp p5chomp lc",
 \ "lcfirst uc ucfirst capitalize normalize pack unpack quotemeta comb",
 \ "samecase sameaccent chars nfd nfc nfkd nfkc printf sprintf caller",
 \ "evalfile run runinstead nothing want bless chr ord gmtime time eof",
 \ "localtime gethost getpw chroot getlogin getpeername kill fork wait",
 \ "perl graphs codes bytes clone print open read write readline say seek",
 \ "close opendir readdir slurp pos fmt vec link unlink symlink uniq pair",
 \ "asin atan sec cosec cotan asec acosec acotan sinh cosh tanh asinh",
 \ "acos acosh atanh sech cosech cotanh sech acosech acotanh asech ok",
 \ "plan_ok dies_ok lives_ok skip todo pass flunk force_todo use_ok isa_ok",
 \ "diag is_deeply isnt like skip_rest unlike cmp_ok eval_dies_ok nok_error",
 \ "eval_lives_ok approx is_approx throws_ok version_lt plan eval succ pred",
 \ "times nonce once signature new connect operator undef undefine sleep",
 \ "from to infix postfix prefix circumfix postcircumfix minmax lazy count",
 \ "unwrap getc pi e context void quasi body each contains rewinddir subst",
 \ "can isa flush arity assuming rewind callwith callsame nextwith nextsame",
 \ "attr eval_elsewhere none srand trim trim_start trim_end lastcall WHAT",
 \ "WHERE HOW WHICH VAR WHO WHENCE ACCEPTS REJECTS does not true iterator by",
 \ "re im invert flip",
\ ]

" we want to highlight builtins like split() though, so this comes afterwards
" TODO: check if this would be faster as one big regex
let s:words_space = join(s:routines, " ")
let s:temp = split(s:words_space)
let s:words = join(s:temp, "\\|")
exec "syn match p6Routine ". s:before_keyword . s:words . s:after_keyword
unlet s:before_keyword s:after_keyword s:words_space s:temp s:words s:routines

" packages, must come after all the keywords
syn match p6Normal display "\%(::\)\@<=\K\%(\k\|[-']\K\@=\)*"
syn match p6Normal display "\K\%(\k\|[-']\K\@=\)*\%(::\)\@="

" some standard packages
syn match p6Type display "\%(::\|\k\|\K\@<=[-']\)\@<!\%(Order\%(::Same\|::Increase\|::Decrease\)\?\)\%(\k\|[-']\K\@=\)\@!"
syn match p6Type display "\%(::\|\k\|\K\@<=[-']\)\@<!\%(Bool\%(::True\|::False\)\?\)\%(\k\|[-']\K\@=\)\@!"


syn match p6Shebang    display "\%^#!.*"
syn match p6BlockLabel display "\%(^\s*\)\@<=\h\w*\s*::\@!\_s\@="
syn match p6Number     display "\k\@<!_\@!\%(\d\|__\@!\)\+_\@<!\%([eE]_\@!+\?\%(\d\|_\)\+\)\?_\@<!"
syn match p6Float      display "\k\@<!_\@!\%(\d\|__\@!\)\+_\@<![eE]_\@!-\%(\d\|_\)\+"
syn match p6Float      display "\k\@<!_\@<!\%(\d\|__\@!\)*_\@<!\.\@<!\._\@!\.\@!\a\@!\%(\d\|_\)\+_\@<!\%([eE]_\@!\%(\d\|_\)\+\)\?"

syn match p6NumberBase display "[obxd]" contained
syn match p6Number     display "\<0\%(o[0-7][0-7_]*\)\@="     nextgroup=p6NumberBase
syn match p6Number     display "\<0\%(b[01][01_]*\)\@="       nextgroup=p6NumberBase
syn match p6Number     display "\<0\%(x\x[[:xdigit:]_]*\)\@=" nextgroup=p6NumberBase
syn match p6Number     display "\<0\%(d\d[[:digit:]_]*\)\@="  nextgroup=p6NumberBase
syn match p6Number     display "\%(\<0o\)\@<=[0-7][0-7_]*"
syn match p6Number     display "\%(\<0b\)\@<=[01][01_]*"
syn match p6Number     display "\%(\<0x\)\@<=\x[[:xdigit:]_]*"
syn match p6Number     display "\%(\<0d\)\@<=\d[[:digit:]_]*"

syn match p6Version    display "\<v\d\@=" nextgroup=p6VersionNum
syn match p6VersionNum display "\d\+" nextgroup=p6VersionDot contained
syn match p6VersionDot display "\.\%(\d\|\*\)\@=" nextgroup=p6VersionNum contained

" try to distinguish the "is" function from the "is" trail auxiliary
syn match p6Routine     display "\%(\%(\S\k\@<!\|^\)\s*\)\@<=is\>"

" does is a type constraint sometimes
syn match p6TypeConstraint display "does\%(\s*\%(\k\|[-']\K\@=\)\)\@="

" int is a type sometimes
syn match p6Type        display "\<int\>\%(\s*(\|\s\+\d\)\@!"

" these Routine names are also Properties, if preceded by "is"
syn match p6Property    display "\%(is\s\+\)\@<=\%(signature\|context\|also\|shape\)"

" The sigil in ::*Package
syn match p6PackageTwigil display "\%(::\)\@<=\*"

" $<match>
syn region p6MatchVarSigil
    \ matchgroup=p6Variable
    \ start="\$\%(<<\@!\)\@="
    \ end=">\@<="
    \ contains=p6MatchVar

syn region p6MatchVar
    \ matchgroup=p6Twigil
    \ start="<"
    \ end=">"
    \ contained

" Contextualizers
syn match p6Context display "\<\%(item\|list\|slice\|hash\)\>"
syn match p6Context display "\%(\$\|@\|%\|&\|@@\)(\@="

" the "$" placeholder in "$var1, $, var2 = @list"
syn match p6Placeholder display "\%(,\s*\)\@<=\$\%(\K\|\%([.^*?=!~]\|:\@<!::\@!\)\)\@!"
syn match p6Placeholder display "\$\%(\K\|\%([.^*?=!~]\|:\@<!::\@!\)\)\@!\%(,\s*\)\@="

" Quoting

" one cluster for every quote adverb
syn cluster p6Interp_s
    \ add=p6InterpScalar
syn cluster p6Interp_scalar
    \ add=p6InterpScalar

syn cluster p6Interp_a
    \ add=p6InterpArray
syn cluster p6Interp_array
    \ add=p6InterpArray

syn cluster p6Interp_h
    \ add=p6InterpHash
syn cluster p6Interp_hash
    \ add=p6InterpHash

syn cluster p6Interp_f
    \ add=p6InterpFunction
syn cluster p6Interp_f
    \ add=p6InterpFunction

syn cluster p6Interp_c
    \ add=p6InterpClosure
syn cluster p6Interp_closure
    \ add=p6InterpClosure


if exists("perl6_extended_q") || exists("perl6_extended_all")
    syn cluster p6Interp_ww
        \ add=p6StringSQ
        \ add=p6StringDQ
    syn cluster p6Interp_quotewords
        \ add=p6StringSQ
        \ add=p6StringDQ
endif

syn cluster p6Interp_q
    \ add=p6EscQQ
    \ add=p6EscBackSlash
syn cluster p6Interp_single
    \ add=p6EscQQ
    \ add=p6EscBackSlash

syn cluster p6Interp_b
    \ add=@p6Interp_q
    \ add=p6Escape
    \ add=p6EscOpenCurly
    \ add=p6EscCodePoint
    \ add=p6EscHex
    \ add=p6EscOct
    \ add=p6EscOctOld
    \ add=p6EscNull
syn cluster p6Interp_backslash
    \ add=@p6Interp_q
    \ add=p6Escape
    \ add=p6EscOpenCurly
    \ add=p6EscCodePoint
    \ add=p6EscHex
    \ add=p6EscOct
    \ add=p6EscOctOld
    \ add=p6EscNull

syn cluster p6Interp_qq
    \ add=@p6Interp_scalar
    \ add=@p6Interp_array
    \ add=@p6Interp_hash
    \ add=@p6Interp_function
    \ add=@p6Interp_closure
    \ add=@p6Interp_backslash
syn cluster p6Interp_double
    \ add=@p6Interp_scalar
    \ add=@p6Interp_array
    \ add=@p6Interp_hash
    \ add=@p6Interp_function
    \ add=@p6Interp_closure
    \ add=@p6Interp_backslash

syn region p6InterpScalar
    \ start="\ze\z(\$\%(\%(\%(\d\+\|!\|/\|¢\)\|\%(\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\@=\)\?\K\%(\k\|[-']\K\@=\)*\)\%(\.\%(\K\%(\k\|[-']\K\@=\)*\)\|\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)*\)\.\?\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)\)"
    \ start="\ze\z(\$\%(\%(\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\@=\)\?\K\%(\k\|[-']\K\@=\)*\)\|\%(\d\+\|!\|/\|¢\)\)\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend

syn region p6InterpScalar
    \ matchgroup=p6Context
    \ start="\$\ze()\@!"
    \ skip="([^)]*)"
    \ end=")\zs"
    \ contained
    \ contains=TOP

syn region p6InterpArray
    \ start="\ze\z(@\$*\%(\%(\%(!\|/\|¢\)\|\%(\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\@=\)\?\K\%(\k\|[-']\K\@=\)*\)\%(\.\%(\K\%(\k\|[-']\K\@=\)*\)\|\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)*\)\.\?\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend

syn region p6InterpArray
    \ matchgroup=p6Context
    \ start="@\ze()\@!"
    \ start="@@\ze()\@!"
    \ skip="([^)]*)"
    \ end=")\zs"
    \ contained
    \ contains=TOP

syn region p6InterpHash
    \ start="\ze\z(%\$*\%(\%(\%(!\|/\|¢\)\|\%(\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\@=\)\?\K\%(\k\|[-']\K\@=\)*\)\%(\.\%(\K\%(\k\|[-']\K\@=\)*\)\|\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)*\)\.\?\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend

syn region p6InterpHash
    \ matchgroup=p6Context
    \ start="%\ze()\@!"
    \ skip="([^)]*)"
    \ end=")\zs"
    \ contained
    \ contains=TOP

syn region p6InterpFunction
    \ start="\ze\z(&\%(\%(!\|/\|¢\)\|\%(\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\@=\)\?\K\%(\k\|[-']\K\@=\)*\%(\.\%(\K\%(\k\|[-']\K\@=\)*\)\|\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)*\)\.\?\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\)\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend

syn region p6InterpFunction
    \ matchgroup=p6Context
    \ start="&\ze()\@!"
    \ skip="([^)]*)"
    \ end=")\zs"
    \ contained
    \ contains=TOP

syn region p6InterpClosure
    \ start="\\\@<!{}\@!"
    \ skip="{[^}]*}"
    \ end="}"
    \ contained
    \ contains=TOP
    \ keepend

" generic escape
syn match p6Escape          display "\\\S" contained

" escaped closing delimiters
syn match p6EscQuote        display "\\'" contained
syn match p6EscDoubleQuote  display "\\\"" contained
syn match p6EscCloseAngle   display "\\>" contained
syn match p6EscCloseFrench  display "\\»" contained
syn match p6EscBackTick     display "\\`" contained
syn match p6EscForwardSlash display "\\/" contained
syn match p6EscVerticalBar  display "\\|" contained
syn match p6EscExclamation  display "\\!" contained
syn match p6EscComma        display "\\," contained
syn match p6EscDollar       display "\\\$" contained
syn match p6EscCloseCurly   display "\\}" contained
syn match p6EscCloseBracket display "\\\]" contained

" misc escapes
syn match p6EscOctOld    display "\\\d\{1,3}" contained
syn match p6EscNull      display "\\0\d\@!" contained
syn match p6EscCodePoint display "\%(\\c\)\@<=\%(\d\|\S\|\[\)\@=" contained nextgroup=p6CodePoint
syn match p6EscHex       display "\%(\\x\)\@<=\%(\x\|\[\)\@=" contained nextgroup=p6HexSequence
syn match p6EscOct       display "\%(\\o\)\@<=\%(\o\|\[\)\@=" contained nextgroup=p6OctSequence
syn match p6EscQQ        display "\\qq" contained nextgroup=p6QQSequence
syn match p6EscOpenCurly display "\\{" contained
syn match p6EscHash      display "\\#" contained
syn match p6EscBackSlash display "\\\\" contained

syn region p6QQSequence
    \ matchgroup=p6Escape
    \ start="\["
    \ skip="\[[^\]]*]"
    \ end="]"
    \ contained
    \ transparent
    \ contains=@p6Interp_qq

syn match p6CodePoint   display "\%(\d\+\|\S\)" contained
syn region p6CodePoint
    \ matchgroup=p6Escape
    \ start="\["
    \ end="]"
    \ contained

syn match p6HexSequence display "\x\+" contained
syn region p6HexSequence
    \ matchgroup=p6Escape
    \ start="\["
    \ end="]"
    \ contained

syn match p6OctSequence display "\o\+" contained
syn region p6OctSequence
    \ matchgroup=p6Escape
    \ start="\["
    \ end="]"
    \ contained

" matches :key, :!key, :$var, :key<var>, etc
" Since we don't know in advance how the adverb ends, we use a trick.
" Consume nothing with the start pattern (\ze at the beginning),
" while capturing the whole adverb into \z1 and then putting it before
" the match start (\zs) of the end pattern.
syn region p6Adverb
    \ start="\ze\z(:!\?\K\%(\k\|[-']\K\@=\)*\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\?\)"
    \ start="\ze\z(:!\?[@$%]\$*\%(::\|\%(\$\@<=\d\+\|!\|/\|¢\)\|\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\)\|\%(\K\%(\k\|[-']\K\@=\)*\)\)\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend

" <words>
" FIXME: not sure how to distinguish this from the "less than" operator
" in all cases. For now, it matches if any of the following is true:
"
" * There is whitespace missing on either side of the "<", since
"   people tend to put spaces around "less than"
" * It comes after "enum", "for", "any", "all", or "none"
" * It's the first or last thing on a line (ignoring whitespace)
" * It's preceded by "= "
"
" It never matches when:
"
" * Preceded by [<+~=] (e.g. <<foo>>, =<$foo>)
" * Followed by [-=] (e.g. <--, <=, <==)
syn region p6StringAngle
    \ matchgroup=p6Quote
    \ start="\%(\<\%(enum\|for\|any\|all\|none\)\>\s*(\?\s*\)\@<=<\%(<\|=>\|[-=]\{1,2}>\@!\)\@!"
    \ start="\%(\s\|[<+~=]\)\@<!<\%(<\|=>\|[-=]\{1,2}>\@!\)\@!"
    \ start="[<+~=]\@<!<\%(\s\|<\|=>\|[-=]\{1,2}>\@!\)\@!"
    \ start="\%(^\s*\)\@<=<\%(<\|=>\|[-=]\{1,2}>\@!\)\@!"
    \ start="[<+~=]\@<!<\%(\s*$\)\@="
    \ start="\%(=\s\+\)\@=<\%(<\|=>\|[-=]\{1,2}>\@!\)\@!"
    \ skip="\\\@<!\\>"
    \ end=">"
    \ contains=p6InnerAnglesOne,p6EscBackSlash,p6EscCloseAngle

syn region p6InnerAnglesOne
    \ matchgroup=p6StringAngle
    \ start="<"
    \ skip="\\\@<!\\>"
    \ end=">"
    \ transparent
    \ contained
    \ contains=p6InnerAnglesOne

" <<words>>
syn region p6StringAngles
    \ matchgroup=p6Quote
    \ start="<<=\@!"
    \ skip="\\\@<!\\>"
    \ end=">>"
    \ contains=p6InnerAnglesTwo,@p6Interp_qq,p6Comment,p6EscHash,p6EscCloseAngle,p6Adverb,p6StringSQ,p6StringDQ

syn region p6InnerAnglesTwo
    \ matchgroup=p6StringAngles
    \ start="<<"
    \ skip="\\\@<!\\>"
    \ end=">>"
    \ transparent
    \ contained
    \ contains=p6InnerAnglesTwo

" «words»
syn region p6StringFrench
    \ matchgroup=p6Quote
    \ start="«"
    \ skip="\\\@<!\\»"
    \ end="»"
    \ contains=p6InnerFrench,@p6Interp_qq,p6Comment,p6EscHash,p6EscCloseFrench,p6Adverb,p6StringSQ,p6StringDQ

syn region p6InnerFrench
    \ matchgroup=p6StringFrench
    \ start="«"
    \ skip="\\\@<!\\»"
    \ end="»"
    \ transparent
    \ contained
    \ contains=p6InnerFrench

" 'string'
syn region p6StringSQ
    \ matchgroup=p6Quote
    \ start="'"
    \ skip="\\\@<!\\'"
    \ end="'"
    \ contains=@p6Interp_q,p6EscQuote

" "string"
syn region p6StringDQ
    \ matchgroup=p6Quote
    \ start=+"+
    \ skip=+\\\@<!\\"+
    \ end=+"+
    \ contains=@p6Interp_qq,p6EscDoubleQuote

" Q// and friends.

syn match p6QuoteQ display "\%([Qq]\%(ww\|to\|[qwxsahfcb]\)\?\)\>" nextgroup=p6QPairs skipwhite skipempty
syn match p6QPairs contained transparent skipwhite skipempty nextgroup=p6StringQ,p6StringQ_PIR "\%(\_s*:!\?\K\%(\k\|[-']\K\@=\)*\%(([^)]*)\|\[[^\]]*]\|<[^>]*>\|«[^»]*»\|{[^}]*}\)\?\)*"

if exists("perl6_embedded_pir")
    syn include @p6PIR syntax/pir.vim
endif

" hardcoded set of delimiters
let s:delims = [
  \ ["\\\"",         "\\\"", "p6EscDoubleQuote",  "\\\\\\@<!\\\\\\\""],
  \ ["'",            "'",    "p6EscQuote",        "\\\\\\@<!\\\\'"],
  \ ["/",            "/",    "p6EscForwardSlash", "\\\\\\@<!\\\\/"],
  \ ["`",            "`",    "p6EscBackTick",     "\\\\\\@<!\\\\`"],
  \ ["|",            "|",    "p6EscVerticalBar",  "\\\\\\@<!\\\\|"],
  \ ["!",            "!",    "p6EscExclamation",  "\\\\\\@<!\\\\!"],
  \ [",",            ",",    "p6EscComma",        "\\\\\\@<!\\\\,"],
  \ ["\\$",          "\\$",  "p6EscDollar",       "\\\\\\@<!\\\\\\$"],
  \ ["{",            "}",    "p6EscCloseCurly",   "\\%(\\\\\\@<!\\\\}\\|{[^}]*}\\)"],
  \ ["<",            ">",    "p6EscCloseAngle",   "\\%(\\\\\\@<!\\\\>\\|<[^>]*>\\)"],
  \ ["«",            "»",    "p6EscCloseFrench",  "\\%(\\\\\\@<!\\\\»\\|«[^»]*»\\)"],
  \ ["\\\[",         "]",    "p6EscCloseBracket", "\\%(\\\\\\@<!\\\\]\\|\\[^\\]]*]\\)"],
  \ ["\\s\\@<=(",    ")",    "p6EscCloseParen",   "\\%(\\\\\\@<!\\\\)\\|([^)]*)\\)"],
\ ]

" double and triple delimiters too
if exists("perl6_extended_q") || exists("perl6_extended_all")
    call add(s:delims, ["««",           "»»",  "p6EscCloseFrench",  "\\%(\\\\\\@<!\\\\»»\\|««\\%([^»]\\|»»\\@!\\)*»»\\)"])
    call add(s:delims, ["«««",          "»»»", "p6EscCloseFrench",  "\\%(\\\\\\@<!\\\\»»»\\|«««\\%([^»]\\|»\\%(»»\\)\\@!\\)*»»»\\)"])
    call add(s:delims, ["{{",           "}}",  "p6EscCloseCurly",   "\\%(\\\\\\@<!\\\\}}\\|{{\\%([^}]\\|}}\\@!\\)*}}\\)"])
    call add(s:delims, ["{{{",          "}}}", "p6EscCloseCurly",   "\\%(\\\\\\@<!\\\\}}}\\|{{{\\%([^}]\\|}\\%(}}\\)\\@!\\)*}}}\\)"])
    call add(s:delims, ["\\\[\\\[",     "]]",  "p6EscCloseBracket", "\\%(\\\\\\@<!\\\\]]\\|\\[\\[\\%([^\\]]\\|]]\\@!\\)*]]\\)"])
    call add(s:delims, ["\\\[\\\[\\\[", "]]]", "p6EscCloseBracket", "\\%(\\\\\\@<!\\\\]]]\\|\\[\\[\\[\\%([^\\]]\\|]\\%(]]\\)\\@!\\)*]]]\\)"])
    call add(s:delims, ["\\s\\@<=((",   "))",  "p6EscCloseParen",   "\\%(\\\\\\@<!\\\\))\\|((\\%([^)]\\|))\\@!\\)*))\\)"])
    call add(s:delims, ["\\s\\@<=(((",  ")))", "p6EscCloseParen",   "\\%(\\\\\\@<!\\\\)))\\|(((\\%([^)]\\|)\\%())\\)\\@!\\)*)))\\)"])
    call add(s:delims, ["\\s\\@<=<<",   ">>",  "p6EscCloseAngle",   "\\%(\\\\\\@<!\\\\>>\\|<<\\%([^>]\\|>>\\@!\\)*>>\\)"])
    call add(s:delims, ["\\s\\@<=<<<",  ">>>", "p6EscCloseAngle",   "\\%(\\\\\\@<!\\\\>>>\\|<<<\\%([^>]\\|>\\%(>>\\)\\@!\\)*>>>\\)"])
endif

if !exists("perl6_extended_q") && !exists("perl6_extended_all")
    " simple version, no special highlighting within the string
    for [start_delim, end_delim, end_group, skip] in s:delims
        exec "syn region p6StringQ matchgroup=p6Quote start=\"".start_delim."\" skip=\"".skip."\" end=\"".end_delim."\" contains=".end_group." contained"
    endfor

    if exists("perl6_embedded_pir")
        " highlight embedded PIR code
        for [start_delim, end_delim, end_group, skip] in s:delims
            exec "syn region p6StringQ_PIR matchgroup=p6Quote start=\"\\%(Q\\s*:PIR\\s*\\)\\@<=".start_delim."\" skip=\"".skip."\" end=\"".end_delim."\" contains=@p6PIR,".end_group." contained"
        endfor
    endif
else
    let s:before = "syn region p6StringQ matchgroup=p6Quote start=\"\\%("
    let s:after  = "\\%(\\_s*:!\\?\\K\\%(\\k\\|[-']\\K\\@=\\)*\\%(([^)]*)\\|\\[[^\\]]*]\\|<[^>]*>\\|«[^»]*»\\|{[^}]*}\\)\\?\\)*\\_s*\\)\\@<="

    let s:adverbs = [
        \ ["s", "scalar"],
        \ ["a", "array"],
        \ ["h", "hash"],
        \ ["f", "function"],
        \ ["c", "closure"],
        \ ["b", "backslash"],
        \ ["w", "words"],
        \ ["ww", "quotewords"],
        \ ["x", "exec"],
    \ ]

    " these can't be conjoined with q and qq (e.g. as qqq and qqqq)
    let s:q_adverbs = [
        \ ["q", "single"],
        \ ["qq", "double"],
    \ ]

    for [start_delim, end_delim, end_group, skip] in s:delims
        " Q, q, and qq with any number of (ignored) adverbs
        exec s:before ."Q". s:after .start_delim."\" end=\"". end_delim ."\""." contained"
        exec s:before ."q". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_q"." contained"
        exec s:before ."qq". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_qq"." contained"

        for [short, long] in s:adverbs
            " Qs, qs, qqs, Qa, qa, qqa, etc, with ignored adverbs
            exec s:before ."Q".short. s:after .start_delim ."\" end=\"". end_delim ."\" contains=@p6Interp_".long." contained"
            exec s:before ."q".short. s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_q,@p6Interp_".long." contained"
            exec s:before ."qq".short. s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_qq,@p6Interp_".long." contained"

            " Q, q, and qq, with one significant adverb
            exec s:before ."Q\\s*:\\%(".short."\\|".long."\\)". s:after .start_delim ."\" end=\"". end_delim ."\" contains=@p6Interp_".long." contained"
            for [q_short, q_long] in s:q_adverbs
                exec s:before ."Q\\s*:\\%(".q_short."\\|".q_long."\\)". s:after .start_delim ."\" end=\"". end_delim ."\" contains=@p6Interp_".q_long." contained"
            endfor
            exec s:before ."q\\s*:\\%(".short."\\|".long."\\)". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_q,@p6Interp_".long." contained"
            exec s:before ."qq\\s*:\\%(".short."\\|".long."\\)". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_qq,@p6Interp_".long." contained"

            for [short2, long2] in s:adverbs
                " Qs, qs, qqs, Qa, qa, qqa, etc, with one significant adverb
                exec s:before ."Q".short."\\s*:\\%(".short2."\\|".long2."\\)". s:after .start_delim ."\" end=\"". end_delim ."\" contains=@p6Interp_".long.",@p6Interp_".long2." contained"
                for [q_short2, q_long2] in s:q_adverbs
                    exec s:before ."Q".short."\\s*:\\%(".q_short2."\\|".q_long2."\\)". s:after .start_delim ."\" end=\"". end_delim ."\" contains=@p6Interp_".long.",@p6Interp_".q_long2." contained"
                endfor
                exec s:before ."q".short."\\s*:\\%(".short2."\\|".long2."\\)". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_q,@p6Interp_".long.",@p6Interp_".long2." contained"
                exec s:before ."qq".short."\\s*:\\%(".short2."\\|".long2."\\)". s:after .start_delim ."\" skip=\"". skip ."\" end=\"". end_delim ."\" contains=". end_group .",@p6Interp_qq,@p6Interp_".long.",@p6Interp_".long2." contained"
            endfor
        endfor
    endfor
    unlet s:before s:after s:adverbs s:q_adverbs
endif
unlet s:delims

" Match these so something else above can't. E.g. the "q" in "role q { }"
" should not be considered a string
syn match p6Normal display "\%(\<\%(role\|grammar\|slang\)\s\+\)\@<=\K\%(\k\|[-']\K\@=\)*"

" :key
syn match p6Operator display ":\@<!::\@!!\?" nextgroup=p6Key
syn match p6Key display "\k\%(\k\|[-']\K\@=\)*" contained

" => and p5=> autoquoting
syn match p6StringP5Auto display "\K\%(\k\|[-']\K\@=\)*\ze\s\+p5=>"
syn match p6StringAuto   display "\K\%(\k\|[-']\K\@=\)*\ze\%(p5\)\@<!=>"
syn match p6StringAuto   display "\K\%(\k\|[-']\K\@=\)*\ze\s\+=>"
syn match p6StringAuto   display "\K\%(\k\|[-']\K\@=\)*p5\ze=>"

" Hyperoperators. Needs to come after the quoting operators (<>, «», etc)
exec "syn match p6HyperOp display \"»"   .s:infix."»\\?\""
exec "syn match p6HyperOp display \"«\\?".s:infix."«\""
exec "syn match p6HyperOp display \"»"   .s:infix."«\""
exec "syn match p6HyperOp display \"«"   .s:infix. "»\""

exec "syn match p6HyperOp display \">>"          .s:infix."\\%(>>\\)\\?\""
exec "syn match p6HyperOp display \"\\%(<<\\)\\?".s:infix."<<\""
exec "syn match p6HyperOp display \">>"          .s:infix."<<\""
exec "syn match p6HyperOp display \"<<"          .s:infix.">>\""
unlet s:infix

" Regexes and grammars

syn match p6RegexName display "\%(\<\%(regex\|rule\|token\)\s\+\)\@<=\K\%(\k\|[-']\K\@=\)*" nextgroup=p6RegexBlockCrap skipwhite skipempty
syn match p6RegexBlockCrap "[^{]*" nextgroup=p6RegexBlock skipwhite skipempty transparent contained

syn region p6RegexBlock
    \ matchgroup=p6Normal
    \ start="{"
    \ end="}"
    \ contained
    \ contains=@p6Regexen,@p6Variables

" Perl 6 regex bits

syn cluster p6Regexen
    \ add=p6RxMeta
    \ add=p6RxEscape
    \ add=p6EscHex
    \ add=p6EscOct
    \ add=p6EscNull
    \ add=p6RxAnchor
    \ add=p6RxCapture
    \ add=p6RxGroup
    \ add=p6RxAlternation
    \ add=p6RxAdverb
    \ add=p6RxAdverbArg
    \ add=p6RxStorage
    \ add=p6RxAssertion
    \ add=p6RxQuoteWords
    \ add=p6RxClosure
    \ add=p6RxStringSQ
    \ add=p6RxStringDQ
    \ add=p6Comment

syn match p6RxMeta        display contained ".\%(\k\|\s\)\@<!"
syn match p6RxAnchor      display contained "[$^]"
syn match p6RxEscape      display contained "\\\S"
syn match p6RxCapture     display contained "[()]"
syn match p6RxAlternation display contained "|"
syn match p6RxRange       display contained "\.\."

syn region p6RxClosure
    \ matchgroup=p6Normal
    \ start="{"
    \ end="}"
    \ contained
    \ containedin=p6RxClosure
    \ contains=TOP
syn region p6RxGroup
    \ matchgroup=p6StringSpecial2
    \ start="\["
    \ end="]"
    \ contained
    \ contains=@p6Regexen,@p6Variables
syn region p6RxAssertion
    \ matchgroup=p6StringSpecial2
    \ start="<"
    \ end=">"
    \ contained
    \ contains=@p6Regexen,@p6Variables,p6RxCharClass,p6RxAssertCall
syn region p6RxAssertCall
    \ matchgroup=p6Normal
    \ start="\%(::\|\%(\K\%(\k\|[-']\K\@=\)*\)\)\@<=(\@="
    \ end=")\@<="
    \ contained
    \ contains=TOP
syn region p6RxCharClass
    \ matchgroup=p6StringSpecial2
    \ start="\%(<[-!+?]\?\)\@<=\["
    \ skip="\\]"
    \ end="]"
    \ contained
    \ contains=p6RxRange,p6RxEscape,p6EscHex,p6EscOct,p6EscNull
syn region p6RxQuoteWords
    \ matchgroup=p6StringSpecial2
    \ start="< "
    \ end=">"
    \ contained
syn region p6RxAdverb
    \ start="\ze\z(:!\?\K\%(\k\|[-']\K\@=\)*\)"
    \ end="\z1\zs"
    \ contained
    \ contains=TOP
    \ keepend
syn region p6RxAdverbArg
    \ start="\%(:!\?\K\%(\k\|[-']\K\@=\)*\)\@<=("
    \ skip="([^)]*)"
    \ end=")"
    \ contained
    \ contains=TOP
syn region p6RxStorage
    \ matchgroup=p6Operator
    \ start="\%(^\s*\)\@<=:\%(my\>\|temp\>\)\@="
    \ end="$"
    \ contains=TOP
    \ contained

" Perl 5 regex bits

syn cluster p6RegexP5Base
    \ add=p6RxP5Escape
    \ add=p6RxP5Oct
    \ add=p6RxP5Hex
    \ add=p6RxP5EscMeta
    \ add=p6RxP5CodePoint
    \ add=p6RxP5Prop

" normal regex stuff
syn cluster p6RegexP5
    \ add=@p6RegexP5Base
    \ add=p6RxP5Quantifier
    \ add=p6RxP5Meta
    \ add=p6RxP5QuoteMeta
    \ add=p6RxP5ParenMod
    \ add=p6RxP5Verb
    \ add=p6RxP5Count
    \ add=p6RxP5Named
    \ add=p6RxP5ReadRef
    \ add=p6RxP5WriteRef
    \ add=p6RxP5CharClass
    \ add=p6RxP5Anchor

" inside character classes
syn cluster p6RegexP5Class
    \ add=@p6RegexP5Base
    \ add=p6RxP5Posix
    \ add=p6RxP5Range

syn match p6RxP5Escape     display contained "\\\S"
syn match p6RxP5CodePoint  display contained "\\c\S\@=" nextgroup=p6RxP5CPId
syn match p6RxP5CPId       display contained "\S"
syn match p6RxP5Oct        display contained "\\\%(\o\{1,3}\)\@=" nextgroup=p6RxP5OctSeq
syn match p6RxP5OctSeq     display contained "\o\{1,3}"
syn match p6RxP5Anchor     display contained "[\^$]"
syn match p6RxP5Hex        display contained "\\x\%({\x\+}\|\x\{1,2}\)\@=" nextgroup=p6RxP5HexSeq
syn match p6RxP5HexSeq     display contained "\x\{1,2}"
syn region p6RxP5HexSeq
    \ matchgroup=p6RxP5Escape
    \ start="{"
    \ end="}"
    \ contained
syn region p6RxP5Named
    \ matchgroup=p6RxP5Escape
    \ start="\%(\\N\)\@<={"
    \ end="}"
    \ contained
syn match p6RxP5Quantifier display contained "\%([+*]\|(\@<!?\)"
syn match p6RxP5ReadRef    display contained "\\[1-9]\d\@!"
syn match p6RxP5ReadRef    display contained "\\k<\@=" nextgroup=p6RxP5ReadRefId
syn region p6RxP5ReadRefId
    \ matchgroup=p6RxP5Escape
    \ start="<"
    \ end=">"
    \ contained
syn match p6RxP5WriteRef   display contained "\\g\%(\d\|{\)\@=" nextgroup=p6RxP5WriteRefId
syn match p6RxP5WriteRefId display contained "\d\+"
syn region p6RxP5WriteRefId
    \ matchgroup=p6RxP5Escape
    \ start="{"
    \ end="}"
    \ contained
syn match p6RxP5Prop       display contained "\\[pP]\%(\a\|{\)\@=" nextgroup=p6RxP5PropId
syn match p6RxP5PropId     display contained "\a"
syn region p6RxP5PropId
    \ matchgroup=p6RxP5Escape
    \ start="{"
    \ end="}"
    \ contained
syn match p6RxP5Meta       display contained "[(|).]"
syn match p6RxP5ParenMod   display contained "(\@<=?\@=" nextgroup=p6RxP5Mod,p6RxP5ModName,p6RxP5Code
syn match p6RxP5Mod        display contained "?\%(<\?=\|<\?!\|[#:|]\)"
syn match p6RxP5Mod        display contained "?-\?[impsx]\+"
syn match p6RxP5Mod        display contained "?\%([-+]\?\d\+\|R\)"
syn match p6RxP5Mod        display contained "?(DEFINE)"
syn match p6RxP5Mod        display contained "?\%(&\|P[>=]\)" nextgroup=p6RxP5ModDef
syn match p6RxP5ModDef     display contained "\h\w*"
syn region p6RxP5ModName
    \ matchgroup=p6StringSpecial
    \ start="?'"
    \ end="'"
    \ contained
syn region p6RxP5ModName
    \ matchgroup=p6StringSpecial
    \ start="?P\?<"
    \ end=">"
    \ contained
syn region p6RxP5Code
    \ matchgroup=p6StringSpecial
    \ start="??\?{"
    \ end="})\@="
    \ contained
    \ contains=TOP
syn match p6RxP5EscMeta    display contained "\\[?*.{}()[\]|\^$]"
syn match p6RxP5Count      display contained "\%({\d\+\%(,\%(\d\+\)\?\)\?}\)\@=" nextgroup=p6RxP5CountId
syn region p6RxP5CountId
    \ matchgroup=p6RxP5Escape
    \ start="{"
    \ end="}"
    \ contained
syn match p6RxP5Verb       display contained "(\@<=\*\%(\%(PRUNE\|SKIP\|THEN\)\%(:[^)]*\)\?\|\%(MARK\|\):[^)]*\|COMMIT\|F\%(AIL\)\?\|ACCEPT\)"
syn region p6RxP5QuoteMeta
    \ matchgroup=p6RxP5Escape
    \ start="\\Q"
    \ end="\\E"
    \ contained
    \ contains=@p6Variables,p6EscBackSlash
syn region p6RxP5CharClass
    \ matchgroup=p6StringSpecial
    \ start="\[\^\?"
    \ skip="\\]"
    \ end="]"
    \ contained
    \ contains=@p6RegexP5Class
syn region p6RxP5Posix
    \ matchgroup=p6RxP5Escape
    \ start="\[:"
    \ end=":]"
    \ contained
syn match p6RxP5Range      display contained "-"

" 'string' inside a regex
syn region p6RxStringSQ
    \ matchgroup=p6Quote
    \ start="'"
    \ skip="\\\@<!\\'"
    \ end="'"
    \ contained
    \ contains=p6EscQuote,p6EscBackSlash

" "string" inside a regex
syn region p6RxStringDQ
    \ matchgroup=p6Quote
    \ start=+"+
    \ skip=+\\\@<!\\"+
    \ end=+"+
    \ contained
    \ contains=p6EscDoubleQuote,p6EscBackSlash

" $!, $var, $!var, $::var, $package::var $*::package::var, etc
" Thus must come after the matches for the "$" regex anchor, but before
" the match for the $ regex delimiter
syn cluster p6Variables
    \ add=p6VarSlash
    \ add=p6VarExclam
    \ add=p6VarMatch
    \ add=p6VarNum
    \ add=p6Variable

syn match p6VarSlash     display "\$/"
syn match p6VarExclam    display "\$!"
syn match p6VarMatch     display "\$¢"
syn match p6VarNum       display "\$\d\+"
syn match p6Variable     display "\%(@@\|[@&$%]\$*\)\%(::\|\%(\%([.^*?=!~]\|:\@<!::\@!\)\K\)\|\K\)\@=" nextgroup=p6Twigil,p6VarName,p6PackageScope
syn match p6VarName      display "\K\%(\k\|[-']\K\@=\)*" contained
syn match p6Twigil       display "\%([.^*?=!~]\|:\@<!::\@!\)\K\@=" nextgroup=p6PackageScope,p6VarName contained
syn match p6PackageScope display "\%(\K\%(\k\|[-']\K\@=\)*\)\?::" nextgroup=p6PackageScope,p6VarName contained

" Perl 6 regex regions

" /foo/
" Below some hacks to recognise the // variant. This is virtually impossible
" to catch in all cases as the / is used in so many other ways, but these
" should be the most obvious ones.
" TODO: mostly stolen from perl.vim, might need more work
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\%(\<\%(split\|while\|until\|if\|unless\)\|\.\.\|[-+*!~(\[{=]\)\s*\)\@<=//\@!"
    \ start="^//\@!"
    \ start=+\s\@<=/[^[:space:][:digit:]$@%=]\@=\%(/\_s*\%([([{$@%&*[:digit:]"'`]\|\_s\w\|[[:upper:]_abd-fhjklnqrt-wyz]\)\)\@!/\@!+
    \ skip="\\/"
    \ end="/"
    \ contains=@p6Regexen,p6Variable,p6VarExclam,p6VarMatch,p6VarNum

" m/foo/, mm/foo/, rx/foo/
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=//\@!"
    \ skip="\\/"
    \ end="/"
    \ keepend
    \ contains=@p6Regexen,p6Variable,p6VarExclam,p6VarMatch,p6VarNum

" m!foo!, mm!foo!, rx!foo!
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=!!\@!"
    \ skip="\\!"
    \ end="!"
    \ keepend
    \ contains=@p6Regexen,p6Variable,p6VarSlash,p6VarMatch,p6VarNum

" m$foo$, mm$foo$, rx$foo$, m|foo|, mm|foo|, rx|foo|, etc
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=\z([\"'`|,$]\)\$\@!"
    \ skip="\\\z1"
    \ end="\z1"
    \ keepend
    \ contains=@p6Regexen,@p6Variables

" m (foo), mm (foo), rx (foo)
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s\+\)\@<=()\@!)\@!"
    \ skip="\\)"
    \ end=")"
    \ contains=@p6Regexen,@p6Variables

" m[foo], mm[foo], rx[foo]
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=\[]\@!]\@!"
    \ skip="\\]"
    \ end="]"
    \ contains=@p6Regexen,@p6Variables

" m{foo}, mm{foo}, rx{foo}
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<={}\@!}\@!"
    \ skip="\\}"
    \ end="}"
    \ contains=@p6Regexen,@p6Variables

" m<foo>, mm<foo>, rx<foo>
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=<>\@!>\@!"
    \ skip="\\>"
    \ end=">"
    \ contains=@p6Regexen,@p6Variables

" m«foo», mm«foo», rx«foo»
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<\%(mm\?\|rx\)\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=«»\@!»\@!"
    \ skip="\\»"
    \ end="»"
    \ contains=@p6Regexen,@p6Variables

" Substitutions

" s/foo/bar/
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=/"
    \ skip="\\/"
    \ end="/"me=e-1
    \ keepend
    \ contains=@p6Regexen,p6Variable,p6VarExclam,p6VarMatch,p6VarNum
    \ nextgroup=p6Substitution

syn region p6Substitution
    \ matchgroup=p6Quote
    \ start="/"
    \ skip="\\/"
    \ end="/"
    \ contained
    \ keepend
    \ contains=@p6Interp_qq

" s!foo!bar!
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=!"
    \ skip="\\!"
    \ end="!"me=e-1
    \ keepend
    \ contains=@p6Regexen,p6Variable,p6VarSlash,p6VarMatch,p6VarNum
    \ nextgroup=p6Substitution

syn region p6Substitution
    \ matchgroup=p6Quote
    \ start="!"
    \ skip="\\!"
    \ end="!"
    \ contained
    \ keepend
    \ contains=@p6Interp_qq

" s$foo$bar$, s|foo|bar, etc
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=\z([\"'`|,$]\)"
    \ skip="\\\z1"
    \ end="\z1"me=e-1
    \ keepend
    \ contains=@p6Regexen,@p6Variables
    \ nextgroup=p6Substitution

syn region p6Substitution
    \ matchgroup=p6Quote
    \ start="\z([\"'`|,$]\)"
    \ skip="\\\z1"
    \ end="\z1"
    \ contained
    \ keepend
    \ contains=@p6Interp_qq

" s{foo}
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<={}\@!"
    \ skip="\\}"
    \ end="}"
    \ contains=@p6Regexen,@p6Variables

" s[foo]
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=\[]\@!"
    \ skip="\\]"
    \ end="]"
    \ contains=@p6Regexen,@p6Variables

" s<foo>
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=<>\@!"
    \ skip="\\>"
    \ end=">"
    \ contains=@p6Regexen,@p6Variables

" s«foo»
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=«»\@!"
    \ skip="\\»"
    \ end="»"
    \ contains=@p6Regexen,@p6Variables

" s (foo)
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<s\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s\+\)\@<=()\@!"
    \ skip="\\)"
    \ end=")"
    \ contains=@p6Regexen,@p6Variables

" Perl 5 regex regions

" m:P5//
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=/"
    \ skip="\\/"
    \ end="/"
    \ contains=@p6RegexP5,p6Variable,p6VarExclam,p6VarMatch,p6VarNum

" m:P5!!
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=!"
    \ skip="\\!"
    \ end="!"
    \ contains=@p6RegexP5,p6Variable,p6VarSlash,p6VarMatch,p6VarNum

" m:P5$$, m:P5||, etc
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=\z([\"'`|,$]\)"
    \ skip="\\\z1"
    \ end="\z1"
    \ contains=@p6RegexP5,@p6Variables

" m:P5 ()
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s\+\)\@<=()\@!"
    \ skip="\\)"
    \ end=")"
    \ contains=@p6RegexP5,@p6Variables

" m:P5[]
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=[]\@!"
    \ skip="\\]"
    \ end="]"
    \ contains=@p6RegexP5,@p6Variables

" m:P5{}
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<={}\@!"
    \ skip="\\}"
    \ end="}"
    \ contains=@p6RegexP5,p6Variables

" m:P5<>
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=<>\@!"
    \ skip="\\>"
    \ end=">"
    \ contains=@p6RegexP5,p6Variables

" m:P5«»
syn region p6Match
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<m\s*:P\%(erl\)\?5\s*\)\@<=«»\@!"
    \ skip="\\»"
    \ end="»"
    \ contains=@p6RegexP5,p6Variables

" Transliteration

" tr/foo/bar/, tr|foo|bar, etc
syn region p6String
    \ matchgroup=p6Quote
    \ start="\%(\%(::\|[$@%&][.!^:*?]\?\|\.\)\@<!\<tr\%(\s*:!\?\k\%(\k\|[-']\K\@=\)*\%(([^)]*)\)\?\)*\s*\)\@<=\z([/\"'`|!,$]\)"
    \ skip="\\\z1"
    \ end="\z1"me=e-1
    \ contains=p6RxRange
    \ nextgroup=p6Transliteration

syn region p6Transliteration
    \ matchgroup=p6Quote
    \ start="\z([/\"'`|!,$]\)"
    \ skip="\\\z1"
    \ end="\z1"
    \ contained
    \ contains=@p6Interp_qq

" Comments

" normal end-of-line comment
syn match p6Comment display "#.*" contains=p6Attention

" Multiline comments. Arbitrary numbers of opening brackets are allowed,
" but we only define regions for 1 to 3
syn region p6Comment
    \ matchgroup=p6Comment
    \ start="^\@<!#("
    \ skip="([^)]*)"
    \ end=")"
    \ matchgroup=p6Error
    \ start="^#("
    \ contains=p6Attention,p6Comment
syn region p6Comment
    \ matchgroup=p6Comment
    \ start="^\@<!#\["
    \ skip="\[[^\]]*]"
    \ end="]"
    \ matchgroup=p6Error
    \ start="^#\["
    \ contains=p6Attention,p6Comment
syn region p6Comment
    \ matchgroup=p6Comment
    \ start="^\@<!#{"
    \ skip="{[^}]*}"
    \ end="}"
    \ matchgroup=p6Error
    \ start="^#{"
    \ contains=p6Attention,p6Comment
syn region p6Comment
    \ matchgroup=p6Comment
    \ start="^\@<!#<"
    \ skip="<[^>]*>"
    \ end=">"
    \ matchgroup=p6Error
    \ start="^#<"
    \ contains=p6Attention,p6Comment
syn region p6Comment
    \ matchgroup=p6Comment
    \ start="^\@<!#«"
    \ skip="«[^»]*»"
    \ end="»"
    \ matchgroup=p6Error
    \ start="^#«"
    \ contains=p6Attention,p6Comment

" double and triple delimiters
if exists("perl6_extended_comments") || exists("perl6_extended_all")
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#(("
        \ skip="((\%([^)\|))\@!]\)*))"
        \ end="))"
        \ matchgroup=p6Error
        \ start="^#(("
        \ contains=p6Attention,p6Comment
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#((("
        \ skip="(((\%([^)]\|)\%())\)\@!\)*)))"
        \ end=")))"
        \ matchgroup=p6Error
        \ start="^#((("
        \ contains=p6Attention,p6Comment

    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#\[\["
        \ skip="\[\[\%([^\]]\|]]\@!\)*]]"
        \ end="]]"
        \ matchgroup=p6Error
        \ start="^#\[\["
        \ contains=p6Attention,p6Comment
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#\[\[\["
        \ skip="\[\[\[\%([^\]]\|]\%(]]\)\@!\)*]]]"
        \ end="]]]"
        \ matchgroup=p6Error
        \ start="^#\[\[\["
        \ contains=p6Attention,p6Comment

    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#{{"
        \ skip="{{\%([^}]\|}}\@!\)*}}"
        \ end="}}"
        \ matchgroup=p6Error
        \ start="^#{{"
        \ contains=p6Attention,p6Comment
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#{{{"
        \ skip="{{{\%([^}]\|}\%(}}\)\@!\)*}}}"
        \ end="}}}"
        \ matchgroup=p6Error
        \ start="^#{{{"
        \ contains=p6Attention,p6Comment

    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#<<"
        \ skip="<<\%([^>]\|>>\@!\)*>>"
        \ end=">>"
        \ matchgroup=p6Error
        \ start="^#<<"
        \ contains=p6Attention,p6Comment
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#<<<"
        \ skip="<<<\%([^>]\|>\%(>>\)\@!\)*>>>"
        \ end=">>>"
        \ matchgroup=p6Error
        \ start="^#<<<"
        \ contains=p6Attention,p6Comment

    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#««"
        \ skip="««\%([^»]\|»»\@!\)*»»"
        \ end="»»"
        \ matchgroup=p6Error
        \ start="^#««"
        \ contains=p6Attention,p6Comment
    syn region p6Comment
        \ matchgroup=p6Comment
        \ start="^\@<!#«««"
        \ skip="«««\%([^»]\|»\%(»»\)\@!\)*»»»"
        \ end="»»»"
        \ matchgroup=p6Error
        \ start="^#«««"
        \ contains=p6Attention,p6Comment
endif

" Pod

" Abbreviated blocks (implicit code forbidden)
syn region p6PodAbbrRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\ze\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodAbbrNoCodeType
    \ keepend

syn region p6PodAbbrNoCodeType
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodName,p6PodAbbrNoCode

syn match p6PodName contained ".\+" contains=@p6PodFormat
syn match p6PodComment contained ".\+"

syn region p6PodAbbrNoCode
    \ start="^"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=@p6PodFormat

" Abbreviated blocks (everything is code)
syn region p6PodAbbrRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\zecode\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodAbbrCodeType
    \ keepend

syn region p6PodAbbrCodeType
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodName,p6PodAbbrCode

syn region p6PodAbbrCode
    \ start="^"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained

" Abbreviated blocks (everything is a comment)
syn region p6PodAbbrRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\zecomment\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodAbbrCommentType
    \ keepend

syn region p6PodAbbrCommentType
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodComment,p6PodAbbrNoCode

" Abbreviated blocks (implicit code allowed)
syn region p6PodAbbrRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\ze\%(pod\|item\|nested\|\u\+\)\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodAbbrType
    \ keepend

syn region p6PodAbbrType
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodName,p6PodAbbr

syn region p6PodAbbr
    \ start="^"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=@p6PodFormat,p6PodImplicitCode

" Abbreviated block to end-of-file
syn region p6PodAbbrRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\zeEND\>"
    \ end="\%$"
    \ contains=p6PodAbbrEOFType
    \ keepend

syn region p6PodAbbrEOFType
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="\%$"
    \ contained
    \ contains=p6PodName,p6PodAbbrEOF

syn region p6PodAbbrEOF
    \ start="^"
    \ end="\%$"
    \ contained
    \ contains=@p6PodNestedBlocks,@p6PodFormat,p6PodImplicitCode

" Directives
syn region p6PodDirectRegion
    \ matchgroup=p6PodPrefix
    \ start="^=\%(config\|use\)\>"
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contains=p6PodDirectArgRegion
    \ keepend

syn region p6PodDirectArgRegion
    \ matchgroup=p6PodType
    \ start="\S\+"
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contained
    \ contains=p6PodDirectConfigRegion

syn region p6PodDirectConfigRegion
    \ start=""
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contained
    \ contains=@p6PodConfig

" =encoding is a special directive
syn region p6PodDirectRegion
    \ matchgroup=p6PodPrefix
    \ start="^=encoding\>"
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contains=p6PodEncodingArgRegion
    \ keepend

syn region p6PodEncodingArgRegion
    \ matchgroup=p6PodName
    \ start="\S\+"
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contained

" Paragraph blocks (implicit code forbidden)
syn region p6PodParaRegion
    \ matchgroup=p6PodPrefix
    \ start="^=for\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodParaNoCodeTypeRegion
    \ keepend
    \ extend

syn region p6PodParaNoCodeTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodParaNoCode,p6PodParaConfigRegion

syn region p6PodParaConfigRegion
    \ start=""
    \ end="^\ze\%([^=]\|=\k\@<!\)"
    \ contained
    \ contains=@p6PodConfig

syn region p6PodParaNoCode
    \ start="^[^=]"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=@p6PodFormat

" Paragraph blocks (everything is code)
syn region p6PodParaRegion
    \ matchgroup=p6PodPrefix
    \ start="^=for\>\ze\s*code\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodParaCodeTypeRegion
    \ keepend
    \ extend

syn region p6PodParaCodeTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodParaCode,p6PodParaConfigRegion

syn region p6PodParaCode
    \ start="^[^=]"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained

" Paragraph blocks (implicit code allowed)
syn region p6PodParaRegion
    \ matchgroup=p6PodPrefix
    \ start="^=for\>\ze\s*\%(pod\|item\|nested\|\u\+\)\>"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contains=p6PodParaTypeRegion
    \ keepend
    \ extend

syn region p6PodParaTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=p6PodPara,p6PodParaConfigRegion

syn region p6PodPara
    \ start="^[^=]"
    \ end="^\ze\%(\s*$\|=\K\)"
    \ contained
    \ contains=@p6PodFormat,p6PodImplicitCode

" Paragraph block to end-of-file
syn region p6PodParaRegion
    \ matchgroup=p6PodPrefix
    \ start="^=for\>\ze\s\+END\>"
    \ end="\%$"
    \ contains=p6PodParaEOFTypeRegion
    \ keepend
    \ extend

syn region p6PodParaEOFTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="\%$"
    \ contained
    \ contains=p6PodParaEOF,p6PodParaConfigRegion

syn region p6PodParaEOF
    \ start="^[^=]"
    \ end="\%$"
    \ contained
    \ contains=@p6PodNestedBlocks,@p6PodFormat,p6PodImplicitCode

" Delimited blocks (implicit code forbidden)
syn region p6PodDelimRegion
    \ matchgroup=p6PodPrefix
    \ start="^=begin\>"
    \ end="^=end\>"
    \ contains=p6PodDelimNoCodeTypeRegion
    \ keepend
    \ extend

syn region p6PodDelimNoCodeTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze=end\>"
    \ contained
    \ contains=p6PodDelimNoCode,p6PodDelimConfigRegion

syn region p6PodDelimConfigRegion
    \ start=""
    \ end="^\ze\%([^=]\|=\K\|\s*$\)"
    \ contained
    \ contains=@p6PodConfig

syn region p6PodDelimNoCode
    \ start="^"
    \ end="^\ze=end\>"
    \ contained
    \ contains=@p6PodNestedBlocks,@p6PodFormat

" Delimited blocks (everything is code)
syn region p6PodDelimRegion
    \ matchgroup=p6PodPrefix
    \ start="^=begin\>\ze\s*code\>"
    \ end="^=end\>"
    \ contains=p6PodDelimCodeTypeRegion
    \ keepend
    \ extend

syn region p6PodDelimCodeTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze=end\>"
    \ contained
    \ contains=p6PodDelimCode,p6PodDelimConfigRegion

syn region p6PodDelimCode
    \ start="^"
    \ end="^\ze=end\>"
    \ contained
    \ contains=@p6PodNestedBlocks

" Delimited blocks (implicit code allowed)
syn region p6PodDelimRegion
    \ matchgroup=p6PodPrefix
    \ start="^=begin\>\ze\s*\%(pod\|item\|nested\|\u\+\)\>"
    \ end="^=end\>"
    \ contains=p6PodDelimTypeRegion
    \ keepend
    \ extend

syn region p6PodDelimTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="^\ze=end\>"
    \ contained
    \ contains=p6PodDelim,p6PodDelimConfigRegion

syn region p6PodDelim
    \ start="^"
    \ end="^\ze=end\>"
    \ contained
    \ contains=@p6PodNestedBlocks,@p6PodFormat,p6PodImplicitCode

" Delimited block to end-of-file
syn region p6PodDelimRegion
    \ matchgroup=p6PodPrefix
    \ start="^=begin\>\ze\s\+END\>"
    \ end="\%$"
    \ contains=p6PodDelimEOFTypeRegion
    \ extend

syn region p6PodDelimEOFTypeRegion
    \ matchgroup=p6PodType
    \ start="\K\k*"
    \ end="\%$"
    \ contained
    \ contains=p6PodDelimEOF,p6PodDelimConfigRegion

syn region p6PodDelimEOF
    \ start="^"
    \ end="\%$"
    \ contained
    \ contains=@p6PodNestedBlocks,@p6PodFormat,p6PodImplicitCode

syn cluster p6PodConfig
    \ add=p6PodConfigOperator
    \ add=p6PodExtraConfig
    \ add=p6StringAuto
    \ add=p6PodAutoQuote
    \ add=p6StringSQ

syn region p6PodParens
    \ start="("
    \ end=")"
    \ contained
    \ contains=p6Number,p6StringSQ

syn match p6PodAutoQuote      display contained "=>"
syn match p6PodConfigOperator display contained ":!\?" nextgroup=p6PodConfigOption
syn match p6PodConfigOption   display contained "[^[:space:](<]\+" nextgroup=p6PodParens,p6StringAngle
syn match p6PodExtraConfig    display contained "^="
syn match p6PodVerticalBar    display contained "|"
syn match p6PodColon          display contained ":"
syn match p6PodSemicolon      display contained ";"
syn match p6PodComma          display contained ","
syn match p6PodImplicitCode   display contained "^\s.*"

syn region p6PodDelimEndRegion
    \ matchgroup=p6PodType
    \ start="\%(^=end\>\)\@<="
    \ end="\K\k*"

" These may appear inside delimited blocks
syn cluster p6PodNestedBlocks
    \ add=p6PodAbbrRegion
    \ add=p6PodDirectRegion
    \ add=p6PodParaRegion
    \ add=p6PodDelimRegion
    \ add=p6PodDelimEndRegion

" Pod formatting codes

syn cluster p6PodFormat
    \ add=p6PodFormatOne
    \ add=p6PodFormatTwo
    \ add=p6PodFormatThree
    \ add=p6PodFormatFrench

" Balanced angles found inside formatting codes. Ensures proper nesting.

syn region p6PodFormatAnglesOne
    \ matchgroup=p6PodFormat
    \ start="<"
    \ skip="<[^>]*>"
    \ end=">"
    \ transparent
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatAnglesOne

syn region p6PodFormatAnglesTwo
    \ matchgroup=p6PodFormat
    \ start="<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ transparent
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatAnglesOne,p6PodFormatAnglesTwo

syn region p6PodFormatAnglesThree
    \ matchgroup=p6PodFormat
    \ start="<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ transparent
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatAnglesOne,p6PodFormatAnglesTwo,p6PodFormatAnglesThree

syn region p6PodFormatAnglesFrench
    \ matchgroup=p6PodFormat
    \ start="«"
    \ skip="«[^»]*»"
    \ end="»"
    \ transparent
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatAnglesOne,p6PodFormatAnglesTwo,p6PodFormatAnglesThree

" All formatting codes

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="\u<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="\u<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="\u<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="\u«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree

" C<> and V<> don't allow nested formatting formatting codes

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="[CV]<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="[CV]<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="[CV]<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="[CV]«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench

" L<> can have a "|" separator

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="L<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne,p6PodVerticalBar

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="L<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodVerticalBar

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="L<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="L«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar

" E<> can have a ";" separator

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="E<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne,p6PodSemiColon

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="E<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodSemiColon

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="E<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodSemiColon

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="E«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodSemiColon

" M<> can have a ":" separator

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="M<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne,p6PodColon

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="M<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodColon

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="M<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodColon

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="M«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodColon

" D<> can have "|" and ";" separators

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="D<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne,p6PodVerticalBar,p6PodSemiColon

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="D<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAngleTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodVerticalBar,p6PodSemiColon

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="D<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar,p6PodSemiColon

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="D«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar,p6PodSemiColon

" X<> can have "|", "," and ";" separators

syn region p6PodFormatOne
    \ matchgroup=p6PodFormatCode
    \ start="X<"
    \ skip="<[^>]*>"
    \ end=">"
    \ contained
    \ contains=p6PodFormatAnglesOne,p6PodFormatFrench,p6PodFormatOne,p6PodVerticalBar,p6PodSemiColon,p6PodComma

syn region p6PodFormatTwo
    \ matchgroup=p6PodFormatCode
    \ start="X<<"
    \ skip="<<[^>]*>>"
    \ end=">>"
    \ contained
    \ contains=p6PodFormatAnglesTwo,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodVerticalBar,p6PodSemiColon,p6PodComma

syn region p6PodFormatThree
    \ matchgroup=p6PodFormatCode
    \ start="X<<<"
    \ skip="<<<[^>]*>>>"
    \ end=">>>"
    \ contained
    \ contains=p6PodFormatAnglesThree,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar,p6PodSemiColon,p6PodComma

syn region p6PodFormatFrench
    \ matchgroup=p6PodFormatCode
    \ start="X«"
    \ skip="«[^»]*»"
    \ end="»"
    \ contained
    \ contains=p6PodFormatAnglesFrench,p6PodFormatFrench,p6PodFormatOne,p6PodFormatTwo,p6PodFormatThree,p6PodVerticalBar,p6PodSemiColon,p6PodComma

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_perl6_syntax_inits")
    if version < 508
        let did_perl6_syntax_inits = 1
        command -nargs=+ HiLink hi link <args>
    else
        command -nargs=+ HiLink hi def link <args>
    endif

    HiLink p6EscOctOld       p6Error
    HiLink p6PackageTwigil   p6Twigil
    HiLink p6StringAngle     p6String
    HiLink p6StringFrench    p6String
    HiLink p6StringAngles    p6String
    HiLink p6StringSQ        p6String
    HiLink p6StringDQ        p6String
    HiLink p6StringQ         p6String
    HiLink p6RxStringSQ      p6String
    HiLink p6RxStringDQ      p6String
    HiLink p6Substitution    p6String
    HiLink p6Transliteration p6String
    HiLink p6StringAuto      p6String
    HiLink p6StringP5Auto    p6String
    HiLink p6Key             p6String
    HiLink p6Match           p6String
    HiLink p6RegexBlock      p6String
    HiLink p6RxP5CharClass   p6String
    HiLink p6RxP5QuoteMeta   p6String
    HiLink p6RxCharClass     p6String
    HiLink p6RxQuoteWords    p6String
    HiLink p6ReduceOp        p6Operator
    HiLink p6ReverseCrossOp  p6Operator
    HiLink p6HyperOp         p6Operator
    HiLink p6QuoteQ          p6Operator
    HiLink p6RxRange         p6StringSpecial
    HiLink p6RxAnchor        p6StringSpecial
    HiLink p6RxP5Anchor      p6StringSpecial
    HiLink p6CodePoint       p6StringSpecial
    HiLink p6RxMeta          p6StringSpecial
    HiLink p6RxP5Range       p6StringSpecial
    HiLink p6RxP5CPId        p6StringSpecial
    HiLink p6RxP5Posix       p6StringSpecial
    HiLink p6RxP5Mod         p6StringSpecial
    HiLink p6RxP5HexSeq      p6StringSpecial
    HiLink p6RxP5OctSeq      p6StringSpecial
    HiLink p6RxP5WriteRefId  p6StringSpecial
    HiLink p6HexSequence     p6StringSpecial
    HiLink p6OctSequence     p6StringSpecial
    HiLink p6RxP5Named       p6StringSpecial
    HiLink p6RxP5PropId      p6StringSpecial
    HiLink p6RxP5Quantifier  p6StringSpecial
    HiLink p6RxP5CountId     p6StringSpecial
    HiLink p6RxP5Verb        p6StringSpecial
    HiLink p6Escape          p6StringSpecial2
    HiLink p6EscNull         p6StringSpecial2
    HiLink p6EscHash         p6StringSpecial2
    HiLink p6EscQQ           p6StringSpecial2
    HiLink p6EscQuote        p6StringSpecial2
    HiLink p6EscDoubleQuote  p6StringSpecial2
    HiLink p6EscBackTick     p6StringSpecial2
    HiLink p6EscForwardSlash p6StringSpecial2
    HiLink p6EscVerticalBar  p6StringSpecial2
    HiLink p6EscExclamation  p6StringSpecial2
    HiLink p6EscDollar       p6StringSpecial2
    HiLink p6EscOpenCurly    p6StringSpecial2
    HiLink p6EscCloseCurly   p6StringSpecial2
    HiLink p6EscCloseBracket p6StringSpecial2
    HiLink p6EscCloseAngle   p6StringSpecial2
    HiLink p6EscCloseFrench  p6StringSpecial2
    HiLink p6EscBackSlash    p6StringSpecial2
    HiLink p6RxEscape        p6StringSpecial2
    HiLink p6RxCapture       p6StringSpecial2
    HiLink p6RxAlternation   p6StringSpecial2
    HiLink p6RxP5            p6StringSpecial2
    HiLink p6RxP5ReadRef     p6StringSpecial2
    HiLink p6RxP5Oct         p6StringSpecial2
    HiLink p6RxP5Hex         p6StringSpecial2
    HiLink p6RxP5EscMeta     p6StringSpecial2
    HiLink p6RxP5Meta        p6StringSpecial2
    HiLink p6RxP5Escape      p6StringSpecial2
    HiLink p6RxP5CodePoint   p6StringSpecial2
    HiLink p6RxP5WriteRef    p6StringSpecial2
    HiLink p6RxP5Prop        p6StringSpecial2

    HiLink p6Property       Tag
    HiLink p6Attention      Todo
    HiLink p6Type           Type
    HiLink p6Error          Error
    HiLink p6BlockLabel     Label
    HiLink p6Float          Float
    HiLink p6Normal         Normal
    HiLink p6Package        Normal
    HiLink p6PackageScope   Normal
    HiLink p6Number         Number
    HiLink p6VersionNum     Number
    HiLink p6String         String
    HiLink p6Repeat         Repeat
    HiLink p6Keyword        Keyword
    HiLink p6Pragma         Keyword
    HiLink p6Module         Keyword
    HiLink p6DeclareRoutine Keyword
    HiLink p6VarStorage     Special
    HiLink p6FlowControl    Special
    HiLink p6NumberBase     Special
    HiLink p6Twigil         Special
    HiLink p6StringSpecial2 Special
    HiLink p6VersionDot     Special
    HiLink p6Comment        Comment
    HiLink p6Include        Include
    HiLink p6Shebang        PreProc
    HiLink p6ClosureTrait   PreProc
    HiLink p6Routine        Function
    HiLink p6Operator       Operator
    HiLink p6Version        Operator
    HiLink p6Context        Operator
    HiLink p6Quote          Delimiter
    HiLink p6TypeConstraint PreCondit
    HiLink p6Exception      Exception
    HiLink p6Placeholder    Identifier
    HiLink p6Variable       Identifier
    HiLink p6VarSlash       Identifier
    HiLink p6VarNum         Identifier
    HiLink p6VarExclam      Identifier
    HiLink p6VarMatch       Identifier
    HiLink p6VarName        Identifier
    HiLink p6MatchVar       Identifier
    HiLink p6RxP5ReadRefId  Identifier
    HiLink p6RxP5ModDef     Identifier
    HiLink p6RxP5ModName    Identifier
    HiLink p6Conditional    Conditional
    HiLink p6StringSpecial  SpecialChar

    HiLink p6PodAbbr         p6Pod
    HiLink p6PodAbbrEOF      p6Pod
    HiLink p6PodAbbrNoCode   p6Pod
    HiLink p6PodAbbrCode     p6PodCode
    HiLink p6PodPara         p6Pod
    HiLink p6PodParaEOF      p6Pod
    HiLink p6PodParaNoCode   p6Pod
    HiLink p6PodParaCode     p6PodCode
    HiLink p6PodDelim        p6Pod
    HiLink p6PodDelimEOF     p6Pod
    HiLink p6PodDelimNoCode  p6Pod
    HiLink p6PodDelimCode    p6PodCode
    HiLink p6PodImplicitCode p6PodCode
    HiLink p6PodExtraConfig  p6PodPrefix
    HiLink p6PodVerticalBar  p6PodFormatCode
    HiLink p6PodColon        p6PodFormatCode
    HiLink p6PodSemicolon    p6PodFormatCode
    HiLink p6PodComma        p6PodFormatCode
    HiLink p6PodFormatOne    p6PodFormat
    HiLink p6PodFormatTwo    p6PodFormat
    HiLink p6PodFormatThree  p6PodFormat
    HiLink p6PodFormatFrench p6PodFormat

    HiLink p6PodType           Type
    HiLink p6PodConfigOption   String
    HiLink p6PodCode           PreProc
    HiLink p6Pod               Comment
    HiLink p6PodComment        Comment
    HiLink p6PodAutoQuote      Operator
    HiLink p6PodConfigOperator Operator
    HiLink p6PodPrefix         Statement
    HiLink p6PodName           Identifier
    HiLink p6PodFormatCode     SpecialChar
    HiLink p6PodFormat         SpecialComment

    delcommand HiLink
endif

" Syncing to speed up processing
"syn sync match p6SyncPod groupthere p6PodAbbrRegion     "^=\K\k*\>"
"syn sync match p6SyncPod groupthere p6PodDirectRegion   "^=\%(config\|use\|encoding\)\>"
"syn sync match p6SyncPod groupthere p6PodParaRegion     "^=for\>"
"syn sync match p6SyncPod groupthere p6PodDelimRegion    "^=begin\>"
"syn sync match p6SyncPod groupthere p6PodDelimEndRegion "^=end\>"

" Let's just sync whole file, the other methods aren't reliable (or I don't
" know how to use them reliably)
syn sync fromstart

setlocal foldmethod=syntax

let b:current_syntax = "perl6"

let &cpo = s:keepcpo
unlet s:keepcpo

" vim:ts=8:sts=4:sw=4:expandtab:ft=vim