Skip to content

Commit f4ffd6c

Browse files
CIAvashalecthomas
authored andcommitted
Fix Raku colon pair, function adverb and POD declaration
1 parent 2cff0c9 commit f4ffd6c

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

Diff for: lexers/r/raku.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ func rakuRules() Rules {
603603
{
604604
// Token with adverbs
605605
`(?<=(?:^|\s)(?:regex|token|rule)(\s+))(['\w:-]+)(?=:['\w-]+` +
606-
colonPairOpeningBrackets + `.+?` + colonPairClosingBrackets + `[({])`,
606+
colonPairOpeningBrackets + `.+?` + colonPairClosingBrackets + `\s*[({])`,
607607
NameFunction,
608608
Push("token", "name-adverb"),
609609
},
@@ -628,7 +628,7 @@ func rakuRules() Rules {
628628
{
629629
// Routine with adverbs
630630
`(?<=(?:^|\s)(?:sub|method|multi sub|multi)\s+)!?['\w:-]+(?=:['\w-]+` +
631-
colonPairOpeningBrackets + `.+?` + colonPairClosingBrackets + `[({])`,
631+
colonPairOpeningBrackets + `.+?` + colonPairClosingBrackets + `\s*[({])`,
632632
NameFunction,
633633
Push("name-adverb"),
634634
},
@@ -737,8 +737,8 @@ func rakuRules() Rules {
737737
{colonPairPattern, colonPair(String), bracketsFinder(rakuNameAttribute)},
738738
// :123abc
739739
{
740-
`(:)(\d+)(\w[\w'-]*)(\s*[,;)]?\s*$)`,
741-
ByGroups(Punctuation, UsingSelf("number"), String, Text),
740+
`(:)(\d+)(\w[\w'-]*)`,
741+
ByGroups(Punctuation, UsingSelf("number"), String),
742742
nil,
743743
},
744744
// :key
@@ -750,8 +750,8 @@ func rakuRules() Rules {
750750
{colonPairPattern, colonPair(NameAttribute), bracketsFinder(rakuNameAttribute)},
751751
// :123abc
752752
{
753-
`(:)(\d+)(\w+)(\s*[,;)]?\s*$)`,
754-
ByGroups(Punctuation, UsingSelf("number"), NameAttribute, Text),
753+
`(:)(\d+)(\w[\w'-]*)`,
754+
ByGroups(Punctuation, UsingSelf("number"), NameAttribute),
755755
nil,
756756
},
757757
// :key
@@ -923,7 +923,7 @@ func rakuRules() Rules {
923923
`keyword`: Keyword,
924924
`opening_delimiters`: Punctuation,
925925
`delimiter`: nil,
926-
`value`: UsingSelf("pod-begin"),
926+
`value`: UsingSelf("pod-declaration"),
927927
`closing_delimiters`: Punctuation,
928928
}),
929929
bracketsFinder(rakuPodDeclaration),
@@ -986,13 +986,13 @@ func rakuRules() Rules {
986986
{
987987
`(?<=^ *)(?<ws> *)(?<keyword>=head\d+)(?<ws2> *)(?<config>#?)`,
988988
ByGroups(Comment, Keyword, GenericHeading, Keyword),
989-
Push("pod-single-heading"),
989+
Push("pod-heading"),
990990
},
991991
// =item ...
992992
{
993993
`(?<=^ *)(?<ws> *)(?<keyword>=(?:item\d*|comment|data|[A-Z]+))(?<ws2> *)(?<config>#?)`,
994994
ByGroups(Comment, Keyword, StringDoc, Keyword),
995-
Push("pod-single"),
995+
Push("pod-paragraph"),
996996
},
997997
{
998998
`(?<=^ *)(?<ws> *)(?<keyword>=finish)(?<config>[^\n]*)`,
@@ -1003,7 +1003,7 @@ func rakuRules() Rules {
10031003
{
10041004
`(?<=^ *)(?<ws> *)(?<name>=\w[\w'-]*)(?<ws2> *)(?<config>#?)`,
10051005
ByGroups(Comment, Name, StringDoc, Keyword),
1006-
Push("pod-single"),
1006+
Push("pod-paragraph"),
10071007
},
10081008
// = podconfig
10091009
{
@@ -1018,8 +1018,12 @@ func rakuRules() Rules {
10181018
Include("pre-pod-formatter"),
10191019
{`.+?`, StringDoc, nil},
10201020
},
1021+
"pod-declaration": {
1022+
Include("pre-pod-formatter"),
1023+
{`.+?`, StringDoc, nil},
1024+
},
10211025
"pod-paragraph": {
1022-
{`\n\s*?\n`, StringDoc, Pop(1)},
1026+
{`\n *\n|\n(?=^ *=)`, StringDoc, Pop(1)},
10231027
Include("pre-pod-formatter"),
10241028
{`.+?`, StringDoc, nil},
10251029
},
@@ -1028,8 +1032,8 @@ func rakuRules() Rules {
10281032
Include("pre-pod-formatter"),
10291033
{`.+?`, StringDoc, nil},
10301034
},
1031-
"pod-single-heading": {
1032-
{`\n`, GenericHeading, Pop(1)},
1035+
"pod-heading": {
1036+
{`\n *\n|\n(?=^ *=)`, GenericHeading, Pop(1)},
10331037
Include("pre-pod-formatter"),
10341038
{`.+?`, GenericHeading, nil},
10351039
},

Diff for: lexers/testdata/raku.actual

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
=begin pod
44
=head1 Some test data for B<Chroma>
55
6+
=head2 Multi-line
7+
heading
8+
9+
=head2 One-line heading
610
=begin code :lang<go>
711
fmt.Println("Hello from Go")
812
=end code
@@ -396,7 +400,9 @@ class Calculations {
396400

397401
say Calculator.parse('2 + 3', actions => Calculations).made;
398402

403+
put Date.today.later(:2years).year;
404+
399405
=finish
400406
C<say> Date.today.year;
401407
# Output: 2020
402-
B<say> Date.today.later(:2years).year;
408+
B<say> Date.today.later(:2years).year;

Diff for: lexers/testdata/raku.expected

+30-10
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
{"type":"Punctuation","value":"\u003c"},
1212
{"type":"GenericStrong","value":"Chroma"},
1313
{"type":"Punctuation","value":"\u003e"},
14-
{"type":"GenericHeading","value":"\n"},
15-
{"type":"LiteralStringDoc","value":"\n"},
14+
{"type":"GenericHeading","value":"\n\n"},
15+
{"type":"Keyword","value":"=head2"},
16+
{"type":"GenericHeading","value":" Multi-line\nheading\n\n"},
17+
{"type":"Keyword","value":"=head2"},
18+
{"type":"GenericHeading","value":" One-line heading\n"},
1619
{"type":"Keyword","value":"=begin code"},
1720
{"type":"Text","value":" "},
1821
{"type":"Punctuation","value":":"},
@@ -591,10 +594,7 @@
591594
{"type":"Punctuation","value":"\u003c"},
592595
{"type":"LiteralStringOther","value":"SomeCode"},
593596
{"type":"Punctuation","value":"\u003e"},
594-
{"type":"LiteralStringDoc","value":"\n"},
595-
{"type":"Keyword","value":"=head1"},
596-
{"type":"GenericHeading","value":" heading\n"},
597-
{"type":"LiteralStringDoc","value":"]"},
597+
{"type":"LiteralStringDoc","value":"\n=head1 heading\n]"},
598598
{"type":"Punctuation","value":"」"},
599599
{"type":"Text","value":"\n"},
600600
{"type":"Keyword","value":"grammar"},
@@ -2005,7 +2005,8 @@
20052005
{"type":"Punctuation","value":":"},
20062006
{"type":"LiteralNumberInteger","value":"23"},
20072007
{"type":"LiteralString","value":"year"},
2008-
{"type":"Text","value":",\n "},
2008+
{"type":"Operator","value":","},
2009+
{"type":"Text","value":"\n "},
20092010
{"type":"LiteralString","value":"m"},
20102011
{"type":"Text","value":" "},
20112012
{"type":"Operator","value":"=\u003e"},
@@ -3208,7 +3209,9 @@
32083209
{"type":"Text","value":"\n "},
32093210
{"type":"Keyword","value":"method"},
32103211
{"type":"Text","value":" "},
3211-
{"type":"NameFunction","value":"calc-op:sym"},
3212+
{"type":"NameFunction","value":"calc-op"},
3213+
{"type":"Punctuation","value":":"},
3214+
{"type":"NameAttribute","value":"sym"},
32123215
{"type":"Punctuation","value":"("},
32133216
{"type":"NameVariable","value":"$/"},
32143217
{"type":"Punctuation","value":")"},
@@ -3226,7 +3229,9 @@
32263229
{"type":"Text","value":"\n "},
32273230
{"type":"Keyword","value":"method"},
32283231
{"type":"Text","value":" "},
3229-
{"type":"NameFunction","value":"calc-op:sym"},
3232+
{"type":"NameFunction","value":"calc-op"},
3233+
{"type":"Punctuation","value":":"},
3234+
{"type":"NameAttribute","value":"sym"},
32303235
{"type":"Punctuation","value":"\u003c"},
32313236
{"type":"LiteralString","value":"sub"},
32323237
{"type":"Punctuation","value":"\u003e"},
@@ -3264,6 +3269,21 @@
32643269
{"type":"Keyword","value":"made"},
32653270
{"type":"Punctuation","value":";"},
32663271
{"type":"Text","value":"\n\n"},
3272+
{"type":"NameBuiltin","value":"put"},
3273+
{"type":"Text","value":" "},
3274+
{"type":"NameBuiltin","value":"Date"},
3275+
{"type":"Operator","value":"."},
3276+
{"type":"NameBuiltin","value":"today"},
3277+
{"type":"Operator","value":"."},
3278+
{"type":"NameBuiltin","value":"later"},
3279+
{"type":"Punctuation","value":"(:"},
3280+
{"type":"LiteralNumberInteger","value":"2"},
3281+
{"type":"LiteralString","value":"years"},
3282+
{"type":"Punctuation","value":")"},
3283+
{"type":"Operator","value":"."},
3284+
{"type":"NameBuiltin","value":"year"},
3285+
{"type":"Punctuation","value":";"},
3286+
{"type":"Text","value":"\n\n"},
32673287
{"type":"Keyword","value":"=finish"},
32683288
{"type":"LiteralStringDoc","value":"\n"},
32693289
{"type":"Keyword","value":"C"},
@@ -3275,5 +3295,5 @@
32753295
{"type":"Punctuation","value":"\u003c"},
32763296
{"type":"GenericStrong","value":"say"},
32773297
{"type":"Punctuation","value":"\u003e"},
3278-
{"type":"LiteralStringDoc","value":" Date.today.later(:2years).year;"}
3298+
{"type":"LiteralStringDoc","value":" Date.today.later(:2years).year;\n"}
32793299
]

0 commit comments

Comments
 (0)