<div dir="ltr"><div>Bonsoir,</div><div><br></div><div>pourrais-tu donner des exemples simples de données pour lesquels ton programme marche (avec le résultat obtenu, si possible) et des exemples pour lesquels ça ne marche pas ?</div><div><br></div><div>Bonne soirée,</div><div>Laurent.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le dim. 28 juin 2020 à 18:15, Alain Barbason <<a href="mailto:alain@barbason.be">alain@barbason.be</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>Bonjour,</p>
<p>Pour mon programme d'interfaçage graphique de fichier Org
(<a href="https://github.com/alainbebe/org-mode-gtk.raku" target="_blank">https://github.com/alainbebe/org-mode-gtk.raku</a>), j'aimerais lire
les fichiers Org à l'aide la grammaire de Raku.</p>
<p>Je suis parvenu à lire des fichiers en liste et/ou en récursif,
mais quand le fichier contient une nouvelle tâche avec une
indentation en moins, je coince.<br>
Le code ci-dessous match chaque fichier (simulé dans $file), mais
, dernier exemple, place en niveau 2 une tâche qui devrait être en
niveau 1. Ce qui me paraît normal vu le code. J'ai essayé la ligne
12, mais ça ne match pas.<br>
<br>
Une idée ?</p>
<p>(posté déjà sur <a href="http://developpez.com" target="_blank">developpez.com</a>)</p>
<p>AlainBB<br>
</p>
<pre style="height:204px"><pre style="margin:0px"><span style="color:rgb(128,128,128)">#!/usr/bin/env perl6</span>
<span style="color:rgb(0,0,255)">use</span> v6;
<span style="color:rgb(0,0,255)">use</span> Data::Dump;
<span style="color:rgb(0,0,255)">use</span> Grammar::Tracer;
<span style="color:rgb(0,0,255)">my</span> <span style="color:rgb(51,153,51)">$level</span>;
<span style="color:rgb(0,0,255)">grammar</span> OrgMode <span>{</span>
<span style="color:rgb(0,0,255)">rule</span> TOP <span>{</span> ^ <span style="color:rgb(51,153,51)"><tasks></span> $ <span>}</span>
<span style="color:rgb(0,0,255)">rule</span> tasks <span>{</span> <span style="color:rgb(128,0,0)">\n</span>?<span style="color:rgb(51,153,51)"><task></span>+ %% <span style="color:rgb(128,0,0)">\n</span><span>}</span>
<span style="color:rgb(0,0,255)">token</span> task <span>{</span> <span style="color:rgb(51,153,51)"><content></span> <span style="color:rgb(51,153,51)"><tasks></span>? <span>{</span><span style="color:rgb(51,153,51)">$level</span>=<span style="color:rgb(255,0,0)">""</span><span>}</span><span>}</span>
<span style="color:rgb(128,128,128)"># token task { <content> <tasks>? {$level=$level.substr(0, *-1)}}</span>
<span style="color:rgb(0,0,255)">token</span> content <span>{</span> ^^ <span>(</span><span style="color:rgb(51,153,51)">$level</span> <span style="color:rgb(255,0,0)">"*"</span>+<span>)</span><span style="color:rgb(255,0,0)">" "</span> .+? $$ <span>{</span><span style="color:rgb(51,153,51)">$level</span>=<span style="color:rgb(51,153,51)">$0</span>.<span style="color:rgb(0,128,255)">Str</span><span>}</span><span>}</span>
<span>}</span>
<span style="color:rgb(0,0,255)">class</span> OM-actions <span>{</span>
<span style="color:rgb(0,0,255)">method</span> TOP<span>(</span><span style="color:rgb(51,153,51)">$/</span><span>)</span> <span>{</span>
make <span style="color:rgb(51,153,51)">$<tasks></span>.made;
<span>}</span>
<span style="color:rgb(0,0,255)">method</span> tasks<span>(</span><span style="color:rgb(51,153,51)">$/</span><span>)</span> <span>{</span>
make <span style="color:rgb(51,153,51)">$<task></span>».made ;
<span>}</span>
<span style="color:rgb(0,0,255)">method</span> task<span>(</span><span style="color:rgb(51,153,51)">$/</span><span>)</span> <span>{</span>
<span style="color:rgb(0,0,255)">my</span> <span style="color:rgb(51,153,51)">%task</span>;
<span style="color:rgb(51,153,51)">%task</span><span>{</span><span style="color:rgb(255,0,0)">"task"</span><span>}</span>=<span style="color:rgb(51,153,51)">$<content></span>.made;
<span style="color:rgb(51,153,51)">%task</span><span>{</span><span style="color:rgb(255,0,0)">"sub-task"</span><span>}</span>=<span style="color:rgb(51,153,51)">$<tasks></span>.made <span style="color:rgb(0,0,255)">if</span> <span style="color:rgb(51,153,51)">$<tasks></span>.made;
make <span style="color:rgb(51,153,51)">%task</span>;
<span>}</span>
<span style="color:rgb(0,0,255)">method</span> content<span>(</span><span style="color:rgb(51,153,51)">$/</span><span>)</span> <span>{</span>
make <span style="color:rgb(51,153,51)">$/</span>.<span style="color:rgb(0,128,255)">Str</span> ;
<span>}</span>
<span>}</span>
<span style="color:rgb(0,0,255)">my</span> <span style="color:rgb(51,153,51)">$file</span> =
<span style="color:rgb(255,0,0)">"* juste un header 1</span>
<span style="color:rgb(255,0,0)">* juste deux header 1</span>
<span style="color:rgb(255,0,0)">* header 2</span>
<span style="color:rgb(255,0,0)">* juste 3 header 1</span>
<span style="color:rgb(255,0,0)">* header 2</span>
<span style="color:rgb(255,0,0)">* header 3</span>
<span style="color:rgb(255,0,0)">* juste un header 1 et un sub</span>
<span style="color:rgb(255,0,0)">** sub-header 1</span>
<span style="color:rgb(255,0,0)">* juste un header 1 et deux sub *</span>
<span style="color:rgb(255,0,0)">** sub-header 1</span>
<span style="color:rgb(255,0,0)">** sub-header 2</span>
<span style="color:rgb(255,0,0)">* juste un header 1 et un sub et un sub-sub</span>
<span style="color:rgb(255,0,0)">** sub-header 1</span>
<span style="color:rgb(255,0,0)">*** sub-sub-header 1</span>
<span style="color:rgb(255,0,0)">* 2 header 1 et un sub au milieu</span>
<span style="color:rgb(255,0,0)">** sub-header 1</span>
<span style="color:rgb(255,0,0)">* header 2"</span>
;
say <span style="color:rgb(255,0,0)">"<span style="color:rgb(128,0,0)">\n</span>"</span> x <span style="color:rgb(204,102,204)">10</span>;
<span style="color:rgb(0,0,255)">sub</span> parse_file<span>(</span><span style="color:rgb(51,153,51)">$file</span><span>)</span> <span>{</span>
say <span style="color:rgb(51,153,51)">$file</span>;
say <span style="color:rgb(255,0,0)">""</span>;
<span style="color:rgb(51,153,51)">$level</span>=<span style="color:rgb(255,0,0)">""</span>;
<span style="color:rgb(128,128,128)"># say OrgMode.parse($file);</span>
say Dump OrgMode.parse<span>(</span><span style="color:rgb(51,153,51)">$file</span>,:actions<span>(</span>OM-actions<span>)</span><span>)</span>.made;
say <span style="color:rgb(255,0,0)">"---------------------------------------------------------------------------------------"</span>;
<span>}</span>
parse_file<span>(</span><span style="color:rgb(51,153,51)">$_</span><span>)</span> <span style="color:rgb(0,0,255)">for</span> split<span>(</span><span style="color:rgb(255,0,0)">"<span style="color:rgb(128,0,0)">\n</span><span style="color:rgb(128,0,0)">\n</span>"</span>,<span style="color:rgb(51,153,51)">$file</span><span>)</span>;</pre></pre>
</div>
_______________________________________________<br>
Perl mailing list<br>
<a href="mailto:Perl@mongueurs.net" target="_blank">Perl@mongueurs.net</a><br>
<a href="http://listes.mongueurs.net/mailman/listinfo/perl" rel="noreferrer" target="_blank">http://listes.mongueurs.net/mailman/listinfo/perl</a><br>
Attention, les archives sont publiques</blockquote></div>