Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created October 31, 2016 18:06
Show Gist options
  • Save zoffixznet/d5e1da4b96839ddab2c50b379277ea30 to your computer and use it in GitHub Desktop.
Save zoffixznet/d5e1da4b96839ddab2c50b379277ea30 to your computer and use it in GitHub Desktop.
my $PHP6_CODE = Q:to/END_CODE/;
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Today's Time and Date</title>
<?πŸ’©
use LWP::Simple;
use JSON::Fast;
my $eco = from-json LWP::Simple.get:
'http://ecosystem-api.p6c.org/projects.json';
πŸ’©>
<h1>The Perl 6 Ecosystem of <?πŸ’© $eco.elems πŸ’©> modules!</h1>
<table>
<thead>
<th>Module</th>
<th>Author</th>
<th>Deps</th>
<th>URL</th>
</thead>
<tbody>
<?πŸ’© for |$eco { πŸ’©πŸ’©>
<tr>
<td><?πŸ’© .<name> πŸ’©></td>
<td><?πŸ’© .<authors> and .<authors>.join: ", " πŸ’©></td>
<td><?πŸ’© .<depends> and .<depends>.join: ", " πŸ’©></td>
<td style="white-space: nowrap;">
<a href="<?πŸ’© .<source-url> πŸ’©>"><?πŸ’© .<source-url> πŸ’©></a>
</td>
</tr>
<?πŸ’© } πŸ’©πŸ’©>
</tbody>
</table>
END_CODE
grammar Acme::PHP6::Grammar {
token TOP { <piece> ** 0..* }
token bs { '<?πŸ’©' }
token be { 'πŸ’©>' }
proto token piece {*}
token piece:sym<html> { [<!before <bs>> .]+ }
token piece:sym<code-block> { <bs> $<code>=.+? <be> }
}
class Acme::PHP6::Actions {
method TOP ($/) { make $<piece>Β».made.join }
method piece:sym<html> ($/) { make ";say QπŸ’©$/πŸ’©;"; }
method piece:sym<code-block>($m) {
given $m<code>.Str -> $_ is copy {
$m.make: /';' \s*$/ || s/'πŸ’©'\s*$// ?? $_ !! 'say do {' ~ $_ ~ '};'
}
}
}
say Acme::PHP6::Grammar.subparse($PHP6_CODE, :actions(Acme::PHP6::Actions))
.made.EVAL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment