Created
February 17, 2023 01:22
-
-
Save cognominal/57aa414a6c79dcd95687acc07ac6c902 to your computer and use it in GitHub Desktop.
delimited-parses.raku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin pod | |
Capturing stuff with arbitrary complex delimiters | |
without real parsinhg... but with Perl parser. | |
Except the end delimiter is brokem | |
Cannot resolve caller end(Any:U: H:D); none of these signatures matches: | |
(Any:U: *%_ --> 0) | |
(Any:D: *%_) | |
in regex end at p.raku line 21 | |
in regex TOP at p.raku line 25 | |
in block <unit> at p.raku line 30 | |
=end pod | |
my $s = q:to<END>; | |
fun a { | |
} | |
# toto | |
fun b { | |
} | |
END | |
role delimiters { | |
rule begin { fun $<name>=\w+ } | |
token end { ^^ '}' } | |
} | |
grammar H does delimiters { | |
# token TOP { .*? $<capture>=[<begin> .*? ^^ '}' ] } | |
token TOP { .*? $<capture>=[<begin> .*? <end> ] } | |
} | |
my $pos = 0; | |
while 1 { | |
my $p = H.subparse($s, :$pos); | |
$pos = $p.pos; | |
exit unless $p; | |
say $p<capture>; | |
# or can print $p<capture><name> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment