Practical Extraction with Perl 6 {{#q|Nathan Gray}} ---- Practical Extraction with Perl 5 {{#q|Nathan Gray}} ---- s:g/5/6/; ---- Practical Extraction with Perl {{#c|6}} {{#q|Nathan Gray}} ---- http://pghpw.org/schedule.html ---- -talk: presenter: brian d foy title: Making Perl Work for You -talk: presenter: Beth Skwarecki title: Make your database work for you ---- <tr> <td class="time">9:45 AM</td> <td class="beginner" rowspan="2"> <span class="talk"><a href="schedule/making_perl_work_for_you.html">Making Perl Work for You</a></span> <span class="speaker"><tt>brian d foy</tt></span> </td> <td class="advanced"> <span class="talk"><a href="schedule/make_your_database_work_for_you.html">Make your database work for you</a></span> <span class="speaker">Beth Skwarecki</span> </td> </tr> ---- <tr> <td class="time">9:45 AM</td> <td class="beginner" rowspan="2"> <span class="talk"><a href="schedule/making_perl_work_for_you.html">Making Perl Work for You</a></span> <span class="speaker">{{#c|<tt>brian d foy</tt>}}</span> </td> <td class="advanced"> <span class="talk"><a href="schedule/make_your_database_work_for_you.html">Make your database work for you</a></span> <span class="speaker">{{#c|Beth Skwarecki}}</span> </td> </tr> ---- package main; my $content = slurp @*ARGS[0]; while (my $match = $content ~~ m:c /<talk>/) { say $match; } ---- package main; my $content = slurp @*ARGS[0]; {{#c|for $content ~~ m:g /<talk>/ -> $match}} { say $match; } ---- package main; my $content = slurp @*ARGS[0]; for $content ~~ m:g /{{#c|<talk>}}/ -> $match { say $match; } ---- use v6-alpha; grammar workshop; token {{#c|talk}} { <presenter> } token presenter { <'<span class="speaker">'> .+? <'</span>'> } ---- use v6-alpha; grammar workshop; token talk { <presenter> } token presenter { <'<span class="speaker">'> {{#c|.+?}} <'</span>'> } ---- <span class="speaker"><tt>brian d foy</tt></span> <span class="speaker">Beth Skwarecki</span> ---- <span class="speaker">{{#c|<tt>brian d foy</tt>}}</span> <span class="speaker">{{#c|Beth Skwarecki}}</span> ---- use v6-alpha; grammar workshop; token talk { <presenter> } token presenter { <'<span class="speaker">'> {{#c|<( .+? )>}} <'</span>'> } ---- <tt>brian d foy</tt> Beth Skwarecki ---- {{#c|<tt>}}brian d foy{{#c|</tt>}} Beth Skwarecki ---- use v6-alpha; grammar workshop; token talk { <presenter> } token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> {{#c|{ return strip_html($$/) } }} } ---- brian d foy Beth Skwarecki ---- use v6-alpha; grammar workshop; token talk { <presenter> {{#c|{ return { talk => $$<presenter> } } }} } token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> {{#c|{ return { presenter => strip_html($$/) } } }} } ---- package main; my $content = slurp @*ARGS[0]; for $content ~~ m:g /<talk>/ -> $match { say {{#c|$$match.yaml}}; } ---- -talk: presenter: brian d foy -talk: presenter: Beth Skwarecki ---- <tr> <td class="time">9:45 AM</td> <td class="beginner" rowspan="2"> <span class="talk"><a href="schedule/making_perl_work_for_you.html">{{#c|Making Perl Work for You}}</a></span> <span class="speaker"><tt>brian d foy</tt></span> </td> <td class="advanced"> <span class="talk"><a href="schedule/make_your_database_work_for_you.html">{{#c|Make your database work for you}}</a></span> <span class="speaker">Beth Skwarecki</span> </td> </tr> ---- use v6-alpha; grammar workshop; token talk { <presenter> { return { talk => $$<presenter> } } } token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> { return { presenter => strip_html($$/) } } } {{#c|token link { }} {{#c| <'<a href="'> $<url> := (.+?) <'">'> $<label> := (.+?) <'</a>'> }} {{#c|} }} ---- use v6-alpha; grammar workshop; token talk { <title> <ws> <presenter> { return { talk => { $$<presenter>, $$<title> } } } } token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> { return { presenter => strip_html($$/) } } } {{#c|token title { }} {{#c| <'<span class="talk">'> <link> <'</span>'> }} {{#c| { return { title => $<link><label> } } }} {{#c|} }} token link { <'<a href="'> $<url> := (.+?) <'">'> $<label> := (.+?) <'</a>'> } ---- use v6-alpha; grammar workshop; token talk { {{#c|<title> <ws>}} <presenter> { return { talk => {{#c|{ $$<presenter>, $$<title> } }} } } } token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> { return { presenter => strip_html($$/) } } } token title { <'<span class="talk">'> <link> <'</span>'> { return { title => $<link><label> } } } token link { <'<a href="'> $<url> := (.+?) <'">'> $<label> := (.+?) <'</a>'> } ---- token title { <'<span class="talk">'> <link> <'</span>'> { return { title => $<link><label> } } } ---- $<link><label> = $<link>{'label'} ---- -talk: presenter: brian d foy title: Making Perl Work for You -talk: presenter: Beth Skwarecki title: Make your database work for you ---- token talk { <title> <ws> <presenter> { return { talk => { $$<presenter>, $$<title> } } } } ---- {{#c|rule}} talk { <title> <presenter> { return { talk => { $$<presenter>, $$<title> } } } } ---- regex { ... } ---- regex :ratchet { ... } = token { ... } ---- token :sigspace { ... } = rule { ... } ---- rule talk { <title> <presenter> { return { talk => { $$<presenter>, $$<title> } } } } ---- rule talk { <title> <presenter> { return { talk => { :$<presenter>, :$<title> } } } } ---- token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> { return { presenter => strip_html($$/) } } } ---- token presenter { <'<span class="speaker">'> <( .+? )> <'</span>'> { return strip_html($$/) } } ---- rule talk { <title> <presenter> } ---- package main; my $content = slurp @*ARGS[0]; for $content ~~ m:g /<talk>/ -> $match { say $$match.yaml; } ---- package main; my $content = slurp @*ARGS[0]; for $content ~~ m:g /<talk>/ -> $match { say hash($match.kv.map( -> $k, $v { $k => ~$v } )).yaml; } ---- magic hand waving ---- -talk: presenter: brian d foy time: 9:45 AM title: Making Perl Work for You -talk: presenter: Beth Skwarecki time: 9:45 AM title: Make your database work for you ---- {{#q|Thank you!}} {{#c|☺}} ---- Credits Larry Wall: creating the syntax and finding my typos Audrey Tang: making my insane <ws> a reality and syntax improvements Patrick Michaud: writing PGE - my initial testing ground Gaal Yahas: helping me realize I had to speak Jerry Gay: syntax improvements Flavio S. Glock: writing Pugs::Compiler::Rule and implementing missing features in v6.pm Capitol Advantage: employing Perl programmers (like me)