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
| #!/usr/bin/env perl6
use v6;
use lib lib;
use Data::Dump;
grammar Content {
token TOP { ^ <header> \n? <properties>? <text>? $ }
token header { .*? $$ };
# token properties { ^^ ":PROPERTIES:\n" (.*?\n) ":END:\n" } # match just one property with text after, not two
# token properties { ^^ ":PROPERTIES:\n" (.*?\n) ":END:" $$ } # match just one property, not two
# token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+?) ":END:\n" } # match just one property, not two
# token properties { ^^ ":PROPERTIES:\n" (.*?) "\n:END:\n" } # no match
# token properties { ^^ ":PROPERTIES:\n" (.*?\n.*?\n) ":END:" $$ } # match just two property with text after, not one
# token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+) ":END:" $$ } # match but if no text after
# token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+) ":END:" \n? } # match but if no text after
# token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+) ":END:\n" } # no match
# token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+) ":END:" } # match but if no text after
token properties { ^^ ":PROPERTIES:\n" ((.*?\n)+) ":END:" } #
token text { .* };
}
class Content-actions {
method TOP($/) {
}
method header($/) {
say "header : ",$/.Str;
}
method properties($/) {
say "--properties--\n",$0.Str;
}
method text($/) {
say "--text--\n",$/.Str;
}
}
my $file =
"One property, no text
:PROPERTIES:
:key1: content
:END:";
Content.parse($file,:actions(Content-actions)).made;
say "";
$file =
"2 properties, no text
:PROPERTIES:
:key1: content
:key2: content2
:END:";
Content.parse($file,:actions(Content-actions)).made;
say "";
$file =
"One property, with text
:PROPERTIES:
:key1: content
:END:
my text";
Content.parse($file,:actions(Content-actions)).made;
say "";
$file =
"2 properties with text
:PROPERTIES:
:key1: content
:key2: content2
:END:
my text";
Content.parse($file,:actions(Content-actions)).made; |
Partager