Grammaire et fichier Org : Propriétés
Bonjour,
Dans les fichiers Org https://orgmode.org/, on peut avoir des propriétés structurée comme suit :
Code:
1 2 3 4
| :PROPERTIES:
:key1: content
:key2: content2
:END: |
Je ne parviens pas à écrire ma grammaire pour lire cela convenablement.
Dans la grammaire complète, (voir https://github.com/alainbebe/org-mod...rgMode.rakumod ), il y d'autres éléments, mais j'ai simplifié.
Dans mes différents test, je parviens à matcher partiellement, mais soit juste une propriété et le texte, soit 1 ou 2 propriétés si pas de texte,...
Une idée ?
Code:
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; |
Ca qui donne
Code:
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
| header : One property, no text
--properties--
:key1: content
--text--
header : 2 properties, no text
--properties--
:key1: content
:key2: content2
--text--
header : One property, with text
--text--
:PROPERTIES:
:key1: content
:END:
my text
header : 2 properties with text
--text--
:PROPERTIES:
:key1: content
:key2: content2
:END:
my text |
Le derniers cas devrait donner
Code:
1 2 3 4 5 6 7
| header : 2 properties, no text
--properties--
:key1: content
:key2: content2
--text--
my text |