Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created January 13, 2016 12:02
Show Gist options
  • Save gfldex/2a9a24c64110da844d7e to your computer and use it in GitHub Desktop.
Save gfldex/2a9a24c64110da844d7e to your computer and use it in GitHub Desktop.
use v6;
class Replacement {
}
use Lib Str;
my $g = Guard.new("");
dd $g ~ "abc";
use v6;
role ConcatGuard[::T-right] {
has T-right $.attr is rw;
method left-type () is nodal { self.WHAT }
method right-type () is nodal { T-right }
method convert () {...} # --> T-right
method new (T-right) {...}
# our proto sub infix:<~>(|) {*}
# our multi sub infix:<~>(T-left \l, T-right \r) {
# l.convert()
# }
# our multi sub infix:<~>(T-right \l, T-left \r) {
# r.new(l);
# }
}
sub EXPORT($T = Str) {
class Example is Mu does ConcatGuard[$T] {
method convert(){
$.attr.subst('&lt;','<').subst('&amp;', '&');
}
method new($s) {
self.bless(attr=>$s.subst('&', '&amp;').subst('<', '&lt'));
}
}
dd $T.WHAT;
constant T := $T;
dd T.WHAT;
{
Guard => Example,
'&infix:<~>' => sub (Example \l, T \r){ l ~ r },
'&infix:<~>' => sub (T \l, Example \r){ l ~ r }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment