Skip to content

Instantly share code, notes, and snippets.

@Mouq
Mouq / gist:7eb9d723d7f05a511529
Last active January 6, 2016 00:25 — forked from anonymous/gist:4beb237a975e65e6e775
perl6 grammar test
grammar Test {
rule TOP { ^ <content>* $ }
rule block { '(' ~ ')' <content>* }
rule content { <-[()]>+ || <block> }
}
class TestActs {
method TOP($/) {
$/.make: $<content>».made.join;
}
use Inline::C;
use C::Parser::Grammar;
use C::Parser::Actions;
use Grammar::Mixin;
my role Inline::Grammar {
method INTERPOLATE(|c) {Grammar.'INTERPOLATE'(self,|c);}
token routine_declarator:sym<inline> {
:my $*InlineC := True;
:my $*LINE_NO := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));
@Mouq
Mouq / reboot.p6
Last active August 29, 2015 14:13
masak's maze puzzle
role Grid::Mazable {
#| Get list of nodes
method nodes { ... }
#|[
A leaf node represents a fringe of the grid that we're allowed to
recurse off of when we build mazes. Not all fringes are leaves, due to
the fact that mazes can include numerous dead-ends. When a fringe is
not a leaf, it's a dead-end.
]
class Lispy {
has $.global-env;
class Env is Associative { # XXX EnumMap
has %.hash handles *;
has $.outer;
method new (*@hash, :$outer) {
bless self: :$outer, :@hash;
}
method get ($k) is rw { self.hash{$k} // self.outer.get($k) }
}
use Math::Symbolic;
# PV=nRT
my $R = .08206;
my %h =
:P(EVAL prompt "P="),
:V(EVAL prompt "V="),
:N(EVAL prompt "N="),
:T(EVAL prompt "T=");
my ($undef, $err) = %h.keys.grep({ %h{$_} eq "" });
my ($f,&t,&r,&c)=lines.comb(/<-[{}]>+/).SetHash,&substr,&return,&chars;while $f>1
{@$f.sort(-*.&c).combinations(2).map({sub
(\a,\b){r \(a,b,:m(a):v(c b))if a.index(b);for b.&c...1
->\v{->\x,\y{r \(a,b,:m(x~t y,v):v(v))if t(x,*-v)eq t y,0,v}(|$_)for
[a,b],[b,a]}}(|$_)}).sort(-*.<v>).uniq(:as{any @$_}:with(&[eq])).map:{$f{@$_}»--;$f{.<m>}++}}
say @$f
S02-bits.pod
1263-The final element of an array is subscripted as C<@a[*-1]>,
1264-which means that when the subscripting operation discovers a C<Code:($)>
1265-object for a subscript, it calls it and supplies an argument indicating
1266-the number of elements in (that dimension of) the array. See S09.
1267-
1268:=head3 The C<HyperWhatever> Type
1269-
1270:A variant of C<*> is the C<**> term, which is of type C<HyperWhatever>.
1271-It is generally understood to be a multidimension form of C<*> when
@Mouq
Mouq / gif-grammar.p6
Last active August 29, 2015 13:57
Binary decoding
# What about encoding back?
# grammar Image::GIF::Grammar {
class Image::GIF::Decoder is Decoder {
token TOP {
:my $*CT-valid; # set in lexical <packed>
:my $*CT-size; # also set in <packed>
<header>
<screen>
<color-table>?
<labeled>*
@Mouq
Mouq / 01-arithmetic.p6
Last active August 29, 2015 13:57
Potential Grammar::Precedence test
use Test;
use Grammar::Precedence;
grammar Arithmetic does Grammar::Precedence {
token TOP { <EXPR> }
# self.push-prec($str) makes $str a new
# precedence level and the loosest level.
# self.unshift-prec($str) would therefor
# make $str a new precedence level and
diff --git a/lib/Pod/To/HTML.pm b/lib/Pod/To/HTML.pm
index 797ea2d..9564d77 100644
--- a/lib/Pod/To/HTML.pm
+++ b/lib/Pod/To/HTML.pm
@@ -248,7 +248,7 @@ multi sub node2html(Pod::Block::Named $node) returns Str {
return qq{<div class="nested">\n} ~ node2html($node.content) ~ qq{\n</div>\n};
}
when 'output' { return "<pre>\n" ~ node2inline($node.content) ~ "</pre>\n"; }
- when 'pod' { return node2html($node.content); }
+ when 'pod' { return qq[<span class="{$node.config<class>}">\n{node2html($node.content)}</span>\n] }